From patchwork Tue Dec 31 22:36:31 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: 13924013 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 EBA0C1B042A; Tue, 31 Dec 2024 22:37:09 +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=1735684630; cv=none; b=AAQkMxOBhdWHxSfrH/Ts9qyQvTwe1f4EMUo/TLgA+BcB/O47Mj3azqu8R9olMcxOwIKyIz8a3w41CuAaUCHtuh37D3dX8gy6Uw2RJuAewLVdig5iVj3SVNDmtut7iMhZqUkaJDb5nUsJY1uidey33Zi3UctM+QHzu+B03cuNqVM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735684630; c=relaxed/simple; bh=4j8MqoiJKVErbLBGKe6ycwnF4jbeDiBki/o5B+5xBO4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=gCnO/wzkucZvfW2Ahkp6eVxLXyxzsAXbBKzoVkN//RgzX5MrN1C+/aahZrrhzvNd+WvxzfOOjUDkW2l+L5o1LcUmvKcPrl2YWK+07ibYHKPNKeCVXuT0+aeKgGuoA2j2gjlLO3naWPWADl7O9+CAHX5sTz9pImuo5DAI6tarAqo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EMrwuBlk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EMrwuBlk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F64EC4CED2; Tue, 31 Dec 2024 22:37:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735684629; bh=4j8MqoiJKVErbLBGKe6ycwnF4jbeDiBki/o5B+5xBO4=; h=From:To:Cc:Subject:Date:From; b=EMrwuBlkUs53KWkw5ZY/N25QGTiRreQgy8C72PoXHOypLGKck2hT/B7bV1m7wyj2S wqiTMx23lHNpShcvhP8RYxAFQF3MUx4/SHa+5gXEr5iaIoJYdzL6/xG9LQ1WIhf0Qb 3bhmj/IReZiRkNFfzeL9+KkxgQD2+ZoM6mXN7AnHHNKEZT48NB4cLYBytTurExBKVN Oezb0KYplrSGTDBkO4X8CyHUhr3ewDXAcuqRqpLWfndXHVrURdfl80HjlH5nufiH8O GiFPRm30fyZF2xDP+m6TmbR18Fs5nXEURAr5qSSOz5YiaBGE8AdE0++z1J9mXCACWD lNa/Jj3tqnQcQ== Received: by pali.im (Postfix) id 4417997E; Tue, 31 Dec 2024 23:37:00 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 01/12] cifs: Fix struct FILE_ALL_INFO Date: Tue, 31 Dec 2024 23:36:31 +0100 Message-Id: <20241231223642.15722-1-pali@kernel.org> X-Mailer: git-send-email 2.39.5 Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 struct FILE_ALL_INFO for level 263 (0x107) used by QPathInfo does not have any IndexNumber, AccessFlags, IndexNumber1, CurrentByteOffset, Mode or AlignmentRequirement members. So remove all of them. Also adjust code in move_cifs_info_to_smb2() function which convers struct FILE_ALL_INFO to struct smb2_file_all_info. Fixed content of struct FILE_ALL_INFO was verified that is correct against: * [MS-CIFS] section 2.2.8.3.10 SMB_QUERY_FILE_ALL_INFO * Samba server implementation of trans2 query file/path for level 263 * Packet structure tests against Windows SMB servers This change fixes CIFSSMBQFileInfo() and CIFSSMBQPathInfo() functions which directly copy received FILE_ALL_INFO network buffers into kernel structures of FILE_ALL_INFO type. Signed-off-by: Pali Rohár --- fs/smb/client/cifsglob.h | 12 +++++++----- fs/smb/client/cifspdu.h | 6 ------ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index 1338b3473ef3..82e819f9d24e 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -2216,11 +2216,13 @@ static inline size_t ntlmssp_workstation_name_size(const struct cifs_ses *ses) static inline void move_cifs_info_to_smb2(struct smb2_file_all_info *dst, const FILE_ALL_INFO *src) { - memcpy(dst, src, (size_t)((u8 *)&src->AccessFlags - (u8 *)src)); - dst->AccessFlags = src->AccessFlags; - dst->CurrentByteOffset = src->CurrentByteOffset; - dst->Mode = src->Mode; - dst->AlignmentRequirement = src->AlignmentRequirement; + memcpy(dst, src, (size_t)((u8 *)&src->EASize - (u8 *)src)); + dst->IndexNumber = 0; + dst->EASize = src->EASize; + dst->AccessFlags = 0; + dst->CurrentByteOffset = 0; + dst->Mode = 0; + dst->AlignmentRequirement = 0; dst->FileNameLength = src->FileNameLength; } diff --git a/fs/smb/client/cifspdu.h b/fs/smb/client/cifspdu.h index 3ad1bb79ea9e..e5e397291da9 100644 --- a/fs/smb/client/cifspdu.h +++ b/fs/smb/client/cifspdu.h @@ -2294,13 +2294,7 @@ typedef struct { /* data block encoding of response to level 263 QPathInfo */ __u8 DeletePending; __u8 Directory; __u16 Pad2; - __le64 IndexNumber; __le32 EASize; - __le32 AccessFlags; - __u64 IndexNumber1; - __le64 CurrentByteOffset; - __le32 Mode; - __le32 AlignmentRequirement; __le32 FileNameLength; union { char __pad; From patchwork Tue Dec 31 22:36:32 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: 13924014 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 196261B2EFB; Tue, 31 Dec 2024 22:37:09 +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=1735684630; cv=none; b=OUJ2BEpnbEz2cO4e2kJtw6R4czZxFLZudpUNRVmJRUWRJm3+vsQWgII59JgYUYX/nzBqtYdWZzoEnAcdNb1omGY1s9q/LPoe6DflG0VVTtCYcSzlzC7tD6icjPTePHHPbuNer68gV06uUWM+4RlpgQ3KtQw2Q3cxFoH4JGw1aKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735684630; c=relaxed/simple; bh=6GSndX9vgk1Jj7hX2LSrDyaH6Z1T2mZF8OG3lq2E9Yo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=nW+19J1A/cCLOFCh2gOobRKQd+gdjE3dvEIzizo/czZKnPyYUazP5gvORMn/V5cqNORYnhfS8SKaTzTWi4+Q/bu7c4Tmw8nZhxDj0kIslHrKYkIx6RNeMNbLlEad8RZZ5qLPwG31+rUG6o8lXkbOAYDQFGUY7aKVPYY8459XlVw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q2/cBQpl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="q2/cBQpl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DDEFC4CED6; Tue, 31 Dec 2024 22:37:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735684629; bh=6GSndX9vgk1Jj7hX2LSrDyaH6Z1T2mZF8OG3lq2E9Yo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q2/cBQplPCrFqdBs0EfzoJG6/668qmnaEAwXcB9bRNo1hqv6aPp4aMlwUzGFhJX6/ EsZX01WBSYz11BQSodzhAifOGWlcbtKpVRzL7yLeex4alTck+m1EveWVnv9Bk6O15K iEqasx5NUFeVdG+1qDagHSwu1jzO5VWs3WYBNoVtVvW3ONH8hWS10Fdcebyp3SxJyi ewcbR80WU5uE0VVBMwp7jfwAkWH3Pqtfd1aPpr5gif51Z1FA4F7NvDlMgvEpipY6CV 5ayHUwnfo2DuyL0JDw4Xe60BcpDPdyd744IlW7aoX5gaL0sUqwQdRDfYV1nUjo5No+ kqniKm0hDKs0Q== Received: by pali.im (Postfix) id 601A6983; Tue, 31 Dec 2024 23:37:00 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 02/12] cifs: Fix calling CIFSFindFirst() for root path without msearch Date: Tue, 31 Dec 2024 23:36:32 +0100 Message-Id: <20241231223642.15722-2-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241231223642.15722-1-pali@kernel.org> References: <20241231223642.15722-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To query root path (without msearch wildcard) it is needed to send pattern "\" instead of "" (empty string). This allows to use CIFSFindFirst() to query information about root path. Signed-off-by: Pali Rohár --- fs/smb/client/cifssmb.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c index 604e204e3f57..7c42a0651138 100644 --- a/fs/smb/client/cifssmb.c +++ b/fs/smb/client/cifssmb.c @@ -4108,6 +4108,12 @@ CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, pSMB->FileName[name_len] = 0; pSMB->FileName[name_len+1] = 0; name_len += 2; + } else if (!searchName[0]) { + pSMB->FileName[0] = CIFS_DIR_SEP(cifs_sb); + pSMB->FileName[1] = 0; + pSMB->FileName[2] = 0; + pSMB->FileName[3] = 0; + name_len = 4; } } else { name_len = copy_path_name(pSMB->FileName, searchName); @@ -4119,6 +4125,10 @@ CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, pSMB->FileName[name_len] = '*'; pSMB->FileName[name_len+1] = 0; name_len += 2; + } else if (!searchName[0]) { + pSMB->FileName[0] = CIFS_DIR_SEP(cifs_sb); + pSMB->FileName[1] = 0; + name_len = 2; } } From patchwork Tue Dec 31 22:36:33 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: 13924016 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 1968B1B4124; Tue, 31 Dec 2024 22:37:09 +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=1735684630; cv=none; b=d2VP69XHeOh4+//tFeNLZgszrCAOFITEKPROMHNxIhrjOH3ZgcGSxfoYvCo0t1bFbY+CnRmKNpeML7QcvWIovl7D83rqyaQeu/nC4hjR2roDQfY+OWKoqt9W9B1pKuKK69ONscTfuwcJnBiOMbGcxgTxtTB0+A5xytJ1WUM1hIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735684630; c=relaxed/simple; bh=qeIuosm52zyCma7WnhBPMzKwH4sWBW0yo2xCyxH0MpI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=X2CTX0oKYJpO8761zojuSxiEFejufSzHKvZ4wdx3ZN2/ZyCGC51Elr//XYnkhlAIzbRGejJ2vk7NE4N1wl278cRn4JIYq5DJIAGwmhQc/Z8MLD3iq7y0OZxmG+1MqXJUq9Hp3bHaAQUKXSHiPHAfidtUXVCuO5oFNOu3PsW88oM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jQs/EV76; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jQs/EV76" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1D43C4CEDE; Tue, 31 Dec 2024 22:37:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735684629; bh=qeIuosm52zyCma7WnhBPMzKwH4sWBW0yo2xCyxH0MpI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jQs/EV76vlGzoTfAno8Y9kBSDzSQyzRpRNrxPhdQkFLVRXY0dzgigPMyp6FsuhOxF PZOMDf/bKhPlfsiz1C2dZUhsAtanccn5QWMnOABxQfTiStZEaLRJMCA7G0mbHMHt5K TLczRRsHvMnDeCuXIvJ93NQuWeSsbeN6NWQuDEVXoETG0guXpzvL3QM4NLnBJslFD9 fW1LgH/UWRmPCBlCAIs6knVvwujVekFjr2SYpNiLVuCoUy/V5GQBalsNV6BW7ziRKS SQwjjt5xtWVzDJIoLSvsNFXrflQoAUGr0sjSS1gYLMfb2HE/vJ2sO+1vMTu/Qk/7dm IibLmdzjWVucg== Received: by pali.im (Postfix) id 7C7B898C; Tue, 31 Dec 2024 23:37:00 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 03/12] cifs: Optimize CIFSFindFirst() response when not searching Date: Tue, 31 Dec 2024 23:36:33 +0100 Message-Id: <20241231223642.15722-3-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241231223642.15722-1-pali@kernel.org> References: <20241231223642.15722-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When not searching for child entries with msearch wildcard pattern then ask server just for one output entry. There is no need to ask for more entries as we are interested only for one search result, as we are doing query on path. Signed-off-by: Pali Rohár --- fs/smb/client/cifssmb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c index 7c42a0651138..c0dc404e27b3 100644 --- a/fs/smb/client/cifssmb.c +++ b/fs/smb/client/cifssmb.c @@ -4155,7 +4155,7 @@ CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, pSMB->SearchAttributes = cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY); - pSMB->SearchCount = cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO)); + pSMB->SearchCount = cpu_to_le16(msearch ? CIFSMaxBufSize/sizeof(FILE_UNIX_INFO) : 1); pSMB->SearchFlags = cpu_to_le16(search_flags); pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); From patchwork Tue Dec 31 22:36:34 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: 13924015 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 1694E1B043E; Tue, 31 Dec 2024 22:37:10 +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=1735684630; cv=none; b=t1kpUiy9vTbnjb19/PKELxsSFkkHJzIhxIqCO0UiuDWmGbratwtW3g7a0+Cda226+ixrEkpS/hWJrALj5StWNt+DiQuMAQurmt3BhbZsnzHI8wT4slx55toAgtjFByBqFe3otzaHIuoP0iEL5qgbFygsyjyo/4nXDn0zZu9ds9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735684630; c=relaxed/simple; bh=y8jvzkyAzxyNwmUGiUFU/ZrZFKeYb2sh7YIJFEf7HB8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=WVvrA2uW4zICrizETuB5PKsJW2ULZ8niF3ZuTC4Q3op9wsEKwq37Pp8hHFA4yht++gfUSQnVWmOD3ZG8CmYaGmHs3EhGlWC4xseQr7rZqNKasxjgU103O0b0YQDezVry6t+RozfHGSeUfEyKrRyoDahqY7oHkS9+knB/YsPTY5c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gLl/i9jq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gLl/i9jq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9E27C4CEDD; Tue, 31 Dec 2024 22:37:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735684630; bh=y8jvzkyAzxyNwmUGiUFU/ZrZFKeYb2sh7YIJFEf7HB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gLl/i9jqiCdV9ki4y6XNyFPjqjxl3quCZMB897JpN6RgNfze9zROc7VAelBNQ91YU M6GA+SZPLIzonllwazQcZHF49QaeOy8/sbjb1ursumBobX1KsLL5BkOZ2FcBMQ8xQ5 eO91dkSQxvBYuGVVfwiEsZi9d6DT3xSo6RDfopSx5JXxKDl67l3MD5auchQf8hb1Sv zTogvAqctOrxqIKYfkETtnQajw5q4oDDQrCWrYS6Ldi1A+Obx3gplOfkug/ktjIJsp n5nKOUnK35Jc1Hz888yP4mn4p4cSFRobsZH8fCBSWsyXJ6F+NiSXK7TRp2UZmhzEbq Bscp2iOUn+YmA== Received: by pali.im (Postfix) id 9698DC2E; Tue, 31 Dec 2024 23:37:00 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 04/12] cifs: Fix and improve cifs_is_path_accessible() function Date: Tue, 31 Dec 2024 23:36:34 +0100 Message-Id: <20241231223642.15722-4-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241231223642.15722-1-pali@kernel.org> References: <20241231223642.15722-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Do not call SMBQueryInformation() command for path with SMB wildcard characters on non-UNICODE connection because server expands wildcards. Function cifs_is_path_accessible() needs to check if the real path exists and must not expand wildcard characters. Do not dynamically allocate memory for small FILE_ALL_INFO structure and instead allocate it on the stack. This structure is allocated on stack by all other functions. When CAP_NT_SMBS was not negotiated then do not issue CIFSSMBQPathInfo() command. This command returns failure by non-NT Win9x SMB servers, so there is no need try it. The purpose of cifs_is_path_accessible() function is just to check if the path is accessible, so SMBQueryInformation() for old servers is enough. Signed-off-by: Pali Rohár --- fs/smb/client/smb1ops.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/fs/smb/client/smb1ops.c b/fs/smb/client/smb1ops.c index d959097ec2d2..bef8e03edf1d 100644 --- a/fs/smb/client/smb1ops.c +++ b/fs/smb/client/smb1ops.c @@ -520,21 +520,27 @@ static int cifs_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, struct cifs_sb_info *cifs_sb, const char *full_path) { - int rc; - FILE_ALL_INFO *file_info; + int rc = -EOPNOTSUPP; + FILE_ALL_INFO file_info; - file_info = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); - if (file_info == NULL) - return -ENOMEM; + if (tcon->ses->capabilities & CAP_NT_SMBS) + rc = CIFSSMBQPathInfo(xid, tcon, full_path, &file_info, + 0 /* not legacy */, cifs_sb->local_nls, + cifs_remap(cifs_sb)); - rc = CIFSSMBQPathInfo(xid, tcon, full_path, file_info, - 0 /* not legacy */, cifs_sb->local_nls, - cifs_remap(cifs_sb)); + /* + * Non-UNICODE variant of fallback functions below expands wildcards, + * so they cannot be used for querying paths with wildcard characters. + * Therefore for such paths returns -ENOENT as they cannot exist. + */ + if ((rc == -EOPNOTSUPP || rc == -EINVAL) && + !(tcon->ses->capabilities & CAP_UNICODE) && + strpbrk(full_path, "*?\"><")) + rc = -ENOENT; if (rc == -EOPNOTSUPP || rc == -EINVAL) - rc = SMBQueryInformation(xid, tcon, full_path, file_info, + rc = SMBQueryInformation(xid, tcon, full_path, &file_info, cifs_sb->local_nls, cifs_remap(cifs_sb)); - kfree(file_info); return rc; } From patchwork Tue Dec 31 22:36:35 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: 13924017 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 32DDF1B422D; Tue, 31 Dec 2024 22:37:10 +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=1735684630; cv=none; b=JiXNYzPd0Tnm1YyX/lPiKaqypk6j4aPdKI2JPCAZjJjk9coIRHFEXThnovKs/S2EcIYNkWB7d+DWUAPh3eycE4D8/uoXP2kPPNeX6HF9Rl4ayw5ObVgNzBgPuZHui1D2oC/pxnxGhYV0vfOXLId9julOWxO9WyEvKiaki7d7UKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735684630; c=relaxed/simple; bh=l0Utkx3SUgSbQuWV7cfRUZJv8R3Vj8FAI5oHLPywygY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=GAyWC+pV3gpE1oBzYYYZE+pl7DLwlKdQEEKCy5XV9K/IkF5Ijr2v4wAmqPtNisylBBBu2VK1F8IwZyqEbvRJo+p7bv/m4J/eFRXdAQHl+xHM7YyAIe3+ja8Q8UZ6mIWC7ZOy8R8aIbVl1ofFsOqEE/7DDxkl3vFpJ72fcU9Mwrk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=A0yE85i/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="A0yE85i/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E468DC4CEE0; Tue, 31 Dec 2024 22:37:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735684630; bh=l0Utkx3SUgSbQuWV7cfRUZJv8R3Vj8FAI5oHLPywygY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A0yE85i/RvaaJAxHnFBCGmrxcKnFJNcFhELP6Ae76/iJDqUZZbjDekzVqxN7Mx+/1 qu2+C41k+xmHCYop8/lYXRLYdMCVY6Z8WYebKEbRiRmiBaulb7PhOv5047D4yhtTuh MtP7Q0zNIoFGdnxYmGrUVmuYa5ebt4GSOw9AAx7mb/4AjHqXemNwRai/ierquTUUjR y//F57uouLfXpahJMwxgqwAtJqnYH9S+owQ7RESG0mim7FgFP0SmgV4ldPv4HkCvC1 xsevuaWQ5pp8dZNXMrrrTmT4DUgQsJrWPnqdwS+H2YoUiYllYBh2abJTGn1C5ZPLca mEXeRHBKGz/1Q== Received: by pali.im (Postfix) id B1BE2D12; Tue, 31 Dec 2024 23:37:00 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/12] cifs: Fix cifs_query_path_info() for Windows NT servers Date: Tue, 31 Dec 2024 23:36:35 +0100 Message-Id: <20241231223642.15722-5-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241231223642.15722-1-pali@kernel.org> References: <20241231223642.15722-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For TRANS2 QUERY_PATH_INFO request when the path does not exist, the Windows NT SMB server returns error response STATUS_OBJECT_NAME_NOT_FOUND or ERRDOS/ERRbadfile without the SMBFLG_RESPONSE flag set. Similarly it returns STATUS_DELETE_PENDING when the file is being deleted. And looks like that any error response from TRANS2 QUERY_PATH_INFO does not have SMBFLG_RESPONSE flag set. So relax check in check_smb_hdr() for detecting if the packet is response for this special case. This change fixes stat() operation against Windows NT SMB servers and also all operations which depends on -ENOENT result from stat like creat() or mkdir(). Signed-off-by: Pali Rohár --- fs/smb/client/misc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/smb/client/misc.c b/fs/smb/client/misc.c index 4373dd64b66d..5122f3895dfc 100644 --- a/fs/smb/client/misc.c +++ b/fs/smb/client/misc.c @@ -323,6 +323,14 @@ check_smb_hdr(struct smb_hdr *smb) if (smb->Command == SMB_COM_LOCKING_ANDX) return 0; + /* + * Windows NT server returns error resposne (e.g. STATUS_DELETE_PENDING + * or STATUS_OBJECT_NAME_NOT_FOUND or ERRDOS/ERRbadfile or any other) + * for some TRANS2 requests without the RESPONSE flag set in header. + */ + if (smb->Command == SMB_COM_TRANSACTION2 && smb->Status.CifsError != 0) + return 0; + cifs_dbg(VFS, "Server sent request, not response. mid=%u\n", get_mid(smb)); return 1; From patchwork Tue Dec 31 22:36:36 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: 13924019 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 783461B4255; Tue, 31 Dec 2024 22:37:10 +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=1735684630; cv=none; b=Mvi0wH50/WbmnGD6c/Ott98axeyOT+tfpiYowmv/eIGX4ECLWfrXiJ0TXf0/x0oM5ZDRgkM8fDIZT7SU7WWggkUJP0qxE1J91/68+98saJjkMC5ZdiP8ecJ6qR5jN1Iz1DWy8EBYt/DYPxKZGjlqFdetVwmYu8st3QivUF7PwWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735684630; c=relaxed/simple; bh=y3q03x/1wYXPLpES29JXGvd1CgnID6pdqYEhdHdHFEg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=F9f+nxQ8CY0WRqDj/qTtWuStNJOX3oPlRmH6U+/21J9l72We/VOPXAV2ZILGqQLOhH6j3NG+tIGPnuKBS6tzAhP9KUGSS1UmgF0PQqweNegg+Q/ngq7if0tuuaGh1wjhhT1QQPtnSuA5Dfd5d6UUsYKzA1AlocXbnqXJ4psAHdY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BAjFNHKw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BAjFNHKw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B1DAC4CEDF; Tue, 31 Dec 2024 22:37:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735684630; bh=y3q03x/1wYXPLpES29JXGvd1CgnID6pdqYEhdHdHFEg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BAjFNHKwnGT6n9+0o7j1I6iWXPV6xEC95hmgj+UokQnjilwxdUauG3wujjE9gM7A5 TGo9J1826M8YXwOHfXZ02uBbvFKxXipUTbI5QK8vQaOQUNNmKUD19L6XmMpYGZrnb4 QZQSBaGqjAsCZJq+Sw310YMZQZMDWxMBk1BO7kMDsIbJgmy+7f/8S1Q9gDzn3kyz9n z3fJ+f6DdFA4A1KyN1Tw9thLv3G7WueA49WIvfLjiolPFh9k08ugB/Ar5iI7vMmmWT YVaYfCEJJIpgw7XlKGwwPHrvD/QNZ3BM01/WbfnrXReQUwrBFnBUOK9dNkl2AfApOU zxjLVfP8AQPdA== Received: by pali.im (Postfix) id CC66CDB3; Tue, 31 Dec 2024 23:37:00 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/12] cifs: Fix and improve cifs_query_path_info() and cifs_query_file_info() Date: Tue, 31 Dec 2024 23:36:36 +0100 Message-Id: <20241231223642.15722-6-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241231223642.15722-1-pali@kernel.org> References: <20241231223642.15722-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When CAP_NT_SMBS was not negotiated then do not issue CIFSSMBQPathInfo() and CIFSSMBQFileInfo() commands. CIFSSMBQPathInfo() is not supported by non-NT Win9x SMB server and CIFSSMBQFileInfo() returns from Win9x SMB server bogus data in Attributes field (for example lot of files are marked as reparse points, even Win9x does not support them and read-only bit is not marked for read-only files). Correct information is returned by CIFSFindFirst() or SMBQueryInformation() command. So as a fallack in cifs_query_path_info() function use CIFSFindFirst() with SMB_FIND_FILE_FULL_DIRECTORY_INFO level which is supported by both NT and non-NT servers and as a last option use SMBQueryInformation() as it was before. And in function cifs_query_file_info() immediately returns -EOPNOTSUPP when not communicating with NT server. Client then revalidate inode entry by the cifs_query_path_info() call, which is working fine. So fstat() syscall on already opened file will receive correct information. Note that both fallback functions in non-UNICODE mode expands wildcards. Therefore those fallback functions cannot be used on paths which contain SMB wildcard characters (* ? " > <). CIFSFindFirst() returns all 4 time attributes as opposite of SMBQueryInformation() which returns only one. With this change it is possible to query all 4 times attributes from Win9x server and at the same time, client minimize sending of unsupported commands to server. Signed-off-by: Pali Rohár --- fs/smb/client/smb1ops.c | 78 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 7 deletions(-) diff --git a/fs/smb/client/smb1ops.c b/fs/smb/client/smb1ops.c index bef8e03edf1d..b0813106df16 100644 --- a/fs/smb/client/smb1ops.c +++ b/fs/smb/client/smb1ops.c @@ -550,19 +550,76 @@ static int cifs_query_path_info(const unsigned int xid, const char *full_path, struct cifs_open_info_data *data) { - int rc; + int rc = -EOPNOTSUPP; FILE_ALL_INFO fi = {}; + FILE_FULL_DIRECTORY_INFO *di; + struct cifs_search_info search_info = {}; data->reparse_point = false; data->adjust_tz = false; - /* could do find first instead but this returns more info */ - rc = CIFSSMBQPathInfo(xid, tcon, full_path, &fi, 0 /* not legacy */, cifs_sb->local_nls, - cifs_remap(cifs_sb)); /* - * BB optimize code so we do not make the above call when server claims - * no NT SMB support and the above call failed at least once - set flag - * in tcon or mount. + * First try CIFSSMBQPathInfo() function which returns more info + * (NumberOfLinks) than CIFSFindFirst() fallback function. + * Some servers like Win9x do not support SMB_QUERY_FILE_ALL_INFO over + * TRANS2_QUERY_PATH_INFORMATION, but supports it with filehandle over + * TRANS2_QUERY_FILE_INFORMATION (function CIFSSMBQFileInfo(). But SMB + * Open command on non-NT servers works only for files, does not work + * for directories. And moreover Win9x SMB server returns bogus data in + * SMB_QUERY_FILE_ALL_INFO Attributes field. So for non-NT servers, + * do not even use CIFSSMBQPathInfo() or CIFSSMBQFileInfo() function. + */ + if (tcon->ses->capabilities & CAP_NT_SMBS) + rc = CIFSSMBQPathInfo(xid, tcon, full_path, &fi, 0 /* not legacy */, + cifs_sb->local_nls, cifs_remap(cifs_sb)); + + /* + * Non-UNICODE variant of fallback functions below expands wildcards, + * so they cannot be used for querying paths with wildcard characters. + * Therefore for such paths returns -ENOENT as they cannot exist. + */ + if ((rc == -EOPNOTSUPP || rc == -EINVAL) && + !(tcon->ses->capabilities & CAP_UNICODE) && + strpbrk(full_path, "*?\"><")) + rc = -ENOENT; + + /* + * Then fallback to CIFSFindFirst() which works also with non-NT servers + * but does not does not provide NumberOfLinks. + */ + if (rc == -EOPNOTSUPP || rc == -EINVAL) { + search_info.info_level = SMB_FIND_FILE_FULL_DIRECTORY_INFO; + rc = CIFSFindFirst(xid, tcon, full_path, cifs_sb, NULL, + CIFS_SEARCH_CLOSE_ALWAYS | CIFS_SEARCH_CLOSE_AT_END, + &search_info, false); + if (rc == 0) { + di = (FILE_FULL_DIRECTORY_INFO *)search_info.srch_entries_start; + fi.CreationTime = di->CreationTime; + fi.LastAccessTime = di->LastAccessTime; + fi.LastWriteTime = di->LastWriteTime; + fi.ChangeTime = di->ChangeTime; + fi.Attributes = di->ExtFileAttributes; + fi.AllocationSize = di->AllocationSize; + fi.EndOfFile = di->EndOfFile; + fi.EASize = di->EaSize; + fi.NumberOfLinks = cpu_to_le32(1); + fi.DeletePending = 0; + fi.Directory = !!(le32_to_cpu(di->ExtFileAttributes) & ATTR_DIRECTORY); + cifs_buf_release(search_info.ntwrk_buf_start); + } else if (!full_path[0]) { + /* + * CIFSFindFirst() does not work on root path if the + * root path was exported on the server from the top + * level path (drive letter). + */ + rc = -EOPNOTSUPP; + } + } + + /* + * If everything failed then fallback to the legacy SMB command + * SMB_COM_QUERY_INFORMATION which works with all servers, but + * provide just few information. */ if ((rc == -EOPNOTSUPP) || (rc == -EINVAL)) { rc = SMBQueryInformation(xid, tcon, full_path, &fi, cifs_sb->local_nls, @@ -646,6 +703,13 @@ static int cifs_query_file_info(const unsigned int xid, struct cifs_tcon *tcon, int rc; FILE_ALL_INFO fi = {}; + /* + * CIFSSMBQFileInfo() for non-NT servers returns bogus data in + * Attributes fields. So do not use this command for non-NT servers. + */ + if (!(tcon->ses->capabilities & CAP_NT_SMBS)) + return -EOPNOTSUPP; + if (cfile->symlink_target) { data->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL); if (!data->symlink_target) From patchwork Tue Dec 31 22:36:37 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: 13924018 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 68DE81B4254; Tue, 31 Dec 2024 22:37:10 +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=1735684630; cv=none; b=IzU2L7/N1CbO0UN5EY66MoKCTMv1j0XnXRiQ5nyoVTjoGdsU+C9GTX956ea1uX0q5gs0PBlkNDWXYMqYsyzHuRHPslB10XvAz7qWGyqUWZzMfzVI2Z9h3m+Yx3RLAmSH7IYAun8+W/3nhek29FOyCpEngAMOS+U3NqLxz8yJy40= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735684630; c=relaxed/simple; bh=Izf59NF6S5+Ds6OjDjX0Gn5vu0iX6iBS0DYB3Ez1QhA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=II6xxh15R3onfQ/wRYtPHpYf7G1kkhBxdi1CeqEO8xeI4DblRaEYNq7DEAIwBS4jS6Xs+3ZdxprRJWHhOi9o+eHRzkglYYF2LaJMuu6/JzOIEj/TJR88uiRrHHMlMIx2mBHizOx0V15n0GSovfUs2mPWZc44SEeYN4WOghFW5cs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZQJfG1c6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZQJfG1c6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26D89C4CED2; Tue, 31 Dec 2024 22:37:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735684630; bh=Izf59NF6S5+Ds6OjDjX0Gn5vu0iX6iBS0DYB3Ez1QhA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZQJfG1c6/Jw0ryuZ4GTzdWbDmGZt+kHUAr5wx1wUa1INPKf/Riy8Ox3V5NuOdRJLH 1vL0RLhzW6bF7/lrS9dB1dzUua02azsJcxN8AlsGhAyigSURQzMK4bJubULijJG4IR R9zD1ggQ8zqffnjtiPN0GkscluPJ0QvAKxsmEkFKAs60zEXcCA5yf7oSXiyDRz/ux9 OprCCxhm5yiJNzjFpbWUpmpjh+L64TRsqTKgCMNoiMTTIYUZeAM7t1xHQ/zNbznRhH xKJV8EVYK6Wrvu1yJ7EYID6eit4Eq33K0uSsxcnHXmLil+reZl8KJlRvM+4WtAmYB1 K/WwT2Z/lxi4g== Received: by pali.im (Postfix) id EDA52EEC; Tue, 31 Dec 2024 23:37:00 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 07/12] cifs: Improve SMB1 stat() to work also for paths in DELETE_PENDING state Date: Tue, 31 Dec 2024 23:36:37 +0100 Message-Id: <20241231223642.15722-7-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241231223642.15722-1-pali@kernel.org> References: <20241231223642.15722-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Windows NT SMB server may return -EBUSY (STATUS_DELETE_PENDING) from CIFSSMBQPathInfo() function for files which are in DELETE_PENDING state. When this happens, it is still possible to use CIFSFindFirst() fallback. So allow to use CIFSFindFirst() fallback also for -EBUSY error. This change fixed stat() to work also against Windows Server 2022 for files in DELETE_PENDING state. Signed-off-by: Pali Rohár --- fs/smb/client/smb1ops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/smb/client/smb1ops.c b/fs/smb/client/smb1ops.c index b0813106df16..a7a846260736 100644 --- a/fs/smb/client/smb1ops.c +++ b/fs/smb/client/smb1ops.c @@ -578,7 +578,7 @@ static int cifs_query_path_info(const unsigned int xid, * so they cannot be used for querying paths with wildcard characters. * Therefore for such paths returns -ENOENT as they cannot exist. */ - if ((rc == -EOPNOTSUPP || rc == -EINVAL) && + if ((rc == -EOPNOTSUPP || rc == -EINVAL || rc == -EBUSY) && !(tcon->ses->capabilities & CAP_UNICODE) && strpbrk(full_path, "*?\"><")) rc = -ENOENT; @@ -587,7 +587,7 @@ static int cifs_query_path_info(const unsigned int xid, * Then fallback to CIFSFindFirst() which works also with non-NT servers * but does not does not provide NumberOfLinks. */ - if (rc == -EOPNOTSUPP || rc == -EINVAL) { + if (rc == -EOPNOTSUPP || rc == -EINVAL || rc == -EBUSY) { search_info.info_level = SMB_FIND_FILE_FULL_DIRECTORY_INFO; rc = CIFSFindFirst(xid, tcon, full_path, cifs_sb, NULL, CIFS_SEARCH_CLOSE_ALWAYS | CIFS_SEARCH_CLOSE_AT_END, From patchwork Tue Dec 31 22:36:38 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: 13924023 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 8112E1BD9DB; Tue, 31 Dec 2024 22:37:12 +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=1735684632; cv=none; b=o8+vPoro4acwpagW5R7vmzN61iSAjJSLTpOCgOtQMs0FEfG8CreNw46h1GGVmA1uEqqjO+Gpd0HO+Qx9MnJX1/yZPCNsu59EsPnrQ6eh1Hthz9pTjHR5JSY0SzkiwoeYEevKfmSyo5xCtRFcKR+pC8sywtaTZAXfARWaLvmLSG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735684632; c=relaxed/simple; bh=UWkpvBOsLVGSoGQCgId4dC2bh1SGJftMfZdSlT04PQs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=XCo6DBr4lfIwnfK+lHlcyUS2KKpzZKHKO05d87ivIFZieiE1/p6lnxblvf4rCeRn2MK/Ll+rZKBYeu+M6tSIgia6Prdi5IO944DFJeVSUrXCkIp4B24WXTEv7aLRgODbyNmXk1weVhvbfLVXby69ucA04uTd6E+OT63IE5ckoXE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=I+YvGGSk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="I+YvGGSk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0803BC4CEEA; Tue, 31 Dec 2024 22:37:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735684632; bh=UWkpvBOsLVGSoGQCgId4dC2bh1SGJftMfZdSlT04PQs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I+YvGGSkwXwkJjiUAgC2Fcsg0pQ//iulHTwTma6kfNmyZZbP6bOTNWjycpEocav0N bH2UhCCIR3xtPJeBuikpGUSTS7aSz8sMPU166GnLco/0mFxhMiJDD4Rt+QdViXd/WE OiQsu2ZiktGeMv09WXsM1ugIcPx6p87Q+RZFyj+lRnTsmnL0WT9e4sBP76gTUu3b9B PqhDzx9NXLZ4reg1YnIiSfYnB0tAVoRorUHKYk6mTMj/xcIYlHDFK0hfX8KVgLykAS zzQAQrdSkQfPBLD2LvGfe9gIkhE0G033wo07/1+WvDKe0wuOaIknPxfsgoWV8gSuqq W2gjJJbxGuR5A== Received: by pali.im (Postfix) id 23F19F3C; Tue, 31 Dec 2024 23:37:01 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/12] cifs: Remove code for querying FILE_INFO_STANDARD via CIFSSMBQPathInfo() Date: Tue, 31 Dec 2024 23:36:38 +0100 Message-Id: <20241231223642.15722-8-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241231223642.15722-1-pali@kernel.org> References: <20241231223642.15722-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Querying FILE_INFO_STANDARD structure via SMB_QUERY_FILE_ALL_INFO level over TRANS2_QUERY_PATH_INFORMATION or TRANS2_QUERY_FILE_INFORMATION command (implemented in CIFSSMBQPathInfo() when called with argument legacy=true) is mostly unusable. Win9x SMB server returns over those commands the FILE_INFO_STANDARD structure with swapped TIME and DATE fields, compared with [MS-CIFS] spec and Samba server implementation. Therefore this command cannot be used unless we know against which server implementation we are connected. There are already two fallback mechanisms for querying information about path which are working correctly against Samba, NT and Win9x servers: CIFSFindFirst() and SMBQueryInformation() commands. So remove TRANS2_QUERY_PATH_INFORMATION/SMB_QUERY_FILE_ALL_INFO code from CIFSSMBQPathInfo() function, when the function is called with legacy=true. Note that there is no use of CIFSSMBQPathInfo(legacy=true) anymore. Signed-off-by: Pali Rohár --- fs/smb/client/cifsproto.h | 1 - fs/smb/client/cifssmb.c | 22 +++------------------- fs/smb/client/smb1ops.c | 4 ++-- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/fs/smb/client/cifsproto.h b/fs/smb/client/cifsproto.h index ea8a0ecce9dc..52548238b467 100644 --- a/fs/smb/client/cifsproto.h +++ b/fs/smb/client/cifsproto.h @@ -351,7 +351,6 @@ extern int CIFSSMBQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, u16 netfid, FILE_ALL_INFO *pFindData); extern int CIFSSMBQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, const char *search_Name, FILE_ALL_INFO *data, - int legacy /* whether to use old info level */, const struct nls_table *nls_codepage, int remap); extern int SMBQueryInformation(const unsigned int xid, struct cifs_tcon *tcon, const char *search_name, FILE_ALL_INFO *data, diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c index c0dc404e27b3..c88b6ea7c00a 100644 --- a/fs/smb/client/cifssmb.c +++ b/fs/smb/client/cifssmb.c @@ -3816,7 +3816,6 @@ CIFSSMBQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, int CIFSSMBQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, const char *search_name, FILE_ALL_INFO *data, - int legacy /* old style infolevel */, const struct nls_table *nls_codepage, int remap) { /* level 263 SMB_QUERY_FILE_ALL_INFO */ @@ -3864,10 +3863,7 @@ CIFSSMBQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, byte_count = params + 1 /* pad */ ; pSMB->TotalParameterCount = cpu_to_le16(params); pSMB->ParameterCount = pSMB->TotalParameterCount; - if (legacy) - pSMB->InformationLevel = cpu_to_le16(SMB_INFO_STANDARD); - else - pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); + pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); pSMB->Reserved4 = 0; inc_rfc1001_len(pSMB, byte_count); pSMB->ByteCount = cpu_to_le16(byte_count); @@ -3881,25 +3877,13 @@ CIFSSMBQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, if (rc) /* BB add auto retry on EOPNOTSUPP? */ rc = -EIO; - else if (!legacy && get_bcc(&pSMBr->hdr) < 40) + else if (get_bcc(&pSMBr->hdr) < 40) rc = -EIO; /* bad smb */ - else if (legacy && get_bcc(&pSMBr->hdr) < 24) - rc = -EIO; /* 24 or 26 expected but we do not read - last field */ else if (data) { int size; __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); - /* - * On legacy responses we do not read the last field, - * EAsize, fortunately since it varies by subdialect and - * also note it differs on Set vs Get, ie two bytes or 4 - * bytes depending but we don't care here. - */ - if (legacy) - size = sizeof(FILE_INFO_STANDARD); - else - size = sizeof(FILE_ALL_INFO); + size = sizeof(FILE_ALL_INFO); memcpy((char *) data, (char *) &pSMBr->hdr.Protocol + data_offset, size); } else diff --git a/fs/smb/client/smb1ops.c b/fs/smb/client/smb1ops.c index a7a846260736..49b5b75ef2f0 100644 --- a/fs/smb/client/smb1ops.c +++ b/fs/smb/client/smb1ops.c @@ -525,7 +525,7 @@ cifs_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, if (tcon->ses->capabilities & CAP_NT_SMBS) rc = CIFSSMBQPathInfo(xid, tcon, full_path, &file_info, - 0 /* not legacy */, cifs_sb->local_nls, + cifs_sb->local_nls, cifs_remap(cifs_sb)); /* @@ -570,7 +570,7 @@ static int cifs_query_path_info(const unsigned int xid, * do not even use CIFSSMBQPathInfo() or CIFSSMBQFileInfo() function. */ if (tcon->ses->capabilities & CAP_NT_SMBS) - rc = CIFSSMBQPathInfo(xid, tcon, full_path, &fi, 0 /* not legacy */, + rc = CIFSSMBQPathInfo(xid, tcon, full_path, &fi, cifs_sb->local_nls, cifs_remap(cifs_sb)); /* From patchwork Tue Dec 31 22:36:39 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: 13924021 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 B8CD01B87C7; Tue, 31 Dec 2024 22:37:10 +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=1735684630; cv=none; b=n5TFrwkGhcXZAonomYNxoHyt9YQCg3PGcJW8dmly7GmytAa1Xg+JkKxF/0ZwN4Z9oLNQfBJt+8TDf/Ve/NOaI7faK1vSRtcAsGhb3w7apXZ+m/vZ9VizYJ3D58WlrstAgj1O6RCNyxWoFtFtjrCROLsBLP2t9JyC573aTpj2AnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735684630; c=relaxed/simple; bh=+arv5vFxEsgoW/DEZyE6e9Vi4gLHCwC1jHGKqTG9YkE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=tWcJ5mwVWGrmBaCxV7H0eywB37UzQTXAGA0YYfhpBaw9SdVOYgMbmXiiTnhmGvejL08yziWLdvHzCYKS1M3+4BXKrjuiXcQS5HsYUSIQLdgOpgDz7znEVIqRavo14ZFm7kbM0tivixpcKOLvqCLUvHPNVG7IzimQKqVKahln0Ig= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=t+FL1HtE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="t+FL1HtE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39EAFC4CEE1; Tue, 31 Dec 2024 22:37:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735684630; bh=+arv5vFxEsgoW/DEZyE6e9Vi4gLHCwC1jHGKqTG9YkE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t+FL1HtEDaYCPPgqIqWlYr7CepO7wLCFicZTs/FJcFlF9cj7gZYkZlS/wFTXuXnKK RFiatERlF7TrkLtWqtxuTPi01nNt4/NX2HY470XyBc6mRkTnSO9HQbS7TepbGqnxo+ XJzXCPmvcbKK4dpwIChh/usgj2EUpO7gC+B12vwAUJuSw9LefCDQ+YGitbED1pEqmk kMTQpBWAmNmnvhmjNyQXhIn2hyPXWlDUXYfPQ5u2D+zDhCbumb7ecS6d1IXczEIGgA BXiwdZ6KVMU3uVWDA4WdK6DdVziKJlwE2/oKtCnhEWiGR65PBUX/iIFx0NUHp6W82c A6pI/u/iPnN1w== Received: by pali.im (Postfix) id 43DDAFE0; Tue, 31 Dec 2024 23:37:01 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 09/12] cifs: Allow fallback code in smb_set_file_info() also for directories Date: Tue, 31 Dec 2024 23:36:39 +0100 Message-Id: <20241231223642.15722-9-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241231223642.15722-1-pali@kernel.org> References: <20241231223642.15722-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On NT systems, it is possible to do SMB open call also for directories. Open argument CREATE_NOT_DIR disallows opening directories. So in fallback code path in smb_set_file_info() remove CREATE_NOT_DIR restriction to allow it also for directories. Similar fallback is implemented also in CIFSSMBSetPathInfoFB() function and this function already allows to call operation for directories. Signed-off-by: Pali Rohár --- fs/smb/client/smb1ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/smb/client/smb1ops.c b/fs/smb/client/smb1ops.c index 49b5b75ef2f0..62f4e1081ea4 100644 --- a/fs/smb/client/smb1ops.c +++ b/fs/smb/client/smb1ops.c @@ -915,7 +915,7 @@ smb_set_file_info(struct inode *inode, const char *full_path, .tcon = tcon, .cifs_sb = cifs_sb, .desired_access = SYNCHRONIZE | FILE_WRITE_ATTRIBUTES, - .create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR), + .create_options = cifs_create_options(cifs_sb, 0), .disposition = FILE_OPEN, .path = full_path, .fid = &fid, From patchwork Tue Dec 31 22:36:40 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: 13924022 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 44F851BBBCF; Tue, 31 Dec 2024 22:37:10 +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=1735684631; cv=none; b=HJvuroVaVHoiQn545ctUhw4e+F/9qLD+vks2njZDadZQ7RkH43Rxm+t4wHZg2Ujie9x6QFwuN/komgBrkIOnX0QyVTE6LNY/WnKIEsdO3d6MXEEMRtP/Ja/0pSdUvUZXN/XJ7pyOR6c9zEqZZSZAg4UfAHHutYDQbuk92ftIBJ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735684631; c=relaxed/simple; bh=VimoVENOUBFL/5bnOr+RfSKO38jU5jUbWV+P+r08x6c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=qGDjP8mWhHUFfGs6mlT69TUlglywgllXUzgrEUHuQ9mlx2YuI7/BPCi4v53fJNZ1WJuIAXtcmapB0BW31Qkm0ZZNdoAlfFNE4Y1y+Qam6uBg9uk8lKh4CGVQkvFdg0msMrOzXZFk1KNKHmcPHcGNMqEw/pksDtzVKyAol+23i9I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=d2pSfzxk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="d2pSfzxk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66247C4CED6; Tue, 31 Dec 2024 22:37:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735684630; bh=VimoVENOUBFL/5bnOr+RfSKO38jU5jUbWV+P+r08x6c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d2pSfzxkFodd2bAZx30BgeeTpKY4htg38wOHvXyKtvvPTCqaTztO6SiC4VN4vj1Sl Ypj74gtcdCywZVqaMYcqFXyBSEO3hhXT1ZbVXGk1wz09ZzPeiPmg4awLjGaNjiap1t NezH1Qs+f5yuXmWh8fXDzDCb59Ydj1HLLqQbbpYmSPoSHw4rkBxKe77yQZuG5ZeihG O0s70DsFq80/FLXRRkrN9v2Bm/6lLNhJZlebtSXRLeyH5ewXzsyci1F7blqYit7Ksv hUqTGhhoY3zRKYiVMtHmakDSBu/m4eQBcRn9WpvhNRg4w95HHOrC/8R9RV5qio77d8 0swXDDrZ19rJQ== Received: by pali.im (Postfix) id 62E53FE3; Tue, 31 Dec 2024 23:37:01 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 10/12] cifs: Fix changing times and read-only attr over SMB1 smb_set_file_info() function Date: Tue, 31 Dec 2024 23:36:40 +0100 Message-Id: <20241231223642.15722-10-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241231223642.15722-1-pali@kernel.org> References: <20241231223642.15722-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Function CIFSSMBSetPathInfo() is not supported by non-NT servers and returns error. Fallback code via open filehandle and CIFSSMBSetFileInfo() does not work neither because CIFS_open() works also only on NT server. Therefore currently the whole smb_set_file_info() function as a SMB1 callback for the ->set_file_info() does not work with older non-NT SMB servers, like Win9x and others. This change implements fallback code in smb_set_file_info() which will works with any server and allows to change time values and also to set or clear read-only attributes. To make existing fallback code via CIFSSMBSetFileInfo() working with also non-NT servers, it is needed to change open function from CIFS_open() (which is NT specific) to cifs_open_file() which works with any server (this is just a open wrapper function which choose the correct open function supported by the server). CIFSSMBSetFileInfo() is working also on non-NT servers, but zero time values are not treated specially. So first it is needed to fill all time values if some of them are missing, via cifs_query_path_info() call. There is another issue, opening file in write-mode (needed for changing attributes) is not possible when the file has read-only attribute set. The only option how to clear read-only attribute is via SMB_COM_SETATTR command. And opening directory is not possible neither and here the SMB_COM_SETATTR command is the only option how to change attributes. And CIFSSMBSetFileInfo() does not honor setting read-only attribute, so for setting is also needed to use SMB_COM_SETATTR command. Existing code in cifs_query_path_info() is already using SMB_COM_GETATTR as a fallback code path (function SMBQueryInformation()), so introduce a new function SMBSetInformation which will implement SMB_COM_SETATTR command. My testing showed that Windows XP SMB1 client is also using SMB_COM_SETATTR command for setting or clearing read-only attribute against non-NT server. So this can prove that this is the correct way how to do it. With this change it is possible set all 4 time values and all attributes, including clearing and setting read-only bit on non-NT SMB servers. Tested against Win98 SMB1 server. This change fixes "touch" command which was failing when called on existing file. And fixes also "chmod +w" and "chmod -w" commands which were also failing (as they are changing read-only attribute). Note that this change depends on following change "cifs: Improve cifs_query_path_info() and cifs_query_file_info()" as it require to query all 4 time attribute values. Signed-off-by: Pali Rohár --- fs/smb/client/cifspdu.h | 3 +- fs/smb/client/cifsproto.h | 4 ++ fs/smb/client/cifssmb.c | 57 +++++++++++++++++++ fs/smb/client/smb1ops.c | 112 +++++++++++++++++++++++++++++++++++--- 4 files changed, 165 insertions(+), 11 deletions(-) diff --git a/fs/smb/client/cifspdu.h b/fs/smb/client/cifspdu.h index e5e397291da9..fd114fcb1320 100644 --- a/fs/smb/client/cifspdu.h +++ b/fs/smb/client/cifspdu.h @@ -1270,8 +1270,7 @@ typedef struct smb_com_query_information_rsp { typedef struct smb_com_setattr_req { struct smb_hdr hdr; /* wct = 8 */ __le16 attr; - __le16 time_low; - __le16 time_high; + __le32 last_write_time; __le16 reserved[5]; /* must be zero */ __u16 ByteCount; __u8 BufferFormat; /* 4 = ASCII */ diff --git a/fs/smb/client/cifsproto.h b/fs/smb/client/cifsproto.h index 52548238b467..8f77b6d5c6ca 100644 --- a/fs/smb/client/cifsproto.h +++ b/fs/smb/client/cifsproto.h @@ -392,6 +392,10 @@ extern int CIFSSMBQFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon); extern int CIFSSMBQFSPosixInfo(const unsigned int xid, struct cifs_tcon *tcon, struct kstatfs *FSData); +extern int SMBSetInformation(const unsigned int xid, struct cifs_tcon *tcon, + const char *fileName, __le32 attributes, __le64 write_time, + const struct nls_table *nls_codepage, + struct cifs_sb_info *cifs_sb); extern int CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, const char *fileName, const FILE_BASIC_INFO *data, const struct nls_table *nls_codepage, diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c index c88b6ea7c00a..acbdb6d92306 100644 --- a/fs/smb/client/cifssmb.c +++ b/fs/smb/client/cifssmb.c @@ -5292,6 +5292,63 @@ CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, return rc; } +int +SMBSetInformation(const unsigned int xid, struct cifs_tcon *tcon, + const char *fileName, __le32 attributes, __le64 write_time, + const struct nls_table *nls_codepage, + struct cifs_sb_info *cifs_sb) +{ + SETATTR_REQ *pSMB; + SETATTR_RSP *pSMBr; + struct timespec64 ts; + int bytes_returned; + int name_len; + int rc; + + cifs_dbg(FYI, "In SMBSetInformation path %s\n", fileName); + +retry: + rc = smb_init(SMB_COM_SETATTR, 8, tcon, (void **) &pSMB, + (void **) &pSMBr); + if (rc) + return rc; + + if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { + name_len = + cifsConvertToUTF16((__le16 *) pSMB->fileName, + fileName, PATH_MAX, nls_codepage, + cifs_remap(cifs_sb)); + name_len++; /* trailing null */ + name_len *= 2; + } else { + name_len = copy_path_name(pSMB->fileName, fileName); + } + /* Only few attributes can be set by this command, others are not accepted by Win9x. */ + pSMB->attr = cpu_to_le16(le32_to_cpu(attributes) & + (ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_ARCHIVE)); + /* Zero write time value (in both NT and SETATTR formats) means to not change it. */ + if (le64_to_cpu(write_time) != 0) { + ts = cifs_NTtimeToUnix(le64_to_cpu(write_time)); + pSMB->last_write_time = cpu_to_le32(ts.tv_sec); + } + pSMB->BufferFormat = 0x04; + name_len++; /* account for buffer type byte */ + inc_rfc1001_len(pSMB, (__u16)name_len); + pSMB->ByteCount = cpu_to_le16(name_len); + + rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, + (struct smb_hdr *) pSMBr, &bytes_returned, 0); + if (rc) + cifs_dbg(FYI, "Send error in SMBSetInformation = %d\n", rc); + + cifs_buf_release(pSMB); + + if (rc == -EAGAIN) + goto retry; + + return rc; +} + /* Some legacy servers such as NT4 require that the file times be set on an open handle, rather than by pathname - this is awkward due to potential access conflicts on the open, but it is unavoidable for these diff --git a/fs/smb/client/smb1ops.c b/fs/smb/client/smb1ops.c index 62f4e1081ea4..33af1a6ab348 100644 --- a/fs/smb/client/smb1ops.c +++ b/fs/smb/client/smb1ops.c @@ -880,6 +880,9 @@ smb_set_file_info(struct inode *inode, const char *full_path, struct cifs_fid fid; struct cifs_open_parms oparms; struct cifsFileInfo *open_file; + FILE_BASIC_INFO new_buf; + struct cifs_open_info_data query_data; + __le64 write_time = buf->LastWriteTime; struct cifsInodeInfo *cinode = CIFS_I(inode); struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); struct tcon_link *tlink = NULL; @@ -887,20 +890,58 @@ smb_set_file_info(struct inode *inode, const char *full_path, /* if the file is already open for write, just use that fileid */ open_file = find_writable_file(cinode, FIND_WR_FSUID_ONLY); + if (open_file) { fid.netfid = open_file->fid.netfid; netpid = open_file->pid; tcon = tlink_tcon(open_file->tlink); - goto set_via_filehandle; + } else { + tlink = cifs_sb_tlink(cifs_sb); + if (IS_ERR(tlink)) { + rc = PTR_ERR(tlink); + tlink = NULL; + goto out; + } + tcon = tlink_tcon(tlink); } - tlink = cifs_sb_tlink(cifs_sb); - if (IS_ERR(tlink)) { - rc = PTR_ERR(tlink); - tlink = NULL; - goto out; + /* + * Non-NT servers interprets zero time value in SMB_SET_FILE_BASIC_INFO + * over TRANS2_SET_FILE_INFORMATION as a valid time value. NT servers + * interprets zero time value as do not change existing value on server. + * API of ->set_file_info() callback expects that zero time value has + * the NT meaning - do not change. Therefore if server is non-NT and + * some time values in "buf" are zero, then fetch missing time values. + */ + if (!(tcon->ses->capabilities & CAP_NT_SMBS) && + (!buf->CreationTime || !buf->LastAccessTime || + !buf->LastWriteTime || !buf->ChangeTime)) { + rc = cifs_query_path_info(xid, tcon, cifs_sb, full_path, &query_data); + if (rc) { + if (open_file) { + cifsFileInfo_put(open_file); + open_file = NULL; + } + goto out; + } + /* + * Original write_time from buf->LastWriteTime is preserved + * as SMBSetInformation() interprets zero as do not change. + */ + new_buf = *buf; + buf = &new_buf; + if (!buf->CreationTime) + buf->CreationTime = query_data.fi.CreationTime; + if (!buf->LastAccessTime) + buf->LastAccessTime = query_data.fi.LastAccessTime; + if (!buf->LastWriteTime) + buf->LastWriteTime = query_data.fi.LastWriteTime; + if (!buf->ChangeTime) + buf->ChangeTime = query_data.fi.ChangeTime; } - tcon = tlink_tcon(tlink); + + if (open_file) + goto set_via_filehandle; rc = CIFSSMBSetPathInfo(xid, tcon, full_path, buf, cifs_sb->local_nls, cifs_sb); @@ -921,8 +962,45 @@ smb_set_file_info(struct inode *inode, const char *full_path, .fid = &fid, }; - cifs_dbg(FYI, "calling SetFileInfo since SetPathInfo for times not supported by this server\n"); - rc = CIFS_open(xid, &oparms, &oplock, NULL); + if (S_ISDIR(inode->i_mode) && !(tcon->ses->capabilities & CAP_NT_SMBS)) { + /* Opening directory path is not possible on non-NT servers. */ + rc = -EOPNOTSUPP; + } else { + /* + * Use cifs_open_file() instead of CIFS_open() as the + * cifs_open_file() selects the correct function which + * works also on non-NT servers. + */ + rc = cifs_open_file(xid, &oparms, &oplock, NULL); + /* + * Opening path for writing on non-NT servers is not + * possible when the read-only attribute is already set. + * Non-NT server in this case returns -EACCES. For those + * servers the only possible way how to clear the read-only + * bit is via SMB_COM_SETATTR command. + */ + if (rc == -EACCES && + (le32_to_cpu(cinode->cifsAttrs) & ATTR_READONLY) && + le32_to_cpu(buf->Attributes) != 0 && /* 0 = do not change attrs */ + !(le32_to_cpu(buf->Attributes) & ATTR_READONLY) && + !(tcon->ses->capabilities & CAP_NT_SMBS)) + rc = -EOPNOTSUPP; + } + + /* Fallback to SMB_COM_SETATTR command when absolutelty needed. */ + if (rc == -EOPNOTSUPP) { + cifs_dbg(FYI, "calling SetInformation since SetPathInfo for attrs/times not supported by this server\n"); + rc = SMBSetInformation(xid, tcon, full_path, + buf->Attributes != 0 ? buf->Attributes : cinode->cifsAttrs, + write_time, + cifs_sb->local_nls, cifs_sb); + if (rc == 0) + cinode->cifsAttrs = le32_to_cpu(buf->Attributes); + else + rc = -EACCES; + goto out; + } + if (rc != 0) { if (rc == -EIO) rc = -EINVAL; @@ -930,6 +1008,7 @@ smb_set_file_info(struct inode *inode, const char *full_path, } netpid = current->tgid; + cifs_dbg(FYI, "calling SetFileInfo since SetPathInfo for attrs/times not supported by this server\n"); set_via_filehandle: rc = CIFSSMBSetFileInfo(xid, tcon, buf, fid.netfid, netpid); @@ -940,6 +1019,21 @@ smb_set_file_info(struct inode *inode, const char *full_path, CIFSSMBClose(xid, tcon, fid.netfid); else cifsFileInfo_put(open_file); + + /* + * Setting the read-only bit is not honered on non-NT servers when done + * via open-semantics. So for setting it, use SMB_COM_SETATTR command. + * This command works only after the file is closed, so use it only when + * operation was called without the filehandle. + */ + if (open_file == NULL && + !(tcon->ses->capabilities & CAP_NT_SMBS) && + le32_to_cpu(buf->Attributes) & ATTR_READONLY) { + SMBSetInformation(xid, tcon, full_path, + buf->Attributes, + 0 /* do not change write time */, + cifs_sb->local_nls, cifs_sb); + } out: if (tlink != NULL) cifs_put_tlink(tlink); From patchwork Tue Dec 31 22:36: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: 13924024 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 D117F1BD9F9; Tue, 31 Dec 2024 22:37:12 +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=1735684632; cv=none; b=iVYioVyOThBxg+7h6E8UjefZFpj7HcekLTRlXbjsYTwNa52Td8qY15GgodadvMDlYMX4imUEaKoOYGNrFr+L+HFeJ/8u25tN/RcQg+Bg2vtSZQDUtnAzio6wvoq4LrAYWPcXAff1Qrwdy043vMgFJXmU0ECjk8vcTTQwZ0SBWhk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735684632; c=relaxed/simple; bh=XJQVj3tQtb2bvc7E0/stCGdfIySzLwcBcImilldPk3A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=cVWMRZQDC/GHSu9mhe9/88mgtQ1gLkJ+HmDHXxJaGADvaQFhtOk8eYDy+Oav5GmHGYkKyAqWTJ7JjNfJP5SbAIGvf/s99nIM5lxnei3Fn8XlVJ1aEZJjAHcHN4JlGJudVvo5vFtIU/TaOMxyFMItgK5Sg0Pn7cLIwa2ORQVYBpA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uTmmHLam; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uTmmHLam" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BFB2C4CEE2; Tue, 31 Dec 2024 22:37:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735684632; bh=XJQVj3tQtb2bvc7E0/stCGdfIySzLwcBcImilldPk3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uTmmHLamXsGipO1yZK9nlid0LP0K5hX9QZcfvgO4RJEHOxA9fVNbY7kaLW6G/SAxI bCVakM1E6tYqDIU7ZFicfXVmQ8LoZgq+tzNs+77Daszr/DUAD1Z70gIe/LVnELvBo+ OtAHkofbyRgdznkoOMIVkiHDGb2AJ3x/6vtiXg4IBiUJlJdAyIf4xvRofESVZrBy2Y U1/Jm+e2lGvPToDzPS2h337UTLWDRrq9B1G45sbxLS6a2PMpFsdjl5d9H0tA2LkLQr Tgjh1sXx4/dHBooetsfx8Rr4dt2hCD8cD9lMQjIiBnPsvZLWodmH/a+26ewyaEw4pe U5mwjY/6gKNaw== Received: by pali.im (Postfix) id 7EFCEFE7; Tue, 31 Dec 2024 23:37:01 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 11/12] cifs: Add fallback code path for cifs_mkdir_setinfo() Date: Tue, 31 Dec 2024 23:36:41 +0100 Message-Id: <20241231223642.15722-11-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241231223642.15722-1-pali@kernel.org> References: <20241231223642.15722-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use SMBSetInformation() as a fallback function (when CIFSSMBSetPathInfo() fails) which can set attribudes on the directory, including changing read-only attribute. Signed-off-by: Pali Rohár --- fs/smb/client/smb1ops.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/smb/client/smb1ops.c b/fs/smb/client/smb1ops.c index 33af1a6ab348..1697c1fc13b0 100644 --- a/fs/smb/client/smb1ops.c +++ b/fs/smb/client/smb1ops.c @@ -800,6 +800,11 @@ cifs_mkdir_setinfo(struct inode *inode, const char *full_path, info.Attributes = cpu_to_le32(dosattrs); rc = CIFSSMBSetPathInfo(xid, tcon, full_path, &info, cifs_sb->local_nls, cifs_sb); + if (rc == -EOPNOTSUPP || rc == -EINVAL) + rc = SMBSetInformation(xid, tcon, full_path, + info.Attributes, + 0 /* do not change write time */, + cifs_sb->local_nls, cifs_sb); if (rc == 0) cifsInode->cifsAttrs = dosattrs; } From patchwork Tue Dec 31 22:36: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: 13924020 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 C1D771B87F2; Tue, 31 Dec 2024 22:37:10 +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=1735684630; cv=none; b=EEeoXvUnBbjKkEyJ1aX7pzOEIAeNmrtY6FPn3r4A7lOd0S7N0lRfmHS/vrHkbczcoD7fYt5xjI5RDgBS9dP4C88whaYQc1iUQhxB/FKsmXvtGT/5lrZe/O5YJeYwkKgEsTIZmRijO5I6a/eP3bVvW/UVGXi61AXFdtYW5TWUmRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735684630; c=relaxed/simple; bh=s1tawBVkNDFFClcfOVkRnxGeBPnAEZaUi3saaIWPAj4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=YJlVYkeLGy5TKQmGHsE9hgeMEVlwYt6ZvzY9FNZ3hdoR6kJQ1RuZg3mVxLeYjIGtMZSiZVcUVgEKl7sVIXEYsbAiJWwlKszIWeATueDhRmNbo+NiIIktLcsF26lSiEqiAtq+crvkWA6tQsxznNypZgGeU36ZOxZ7cJmPWki3i6I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pRFw+9ZP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pRFw+9ZP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FF45C4CEDD; Tue, 31 Dec 2024 22:37:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735684630; bh=s1tawBVkNDFFClcfOVkRnxGeBPnAEZaUi3saaIWPAj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pRFw+9ZPNoC9wIIIUgv0pdhrfLre83v/2u+3QHLqgZDqHJOT4hc1h1LdLAe5mexzP L8BNil5pdUxVDjevODS16HR0bYW/KmUExS1DICxppSegb+RIdp5nnlfX1hycuAg3uE t9h/C5x4w8ZRODM7RT/sbL4YCIXDWfj54NJBqbJjQP/m3z5yFkBGbMNlKxehc2NT9H pkzCUdTqLu4am7Q+4X4URtA/Dd/XYb7aeMmlAikAu1iVG374GNrkIuf+wR5GeFMg1Y iUa77bF6MMqnZq2cMCx9Cr4lWfqGdo2QHIxA+6IHlKqB+00kK9o1ndWW7vMsT6QOyx i+Mu5IOotJPLQ== Received: by pali.im (Postfix) id 993D6FEC; Tue, 31 Dec 2024 23:37:01 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/12] cifs: Remove CIFSSMBSetPathInfoFB() fallback function Date: Tue, 31 Dec 2024 23:36:42 +0100 Message-Id: <20241231223642.15722-12-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241231223642.15722-1-pali@kernel.org> References: <20241231223642.15722-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 fallback function CIFSSMBSetPathInfoFB() is called only from CIFSSMBSetPathInfo() function. CIFSSMBSetPathInfo() is used in smb_set_file_info() which contains all required fallback code, including fallback via filehandle. So the CIFSSMBSetPathInfoFB() is just code duplication, which is not needed anymore. Therefore remove it. This change depends on other changes which are extending cifs_mkdir_setinfo() and smb_set_file_info() functions. Signed-off-by: Pali Rohár --- fs/smb/client/cifssmb.c | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c index acbdb6d92306..9dc946138f18 100644 --- a/fs/smb/client/cifssmb.c +++ b/fs/smb/client/cifssmb.c @@ -5478,38 +5478,6 @@ CIFSSMBSetFileDisposition(const unsigned int xid, struct cifs_tcon *tcon, return rc; } -static int -CIFSSMBSetPathInfoFB(const unsigned int xid, struct cifs_tcon *tcon, - const char *fileName, const FILE_BASIC_INFO *data, - const struct nls_table *nls_codepage, - struct cifs_sb_info *cifs_sb) -{ - int oplock = 0; - struct cifs_open_parms oparms; - struct cifs_fid fid; - int rc; - - oparms = (struct cifs_open_parms) { - .tcon = tcon, - .cifs_sb = cifs_sb, - .desired_access = GENERIC_WRITE, - .create_options = cifs_create_options(cifs_sb, 0), - .disposition = FILE_OPEN, - .path = fileName, - .fid = &fid, - }; - - rc = CIFS_open(xid, &oparms, &oplock, NULL); - if (rc) - goto out; - - rc = CIFSSMBSetFileInfo(xid, tcon, data, fid.netfid, current->tgid); - CIFSSMBClose(xid, tcon, fid.netfid); -out: - - return rc; -} - int CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, const char *fileName, const FILE_BASIC_INFO *data, @@ -5586,10 +5554,6 @@ CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, if (rc == -EAGAIN) goto SetTimesRetry; - if (rc == -EOPNOTSUPP) - return CIFSSMBSetPathInfoFB(xid, tcon, fileName, data, - nls_codepage, cifs_sb); - return rc; }