From patchwork Fri Jun 16 09:07:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 13282360 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 C7291EB64D7 for ; Fri, 16 Jun 2023 09:10:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232796AbjFPJKj (ORCPT ); Fri, 16 Jun 2023 05:10:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343764AbjFPJJk (ORCPT ); Fri, 16 Jun 2023 05:09:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1952149D2; Fri, 16 Jun 2023 02:07:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 967E763251; Fri, 16 Jun 2023 09:07:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C8C3C433CD; Fri, 16 Jun 2023 09:07:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686906475; bh=4phIGceOvtI2yxKDIT1C76n8i2VAK0TTfcMygNtE+64=; h=From:To:Cc:Subject:Date:From; b=OQgajVQV62OKGC/9ew5Mw9zNBUvWBMyfnUuOHneuy+cdi3NMZdc61WUdw4PWMpnv1 PDZble9eXjKhIG4raJnoCLlv0YKxvlCKQyu6URXNE0LezsYrXYKfwcgsnrwK4SOkDK o+/YEqHfDEHlor+xmDv2jxNqnPK7xaeMWeRWGqsVlKdgEQPPwRxr++OuC8eD0JmUNG JWKro2+aG33LZFyN/Pq7qDPWzy/L1+em8T4mOMikd1bNlSOIRypD6O9eMo8+MVW9je mnV5SVIMCisxridyPv6HAAI5uF1a9xJXk8/WQg5/0bMLeTQpCa+/otjDjLfORtakFY XrxgVmIS9ZD5A== From: Arnd Bergmann To: Namjae Jeon , Steve French Cc: Arnd Bergmann , Sergey Senozhatsky , Tom Talpey , Nathan Chancellor , Nick Desaulniers , Tom Rix , Christian Brauner , Dave Chinner , Kees Cook , =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= , Ronnie Sahlberg , Hyunchul Lee , linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH] smb: avoid field overflow warning Date: Fri, 16 Jun 2023 11:07:28 +0200 Message-Id: <20230616090749.2646749-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org From: Arnd Bergmann clang warns about a possible field overflow in a memcpy: In file included from fs/smb/server/smb_common.c:7: include/linux/fortify-string.h:583:4: error: call to '__write_overflow_field' declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror,-Wattribute-warning] __write_overflow_field(p_size_field, size); It appears to interpret the "&out[baselen + 4]" as referring to a single byte of the character array, while the equivalen "out + baselen + 4" is seen as an offset into the array. I don't see that kind of warning elsewhere, so just go with the simple rework. Fixes: e2f34481b24db ("cifsd: add server-side procedures for SMB3") Signed-off-by: Arnd Bergmann --- fs/smb/server/smb_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/smb/server/smb_common.c b/fs/smb/server/smb_common.c index a7e81067bc991..e3273fa640b07 100644 --- a/fs/smb/server/smb_common.c +++ b/fs/smb/server/smb_common.c @@ -536,7 +536,7 @@ int ksmbd_extract_shortname(struct ksmbd_conn *conn, const char *longname, out[baselen + 3] = PERIOD; if (dot_present) - memcpy(&out[baselen + 4], extension, 4); + memcpy(out + baselen + 4, extension, 1); else out[baselen + 4] = '\0'; smbConvertToUTF16((__le16 *)shortname, out, PATH_MAX,