From patchwork Sat Sep 28 21:59:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 1990524 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=B/L1YbNQ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-cifs+bounces-2947-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XGLr604ZDz1xt9 for ; Sun, 29 Sep 2024 08:00:53 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 9949AB23549 for ; Sat, 28 Sep 2024 22:00:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A452A15EFA1; Sat, 28 Sep 2024 22:00:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="B/L1YbNQ" X-Original-To: linux-cifs@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C93482488; Sat, 28 Sep 2024 22:00:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727560847; cv=none; b=obcIcLVHrS/ffgvnRbni4vAPM8iPoW+h0E5y4WulSPv+DKi6Xt+5+7ccEhC+2XeiJbIlcE6z0qQK6RTk+0ppQ8u2tv0UDptky2QV6i/TEZDVgg18N7rWJoNzeu6I+w4X0J32wKrewJ/tq2AbRD4rmrbMwX0zY9qp7hV4mYwTFPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727560847; c=relaxed/simple; bh=30vYceahhAZ6cpDf6/qon3ZtC2Ak+QBMUSkaa2C2LTQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=RC0U4l9/j3jERoOvk94yasQqap1GN/AmQJo1ynTzB8i/OZe7eMb+CxdN3WafgOh9y8oXlhRZpZFa89S5NsqbSmDdFJezK0aRyjtKPqNJvwteHs98pXoYwsTW6Hg0zkH27h1ZaWGpKxfJzBWKNslk2DTFariXQrWJNdbznadovGs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=B/L1YbNQ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 103CDC4CEC5; Sat, 28 Sep 2024 22:00:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727560847; bh=30vYceahhAZ6cpDf6/qon3ZtC2Ak+QBMUSkaa2C2LTQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B/L1YbNQ4eAf5eSMc2BCNwNXBHBlz8kVTzMQ5Z3h0yyUuDPiJd49dzATnPAahPPZi RLz1Nk/NjcJyh2+8djh8+xRJJhwozlkEMBWGR4SuAN+H5YNzrasVDUU7TtFy4GhnoS i1sryzAo9BXMzdEpeHLj+NIZkpdavlnt3tiUVyWisP5zH16rxw94Ym5LnNTL96utAQ Gd1h0sdEL/1WQegu351IdPu1f6v5jlJSYzkET4yr7N5Z9s23yvptGcbD5kHxb5Mzkc 6QXM7mtUvGvdJdFW0zTbPPcCIXcWXw35S1S8eOqeu/2hBBSXpokU7BZ8V7VTQtdahq Q6gUOWaUrVPQg== Received: by pali.im (Postfix) id 5F9EF9F7; Sun, 29 Sep 2024 00:00:40 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara , Ronnie Sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/8] smb: Update comments about some reparse point tags Date: Sat, 28 Sep 2024 23:59:41 +0200 Message-Id: <20240928215948.4494-2-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240928215948.4494-1-pali@kernel.org> References: <20240928215948.4494-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 NFS-style reparse points are recognized only by the Windows NFS server 2012 and new. Windows 8 does not contain Windows NFS server, so these reparse points are not used on Windows 8. Reparse points with IO_REPARSE_TAG_AF_UNIX tag were primarily introduced for native Win32 AF_UNIX sockets and later were re-used by also by WSL: https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/ https://devblogs.microsoft.com/commandline/windowswsl-interop-with-af_unix/ Signed-off-by: Pali Rohár --- fs/smb/common/smbfsctl.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/smb/common/smbfsctl.h b/fs/smb/common/smbfsctl.h index a94d658b88e8..4b379e84c46b 100644 --- a/fs/smb/common/smbfsctl.h +++ b/fs/smb/common/smbfsctl.h @@ -140,20 +140,21 @@ /* Used by the DFS filter See MS-DFSC */ #define IO_REPARSE_TAG_DFSR 0x80000012 #define IO_REPARSE_TAG_FILTER_MANAGER 0x8000000B -/* See section MS-FSCC 2.1.2.4 */ +/* Native SMB symlinks since Windows Vista, see MS-FSCC 2.1.2.4 */ #define IO_REPARSE_TAG_SYMLINK 0xA000000C #define IO_REPARSE_TAG_DEDUP 0x80000013 #define IO_REPARSE_APPXSTREAM 0xC0000014 -/* NFS symlinks, Win 8/SMB3 and later */ +/* NFS special files used by Windows NFS server since Windows Server 2012, see MS-FSCC 2.1.2.6 */ #define IO_REPARSE_TAG_NFS 0x80000014 /* * AzureFileSync - see * https://docs.microsoft.com/en-us/azure/storage/files/storage-sync-cloud-tiering */ #define IO_REPARSE_TAG_AZ_FILE_SYNC 0x8000001e +/* Native Win32 AF_UNIX sockets since Windows 10 April 2018 Update, used also by WSL */ +#define IO_REPARSE_TAG_AF_UNIX 0x80000023 /* WSL reparse tags */ #define IO_REPARSE_TAG_LX_SYMLINK 0xA000001D -#define IO_REPARSE_TAG_AF_UNIX 0x80000023 #define IO_REPARSE_TAG_LX_FIFO 0x80000024 #define IO_REPARSE_TAG_LX_CHR 0x80000025 #define IO_REPARSE_TAG_LX_BLK 0x80000026 From patchwork Sat Sep 28 21:59:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 1990526 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=aucaODyi; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-cifs+bounces-2948-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XGLr84jVwz1xt9 for ; Sun, 29 Sep 2024 08:00:56 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0A450285C64 for ; Sat, 28 Sep 2024 22:00:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C9108186294; Sat, 28 Sep 2024 22:00:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aucaODyi" X-Original-To: linux-cifs@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F2B21448E2; Sat, 28 Sep 2024 22:00:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727560847; cv=none; b=ahVqBJOvPKBIccmUF6KZ8QnTxAHONd23kJ2RJYAwCDoc4WtapTj451XDD66oUJYcsOXQhqSFoZ9dxZAufWwLwPF9ZACpj+O2Uo5N0VUyPisZRjcx2q3KnR8EnKzsxE+zk/YpjkUrz6pKr2QZe4+eli1suAvgEbyw2k8QuUGpKbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727560847; c=relaxed/simple; bh=ibU0NV9N4+As9CYwIR1i1p9CSz0pkS/imGG+NsSGISs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Tp5gh+M7XcHNaFm+3ibqx3QFVpU0LqWcGZ+U7bjJWJ5i7g0fYs4HvAtjWpA4Y3V1VlN4JNpjddyZwCup93S2pmzdsDRXyPIZjHjxWyc+2PHLI4kEPRosGjHZ9EPjOEewORHJuxHp41lBLpmixV419tUY9tnxtY3p5C8kQnNQ0l0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aucaODyi; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16324C4AF0B; Sat, 28 Sep 2024 22:00:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727560847; bh=ibU0NV9N4+As9CYwIR1i1p9CSz0pkS/imGG+NsSGISs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aucaODyiw5YiE+714jUSi/JtbTY+9MMtXGxUpmNd99cD6wfXLmWa6QtjhMTu/xCdH Z7L8TfLyZrqcB35EgcLTUhNrPclEFZnScdC9PU5ypTnn/DH9bRJiCF2/L8guUa1pi1 GFF478yGrzNRoIdQtpHELR9NwmY3yixdwRFN4OuBBzJoih5jmtEFk8kFEITFvS6Dkm bKTX9OFLqeEOE5OULKCNlm7+qIOD75IJGTEUmsyeSFQhuRIQAiMww4DmuLJedkND5I yBS9C41UkCbf3NpsQnvhhy2o/LHgmbrf+BzOzJYlz0myYIfoNzjOe2UN7fQGSMfqwE ppYsbMlavpeXg== Received: by pali.im (Postfix) id 9E3A6A4E; Sun, 29 Sep 2024 00:00:40 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara , Ronnie Sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/8] cifs: Remove intermediate object of failed create reparse call Date: Sat, 28 Sep 2024 23:59:42 +0200 Message-Id: <20240928215948.4494-3-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240928215948.4494-1-pali@kernel.org> References: <20240928215948.4494-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If CREATE was successful but SMB2_OP_SET_REPARSE failed then remove the intermediate object created by CREATE. Otherwise empty object stay on the server when reparse call failed. This ensures that if the creating of special files is unsupported by the server then no empty file stay on the server as a result of unsupported operation. Fixes: 102466f303ff ("smb: client: allow creating special files via reparse points") Signed-off-by: Pali Rohár --- fs/smb/client/smb2inode.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/fs/smb/client/smb2inode.c b/fs/smb/client/smb2inode.c index 11a1c53c64e0..af42f44bdcf4 100644 --- a/fs/smb/client/smb2inode.c +++ b/fs/smb/client/smb2inode.c @@ -1205,6 +1205,8 @@ struct inode *smb2_get_reparse_inode(struct cifs_open_info_data *data, struct cifs_sb_info *cifs_sb = CIFS_SB(sb); struct cifsFileInfo *cfile; struct inode *new = NULL; + int out_buftype[2] = {}; + struct kvec out_iov[2]; struct kvec in_iov[2]; int cmds[2]; int rc; @@ -1228,7 +1230,7 @@ struct inode *smb2_get_reparse_inode(struct cifs_open_info_data *data, cmds[1] = SMB2_OP_POSIX_QUERY_INFO; cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile); rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, &oparms, - in_iov, cmds, 2, cfile, NULL, NULL, NULL); + in_iov, cmds, 2, cfile, out_iov, out_buftype, NULL); if (!rc) { rc = smb311_posix_get_inode_info(&new, full_path, data, sb, xid); @@ -1237,12 +1239,27 @@ struct inode *smb2_get_reparse_inode(struct cifs_open_info_data *data, cmds[1] = SMB2_OP_QUERY_INFO; cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile); rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, &oparms, - in_iov, cmds, 2, cfile, NULL, NULL, NULL); + in_iov, cmds, 2, cfile, out_iov, out_buftype, NULL); if (!rc) { rc = cifs_get_inode_info(&new, full_path, data, sb, xid, NULL); } } + + if (rc) { + /* + * If CREATE was successful but SMB2_OP_SET_REPARSE failed then + * remove the intermediate object created by CREATE. Otherwise + * empty object stay on the server when reparse call failed. + */ + if (((struct smb2_hdr *)out_iov[0].iov_base)->Status == STATUS_SUCCESS && + ((struct smb2_hdr *)out_iov[1].iov_base)->Status != STATUS_SUCCESS) + smb2_unlink(xid, tcon, full_path, cifs_sb, NULL); + } + + free_rsp_buf(out_buftype[0], out_iov[0].iov_base); + free_rsp_buf(out_buftype[1], out_iov[1].iov_base); + return rc ? ERR_PTR(rc) : new; } From patchwork Sat Sep 28 21:59:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 1990528 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=V/a4gQ0p; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=139.178.88.99; helo=sv.mirrors.kernel.org; envelope-from=linux-cifs+bounces-2950-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [139.178.88.99]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XGLrG4xCLz1xtT for ; Sun, 29 Sep 2024 08:01:02 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id DA0B0285826 for ; Sat, 28 Sep 2024 22:01:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3316118785C; Sat, 28 Sep 2024 22:00:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="V/a4gQ0p" X-Original-To: linux-cifs@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B22618734F; Sat, 28 Sep 2024 22:00:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727560848; cv=none; b=iA1buqDIWkHbRjR+t9eK3gk7U2B5Ak3FxTX4LdEbdt7YObZ/G5Rh1tYsSaF3X7AkCP3cTg1uXTJWU9rCH4DIao/L+QHvaJn19rphXX/jkOEXHPiXb+cC82/rsB+06LMJdxyLXZ/ZL4yAHc5l0NHz0JH2xPdPa+rosBHlSuiTZWM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727560848; c=relaxed/simple; bh=CzIXaOQ1+8uUZLsrIfoiPMK2AQjdBSqSjgcG93qH1FY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=hPVQdE0MCAqj4ekPTZuTdKRdaDlJ1Rvs1KM/z1E/9/A2j1VlgDpvK7ODX08NAhBBSrC9BhbUbSNG5zndUhaY4HuavawxL7+9xkU8RbBJBkmOvJGiP122Nj35fJzKjB4Rn4vELYkT7ot5bNKRkcHcqHtZqUu5cIFjfeTVCuTGrD0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=V/a4gQ0p; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F544C4AF09; Sat, 28 Sep 2024 22:00:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727560847; bh=CzIXaOQ1+8uUZLsrIfoiPMK2AQjdBSqSjgcG93qH1FY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V/a4gQ0pdnp4dwFv61YWJszsVVZdGy00Q94RFCwO7i5HE/gmOzM8e138zYPXskt9g C0VsdQW1WnNKcJix8IVGijtjc+D1Fonmy+e65ZmdK9mwCM9BQvQFBZHXzTM3KRsX5w y/EhumfhyTUNQd6/sA0fmc84Lr9kWhIoOnfw4XAg4EdtiedyWcF+ct6lVWEjubHcxu mkieL8a6e2zeOxjZM26dXJixlDizjH8ctODbN3FiSROVSRZWj5bnzf+Kf6z2TgU5kT wy9ovN5m4vkVW+Ji+NxGt59sZBjaoBNTCsBFGWU+eGZO9D8X9Avt5m3lS76l0tHXgP 9GQy7SeQLQ3CA== Received: by pali.im (Postfix) id C6287A7F; Sun, 29 Sep 2024 00:00:40 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara , Ronnie Sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/8] cifs: Fix parsing NFS-style char/block devices Date: Sat, 28 Sep 2024 23:59:43 +0200 Message-Id: <20240928215948.4494-4-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240928215948.4494-1-pali@kernel.org> References: <20240928215948.4494-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Linux SMB client currently parses NFS-style char and block devices incorrectly. It reads major number from location of minor and major from location of minor. Per MS-FSCC 2.1.2.6 NFS_SPECFILE_CHR and NFS_SPECFILE_BLK DataBuffer's field contains two 32-bit integers that represent major and minor device numbers. So the first one 32-bit integer in DataBuffer is major number and second one in DataBuffer is minor number. Microsoft Windows NFS server reads them in this order too. This issue was introduced in commit 45e724022e27 ("smb: client: set correct file type from NFS reparse points") and probably because in commit message was test of char and block devices with same major and minor numbers. So swapped major and minor numbers were not spotted. Fix this problem in Linux SMB client by reading major and minor numbers from correct position of DataBuffer. This change fixes interoperability of char and block devices on Windows share which is exported over both SMB and NFS protocols. Fixes: 45e724022e27 ("smb: client: set correct file type from NFS reparse points") Signed-off-by: Pali Rohár --- fs/smb/client/reparse.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/smb/client/reparse.h b/fs/smb/client/reparse.h index 2c0644bc4e65..790360f8a53b 100644 --- a/fs/smb/client/reparse.h +++ b/fs/smb/client/reparse.h @@ -20,9 +20,12 @@ static inline dev_t reparse_nfs_mkdev(struct reparse_posix_data *buf) { - u64 v = le64_to_cpu(*(__le64 *)buf->DataBuffer); + u32 major, minor; - return MKDEV(v >> 32, v & 0xffffffff); + major = le32_to_cpu(((__le32 *)buf->DataBuffer)[0]); + minor = le32_to_cpu(((__le32 *)buf->DataBuffer)[1]); + + return MKDEV(major, minor); } static inline dev_t wsl_mkdev(void *ptr) From patchwork Sat Sep 28 21:59:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 1990531 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=k1JUOchg; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-cifs+bounces-2953-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XGLrV6KRJz1xt9 for ; Sun, 29 Sep 2024 08:01:14 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 18A49B23C6E for ; Sat, 28 Sep 2024 22:01:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A5675188591; Sat, 28 Sep 2024 22:00:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="k1JUOchg" X-Original-To: linux-cifs@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E39B188006; Sat, 28 Sep 2024 22:00:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727560848; cv=none; b=gJjZ7UwJd939x6eqOYyrlIHub/yN0EYGNzm4y1mN9bfnQEs/O/LgTEPoH3YLOm2aSLo0dbPMr8zDZw/MuCqYyyR8CebMp3mApBHrdVj9TqvYHDmgOc21m3aYPPEEyqPgsDIRSUmMstk2rayfAAwH4jyJUa5tY/devU8GmzlomJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727560848; c=relaxed/simple; bh=+5MshYdIWOim2Y4JZXynrXZzEYNgicdvjusLOdJ6Br4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=swROwY4Ro6YrcF+UTSGU/f1MDTrzlQ8AnPjvcyJy7XSbTT81jW7r2C2OouhXQbdQ/qGrzyeX5w0R+h3lNr+KWVtXmgOXKCm5ESLR1Y21Xt3zF+mnBqKV9oWYnZZtAkYOWWTaC5H52kQrATGK3kndIv5TUzHxGajUT1Uv+gUz25I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k1JUOchg; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3765AC4CEC3; Sat, 28 Sep 2024 22:00:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727560848; bh=+5MshYdIWOim2Y4JZXynrXZzEYNgicdvjusLOdJ6Br4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k1JUOchgCjeCmgw6ecTxMTsoXaOitkoJGu5M8Hri2le4YCIEXg1qinrrdLDq8EwCs G23lXrrgpldKOmon24hANOP7vUrmUqcRJWvLx1c1CHFkRyfzXu5rTsx2hdeCI/xsx1 bnDonb7ck9TMIp8riklEZbSxizGftcuxALMH1pPGQTwVB5WaHTN59g52w9YIDNshEg /yzEZffRXHuojUSRaygluvpRH9o7nAJeBIaq+weKUngEAdD5nHETPcMy6IfoEKGfhL m/cvPLpZwmApFWOPrR55Zt9kOHsnVGKarAR6cT47b3V2D+cSeWVh/NsIUNyjDp+/88 xKSKWnQE/tAuw== Received: by pali.im (Postfix) id EF87DAA2; Sun, 29 Sep 2024 00:00:40 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara , Ronnie Sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/8] cifs: Fix creating NFS-style char/block devices Date: Sat, 28 Sep 2024 23:59:44 +0200 Message-Id: <20240928215948.4494-5-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240928215948.4494-1-pali@kernel.org> References: <20240928215948.4494-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Linux SMB client currently creates NFS-style char and block devices with swapped major and minor numbers. Per MS-FSCC 2.1.2.6 NFS_SPECFILE_CHR and NFS_SPECFILE_BLK DataBuffer's field contains two 32-bit integers that represent major and minor device numbers. So the first one 32-bit integer in DataBuffer is major number and second one in DataBuffer is minor number. Microsoft Windows NFS server reads them in this order too. But Linux CIFS client creates new reparse point DataBuffer with minor number first and major number second. Fix this problem in Linux SMB client and puts major and minor number in the correct order into DataBuffer. This change fixes interoperability of char and block devices on Windows share which is exported over both SMB and NFS protocols. Fixes: 102466f303ff ("smb: client: allow creating special files via reparse points") Signed-off-by: Pali Rohár --- fs/smb/client/reparse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/smb/client/reparse.c b/fs/smb/client/reparse.c index 48c27581ec51..63984796721a 100644 --- a/fs/smb/client/reparse.c +++ b/fs/smb/client/reparse.c @@ -108,8 +108,8 @@ static int nfs_set_reparse_buf(struct reparse_posix_data *buf, buf->InodeType = cpu_to_le64(type); buf->ReparseDataLength = cpu_to_le16(len + dlen - sizeof(struct reparse_data_buffer)); - *(__le64 *)buf->DataBuffer = cpu_to_le64(((u64)MAJOR(dev) << 32) | - MINOR(dev)); + *(__le64 *)buf->DataBuffer = cpu_to_le64(((u64)MINOR(dev) << 32) | + MAJOR(dev)); iov->iov_base = buf; iov->iov_len = len + dlen; return 0; From patchwork Sat Sep 28 21:59:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 1990530 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=Vyq8lk/4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-cifs+bounces-2951-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XGLrJ2QnWz1xtT for ; Sun, 29 Sep 2024 08:01:04 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2A7381C22DE5 for ; Sat, 28 Sep 2024 22:01:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 35B52187861; Sat, 28 Sep 2024 22:00:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Vyq8lk/4" X-Original-To: linux-cifs@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B277187352; Sat, 28 Sep 2024 22:00:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727560848; cv=none; b=I9spRKOdhIpxo+Q5F34PU3BGB3OuK+8iGYH7HWPsVg9w6p/GWOaUD19HqB8COAi0p5s/jcpdBeAN9WMtPrUHGTO7uCe9HgJR229ZN4pJcEMmVgeKxdeBi2RNq0M5g5JQed1UYAe3nwcnK/TP9G80aPpzBK6P1+tvj9n/Dlg7OhQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727560848; c=relaxed/simple; bh=a7tslZvUsg1bUvIyZkA6rSXDt4yPUK/VEUdHYfacFAM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Q7pTYzUXkRqBKogowgnbQUIGwWFc7Q2ReXZ4UFK4qVIc1E/32fkDOpWR1Pab0XKUJ+BAQMbfItfn/6ORvWM7NnCPsrlJrdWNd9GG4e+Y/tFKFlAVt3HMelG1rqf/T7anapiJcykxfeupIs390Z2vpa8Y36tbN5CdM/xlKQ/Ozhw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Vyq8lk/4; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9904AC4CECD; Sat, 28 Sep 2024 22:00:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727560847; bh=a7tslZvUsg1bUvIyZkA6rSXDt4yPUK/VEUdHYfacFAM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vyq8lk/4dR8qzyMBTjwabn0ZlQl4ELoGmpHPzWNmlHb0V/afgVtwTVSp3RdlEFyFN Ck/up4CcpXvQl5k/mQOgDqIWmHxUS2MOvOsw0twSJl97kD9Ydi8yKsj3R0ZazfyzaK xua3aF6C1uyhnvlBp1DNkUyO8poyCWvDRGkaPupVBrBV6YYJgqOzRaE15y0enfGqf4 dLBd3VTgPvlCRW5YCbIRy9IoOYctG55FkTmxgSm2WzGSpgaau0B9fUEc7Es/tc5UVr nyuPtVCxm82KJO6+Uhard0WJG61L5/C76y+tm0Gi+54FctfAxPOwQNwrrE3hEaoie+ oGlaR5V62iS6Q== Received: by pali.im (Postfix) id 2C290BA8; Sun, 29 Sep 2024 00:00:41 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara , Ronnie Sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/8] cifs: Fix buffer overflow when parsing NFS reparse points Date: Sat, 28 Sep 2024 23:59:45 +0200 Message-Id: <20240928215948.4494-6-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240928215948.4494-1-pali@kernel.org> References: <20240928215948.4494-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 ReparseDataLength is sum of the InodeType size and DataBuffer size. So to get DataBuffer size it is needed to subtract InodeType's size from ReparseDataLength. Function cifs_strndup_from_utf16() is currentlly accessing buf->DataBuffer at position after the end of the buffer because it does not subtract InodeType size from the length. Fix this problem and correctly subtract variable len. Member InodeType is present only when reparse buffer is large enough. Check for ReparseDataLength before accessing InodeType to prevent another invalid memory access. Major and minor rdev values are present also only when reparse buffer is large enough. Check for reparse buffer size in reparse_nfs_mkdev(). Fixes: d5ecebc4900d ("smb3: Allow query of symlinks stored as reparse points") Signed-off-by: Pali Rohár --- fs/smb/client/reparse.c | 11 ++++++++++- fs/smb/client/reparse.h | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/fs/smb/client/reparse.c b/fs/smb/client/reparse.c index 63984796721a..af32a7dbca4b 100644 --- a/fs/smb/client/reparse.c +++ b/fs/smb/client/reparse.c @@ -320,9 +320,16 @@ static int parse_reparse_posix(struct reparse_posix_data *buf, unsigned int len; u64 type; + len = le16_to_cpu(buf->ReparseDataLength); + if (len < sizeof(buf->InodeType)) { + cifs_dbg(VFS, "srv returned malformed nfs buffer\n"); + return -EIO; + } + + len -= sizeof(buf->InodeType); + switch ((type = le64_to_cpu(buf->InodeType))) { case NFS_SPECFILE_LNK: - len = le16_to_cpu(buf->ReparseDataLength); data->symlink_target = cifs_strndup_from_utf16(buf->DataBuffer, len, true, cifs_sb->local_nls); @@ -482,6 +489,8 @@ bool cifs_reparse_point_to_fattr(struct cifs_sb_info *cifs_sb, u32 tag = data->reparse.tag; if (tag == IO_REPARSE_TAG_NFS && buf) { + if (le16_to_cpu(buf->ReparseDataLength) < sizeof(buf->InodeType)) + return false; switch (le64_to_cpu(buf->InodeType)) { case NFS_SPECFILE_CHR: fattr->cf_mode |= S_IFCHR; diff --git a/fs/smb/client/reparse.h b/fs/smb/client/reparse.h index 790360f8a53b..5be54878265e 100644 --- a/fs/smb/client/reparse.h +++ b/fs/smb/client/reparse.h @@ -22,6 +22,9 @@ static inline dev_t reparse_nfs_mkdev(struct reparse_posix_data *buf) { u32 major, minor; + if (le16_to_cpu(buf->ReparseDataLength) != sizeof(buf->InodeType) + 2*sizeof(__le32)) + return 0; + major = le32_to_cpu(((__le32 *)buf->DataBuffer)[0]); minor = le32_to_cpu(((__le32 *)buf->DataBuffer)[1]); From patchwork Sat Sep 28 21:59:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 1990529 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=bqGklTFY; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-cifs+bounces-2952-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XGLrH56mXz1xt9 for ; Sun, 29 Sep 2024 08:01:03 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 4E53D285C04 for ; Sat, 28 Sep 2024 22:01:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 38E5B187862; Sat, 28 Sep 2024 22:00:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bqGklTFY" X-Original-To: linux-cifs@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D9CE18754D; Sat, 28 Sep 2024 22:00:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727560848; cv=none; b=JDmQBEiBteIfcFXmZbnJnShRR3Q1KWndXrNhH3fEsZymLLal4RB8+/j/MgLI3KtdTFytqsnmJfrPCiQUWqrfr2fRqhSmJ37XnQe8EKBAeWXYX/l3uLBFCt4OQAdFV1QCDd/324wh/IYug6o8evLh6qS5CfhF+NvNE37o+M+4fMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727560848; c=relaxed/simple; bh=yafdB9R1iS/MIPawy5b6gSA2MMikl+1Y9iR4oZxhH0c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=uNZS8jJ911ztJvSH/Qdhh7WDwX66nvd6aBHkyLh6RVVH9O2rXs68ChUAk0CLL6ciR+rI/gZ5YjHvI34e6zo+AFylMqfoNSVQqv+XRtMfSmTj3vs3HYdn32XvTstKe8lSgZo7dNGCXYloXR8DosMTFi7BH+awefP3azjFphqKhVo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bqGklTFY; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99D97C4CECE; Sat, 28 Sep 2024 22:00:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727560847; bh=yafdB9R1iS/MIPawy5b6gSA2MMikl+1Y9iR4oZxhH0c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bqGklTFYYorgtFAQtQrttOJoheU+LqSrmOlXvf5Pi5h+GZZ7fZGErPRnHPybPJwNx EMB9//b/EjTw0OxmlH/+vu1g59QUt+GXo0TX/u8s/aVSQa7UPqTw+oigemBLI3IVVu 7a6rfdAr8f1zDzpPv8Gvef1h9dCAxB3/VVfDE+T9jxKEo9ivIHDmsHl/uaq5qGy694 nCPtQTfRm4l+7bg9UF0gEuC7JYgBb6st1V9XchclCPqluVklrGOnKQwVS3aSVmTC1L cIBnsQLRm/FuRRPIrATy4xVbuCHWBxcIV3fx/5EFmjw+GafSq8Q0tutW/JoNRSQfto R5zok+GBwXYDA== Received: by pali.im (Postfix) id 6A215C46; Sun, 29 Sep 2024 00:00:41 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara , Ronnie Sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/8] cifs: Do not convert delimiter when parsing NFS-style symlinks Date: Sat, 28 Sep 2024 23:59:46 +0200 Message-Id: <20240928215948.4494-7-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240928215948.4494-1-pali@kernel.org> References: <20240928215948.4494-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 NFS-style symlinks have target location always stored in NFS/UNIX form where backslash means the real UNIX backslash and not the SMB path separator. So do not mangle slash and backslash content of NFS-style symlink during readlink() syscall as it is already in the correct Linux form. This fixes interoperability of NFS-style symlinks with backslashes created by Linux NFS3 client throw Windows NFS server and retrieved by Linux SMB client throw Windows SMB server, where both Windows servers exports the same directory. Fixes: d5ecebc4900d ("smb3: Allow query of symlinks stored as reparse points") Signed-off-by: Pali Rohár --- fs/smb/client/reparse.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/smb/client/reparse.c b/fs/smb/client/reparse.c index af32a7dbca4b..e3cf7ae516cb 100644 --- a/fs/smb/client/reparse.c +++ b/fs/smb/client/reparse.c @@ -335,7 +335,6 @@ static int parse_reparse_posix(struct reparse_posix_data *buf, cifs_sb->local_nls); if (!data->symlink_target) return -ENOMEM; - convert_delimiter(data->symlink_target, '/'); cifs_dbg(FYI, "%s: target path: %s\n", __func__, data->symlink_target); break; From patchwork Sat Sep 28 21:59:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 1990527 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=cksvZ6JC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.48.161; helo=sy.mirrors.kernel.org; envelope-from=linux-cifs+bounces-2949-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [147.75.48.161]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XGLrG11fNz1xt9 for ; Sun, 29 Sep 2024 08:01:02 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 37303B2378B for ; Sat, 28 Sep 2024 22:01:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 32D71187855; Sat, 28 Sep 2024 22:00:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cksvZ6JC" X-Original-To: linux-cifs@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B1D1187347; Sat, 28 Sep 2024 22:00:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727560848; cv=none; b=BQ5v49ceOM8iTwRmwCvnG4pF7TO8d0Y0bQ0Jvkqyb0TWtAjwZvJzO16yKzDRPkMfyV/xOkSceEK4eTEu7S+7gsd5QeweLsROF2vX46W1UV4/5vT3TQ6QGVt1P1H1YQHgTtIyskirwrZ22upnoc55h2ui2VaGWOqSJIP7gf4sFO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727560848; c=relaxed/simple; bh=Nqkkzjy+oFOwXzYUoBJUIL1MmPuVBHIvi/pv18rAyK0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=oMJc0mf9UsPY6vbT5EbqKW7PF+/zXUGfFeYoDXe90hjkVRss7t7ZOD1tohqYp5y8JSdwc/L02JcVMgadU6BnGcdGyPGsB+4rQ3muQHSvHzIwysvVLvcmPXl+T9geL41SdK3s5cBHdohTf0Pbf3+bHZhIyss3c7dEJg1Sh4vspH0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cksvZ6JC; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A32E8C4CED0; Sat, 28 Sep 2024 22:00:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727560847; bh=Nqkkzjy+oFOwXzYUoBJUIL1MmPuVBHIvi/pv18rAyK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cksvZ6JCi5VSD4a7dMInohSiPPyy0WI4KbyeJWJ0sheXwEQCyuKjuV6WT2+4RwOy8 S4MoyMnT5rZ+0K7rt8y/nOvzAOXyPaYXHl3F2WUTVhhj+809lSNF9bI5WQ2fn+vCW6 z8p9cb5URZdiFSCclJBWL2qKO/em1Q8fk9xYYxz565pq/lB1RYHX88287tSUaE7SBu 5AZkYLtmDxCWmhMkNUol1kEINleTnObQpBlibQMij+knFlbPHALcPBDhPxIg2zHUnr KayKqvgXUUSxc6bHLvI3RXx/Px5FDZtg6cEITuUzBNcJQjwNilApDTYAA6X4+Oxolc 2n8TrShDFvn5w== Received: by pali.im (Postfix) id 9A42AC7D; Sun, 29 Sep 2024 00:00:41 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara , Ronnie Sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 7/8] cifs: Validate content of NFS reparse point buffer Date: Sat, 28 Sep 2024 23:59:47 +0200 Message-Id: <20240928215948.4494-8-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240928215948.4494-1-pali@kernel.org> References: <20240928215948.4494-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Symlink target location stored in DataBuffer is encoded in UTF-16. So check that symlink DataBuffer length is non-zero and even number. And check that DataBuffer does not contain UTF-16 null codepoint because Linux cannot process symlink with null byte. DataBuffer for char and block devices is 8 bytes long as it contains two 32-bit numbers (major and minor). Add check for this. DataBuffer buffer for sockets and fifos zero-length. Add checks for this. Signed-off-by: Pali Rohár --- fs/smb/client/reparse.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/fs/smb/client/reparse.c b/fs/smb/client/reparse.c index e3cf7ae516cb..35e8f2e18530 100644 --- a/fs/smb/client/reparse.c +++ b/fs/smb/client/reparse.c @@ -330,6 +330,18 @@ static int parse_reparse_posix(struct reparse_posix_data *buf, switch ((type = le64_to_cpu(buf->InodeType))) { case NFS_SPECFILE_LNK: + if (len == 0 || (len % 2)) { + cifs_dbg(VFS, "srv returned malformed nfs symlink buffer\n"); + return -EIO; + } + /* + * Check that buffer does not contain UTF-16 null codepoint + * because Linux cannot process symlink with null byte. + */ + if (UniStrnlen((wchar_t *)buf->DataBuffer, len/2) != len/2) { + cifs_dbg(VFS, "srv returned null byte in nfs symlink target location\n"); + return -EIO; + } data->symlink_target = cifs_strndup_from_utf16(buf->DataBuffer, len, true, cifs_sb->local_nls); @@ -340,8 +352,19 @@ static int parse_reparse_posix(struct reparse_posix_data *buf, break; case NFS_SPECFILE_CHR: case NFS_SPECFILE_BLK: + /* DataBuffer for block and char devices contains two 32-bit numbers */ + if (len != 8) { + cifs_dbg(VFS, "srv returned malformed nfs buffer for type: 0x%llx\n", type); + return -EIO; + } + break; case NFS_SPECFILE_FIFO: case NFS_SPECFILE_SOCK: + /* DataBuffer for fifos and sockets is empty */ + if (len != 0) { + cifs_dbg(VFS, "srv returned malformed nfs buffer for type: 0x%llx\n", type); + return -EIO; + } break; default: cifs_dbg(VFS, "%s: unhandled inode type: 0x%llx\n", From patchwork Sat Sep 28 21:59:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 1990532 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=jwXOp17E; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-cifs+bounces-2954-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XGLsL6CYPz1xt9 for ; Sun, 29 Sep 2024 08:01:58 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B35471C233BB for ; Sat, 28 Sep 2024 22:01:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7B48B18952C; Sat, 28 Sep 2024 22:00:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jwXOp17E" X-Original-To: linux-cifs@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52DCF189502; Sat, 28 Sep 2024 22:00:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727560850; cv=none; b=oy79w4V0LVyABm34SKnyg1DwR1ApwkZ81teg5GKbJbB0t+uCsclP5au/xt0tUjIvGNUkbLZ1z8OTYSaJF2LfCyAAe9p56z/DYRHJjCbq/jAh0KaRuWQ4hX2h26xTKXVsCKOYfB+gAmHBqr8en7o8eB0m2wUZMQfk7pkSFyZoka0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727560850; c=relaxed/simple; bh=Un5y3IwAsPJjjVsTLoX+SCgsvxWycXjRtC2sfJf3T0w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=jp4MnHOsdP2SlGDnsh1M1+DP3vn1/BNeD5jVX6nCuEZR7H/g37SpZV+FacUqIukOYoxwop/B4uY2gbOuYelImYFBD5m8LNcWJKMTqf3aJwxCupSlvagASreM6dU8sWcJXrr8FoMbQSWViqt1wzpe8yPxC4UC5+rv6ge5a7+v7Z0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jwXOp17E; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0045C4CECE; Sat, 28 Sep 2024 22:00:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727560850; bh=Un5y3IwAsPJjjVsTLoX+SCgsvxWycXjRtC2sfJf3T0w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jwXOp17EpF/sGoDvIDyxR9/p5sbUIzz13D5DJ0FXGqo8waEgwMy5pHjwsvS6Gg8GN 5tNpGLQsukYm18B97LrtLvEAYUhZdSl9nJ5ZnYdckqg/UPtlne+fELfKk1+9rJMzqC /MkrWLEWWnxmwi1wgTqQyh0rUzluQDWfM/9XlJCdNXeM0Z/+iA7Uzh2N57/QvGuSEz yqr2+K1MUpEEGGN8qZHn3dsNxw/oALrHPZkZrAb4yLvVoEbgTYZbKDjxpQ/Gh+YPwe bTUFZflfl1ZoVTdG/5fdx8Qp1vnUkxiC3cpmwU6KchHpSzhv/O56wz4OHTqFHBRQCP xUFkJE+RK4rHQ== Received: by pali.im (Postfix) id D9305CB5; Sun, 29 Sep 2024 00:00:41 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara , Ronnie Sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 8/8] cifs: Rename posix to nfs in parse_reparse_posix() and reparse_posix_data Date: Sat, 28 Sep 2024 23:59:48 +0200 Message-Id: <20240928215948.4494-9-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240928215948.4494-1-pali@kernel.org> References: <20240928215948.4494-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This function parses NFS-style reparse points, which are used only by Windows NFS server since Windows Server 2012 version. This style of special files is not understood by Microsoft POSIX / Interix / SFU / SUA subsystems. So make it clear that parse_reparse_posix() function and reparse_posix_data structure are not POSIX general, but rather NFS specific. Signed-off-by: Pali Rohár --- fs/smb/client/cifsglob.h | 2 +- fs/smb/client/cifspdu.h | 2 +- fs/smb/client/reparse.c | 14 +++++++------- fs/smb/client/reparse.h | 2 +- fs/smb/common/smb2pdu.h | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index 9eae8649f90c..119537e98f77 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -223,7 +223,7 @@ struct cifs_open_info_data { __u32 tag; union { struct reparse_data_buffer *buf; - struct reparse_posix_data *posix; + struct reparse_nfs_data *nfs; }; } reparse; struct { diff --git a/fs/smb/client/cifspdu.h b/fs/smb/client/cifspdu.h index c3b6263060b0..fefd7e5eb170 100644 --- a/fs/smb/client/cifspdu.h +++ b/fs/smb/client/cifspdu.h @@ -1506,7 +1506,7 @@ struct reparse_symlink_data { #define NFS_SPECFILE_BLK 0x00000000004B4C42 #define NFS_SPECFILE_FIFO 0x000000004F464946 #define NFS_SPECFILE_SOCK 0x000000004B434F53 -struct reparse_posix_data { +struct reparse_nfs_data { __le32 ReparseTag; __le16 ReparseDataLength; __u16 Reserved; diff --git a/fs/smb/client/reparse.c b/fs/smb/client/reparse.c index 35e8f2e18530..a23ea2f78c09 100644 --- a/fs/smb/client/reparse.c +++ b/fs/smb/client/reparse.c @@ -81,7 +81,7 @@ int smb2_create_reparse_symlink(const unsigned int xid, struct inode *inode, return rc; } -static int nfs_set_reparse_buf(struct reparse_posix_data *buf, +static int nfs_set_reparse_buf(struct reparse_nfs_data *buf, mode_t mode, dev_t dev, struct kvec *iov) { @@ -120,20 +120,20 @@ static int mknod_nfs(unsigned int xid, struct inode *inode, const char *full_path, umode_t mode, dev_t dev) { struct cifs_open_info_data data; - struct reparse_posix_data *p; + struct reparse_nfs_data *p; struct inode *new; struct kvec iov; __u8 buf[sizeof(*p) + sizeof(__le64)]; int rc; - p = (struct reparse_posix_data *)buf; + p = (struct reparse_nfs_data *)buf; rc = nfs_set_reparse_buf(p, mode, dev, &iov); if (rc) return rc; data = (struct cifs_open_info_data) { .reparse_point = true, - .reparse = { .tag = IO_REPARSE_TAG_NFS, .posix = p, }, + .reparse = { .tag = IO_REPARSE_TAG_NFS, .nfs = p, }, }; new = smb2_get_reparse_inode(&data, inode->i_sb, xid, @@ -313,7 +313,7 @@ int smb2_mknod_reparse(unsigned int xid, struct inode *inode, } /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */ -static int parse_reparse_posix(struct reparse_posix_data *buf, +static int parse_reparse_nfs(struct reparse_nfs_data *buf, struct cifs_sb_info *cifs_sb, struct cifs_open_info_data *data) { @@ -414,7 +414,7 @@ int parse_reparse_point(struct reparse_data_buffer *buf, /* See MS-FSCC 2.1.2 */ switch (le32_to_cpu(buf->ReparseTag)) { case IO_REPARSE_TAG_NFS: - return parse_reparse_posix((struct reparse_posix_data *)buf, + return parse_reparse_nfs((struct reparse_nfs_data *)buf, cifs_sb, data); case IO_REPARSE_TAG_SYMLINK: return parse_reparse_symlink( @@ -507,7 +507,7 @@ bool cifs_reparse_point_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr, struct cifs_open_info_data *data) { - struct reparse_posix_data *buf = data->reparse.posix; + struct reparse_nfs_data *buf = data->reparse.nfs; u32 tag = data->reparse.tag; if (tag == IO_REPARSE_TAG_NFS && buf) { diff --git a/fs/smb/client/reparse.h b/fs/smb/client/reparse.h index 5be54878265e..2a91f64de557 100644 --- a/fs/smb/client/reparse.h +++ b/fs/smb/client/reparse.h @@ -18,7 +18,7 @@ */ #define IO_REPARSE_TAG_INTERNAL ((__u32)~0U) -static inline dev_t reparse_nfs_mkdev(struct reparse_posix_data *buf) +static inline dev_t reparse_nfs_mkdev(struct reparse_nfs_data *buf) { u32 major, minor; diff --git a/fs/smb/common/smb2pdu.h b/fs/smb/common/smb2pdu.h index c769f9dbc0b4..0e77a4c0145a 100644 --- a/fs/smb/common/smb2pdu.h +++ b/fs/smb/common/smb2pdu.h @@ -1550,7 +1550,7 @@ struct reparse_symlink_data_buffer { __u8 PathBuffer[]; /* Variable Length */ } __packed; -/* See MS-FSCC 2.1.2.6 and cifspdu.h for struct reparse_posix_data */ +/* See MS-FSCC 2.1.2.6 and cifspdu.h for struct reparse_nfs_data */ struct validate_negotiate_info_req { __le32 Capabilities;