From patchwork Tue Aug 23 07:42:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 12951824 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0000C32774 for ; Tue, 23 Aug 2022 07:42:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236517AbiHWHmz (ORCPT ); Tue, 23 Aug 2022 03:42:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240615AbiHWHmy (ORCPT ); Tue, 23 Aug 2022 03:42:54 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 794094AD4B for ; Tue, 23 Aug 2022 00:42:53 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id gb36so25695021ejc.10 for ; Tue, 23 Aug 2022 00:42:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc; bh=uJhd1oybMv+ij0w4h+RApiv7TGpcybuCij1a8hf1bgI=; b=cEA3N4nY5BHX4RTWrl0zOqflEhaIZ8/+iOc5ZnUqXh8EyYU5a4sTBN2D+1cLlnpGoO a4VjgxAnccItoeow/TC8URuaHgDWv2IsCKLM/ZJ2vgeH046BuMz8W55XTTppZLmwwZJ9 d0zG+0dFMcnyc/LdR0Eyz1ftFMAnfzgLlqqG6O6aGrFjKO/2EOt8kWwJ/dKTeDCVX4C8 B6qs9YhQtTz41VuIFJDsN4JuKljm2rDdgQbx/S5msNcKB85yQnJ3oERvIGy2bSbEpgQa lv5srcRevpXb8ayoKIPxIHu/62eqe5sGUg6CD0JNirrOtV5kZMtscfl4rdRuZX6pwj7p Wm8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc; bh=uJhd1oybMv+ij0w4h+RApiv7TGpcybuCij1a8hf1bgI=; b=Lvl1Cq7APg8cFbqyPtrpKv+5fgtZ3xONTMHnGr7s6sPaErhanUK03ySQa/RzC2p2Uw F4KpjXQnRrFyvbpBtYcw7HRaTXY7cuALR+f1v2+Efk3HaKWS58WmGrbrdViFeQ55+m1K TWaNJBHg2mBUw13jj8/RATOyL3xZEwfDmJBPrYnjbqHvzIZ8SqbIT35BVQqjHyTcDiNV dmT8DWrWzxK3HpEvom5xxfuEGu4oen1nXOIwXMUPkMUxKW4fziJtvXA4QHmtFAHINz3m tHyPeIrQ980Ke5LV/rTAfqFXtjbnRPgOrMNAB7/oRIGFQLaxnL6b8JPRv9s6L3WbMEof yPRQ== X-Gm-Message-State: ACgBeo0RqAfJz6DRBwnBFpNo9MSebN0FDEerCRCDgEzFj8eBQBuEuyPt N86FA9T1nA2ps5OPnkPmhXXy7jqFhn2JMXyPaN2iBjHlWRDJKQ== X-Google-Smtp-Source: AA6agR6o8BJ7MVsKPGvrdbf1Ku9+8d6RAuD14o+OajFHujIH60OLFIIEA/UeJksZrHF5sQh1P4J6HtoIFtMz2128YNA= X-Received: by 2002:a17:906:4790:b0:73d:7d7a:94aa with SMTP id cw16-20020a170906479000b0073d7d7a94aamr6237880ejc.333.1661240571588; Tue, 23 Aug 2022 00:42:51 -0700 (PDT) MIME-Version: 1.0 From: Steve French Date: Tue, 23 Aug 2022 02:42:40 -0500 Message-ID: Subject: [PATCH][SMB3] skip extra NULL byte in filenames To: CIFS Cc: Paulo Alcantara Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Any comments on Paulo's recent patch below? Since commit: cifs: alloc_path_with_tree_prefix: do not append sep. if the path is empty alloc_path_with_tree_prefix() function was no longer including the trailing separator when @path is empty, although @out_len was still assuming a path separator thus adding an extra byte to the final filename. This has caused mount issues in some Synology servers due to the extra NULL byte in filenames when sending SMB2_CREATE requests with SMB2_FLAGS_DFS_OPERATIONS set. Fix this by checking if @path is not empty and then add extra byte for separator. Also, do not include any trailing NULL bytes in filename as MS-SMB2 requires it to be 8-byte aligned and not NULL terminated. Reviewed-by: Enzo Matsumiya --- Thanks, Steve From 93bbb2c27d8543abb03254a0b5d953c5f3f0b501 Mon Sep 17 00:00:00 2001 From: Paulo Alcantara Date: Fri, 19 Aug 2022 17:00:19 -0300 Subject: [PATCH] cifs: skip extra NULL byte in filenames Since commit: cifs: alloc_path_with_tree_prefix: do not append sep. if the path is empty alloc_path_with_tree_prefix() function was no longer including the trailing separator when @path is empty, although @out_len was still assuming a path separator thus adding an extra byte to the final filename. This has caused mount issues in some Synology servers due to the extra NULL byte in filenames when sending SMB2_CREATE requests with SMB2_FLAGS_DFS_OPERATIONS set. Fix this by checking if @path is not empty and then add extra byte for separator. Also, do not include any trailing NULL bytes in filename as MS-SMB2 requires it to be 8-byte aligned and not NULL terminated. Fixes: 7eacba3b00a3 ("cifs: alloc_path_with_tree_prefix: do not append sep. if the path is empty") Signed-off-by: Paulo Alcantara (SUSE) Signed-off-by: Steve French --- fs/cifs/smb2pdu.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 91cfc5b47ac7..128e44e57528 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -2572,19 +2572,15 @@ alloc_path_with_tree_prefix(__le16 **out_path, int *out_size, int *out_len, path_len = UniStrnlen((wchar_t *)path, PATH_MAX); - /* - * make room for one path separator between the treename and - * path - */ - *out_len = treename_len + 1 + path_len; + /* make room for one path separator only if @path isn't empty */ + *out_len = treename_len + (path[0] ? 1 : 0) + path_len; /* - * final path needs to be null-terminated UTF16 with a - * size aligned to 8 + * final path needs to be 8-byte aligned as specified in + * MS-SMB2 2.2.13 SMB2 CREATE Request. */ - - *out_size = roundup((*out_len+1)*2, 8); - *out_path = kzalloc(*out_size, GFP_KERNEL); + *out_size = roundup(*out_len * sizeof(__le16), 8); + *out_path = kzalloc(*out_size + sizeof(__le16) /* null */, GFP_KERNEL); if (!*out_path) return -ENOMEM; -- 2.34.1