Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp197886imj; Thu, 14 Feb 2019 18:29:44 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib9A2UOodX6Wjrzf0oENjwRl/+FLZD7MePjjaAF5ey23kZy2IXifp4m6hUp5fmBMnHlLBZW X-Received: by 2002:aa7:9099:: with SMTP id i25mr7511225pfa.102.1550197783952; Thu, 14 Feb 2019 18:29:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550197783; cv=none; d=google.com; s=arc-20160816; b=sGC2dC55lCs/hbFYBXwF1vsKVFsSRG5zwJErjsyRz6e5u3gIO+LX0nFwWvcFQMv8AL 7W2PRvZw1B+iW/eofXaYGX2EAaKuv4iKt78q1yiZCFN1mPyFJhHuEsbFRCEKGgU5dvCz 9EaVeMnmPnvcreCCj5fUgZQfu2tkyG1yfxSN4fY+daLUS9NwucEvfxy4knu22wkuebfK EGV70ypbFm99x/9HNzeob0IbvUadOJ15QFzVxsDGiN6Fzgd4N7TdW6R27q5VuWJiMH9F mDW2Qj4EefOMsUTxg/OCywwZPabWxjukwwQB93lJutHtznI3Or0MR4RQj5kmqtxO1wib I6bg== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FPXNsGSIBvUrUIw89Z5NW1OMqic7qjW+XV1xW7B4nLA=; b=tNHT4vVcpx4fZ2uiTJoWHbj9knFH3YTUixTYg3KYxvZt2MvhoyZIedaLHexwqm5Vpa nQyBhzlTwVqe9y5Di+ZBCXv68BNW3t7KlF6ng8vPgYRf4o79xaez8uncorlUoDrcqaor lWFocSiMYHoRnaLbGdCxClNx6aiL6qHO8G6s0GlvA47RlKwaLyDxLZ2GQgeYmcXgfLjY hejfA7wtJWNfeIuZphbeExCGnk4crZUqvbgvyuGSxyRADcwvh5anTSdUmz6Ltjimxwca SHRKZ5FjSfry79jQ0mDp20rWEKgpZP4L5InUL2cHocZXH3CKtzL4NKItdsw0aesux09e NTnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MhRroohj; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o3si4007499pls.265.2019.02.14.18.29.27; Thu, 14 Feb 2019 18:29:43 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=MhRroohj; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390709AbfBOCKj (ORCPT + 99 others); Thu, 14 Feb 2019 21:10:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:50814 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390663AbfBOCKi (ORCPT ); Thu, 14 Feb 2019 21:10:38 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E206C222A1; Fri, 15 Feb 2019 02:10:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550196637; bh=OV/rdYHQmSlP/1aWBJ/SzhvP3Wu6ISfOiCoS98We1ns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MhRroohjxB198FBOP3h/vR35FLzlmNqVhlBSei0920UJksMH0bBzXlN9PNnrgvpuK bmvOj/mpKGQRYfts8oU6/GgrZe+18AIlmT2eR2nGtquKe9lbFfgHKkGy0yRhqvuGYr FgS3L2UuOUmmHnM3sQOM76I2+MXeWs/quXHNehtI= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Colin Ian King , Steve French , Sasha Levin , linux-cifs@vger.kernel.org Subject: [PATCH AUTOSEL 4.20 62/77] cifs: fix memory leak of an allocated cifs_ntsd structure Date: Thu, 14 Feb 2019 21:08:40 -0500 Message-Id: <20190215020855.176727-62-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190215020855.176727-1-sashal@kernel.org> References: <20190215020855.176727-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King [ Upstream commit 73aaf920cc72024c4a4460cfa46d56e5014172f3 ] The call to SMB2_queary_acl can allocate memory to pntsd and also return a failure via a call to SMB2_query_acl (and then query_info). This occurs when query_info allocates the structure and then in query_info the call to smb2_validate_and_copy_iov fails. Currently the failure just returns without kfree'ing pntsd hence causing a memory leak. Currently, *data is allocated if it's not already pointing to a buffer, so it needs to be kfree'd only if was allocated in query_info, so the fix adds an allocated flag to track this. Also set *dlen to zero on an error just to be safe since *data is kfree'd. Also set errno to -ENOMEM if the allocation of *data fails. Signed-off-by: Colin Ian King Signed-off-by: Steve French Reviewed-by: Dan Carpener Signed-off-by: Sasha Levin --- fs/cifs/smb2pdu.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index c393ac255af7..d1ae7cdb236d 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -2714,6 +2714,7 @@ query_info(const unsigned int xid, struct cifs_tcon *tcon, int resp_buftype = CIFS_NO_BUFFER; struct cifs_ses *ses = tcon->ses; int flags = 0; + bool allocated = false; cifs_dbg(FYI, "Query Info\n"); @@ -2753,14 +2754,21 @@ query_info(const unsigned int xid, struct cifs_tcon *tcon, "Error %d allocating memory for acl\n", rc); *dlen = 0; + rc = -ENOMEM; goto qinf_exit; } + allocated = true; } } rc = smb2_validate_and_copy_iov(le16_to_cpu(rsp->OutputBufferOffset), le32_to_cpu(rsp->OutputBufferLength), &rsp_iov, min_len, *data); + if (rc && allocated) { + kfree(*data); + *data = NULL; + *dlen = 0; + } qinf_exit: SMB2_query_info_free(&rqst); -- 2.19.1