From patchwork Fri Oct 28 12:11:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Xiaoxu X-Patchwork-Id: 13023510 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3059AFA3741 for ; Fri, 28 Oct 2022 11:56:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230133AbiJ1L4w (ORCPT ); Fri, 28 Oct 2022 07:56:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230111AbiJ1L4t (ORCPT ); Fri, 28 Oct 2022 07:56:49 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 650331D2B7F for ; Fri, 28 Oct 2022 04:56:48 -0700 (PDT) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MzLXZ5MnmzpWFL; Fri, 28 Oct 2022 19:53:18 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 28 Oct 2022 19:56:46 +0800 From: Zhang Xiaoxu To: , , , , , , , Subject: [PATCH 1/7] cifs: Use helper macro SMB2_CREATE_* instead of assignment one by one Date: Fri, 28 Oct 2022 20:11:23 +0800 Message-ID: <20221028121129.3375402-2-zhangxiaoxu5@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221028121129.3375402-1-zhangxiaoxu5@huawei.com> References: <20221028121129.3375402-1-zhangxiaoxu5@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500023.china.huawei.com (7.185.36.114) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org The create context macros has defined in fs/smbfs_common/smb2pdu.h, use SMB2_CREATE_* instead of the assignment one by one to simplify the codes, no functional changed. Signed-off-by: Zhang Xiaoxu --- fs/cifs/smb2ops.c | 12 ++----- fs/cifs/smb2pdu.c | 89 ++++++++--------------------------------------- 2 files changed, 16 insertions(+), 85 deletions(-) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 4f53fa012936..5d537a4c6881 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -4106,11 +4106,7 @@ smb2_create_lease_buf(u8 *lease_key, u8 oplock) buf->ccontext.NameOffset = cpu_to_le16(offsetof (struct create_lease, Name)); buf->ccontext.NameLength = cpu_to_le16(4); - /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */ - buf->Name[0] = 'R'; - buf->Name[1] = 'q'; - buf->Name[2] = 'L'; - buf->Name[3] = 's'; + memcpy(buf->Name, SMB2_CREATE_REQUEST_LEASE, 4); return (char *)buf; } @@ -4132,11 +4128,7 @@ smb3_create_lease_buf(u8 *lease_key, u8 oplock) buf->ccontext.NameOffset = cpu_to_le16(offsetof (struct create_lease_v2, Name)); buf->ccontext.NameLength = cpu_to_le16(4); - /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */ - buf->Name[0] = 'R'; - buf->Name[1] = 'q'; - buf->Name[2] = 'L'; - buf->Name[3] = 's'; + memcpy(buf->Name, SMB2_CREATE_REQUEST_LEASE, 4); return (char *)buf; } diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index a5695748a89b..e685e4d1f044 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -518,23 +518,7 @@ build_posix_ctxt(struct smb2_posix_neg_context *pneg_ctxt) { pneg_ctxt->ContextType = SMB2_POSIX_EXTENSIONS_AVAILABLE; pneg_ctxt->DataLength = cpu_to_le16(POSIX_CTXT_DATA_LEN); - /* SMB2_CREATE_TAG_POSIX is "0x93AD25509CB411E7B42383DE968BCD7C" */ - pneg_ctxt->Name[0] = 0x93; - pneg_ctxt->Name[1] = 0xAD; - pneg_ctxt->Name[2] = 0x25; - pneg_ctxt->Name[3] = 0x50; - pneg_ctxt->Name[4] = 0x9C; - pneg_ctxt->Name[5] = 0xB4; - pneg_ctxt->Name[6] = 0x11; - pneg_ctxt->Name[7] = 0xE7; - pneg_ctxt->Name[8] = 0xB4; - pneg_ctxt->Name[9] = 0x23; - pneg_ctxt->Name[10] = 0x83; - pneg_ctxt->Name[11] = 0xDE; - pneg_ctxt->Name[12] = 0x96; - pneg_ctxt->Name[13] = 0x8B; - pneg_ctxt->Name[14] = 0xCD; - pneg_ctxt->Name[15] = 0x7C; + memcpy(pneg_ctxt->Name, SMB2_CREATE_TAG_POSIX, 16); } static void @@ -800,23 +784,7 @@ create_posix_buf(umode_t mode) cpu_to_le16(offsetof(struct create_posix, Name)); buf->ccontext.NameLength = cpu_to_le16(16); - /* SMB2_CREATE_TAG_POSIX is "0x93AD25509CB411E7B42383DE968BCD7C" */ - buf->Name[0] = 0x93; - buf->Name[1] = 0xAD; - buf->Name[2] = 0x25; - buf->Name[3] = 0x50; - buf->Name[4] = 0x9C; - buf->Name[5] = 0xB4; - buf->Name[6] = 0x11; - buf->Name[7] = 0xE7; - buf->Name[8] = 0xB4; - buf->Name[9] = 0x23; - buf->Name[10] = 0x83; - buf->Name[11] = 0xDE; - buf->Name[12] = 0x96; - buf->Name[13] = 0x8B; - buf->Name[14] = 0xCD; - buf->Name[15] = 0x7C; + memcpy(buf->Name, SMB2_CREATE_TAG_POSIX, 16); buf->Mode = cpu_to_le32(mode); cifs_dbg(FYI, "mode on posix create 0%o\n", mode); return buf; @@ -2034,11 +2002,8 @@ create_durable_buf(void) buf->ccontext.NameOffset = cpu_to_le16(offsetof (struct create_durable, Name)); buf->ccontext.NameLength = cpu_to_le16(4); - /* SMB2_CREATE_DURABLE_HANDLE_REQUEST is "DHnQ" */ - buf->Name[0] = 'D'; - buf->Name[1] = 'H'; - buf->Name[2] = 'n'; - buf->Name[3] = 'Q'; + memcpy(buf->Name, SMB2_CREATE_DURABLE_HANDLE_REQUEST, 4); + return buf; } @@ -2059,11 +2024,8 @@ create_reconnect_durable_buf(struct cifs_fid *fid) buf->ccontext.NameLength = cpu_to_le16(4); buf->Data.Fid.PersistentFileId = fid->persistent_fid; buf->Data.Fid.VolatileFileId = fid->volatile_fid; - /* SMB2_CREATE_DURABLE_HANDLE_RECONNECT is "DHnC" */ - buf->Name[0] = 'D'; - buf->Name[1] = 'H'; - buf->Name[2] = 'n'; - buf->Name[3] = 'C'; + memcpy(buf->Name, SMB2_CREATE_DURABLE_HANDLE_RECONNECT, 4); + return buf; } @@ -2124,11 +2086,6 @@ smb2_parse_contexts(struct TCP_Server_Info *server, unsigned int next; unsigned int remaining; char *name; - static const char smb3_create_tag_posix[] = { - 0x93, 0xAD, 0x25, 0x50, 0x9C, - 0xB4, 0x11, 0xE7, 0xB4, 0x23, 0x83, - 0xDE, 0x96, 0x8B, 0xCD, 0x7C - }; *oplock = 0; data_offset = (char *)rsp + le32_to_cpu(rsp->CreateContextsOffset); @@ -2150,7 +2107,7 @@ smb2_parse_contexts(struct TCP_Server_Info *server, parse_query_id_ctxt(cc, buf); else if ((le16_to_cpu(cc->NameLength) == 16)) { if (posix && - memcmp(name, smb3_create_tag_posix, 16) == 0) + memcmp(name, SMB2_CREATE_TAG_POSIX, 16) == 0) parse_posix_ctxt(cc, buf, posix); } /* else { @@ -2222,12 +2179,8 @@ create_durable_v2_buf(struct cifs_open_parms *oparms) buf->dcontext.Flags = cpu_to_le32(SMB2_DHANDLE_FLAG_PERSISTENT); generate_random_uuid(buf->dcontext.CreateGuid); memcpy(pfid->create_guid, buf->dcontext.CreateGuid, 16); + memcpy(buf->Name, SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2, 4); - /* SMB2_CREATE_DURABLE_HANDLE_REQUEST is "DH2Q" */ - buf->Name[0] = 'D'; - buf->Name[1] = 'H'; - buf->Name[2] = '2'; - buf->Name[3] = 'Q'; return buf; } @@ -2255,12 +2208,8 @@ create_reconnect_durable_v2_buf(struct cifs_fid *fid) buf->dcontext.Fid.VolatileFileId = fid->volatile_fid; buf->dcontext.Flags = cpu_to_le32(SMB2_DHANDLE_FLAG_PERSISTENT); memcpy(buf->dcontext.CreateGuid, fid->create_guid, 16); + memcpy(buf->Name, SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2, 4); - /* SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 is "DH2C" */ - buf->Name[0] = 'D'; - buf->Name[1] = 'H'; - buf->Name[2] = '2'; - buf->Name[3] = 'C'; return buf; } @@ -2357,12 +2306,9 @@ create_twarp_buf(__u64 timewarp) buf->ccontext.NameOffset = cpu_to_le16(offsetof (struct crt_twarp_ctxt, Name)); buf->ccontext.NameLength = cpu_to_le16(4); - /* SMB2_CREATE_TIMEWARP_TOKEN is "TWrp" */ - buf->Name[0] = 'T'; - buf->Name[1] = 'W'; - buf->Name[2] = 'r'; - buf->Name[3] = 'p'; + memcpy(buf->Name, SMB2_CREATE_TIMEWARP_TOKEN, 4); buf->Timestamp = cpu_to_le64(timewarp); + return buf; } @@ -2450,11 +2396,7 @@ create_sd_buf(umode_t mode, bool set_owner, unsigned int *len) buf->ccontext.DataOffset = cpu_to_le16(offsetof(struct crt_sd_ctxt, sd)); buf->ccontext.NameOffset = cpu_to_le16(offsetof(struct crt_sd_ctxt, Name)); buf->ccontext.NameLength = cpu_to_le16(4); - /* SMB2_CREATE_SD_BUFFER_TOKEN is "SecD" */ - buf->Name[0] = 'S'; - buf->Name[1] = 'e'; - buf->Name[2] = 'c'; - buf->Name[3] = 'D'; + memcpy(buf->Name, SMB2_CREATE_SD_BUFFER, 4); buf->sd.Revision = 1; /* Must be one see MS-DTYP 2.4.6 */ /* @@ -2535,11 +2477,8 @@ create_query_id_buf(void) buf->ccontext.NameOffset = cpu_to_le16(offsetof (struct crt_query_id_ctxt, Name)); buf->ccontext.NameLength = cpu_to_le16(4); - /* SMB2_CREATE_QUERY_ON_DISK_ID is "QFid" */ - buf->Name[0] = 'Q'; - buf->Name[1] = 'F'; - buf->Name[2] = 'i'; - buf->Name[3] = 'd'; + memcpy(buf->Name, SMB2_CREATE_QUERY_ON_DISK_ID, 4); + return buf; } From patchwork Fri Oct 28 12:11:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Xiaoxu X-Patchwork-Id: 13023512 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC54FFA3740 for ; Fri, 28 Oct 2022 11:56:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229519AbiJ1L4v (ORCPT ); Fri, 28 Oct 2022 07:56:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230046AbiJ1L4t (ORCPT ); Fri, 28 Oct 2022 07:56:49 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13AC71D2B7D for ; Fri, 28 Oct 2022 04:56:49 -0700 (PDT) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4MzLVv4CqVz15M7K; Fri, 28 Oct 2022 19:51:51 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 28 Oct 2022 19:56:46 +0800 From: Zhang Xiaoxu To: , , , , , , , Subject: [PATCH 2/7] cifs: Use helper macro NTLMSSP_SIGNATURE in decode_ntlmssp_challenge() Date: Fri, 28 Oct 2022 20:11:24 +0800 Message-ID: <20221028121129.3375402-3-zhangxiaoxu5@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221028121129.3375402-1-zhangxiaoxu5@huawei.com> References: <20221028121129.3375402-1-zhangxiaoxu5@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500023.china.huawei.com (7.185.36.114) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org The siguature type NTLMSSP already defined as macro, use it. Signed-off-by: Zhang Xiaoxu --- fs/cifs/sess.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c index 92e4278ec35d..e08c5f547afb 100644 --- a/fs/cifs/sess.c +++ b/fs/cifs/sess.c @@ -764,7 +764,7 @@ int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, return -EINVAL; } - if (memcmp(pblob->Signature, "NTLMSSP", 8)) { + if (memcmp(pblob->Signature, NTLMSSP_SIGNATURE, 8)) { cifs_dbg(VFS, "blob signature incorrect %s\n", pblob->Signature); return -EINVAL; From patchwork Fri Oct 28 12:11:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Xiaoxu X-Patchwork-Id: 13023513 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8529BFA3746 for ; Fri, 28 Oct 2022 11:56:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230128AbiJ1L4x (ORCPT ); Fri, 28 Oct 2022 07:56:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230122AbiJ1L4u (ORCPT ); Fri, 28 Oct 2022 07:56:50 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31C951D2F42 for ; Fri, 28 Oct 2022 04:56:49 -0700 (PDT) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MzLXb4y0SzpWFS; Fri, 28 Oct 2022 19:53:19 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 28 Oct 2022 19:56:47 +0800 From: Zhang Xiaoxu To: , , , , , , , Subject: [PATCH 3/7] cifs: Remove the redundant null pointer check in SMB2_sess_setup() Date: Fri, 28 Oct 2022 20:11:25 +0800 Message-ID: <20221028121129.3375402-4-zhangxiaoxu5@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221028121129.3375402-1-zhangxiaoxu5@huawei.com> References: <20221028121129.3375402-1-zhangxiaoxu5@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500023.china.huawei.com (7.185.36.114) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org The cifs_setup_session() is the only caller of .sess_setup(), and it's already ensure the server and sess not null, so remove the redundant nullptr check. Signed-off-by: Zhang Xiaoxu --- fs/cifs/sess.c | 5 ----- fs/cifs/smb2pdu.c | 5 ----- 2 files changed, 10 deletions(-) diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c index e08c5f547afb..40e4dd42cc2b 100644 --- a/fs/cifs/sess.c +++ b/fs/cifs/sess.c @@ -1822,11 +1822,6 @@ int CIFS_SessSetup(const unsigned int xid, struct cifs_ses *ses, int rc = 0; struct sess_data *sess_data; - if (ses == NULL) { - WARN(1, "%s: ses == NULL!", __func__); - return -EINVAL; - } - sess_data = kzalloc(sizeof(struct sess_data), GFP_KERNEL); if (!sess_data) return -ENOMEM; diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index e685e4d1f044..1e64175aa5bd 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -1676,11 +1676,6 @@ SMB2_sess_setup(const unsigned int xid, struct cifs_ses *ses, cifs_dbg(FYI, "Session Setup\n"); - if (!server) { - WARN(1, "%s: server is NULL!\n", __func__); - return -EIO; - } - sess_data = kzalloc(sizeof(struct SMB2_sess_data), GFP_KERNEL); if (!sess_data) return -ENOMEM; From patchwork Fri Oct 28 12:11:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Xiaoxu X-Patchwork-Id: 13023511 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73F51ECAAA1 for ; Fri, 28 Oct 2022 11:56:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230111AbiJ1L4x (ORCPT ); Fri, 28 Oct 2022 07:56:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230128AbiJ1L4u (ORCPT ); Fri, 28 Oct 2022 07:56:50 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3C531D2F46 for ; Fri, 28 Oct 2022 04:56:49 -0700 (PDT) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MzLVw1HyPzmV7c; Fri, 28 Oct 2022 19:51:52 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 28 Oct 2022 19:56:47 +0800 From: Zhang Xiaoxu To: , , , , , , , Subject: [PATCH 4/7] cifs: Remove the redundant null pointer check in SMB2_negotiate() Date: Fri, 28 Oct 2022 20:11:26 +0800 Message-ID: <20221028121129.3375402-5-zhangxiaoxu5@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221028121129.3375402-1-zhangxiaoxu5@huawei.com> References: <20221028121129.3375402-1-zhangxiaoxu5@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500023.china.huawei.com (7.185.36.114) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org The smb2_negotiate() is the only caller of function SMB2_negotiate(), and it's already ensure the server not null, so remove the redundant nullptr check. Signed-off-by: Zhang Xiaoxu --- fs/cifs/smb2pdu.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 1e64175aa5bd..91c134953b9b 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -846,11 +846,6 @@ SMB2_negotiate(const unsigned int xid, cifs_dbg(FYI, "Negotiate protocol\n"); - if (!server) { - WARN(1, "%s: server is NULL!\n", __func__); - return -EIO; - } - rc = smb2_plain_req_init(SMB2_NEGOTIATE, NULL, server, (void **) &req, &total_len); if (rc) From patchwork Fri Oct 28 12:11:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Xiaoxu X-Patchwork-Id: 13023514 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E654C38A02 for ; Fri, 28 Oct 2022 11:56:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230012AbiJ1L4y (ORCPT ); Fri, 28 Oct 2022 07:56:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230129AbiJ1L4u (ORCPT ); Fri, 28 Oct 2022 07:56:50 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31C3F1D2F4D for ; Fri, 28 Oct 2022 04:56:50 -0700 (PDT) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MzLXc4dtWzpWFR; Fri, 28 Oct 2022 19:53:20 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 28 Oct 2022 19:56:48 +0800 From: Zhang Xiaoxu To: , , , , , , , Subject: [PATCH 5/7] cifs: remove the unused xid parameter from smb_mnt_get_fsinfo Date: Fri, 28 Oct 2022 20:11:27 +0800 Message-ID: <20221028121129.3375402-6-zhangxiaoxu5@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221028121129.3375402-1-zhangxiaoxu5@huawei.com> References: <20221028121129.3375402-1-zhangxiaoxu5@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500023.china.huawei.com (7.185.36.114) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org The xid is unused in smb_mnt_get_fsinfo, remove it. Fixes: 0de1f4c6f6c0 ("Add way to query server fs info for smb3") Signed-off-by: Zhang Xiaoxu --- fs/cifs/ioctl.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/cifs/ioctl.c b/fs/cifs/ioctl.c index 89d5fa887364..c25e8442068a 100644 --- a/fs/cifs/ioctl.c +++ b/fs/cifs/ioctl.c @@ -117,8 +117,7 @@ static long cifs_ioctl_copychunk(unsigned int xid, struct file *dst_file, return rc; } -static long smb_mnt_get_fsinfo(unsigned int xid, struct cifs_tcon *tcon, - void __user *arg) +static long smb_mnt_get_fsinfo(struct cifs_tcon *tcon, void __user *arg) { int rc = 0; struct smb_mnt_fs_info *fsinf; @@ -408,7 +407,7 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) if (pSMBFile == NULL) break; tcon = tlink_tcon(pSMBFile->tlink); - rc = smb_mnt_get_fsinfo(xid, tcon, (void __user *)arg); + rc = smb_mnt_get_fsinfo(tcon, (void __user *)arg); break; case CIFS_ENUMERATE_SNAPSHOTS: if (pSMBFile == NULL) From patchwork Fri Oct 28 12:11:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Xiaoxu X-Patchwork-Id: 13023515 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8020FA3747 for ; Fri, 28 Oct 2022 11:56:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230129AbiJ1L4z (ORCPT ); Fri, 28 Oct 2022 07:56:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230146AbiJ1L4v (ORCPT ); Fri, 28 Oct 2022 07:56:51 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A31361C8D48 for ; Fri, 28 Oct 2022 04:56:50 -0700 (PDT) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MzLW24xyKzVhqF; Fri, 28 Oct 2022 19:51:58 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 28 Oct 2022 19:56:48 +0800 From: Zhang Xiaoxu To: , , , , , , , Subject: [PATCH 6/7] cifs: Fix wrong return value checking when GETFLAGS Date: Fri, 28 Oct 2022 20:11:28 +0800 Message-ID: <20221028121129.3375402-7-zhangxiaoxu5@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221028121129.3375402-1-zhangxiaoxu5@huawei.com> References: <20221028121129.3375402-1-zhangxiaoxu5@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500023.china.huawei.com (7.185.36.114) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org The return value of CIFSGetExtAttr is negative, should be checked with -EOPNOTSUPP rather than EOPNOTSUPP. Fixes: 64a5cfa6db9 ("Allow setting per-file compression via SMB2/3") Signed-off-by: Zhang Xiaoxu --- fs/cifs/ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/cifs/ioctl.c b/fs/cifs/ioctl.c index c25e8442068a..1494fb5c1c45 100644 --- a/fs/cifs/ioctl.c +++ b/fs/cifs/ioctl.c @@ -342,7 +342,7 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) rc = put_user(ExtAttrBits & FS_FL_USER_VISIBLE, (int __user *)arg); - if (rc != EOPNOTSUPP) + if (rc != -EOPNOTSUPP) break; } #endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ @@ -372,7 +372,7 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) * pSMBFile->fid.netfid, * extAttrBits, * &ExtAttrMask); - * if (rc != EOPNOTSUPP) + * if (rc != -EOPNOTSUPP) * break; */ From patchwork Fri Oct 28 12:11:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Xiaoxu X-Patchwork-Id: 13023516 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D453FA3749 for ; Fri, 28 Oct 2022 11:56:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230122AbiJ1L4z (ORCPT ); Fri, 28 Oct 2022 07:56:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230046AbiJ1L4w (ORCPT ); Fri, 28 Oct 2022 07:56:52 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 193501D2B7D for ; Fri, 28 Oct 2022 04:56:51 -0700 (PDT) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MzLW31GsmzVj1t; Fri, 28 Oct 2022 19:51:59 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 28 Oct 2022 19:56:49 +0800 From: Zhang Xiaoxu To: , , , , , , , Subject: [PATCH 7/7] cifs: Reset rc before free_xid() Date: Fri, 28 Oct 2022 20:11:29 +0800 Message-ID: <20221028121129.3375402-8-zhangxiaoxu5@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221028121129.3375402-1-zhangxiaoxu5@huawei.com> References: <20221028121129.3375402-1-zhangxiaoxu5@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500023.china.huawei.com (7.185.36.114) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org The variable 'rc' was implicitly used by free_xid(), should reset it to correct value before free xid. Signed-off-by: Zhang Xiaoxu --- fs/cifs/dir.c | 2 ++ fs/cifs/file.c | 46 +++++++++++++++++++++++++--------------------- fs/cifs/smb2file.c | 9 +++++---- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c index 8b1c37158556..1db20a3d981c 100644 --- a/fs/cifs/dir.c +++ b/fs/cifs/dir.c @@ -637,6 +637,7 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry, cifs_sb = CIFS_SB(parent_dir_inode->i_sb); tlink = cifs_sb_tlink(cifs_sb); if (IS_ERR(tlink)) { + rc = PTR_ERR(tlink); free_xid(xid); return ERR_CAST(tlink); } @@ -656,6 +657,7 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry, full_path = build_path_from_dentry(direntry, page); if (IS_ERR(full_path)) { cifs_put_tlink(tlink); + rc = PTR_ERR(full_path); free_xid(xid); free_dentry_path(page); return ERR_CAST(full_path); diff --git a/fs/cifs/file.c b/fs/cifs/file.c index cd9698209930..d31d5c0a4aa2 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -560,7 +560,7 @@ void _cifsFileInfo_put(struct cifsFileInfo *cifs_file, int cifs_open(struct inode *inode, struct file *file) { - int rc = -EACCES; + int rc; unsigned int xid; __u32 oplock; struct cifs_sb_info *cifs_sb; @@ -577,16 +577,18 @@ int cifs_open(struct inode *inode, struct file *file) xid = get_xid(); + rc = -EIO; cifs_sb = CIFS_SB(inode->i_sb); if (unlikely(cifs_forced_shutdown(cifs_sb))) { free_xid(xid); - return -EIO; + return rc; } tlink = cifs_sb_tlink(cifs_sb); if (IS_ERR(tlink)) { + rc = PTR_ERR(tlink); free_xid(xid); - return PTR_ERR(tlink); + return rc; } tcon = tlink_tcon(tlink); server = tcon->ses->server; @@ -759,7 +761,7 @@ cifs_relock_file(struct cifsFileInfo *cfile) static int cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) { - int rc = -EACCES; + int rc; unsigned int xid; __u32 oplock; struct cifs_sb_info *cifs_sb; @@ -774,6 +776,7 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) int create_options = CREATE_NOT_DIR; struct cifs_open_parms oparms; + rc = 0; xid = get_xid(); mutex_lock(&cfile->fh_mutex); if (!cfile->invalidHandle) { @@ -798,8 +801,9 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) if (IS_ERR(full_path)) { mutex_unlock(&cfile->fh_mutex); free_dentry_path(page); + rc = PTR_ERR(full_path); free_xid(xid); - return PTR_ERR(full_path); + return rc; } cifs_dbg(FYI, "inode = 0x%p file flags 0x%x for %s\n", @@ -1337,8 +1341,8 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) */ max_buf = tcon->ses->server->maxBuf; if (max_buf < (sizeof(struct smb_hdr) + sizeof(LOCKING_ANDX_RANGE))) { - free_xid(xid); - return -EINVAL; + rc = -EINVAL; + goto out; } BUILD_BUG_ON(sizeof(struct smb_hdr) + sizeof(LOCKING_ANDX_RANGE) > @@ -1349,8 +1353,8 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) sizeof(LOCKING_ANDX_RANGE); buf = kcalloc(max_num, sizeof(LOCKING_ANDX_RANGE), GFP_KERNEL); if (!buf) { - free_xid(xid); - return -ENOMEM; + rc = -ENOMEM; + goto out; } for (i = 0; i < 2; i++) { @@ -1386,6 +1390,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) } kfree(buf); +out: free_xid(xid); return rc; } @@ -1934,7 +1939,6 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *flock) struct cifsFileInfo *cfile; __u32 type; - rc = -EACCES; xid = get_xid(); cifs_dbg(FYI, "%s: %pD2 cmd=0x%x type=0x%x flags=0x%x r=%lld:%lld\n", __func__, file, cmd, @@ -1959,8 +1963,7 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *flock) */ if (IS_GETLK(cmd)) { rc = cifs_getlk(file, flock, type, wait_flag, posix_lck, xid); - free_xid(xid); - return rc; + goto out; } if (!lock && !unlock) { @@ -1968,12 +1971,13 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *flock) * if no lock or unlock then nothing to do since we do not * know what it is */ - free_xid(xid); - return -EOPNOTSUPP; + rc = -EOPNOTSUPP; + goto out; } rc = cifs_setlk(file, flock, type, wait_flag, posix_lck, lock, unlock, xid); +out: free_xid(xid); return rc; } @@ -4410,6 +4414,7 @@ cifs_read(struct file *file, char *read_data, size_t read_size, loff_t *offset) if (file->private_data == NULL) { rc = -EBADF; + goto out; free_xid(xid); return rc; } @@ -4418,8 +4423,8 @@ cifs_read(struct file *file, char *read_data, size_t read_size, loff_t *offset) server = cifs_pick_channel(tcon->ses); if (!server->ops->sync_read) { - free_xid(xid); - return -ENOSYS; + rc = -ENOSYS; + goto out; } if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) @@ -4461,17 +4466,16 @@ cifs_read(struct file *file, char *read_data, size_t read_size, loff_t *offset) } while (rc == -EAGAIN); if (rc || (bytes_read == 0)) { - if (total_read) { + if (total_read) break; - } else { - free_xid(xid); - return rc; - } + else + goto out; } else { cifs_stats_bytes_read(tcon, total_read); *offset += bytes_read; } } +out: free_xid(xid); return total_read; } diff --git a/fs/cifs/smb2file.c b/fs/cifs/smb2file.c index ffbd9a99fc12..420d176791c5 100644 --- a/fs/cifs/smb2file.c +++ b/fs/cifs/smb2file.c @@ -346,8 +346,8 @@ smb2_push_mandatory_locks(struct cifsFileInfo *cfile) */ max_buf = tlink_tcon(cfile->tlink)->ses->server->maxBuf; if (max_buf < sizeof(struct smb2_lock_element)) { - free_xid(xid); - return -EINVAL; + rc = -EINVAL; + goto out; } BUILD_BUG_ON(sizeof(struct smb2_lock_element) > PAGE_SIZE); @@ -355,8 +355,8 @@ smb2_push_mandatory_locks(struct cifsFileInfo *cfile) max_num = max_buf / sizeof(struct smb2_lock_element); buf = kcalloc(max_num, sizeof(struct smb2_lock_element), GFP_KERNEL); if (!buf) { - free_xid(xid); - return -ENOMEM; + rc = -ENOMEM; + goto out; } list_for_each_entry(fdlocks, &cinode->llist, llist) { @@ -366,6 +366,7 @@ smb2_push_mandatory_locks(struct cifsFileInfo *cfile) } kfree(buf); +out: free_xid(xid); return rc; }