Received: by 10.192.165.156 with SMTP id m28csp1507956imm; Wed, 18 Apr 2018 10:44:15 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+HUpLo1cvTItR+i/RIvP/Q/oaw3sR6DXq/+6D92u4c+Tdtf/jQQBaiAjAR7kW1J3rJ+CWK X-Received: by 2002:a17:902:b595:: with SMTP id a21-v6mr2958083pls.68.1524073455468; Wed, 18 Apr 2018 10:44:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524073455; cv=none; d=google.com; s=arc-20160816; b=W8bY7EHHxsKuQNRA4tWrhhpNoLd25r4JbRQQHjjJJjHfTH4JZAJn2J0H1pBJ8F9YfG S9qVQbOi1uNtl+ReTiPsCMAT17odWrRIbNkcvTWdB21p4w68LXRg0ScCtnISa+TPHSlu 1UKhRofuSovrGsjGlEgvgsF62elP/78591nb7PvN3edZbRKBY25TKqO7cFjNjwQmQKRL QVlsjOJCBICjmTGFnRFeeXR/hauHzYjkXeG7XiIgizZpdmr125V69woqFiGS8XAhnRv6 VJTN7N0Bc0bcDX81xN0GCecjqNWR8o40VWJ4cEjkdJLvLY8Jt2+omoQWodKPeIVaOSom P1Hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=RcMtlKM/teT9DMqDkSY/tj7fwBJk7jac4IH5//dzmD8=; b=rJGpCCcepNMY8TxmlC4OiraFC8Vxag4Xjsca+2lCemW0EPG8yLePf50q6Ix93NcY9E d6xb6A/aY9I+giZ6t/2vMne9EUG3exH7xdErg7y3DgenQhO7Th8ZzTXGpTMeOTdCNbDz eL4nSrswo4Y8zenmC3FG4Qg1S+Nn3A5sercBtVsWHcX2nDrzm9wEMoutOiJprlitrpHd XG/TFJ/o1faVvX12Yqr0Y0wl/NOuQvXkKEsmbV9UE73s9pIfND+XgXSOG3osuzRetNTp 2pNhRwh1JzJE15M8jIBKoYy6au4tRstvXQWetGSPDpvgA36CZb6wiSqVUMvd+inEISlz 7grQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t10si1456260pgr.548.2018.04.18.10.44.01; Wed, 18 Apr 2018 10:44:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752864AbeDRRmw (ORCPT + 99 others); Wed, 18 Apr 2018 13:42:52 -0400 Received: from p3plsmtpa11-05.prod.phx3.secureserver.net ([68.178.252.106]:47394 "EHLO p3plsmtpa11-05.prod.phx3.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752336AbeDRRmr (ORCPT ); Wed, 18 Apr 2018 13:42:47 -0400 Received: from [192.168.0.55] ([24.218.182.144]) by :SMTPAUTH: with SMTP id 8r6Tfk9Ic0pGS8r6UfGEEK; Wed, 18 Apr 2018 10:42:47 -0700 Subject: Re: [Patch v3 2/6] cifs: Allocate validate negotiation request through kmalloc To: Long Li , Steve French , "linux-cifs@vger.kernel.org" , "samba-technical@lists.samba.org" , "linux-kernel@vger.kernel.org" , "linux-rdma@vger.kernel.org" Cc: "stable@vger.kernel.org" References: <20180418003358.25098-1-longli@linuxonhyperv.com> From: Tom Talpey Message-ID: Date: Wed, 18 Apr 2018 13:42:44 -0400 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4wfPjs3boyOoqXtBLrK6fF3hWYorRfqSwJle7iwUzxVJZqdvBa4P2j1848Pig2XprAkVBV04Zerqg43KFyIeBsPra+E24saMrwSUOgGOfk9MNCa/hxeqWq vRiGLGhgbnD6w3KhcRqGw225g6Jnklyd/GRplqyCpNFnFK7aCeESqRcpaS3j2CxWULl4O5Kwl9FM1mkzlNVIQBDcnLV/V09UapwpEM3WtPnTA+bqCK15NBvj xeIsGmQzSUvaPSx4tbjJv8qeRO0fTRtkVpTXewHwF4oUKsRu7ikt8L55zkwSdcUgQ32MF7uvwlog9F9HfmpMVF1Wm+D8P9LkQYs+Nd5xYh1woN8mPMIwun3J 1zRFJp9+42g8fpErzsNNn/4wTzdmTOPB5lrLjwniL19XKEJ7ja0= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/18/2018 1:16 PM, Long Li wrote: >> Subject: Re: [Patch v3 2/6] cifs: Allocate validate negotiation request through >> kmalloc >> >> Two comments. >> >> On 4/17/2018 8:33 PM, Long Li wrote: >>> From: Long Li >>> >>> The data buffer allocated on the stack can't be DMA'ed, and hence >>> can't send through RDMA via SMB Direct. >> >> This comment is confusing. Any registered memory can be DMA'd, need to >> state the reason for the choice here more clearly. >> >>> >>> Fix this by allocating the request on the heap in smb3_validate_negotiate. >>> >>> Changes in v2: >>> Removed duplicated code on freeing buffers on function exit. >>> (Thanks to Parav Pandit ) Fixed typo in the patch >>> title. >>> >>> Changes in v3: >>> Added "Fixes" to the patch. >>> Changed sizeof() to use *pointer in place of struct. >>> >>> Fixes: ff1c038addc4 ("Check SMB3 dialects against downgrade attacks") >>> Signed-off-by: Long Li >>> Cc: stable@vger.kernel.org >>> --- >>> fs/cifs/smb2pdu.c | 59 ++++++++++++++++++++++++++++++-------------- >> ----------- >>> 1 file changed, 32 insertions(+), 27 deletions(-) >>> >>> diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index >>> 0f044c4..5582a02 100644 >>> --- a/fs/cifs/smb2pdu.c >>> +++ b/fs/cifs/smb2pdu.c >>> @@ -729,8 +729,8 @@ SMB2_negotiate(const unsigned int xid, struct >>> cifs_ses *ses) >>> >>> int smb3_validate_negotiate(const unsigned int xid, struct cifs_tcon *tcon) >>> { >>> - int rc = 0; >>> - struct validate_negotiate_info_req vneg_inbuf; >>> + int ret, rc = -EIO; >>> + struct validate_negotiate_info_req *pneg_inbuf; >>> struct validate_negotiate_info_rsp *pneg_rsp = NULL; >>> u32 rsplen; >>> u32 inbuflen; /* max of 4 dialects */ @@ -741,6 +741,9 @@ int >>> smb3_validate_negotiate(const unsigned int xid, struct cifs_tcon *tcon) >>> if (tcon->ses->server->rdma) >>> return 0; >>> #endif >>> + pneg_inbuf = kmalloc(sizeof(*pneg_inbuf), GFP_KERNEL); >>> + if (!pneg_inbuf) >>> + return -ENOMEM; >> >> Why is this a nonblocking allocation? It would seem more robust to use >> GFP_NOFS here. > > I agree it makes sense to use GFP_NOFS. > > The choice here is made consistent with all the rest CIFS code allocating protocol request buffers. Maybe we should do another patch to cleanup all those code. It'll be required sooner or later. I'm agnostic as to how you apply it, but I still suggest you change this one now rather than continue the fragile behavior. It may not be a global search-and-replace since some allocations may require nonblocking. > >> >> Tom. >> >>> >>> /* In SMB3.11 preauth integrity supersedes validate negotiate */ >>> if (tcon->ses->server->dialect == SMB311_PROT_ID) @@ -764,63 >>> +767,63 @@ int smb3_validate_negotiate(const unsigned int xid, struct >> cifs_tcon *tcon) >>> if (tcon->ses->session_flags & SMB2_SESSION_FLAG_IS_NULL) >>> cifs_dbg(VFS, "Unexpected null user (anonymous) auth flag >> sent by >>> server\n"); >>> >>> - vneg_inbuf.Capabilities = >>> + pneg_inbuf->Capabilities = >>> cpu_to_le32(tcon->ses->server->vals- >>> req_capabilities); >>> - memcpy(vneg_inbuf.Guid, tcon->ses->server->client_guid, >>> + memcpy(pneg_inbuf->Guid, tcon->ses->server->client_guid, >>> SMB2_CLIENT_GUID_SIZE); >>> >>> if (tcon->ses->sign) >>> - vneg_inbuf.SecurityMode = >>> + pneg_inbuf->SecurityMode = >>> >> cpu_to_le16(SMB2_NEGOTIATE_SIGNING_REQUIRED); >>> else if (global_secflags & CIFSSEC_MAY_SIGN) >>> - vneg_inbuf.SecurityMode = >>> + pneg_inbuf->SecurityMode = >>> >> cpu_to_le16(SMB2_NEGOTIATE_SIGNING_ENABLED); >>> else >>> - vneg_inbuf.SecurityMode = 0; >>> + pneg_inbuf->SecurityMode = 0; >>> >>> >>> if (strcmp(tcon->ses->server->vals->version_string, >>> SMB3ANY_VERSION_STRING) == 0) { >>> - vneg_inbuf.Dialects[0] = cpu_to_le16(SMB30_PROT_ID); >>> - vneg_inbuf.Dialects[1] = cpu_to_le16(SMB302_PROT_ID); >>> - vneg_inbuf.DialectCount = cpu_to_le16(2); >>> + pneg_inbuf->Dialects[0] = cpu_to_le16(SMB30_PROT_ID); >>> + pneg_inbuf->Dialects[1] = cpu_to_le16(SMB302_PROT_ID); >>> + pneg_inbuf->DialectCount = cpu_to_le16(2); >>> /* structure is big enough for 3 dialects, sending only 2 */ >>> inbuflen = sizeof(struct validate_negotiate_info_req) - 2; >>> } else if (strcmp(tcon->ses->server->vals->version_string, >>> SMBDEFAULT_VERSION_STRING) == 0) { >>> - vneg_inbuf.Dialects[0] = cpu_to_le16(SMB21_PROT_ID); >>> - vneg_inbuf.Dialects[1] = cpu_to_le16(SMB30_PROT_ID); >>> - vneg_inbuf.Dialects[2] = cpu_to_le16(SMB302_PROT_ID); >>> - vneg_inbuf.DialectCount = cpu_to_le16(3); >>> + pneg_inbuf->Dialects[0] = cpu_to_le16(SMB21_PROT_ID); >>> + pneg_inbuf->Dialects[1] = cpu_to_le16(SMB30_PROT_ID); >>> + pneg_inbuf->Dialects[2] = cpu_to_le16(SMB302_PROT_ID); >>> + pneg_inbuf->DialectCount = cpu_to_le16(3); >>> /* structure is big enough for 3 dialects */ >>> inbuflen = sizeof(struct validate_negotiate_info_req); >>> } else { >>> /* otherwise specific dialect was requested */ >>> - vneg_inbuf.Dialects[0] = >>> + pneg_inbuf->Dialects[0] = >>> cpu_to_le16(tcon->ses->server->vals->protocol_id); >>> - vneg_inbuf.DialectCount = cpu_to_le16(1); >>> + pneg_inbuf->DialectCount = cpu_to_le16(1); >>> /* structure is big enough for 3 dialects, sending only 1 */ >>> inbuflen = sizeof(struct validate_negotiate_info_req) - 4; >>> } >>> >>> - rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, >>> + ret = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, >>> FSCTL_VALIDATE_NEGOTIATE_INFO, true /* is_fsctl */, >>> - (char *)&vneg_inbuf, sizeof(struct >> validate_negotiate_info_req), >>> + (char *)pneg_inbuf, sizeof(*pneg_inbuf), >>> (char **)&pneg_rsp, &rsplen); >>> >>> - if (rc != 0) { >>> - cifs_dbg(VFS, "validate protocol negotiate failed: %d\n", rc); >>> - return -EIO; >>> + if (ret) { >>> + cifs_dbg(VFS, "validate protocol negotiate failed: %d\n", ret); >>> + goto out_free_inbuf; >>> } >>> >>> - if (rsplen != sizeof(struct validate_negotiate_info_rsp)) { >>> + if (rsplen != sizeof(*pneg_rsp)) { >>> cifs_dbg(VFS, "invalid protocol negotiate response >> size: %d\n", >>> rsplen); >>> >>> /* relax check since Mac returns max bufsize allowed on ioctl >> */ >>> if ((rsplen > CIFSMaxBufSize) >>> || (rsplen < sizeof(struct validate_negotiate_info_rsp))) >>> - goto err_rsp_free; >>> + goto out_free_rsp; >>> } >>> >>> /* check validate negotiate info response matches what we got >>> earlier */ @@ -838,14 +841,16 @@ int smb3_validate_negotiate(const >>> unsigned int xid, struct cifs_tcon *tcon) >>> >>> /* validate negotiate successful */ >>> cifs_dbg(FYI, "validate negotiate info successful\n"); >>> - kfree(pneg_rsp); >>> - return 0; >>> + rc = 0; >>> + goto out_free_rsp; >>> >>> vneg_out: >>> cifs_dbg(VFS, "protocol revalidation - security settings >>> mismatch\n"); >>> -err_rsp_free: >>> +out_free_rsp: >>> kfree(pneg_rsp); >>> - return -EIO; >>> +out_free_inbuf: >>> + kfree(pneg_inbuf); >>> + return rc; >>> } >>> >>> enum securityEnum >>> > N�����r��y���b�X��ǧv�^�)޺{.n�+����{��ٚ�{ay�ʇڙ�,j��f���h���z��w��� ���j:+v���w�j�m��������zZ+�����ݢj"��!tml= >