From patchwork Tue Sep 29 17:08:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Boris Protopopov X-Patchwork-Id: 1373531 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=fgnDM58T; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4C15SN1qwqz9s1t for ; Wed, 30 Sep 2020 03:08:20 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728327AbgI2RIS (ORCPT ); Tue, 29 Sep 2020 13:08:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725554AbgI2RIS (ORCPT ); Tue, 29 Sep 2020 13:08:18 -0400 Received: from mail-yb1-xb31.google.com (mail-yb1-xb31.google.com [IPv6:2607:f8b0:4864:20::b31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD239C061755 for ; Tue, 29 Sep 2020 10:08:17 -0700 (PDT) Received: by mail-yb1-xb31.google.com with SMTP id v60so4148619ybi.10 for ; Tue, 29 Sep 2020 10:08:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-transfer-encoding; bh=xI0BuAK+U0cN8XReY9WHEesp5MjH5D5qb4yhis/59bI=; b=fgnDM58T0XoGIGgfaV7pEmitlbpljta+/sPeAesk4LvdySjG3IUhsb1DXSdyZCKUvG 1H4XtBBCpM+cFnLZ7TD2Vgb7ePcyHvU0A44uZszpcPaH+BrHA6zlJa88S7hpuV5r6NWO wrjQ55943eEoVSymzR/9SbUmYKsrKYxVK7EjSMfnx1GWKQH9dgkmRmnriuBHgDdCOOy7 MHQLOKBABtdi3b3/NJSZ4fBHN0UuGxoVmeyw+vJdHmjl+VD76moxJxxQyQe4p26kIpBF d8iNAz5dhwVYkVwJh46ri04lhlYsyixgIYOouSMOdk0C+V+o3RDqha6S06MCWqpAcaCO Stdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:content-transfer-encoding; bh=xI0BuAK+U0cN8XReY9WHEesp5MjH5D5qb4yhis/59bI=; b=O4SQR88RbocvIS/BDYVCnypXXmKeqb3h0FOLysltjkH+pO1Gk2/LQ95hcAsffzDiB3 RkK3RUuReFsIYGcZBg8LNYNR7BSMSaMiaXWqGVkBMu0DI3GiYw7boaKL+Z5nx7J6Ud5f q3k4seKM54cpQC4+v/cINN5ItyGvPwqwWcRTK1rB7HSZQSexDoQM+fBV65L3KxzefZA6 f5CZThQ4oiobtzWshqdoUbWASWlYb7XT3X4F98LVD9OmbUkxwTpHKQTa3fA7JmsVUanL gnRruKz9gdzOvlfh8jJuipqHx/hZKFxt7JA/YIqHLASS/TSQd+8DtUQqngdYBniMcrvt h7JA== X-Gm-Message-State: AOAM533MwrXaP5daMzwrP/0ZOZAwjREfofW4afTqlhgkyXm9sCN97Ta9 e12iUqV25eMyR6aXyGscIEQ8Hr/Sp1KzdwfrXJkSHFUn7C0jGg== X-Google-Smtp-Source: ABdhPJwkwuivPLeigPMvLnKfuTK4h+qaHPiaTYhc4PqG9v8rKuJM9W8CNtcFl8aXffsTz9599Emm/lpO25vjPPMn8Gk= X-Received: by 2002:a25:d848:: with SMTP id p69mr7383065ybg.414.1601399297095; Tue, 29 Sep 2020 10:08:17 -0700 (PDT) MIME-Version: 1.0 References: <20200924003638.2668-1-pboris@amazon.com> In-Reply-To: <20200924003638.2668-1-pboris@amazon.com> From: Boris Protopopov Date: Tue, 29 Sep 2020 13:08:06 -0400 Message-ID: Subject: Fwd: [PATCH] Convert trailing spaces and periods in path components To: Steve French , linux-cifs Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Testing: Prior to the patch: % mount -v … //host/share/home on /tmp/diry type cifs (rw,relatime,vers=default,... % ls -l /tmp/diry/tmp total 0 % mkdir /tmp/diry/tmp/DirWithTrailingDot. % ls -l /tmp/diry/tmp/DirWithTrailingDot. total 0 % touch /tmp/diry/tmp/DirWithTrailingDot./file touch: cannot touch ‘/tmp/diry/tmp/DirWithTrailingDot./file’: No such file or directory % mkdir /tmp/diry/tmp/DirWithTrailingDot./dir mkdir: cannot create directory ‘/tmp/diry/tmp/DirWithTrailingDot./dir’: No such file or directory % find /tmp/diry/tmp/DirWithTrailingDot. /tmp/diry/tmp/DirWithTrailingDot. % find /tmp/diry/tmp/DirWithTrailingSpace\ find: `/tmp/diry/tmp/DirWithTrailingSpace ': No such file or directory % mkdir /tmp/diry/tmp/DirWithTrailingSpace\ % ls -l /tmp/diry/tmp/DirWithTrailingSpace\ total 0 % touch /tmp/diry/tmp/DirWithTrailingSpace\ /file touch: cannot touch ‘/tmp/diry/tmp/DirWithTrailingSpace /file’: No such file or directory % mkdir /tmp/diry/tmp/DirWithTrailingSpace\ /dir mkdir: cannot create directory ‘/tmp/diry/tmp/DirWithTrailingSpace /dir’: No such file or directory After the patch: % umount /tmp/diry % modprobe -r cifs # load the fix % modprobe cifs % mount -t cifs -o... //host/share/home /tmp/diry ... % mkdir /tmp/diry/tmp/DirWithTrailingSpace\ /dir % touch /tmp/diry/tmp/DirWithTrailingSpace\ /file % mkdir /tmp/diry/tmp/DirWithTrailingDot./dir % touch /tmp/diry/tmp/DirWithTrailingDot./file % find /tmp/diry/tmp/ /tmp/diry/tmp/ /tmp/diry/tmp/DirWithTrailingDot. /tmp/diry/tmp/DirWithTrailingDot./dir /tmp/diry/tmp/DirWithTrailingDot./file /tmp/diry/tmp/DirWithTrailingSpace /tmp/diry/tmp/DirWithTrailingSpace /dir /tmp/diry/tmp/DirWithTrailingSpace /file % rm -rf /tmp/diry/tmp/* % find /tmp/diry/tmp/ /tmp/diry/tmp/ ---------- Forwarded message --------- From: Boris Protopopov Date: Wed, Sep 23, 2020 at 8:39 PM Subject: [PATCH] Convert trailing spaces and periods in path components To: Cc: , , Boris Protopopov When converting trailing spaces and periods in paths, do so for every component of the path, not just the last component. If the conversion is not done for every path component, then subsequent operations in directories with trailing spaces or periods (e.g. create(), mkdir()) will fail with ENOENT. This is because on the server, the directory will have a special symbol in its name, and the client needs to provide the same. Signed-off-by: Boris Protopopov --- fs/cifs/cifs_unicode.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) end_of_string = false; -- 2.18.4 diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c index 498777d859eb..9bd03a231032 100644 --- a/fs/cifs/cifs_unicode.c +++ b/fs/cifs/cifs_unicode.c @@ -488,7 +488,13 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen, else if (map_chars == SFM_MAP_UNI_RSVD) { bool end_of_string; - if (i == srclen - 1) + /** + * Remap spaces and periods found at the end of every + * component of the path. The special cases of '.' and + * '..' do not need to be dealt with explicitly because + * they are addressed in namei.c:link_path_walk(). + **/ + if ((i == srclen - 1) || (source[i+1] == '\\')) end_of_string = true; else