From patchwork Fri Jan 1 03:35:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 11994583 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03D8FC433DB for ; Fri, 1 Jan 2021 03:36:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AFB35207A3 for ; Fri, 1 Jan 2021 03:36:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726314AbhAADgR (ORCPT ); Thu, 31 Dec 2020 22:36:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726044AbhAADgR (ORCPT ); Thu, 31 Dec 2020 22:36:17 -0500 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03851C061573 for ; Thu, 31 Dec 2020 19:35:36 -0800 (PST) Received: by mail-lf1-x131.google.com with SMTP id s26so47282989lfc.8 for ; Thu, 31 Dec 2020 19:35:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to:cc; bh=PzHWKB4oDEBjEu6qHGV4isGKa2Be4k1zGdzgyHO/+VY=; b=dEoobE5dHGfPSqWJrINMYeXidcOfNakHe9l4MO0lWgRDMQ8DG/u9FIYBK/sGfk/aUP P4XRcC/dAZq0aan63GEXprhW3kdAnnKCdDn6NwdNLXJfGhfYYKcpvIzesrDyitFXn4Ji 5x3Kd9htmeo5DbaZ/ZX1nAvFtmOtCIjYBOBXd19r9HoFbOf7jxqngRyyQTAkHqTKGx7m puPGiZNob9XjWQq03AE8nGSrYr15dhrUn6F+RZ3VZBdKI8EkNnOEh5EoOKBHjNlD40lQ dYQN4XzYMEATCvyLVnXBVG6QAq0t073GKJ/E3VTxP4UKUcBNGVUCAoePNJerVGtNdJhP IJ5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=PzHWKB4oDEBjEu6qHGV4isGKa2Be4k1zGdzgyHO/+VY=; b=dQJ5+OK2v8JXTyU0erHpKjEpoi1VPFRkhjfSLENZT1Z0v5B5w9AoGoP3PBAKBl64ur fS1C6mN90sFxUt6XXhxO/X1LxGcU+/A+EOG5WhY4qr0hV6ojpCDW0cDvDzxhwjc48Se2 sPFUyO4JzLJCjqPIASuV1iS20BgX2lFRQuD+X2SOyWCMXwoyjxEoxKi91cc4KJ9Gt4Jv qYbCZsfuqI4bG3TKN1actFYD5u2kI/4qBGbrbZQxV9Cl9UmE4lzsCq7yBfqmRSUyyv6f ZZ4VmgruZxN10kricpSUsM/oux4Axsra7MNiI788jkIgNTVvy4kIYPUm2s49DzelfZBz FhHA== X-Gm-Message-State: AOAM533LisibayQICcdUKFw3UsS/avVcF79keKardFo1Zo32aZcOOEuq tS+oC3Fhw+u0VbITA0a7FaeDeaznoNecAJSuMD0= X-Google-Smtp-Source: ABdhPJwpmjucyqwt8MdFj8Jsi/3/U31nqDlYbPn9PqDTTFpG0RpYQjxcfAOBC1sbUdglYcx1yZQXzTgLnCzAYm7LSh4= X-Received: by 2002:a2e:87cb:: with SMTP id v11mr28773359ljj.218.1609472134510; Thu, 31 Dec 2020 19:35:34 -0800 (PST) MIME-Version: 1.0 From: Steve French Date: Thu, 31 Dec 2020 21:35:23 -0600 Message-ID: Subject: [PATCH][SMB3] allow files to be created with backslash in file name To: Xiaoli Feng , CIFS Cc: samba-technical Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Backslash is reserved in Windows (and SMB2/SMB3 by default) but allowed in POSIX so must be remapped when POSIX extensions are not enabled. The default mapping for SMB3 mounts ("SFM") allows mapping backslash (ie 0x5C in UTF8) to 0xF026 in UCS-2 (using the Unicode remapping range reserved for these characters), but this was not mapped by cifs.ko (unlike asterisk, greater than, question mark etc). This patch fixes that to allow creating files and directories with backslash in the file or directory name. Before this patch: touch "/mnt2/filewith\slash" would return touch: setting times of '/mnt2/filewith\slash': Invalid argument With the patch touch and mkdir with the backslash in the name works. This problem was found while debugging xfstest 453 - see https://bugzilla.kernel.org/show_bug.cgi?id=210961 This patch may be even more important to Samba, as alternative ways of storing these files can create more problems. Interestingly Samba server reports local files with backslashes in them over the wire without remapping, even though these are illegal in SMB3 which would cause confusion on the client(s). Has anyone tried Windows mounting to Samba and viewing files with locally created Linux files that include these reserved characters (presumably Windows clients won't like it either)? This patch does allow creating/viewing files with remotely with '\' in the file name from Linux (cifs.ko) but does not completely fix xfstest 453 kernel (more investigation of this test is needed). Test 453 creates filenames with 'horrifying' (using their term) sequences of arbitrary bytes in file names. Reported-by: Xiaoli Feng From 03596841d4119840548676a9b6d916580baa618c Mon Sep 17 00:00:00 2001 From: Steve French Date: Thu, 31 Dec 2020 21:12:19 -0600 Subject: [PATCH] smb3: allow files to be created with backslash in file name Backslash is reserved in Windows (and SMB2/SMB3 by default) but allowed in POSIX so must be remapped when POSIX extensions are not enabled. The default mapping for SMB3 mounts ("SFM") allows mapping backslash (ie 0x5C in UTF8) to 0xF026 in UCS-2 (using the Unicode remapping range reserved for these characters), but this was not mapped by cifs.ko (unlike asterisk, greater than, question mark etc). This patch fixes that to allow creating files and directories with backslash in the file or directory name. Before this patch: touch "/mnt2/filewith\slash" would return touch: setting times of '/mnt2/filewith\slash': Invalid argument With the patch touch and mkdir with the backslash in the name works. This problem was found while debugging https://bugzilla.kernel.org/show_bug.cgi?id=210961 Reported-by: Xiaoli Feng Signed-off-by: Steve French --- fs/cifs/cifs_unicode.c | 6 ++++++ fs/cifs/dir.c | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c index 9bd03a231032..a65310c87db4 100644 --- a/fs/cifs/cifs_unicode.c +++ b/fs/cifs/cifs_unicode.c @@ -98,6 +98,9 @@ convert_sfm_char(const __u16 src_char, char *target) case SFM_PERIOD: *target = '.'; break; + case SFM_SLASH: + *target = '\\'; + break; default: return false; } @@ -431,6 +434,9 @@ static __le16 convert_to_sfm_char(char src_char, bool end_of_string) case '|': dest_char = cpu_to_le16(SFM_PIPE); break; + case '\\': + dest_char = cpu_to_le16(SFM_SLASH); + break; case '.': if (end_of_string) dest_char = cpu_to_le16(SFM_PERIOD); diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c index 68900f1629bf..62cc589e33cd 100644 --- a/fs/cifs/dir.c +++ b/fs/cifs/dir.c @@ -208,8 +208,14 @@ check_name(struct dentry *direntry, struct cifs_tcon *tcon) direntry->d_name.len > le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength))) return -ENAMETOOLONG; - - if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)) { + /* + * If POSIX extensions negotiated or if mapping reserved characters + * (via SFM, the default on most mounts currently, then '\' is + * remapped on the wire into the Unicode reserved range, 0xF026) then + * do not need to reject get/set requests with backslash in path + */ + if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) && + !(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SFM_CHR)) { for (i = 0; i < direntry->d_name.len; i++) { if (direntry->d_name.name[i] == '\\') { cifs_dbg(FYI, "Invalid file name\n"); -- 2.27.0