From patchwork Sat Oct 29 09:00:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Xiaoxu X-Patchwork-Id: 13024539 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 A81A5C38A02 for ; Sat, 29 Oct 2022 07:56:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229632AbiJ2Hzz (ORCPT ); Sat, 29 Oct 2022 03:55:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229647AbiJ2Hzn (ORCPT ); Sat, 29 Oct 2022 03:55:43 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EAB86D9F3 for ; Sat, 29 Oct 2022 00:55:37 -0700 (PDT) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Mzs8Z2Rz4zFqSY; Sat, 29 Oct 2022 15:52:46 +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; Sat, 29 Oct 2022 15:55:35 +0800 From: Zhang Xiaoxu To: , , , , , , , Subject: [PATCH v2 1/7] cifs: Use helper macro SMB2_CREATE_* instead of assignment one by one Date: Sat, 29 Oct 2022 17:00:05 +0800 Message-ID: <20221029090011.79367-2-zhangxiaoxu5@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221029090011.79367-1-zhangxiaoxu5@huawei.com> References: <20221029090011.79367-1-zhangxiaoxu5@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) 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..3a0c34e43a9d 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_REQUEST, 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 Sat Oct 29 09:00:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Xiaoxu X-Patchwork-Id: 13024535 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 7B240C38A02 for ; Sat, 29 Oct 2022 07:55:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229489AbiJ2Hzu (ORCPT ); Sat, 29 Oct 2022 03:55:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229613AbiJ2Hzn (ORCPT ); Sat, 29 Oct 2022 03:55:43 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2ECAE6DAC4 for ; Sat, 29 Oct 2022 00:55:37 -0700 (PDT) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Mzs7q463CzpW5f; Sat, 29 Oct 2022 15:52:07 +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; Sat, 29 Oct 2022 15:55:36 +0800 From: Zhang Xiaoxu To: , , , , , , , Subject: [PATCH v2 2/7] cifs: Use helper macro NTLMSSP_SIGNATURE in decode_ntlmssp_challenge() Date: Sat, 29 Oct 2022 17:00:06 +0800 Message-ID: <20221029090011.79367-3-zhangxiaoxu5@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221029090011.79367-1-zhangxiaoxu5@huawei.com> References: <20221029090011.79367-1-zhangxiaoxu5@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) 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 Sat Oct 29 09:00:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Xiaoxu X-Patchwork-Id: 13024533 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 817EAC433FE for ; Sat, 29 Oct 2022 07:55:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229544AbiJ2Hzq (ORCPT ); Sat, 29 Oct 2022 03:55:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229571AbiJ2Hzn (ORCPT ); Sat, 29 Oct 2022 03:55:43 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8DB46DAEC for ; Sat, 29 Oct 2022 00:55:38 -0700 (PDT) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Mzs681ZDdz15M23; Sat, 29 Oct 2022 15:50:40 +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; Sat, 29 Oct 2022 15:55:36 +0800 From: Zhang Xiaoxu To: , , , , , , , Subject: [PATCH v2 3/7] cifs: Remove the redundant null pointer check in SMB2_sess_setup() Date: Sat, 29 Oct 2022 17:00:07 +0800 Message-ID: <20221029090011.79367-4-zhangxiaoxu5@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221029090011.79367-1-zhangxiaoxu5@huawei.com> References: <20221029090011.79367-1-zhangxiaoxu5@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) 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 3a0c34e43a9d..5cda7f029b60 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 Sat Oct 29 09:00:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Xiaoxu X-Patchwork-Id: 13024536 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 5C534C433FE for ; Sat, 29 Oct 2022 07:55:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229613AbiJ2Hzw (ORCPT ); Sat, 29 Oct 2022 03:55:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229670AbiJ2Hzo (ORCPT ); Sat, 29 Oct 2022 03:55:44 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8CF56DAE1 for ; Sat, 29 Oct 2022 00:55:38 -0700 (PDT) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Mzs8b5MRPzFqSX; Sat, 29 Oct 2022 15:52:47 +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; Sat, 29 Oct 2022 15:55:37 +0800 From: Zhang Xiaoxu To: , , , , , , , Subject: [PATCH v2 4/7] cifs: Remove the redundant null pointer check in SMB2_negotiate() Date: Sat, 29 Oct 2022 17:00:08 +0800 Message-ID: <20221029090011.79367-5-zhangxiaoxu5@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221029090011.79367-1-zhangxiaoxu5@huawei.com> References: <20221029090011.79367-1-zhangxiaoxu5@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) 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 5cda7f029b60..11643fb25347 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 Sat Oct 29 09:00:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Xiaoxu X-Patchwork-Id: 13024538 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 3E078C433FE for ; Sat, 29 Oct 2022 07:55:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229615AbiJ2Hzx (ORCPT ); Sat, 29 Oct 2022 03:55:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229632AbiJ2Hzn (ORCPT ); Sat, 29 Oct 2022 03:55:43 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E91DF6DF9B for ; Sat, 29 Oct 2022 00:55:39 -0700 (PDT) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Mzs691Hvvz15MDv; Sat, 29 Oct 2022 15:50:41 +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; Sat, 29 Oct 2022 15:55:37 +0800 From: Zhang Xiaoxu To: , , , , , , , Subject: [PATCH v2 5/7] cifs: remove the unused xid parameter from smb_mnt_get_fsinfo Date: Sat, 29 Oct 2022 17:00:09 +0800 Message-ID: <20221029090011.79367-6-zhangxiaoxu5@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221029090011.79367-1-zhangxiaoxu5@huawei.com> References: <20221029090011.79367-1-zhangxiaoxu5@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) 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 Sat Oct 29 09:00:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Xiaoxu X-Patchwork-Id: 13024537 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 DADF8C38A02 for ; Sat, 29 Oct 2022 07:55:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229500AbiJ2Hzw (ORCPT ); Sat, 29 Oct 2022 03:55:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229665AbiJ2Hzo (ORCPT ); Sat, 29 Oct 2022 03:55:44 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA60F6EF29 for ; Sat, 29 Oct 2022 00:55:39 -0700 (PDT) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Mzs6G4xm9zVhyl; Sat, 29 Oct 2022 15:50:46 +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; Sat, 29 Oct 2022 15:55:37 +0800 From: Zhang Xiaoxu To: , , , , , , , Subject: [PATCH v2 6/7] cifs: Fix wrong return value checking when GETFLAGS Date: Sat, 29 Oct 2022 17:00:10 +0800 Message-ID: <20221029090011.79367-7-zhangxiaoxu5@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221029090011.79367-1-zhangxiaoxu5@huawei.com> References: <20221029090011.79367-1-zhangxiaoxu5@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) 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 Sat Oct 29 09:00:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Xiaoxu X-Patchwork-Id: 13024534 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 DEAB0FA3743 for ; Sat, 29 Oct 2022 07:55:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229571AbiJ2Hzs (ORCPT ); Sat, 29 Oct 2022 03:55:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229615AbiJ2Hzn (ORCPT ); Sat, 29 Oct 2022 03:55:43 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA98D6BCE6 for ; Sat, 29 Oct 2022 00:55:40 -0700 (PDT) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Mzs7s6vd1zpW37; Sat, 29 Oct 2022 15:52:09 +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; Sat, 29 Oct 2022 15:55:38 +0800 From: Zhang Xiaoxu To: , , , , , , , Subject: [PATCH v2 7/7] cifs: Reset rc before free_xid() Date: Sat, 29 Oct 2022 17:00:11 +0800 Message-ID: <20221029090011.79367-8-zhangxiaoxu5@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221029090011.79367-1-zhangxiaoxu5@huawei.com> References: <20221029090011.79367-1-zhangxiaoxu5@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) 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 | 36 ++++++++++++++++++++---------------- fs/cifs/smb2file.c | 9 +++++---- 3 files changed, 27 insertions(+), 20 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 5b3b308e115c..238427b2aed2 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; @@ -579,14 +579,16 @@ int cifs_open(struct inode *inode, struct file *file) cifs_sb = CIFS_SB(inode->i_sb); if (unlikely(cifs_forced_shutdown(cifs_sb))) { + rc = -EIO; 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 = 0; unsigned int xid; __u32 oplock; struct cifs_sb_info *cifs_sb; @@ -779,7 +781,7 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) if (!cfile->invalidHandle) { mutex_unlock(&cfile->fh_mutex); free_xid(xid); - return 0; + return rc; } inode = d_inode(cfile->dentry); @@ -798,8 +800,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 +1340,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 +1352,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 +1389,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) } kfree(buf); +out: free_xid(xid); return rc; } @@ -1934,7 +1938,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 +1962,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 +1970,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; } @@ -4411,8 +4414,9 @@ 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) { + rc = -ENOSYS; free_xid(xid); - return -ENOSYS; + return rc; } if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) 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; }