Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2281196ybl; Thu, 19 Dec 2019 10:57:31 -0800 (PST) X-Google-Smtp-Source: APXvYqwN/vxk35ZQwXXnTnYbgttJkl7PKn7LafNujwQXKgqCsaBszw7GdoGty9U3wX0MbAnpO4GM X-Received: by 2002:a9d:7590:: with SMTP id s16mr9682999otk.89.1576781850929; Thu, 19 Dec 2019 10:57:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576781850; cv=none; d=google.com; s=arc-20160816; b=X0tlnBSHDi4Vm51+RTrQXhYMNSFydMFf8kA76ckTz850BQrZ0Y1JdnFvjEL024WCne RwCwRbZnnYKzyuwuDiRf9EAEVtbFQcbkQW3MDPbzjuj31beePnSwSGYkOfIcBKDJlVEH 5y2s7YZ0ezLfPoNutDGj97fKtCWsGR9D2WBiB1W4ufCIhEs8OypzXuJ0BV0YkkVFnGAU DTS7BGW9scIXkV3fAOSOohfNu5rDxg6wTyPGwQPEft1F4bJovzOA/lSBA4MHXj+GvNGU LyyGbKjtBVQx3QGvvIHWVoCyR+fYKRxhFPrIHMIVVMdoTauqsM8nmStk8ug/0XYQpRNM 0bVg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SOa/88R6fobIWFr2N3s2G/AU6/GhH+c7ULWO7xv5J3I=; b=JKwiobAg0RNccRicoU9SkY2y//WaNqu3I9XiM9Lxi5rJm61tKehSAk81jaq674bWiq /q04JrNHFPmj/lBpzizdD8wvxfZPE24MIM2g7tO9mbcXRDleagaRZ671xZPCWAafZb4V I5YRwtKCdc6KwwjW9bgeQk5ZJMXlrTg+4tv98gEUYMYnWzkzl2WxlqjX9yPg4XeuCeMv yomzqaUKk/k51srPML/RM4z+PowRxzdAWEZGJHLbnnqZmM8NvFtt4ay7BD5lWlZKPRsq 415OwicSls2PLi01yEkpeKOHGxDvBlkDipYhY1C4kAzZoOEqW8HxiwtlSbxqxDboV0xK 1jUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NdFRQq3L; 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 2si2780509ois.221.2019.12.19.10.57.18; Thu, 19 Dec 2019 10:57:30 -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=NdFRQq3L; 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 S1730270AbfLSS4W (ORCPT + 99 others); Thu, 19 Dec 2019 13:56:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:52784 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730791AbfLSS4R (ORCPT ); Thu, 19 Dec 2019 13:56:17 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0FAE9206EC; Thu, 19 Dec 2019 18:56:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576781776; bh=BahGp/WcvJzSgRLqgRvYNiiQbWUBKF2w/g8tzngIBnw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NdFRQq3L+VZRXlbVAM++tUdiftVhk56eb4Ci1+FKYSLeI3OBEyXAN2Lwefmek0VvN 3bmh+AZzmj1dySJpzE0/Lgd4hBGHhBKCuQsUFaVxNcIUEsBHr5SdzlH5sHE65D8NJy sgEezNPB4Y3gMyADgkecXivJTE2Y1LrqXg4GW1rE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Frank Sorenson , Ronnie Sahlberg , Pavel Shilovsky , Steve French Subject: [PATCH 5.4 37/80] CIFS: Fix NULL pointer dereference in mid callback Date: Thu, 19 Dec 2019 19:34:29 +0100 Message-Id: <20191219183107.612439697@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219183031.278083125@linuxfoundation.org> References: <20191219183031.278083125@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Shilovsky commit 86a7964be7afaf3df6b64faaa10a7032d2444e51 upstream. There is a race between a system call processing thread and the demultiplex thread when mid->resp_buf becomes NULL and later is being accessed to get credits. It happens when the 1st thread wakes up before a mid callback is called in the 2nd one but the mid state has already been set to MID_RESPONSE_RECEIVED. This causes NULL pointer dereference in mid callback. Fix this by saving credits from the response before we update the mid state and then use this value in the mid callback rather then accessing a response buffer. Cc: Stable Fixes: ee258d79159afed5 ("CIFS: Move credit processing to mid callbacks for SMB3") Tested-by: Frank Sorenson Reviewed-by: Ronnie Sahlberg Signed-off-by: Pavel Shilovsky Signed-off-by: Steve French Signed-off-by: Greg Kroah-Hartman --- fs/cifs/cifsglob.h | 1 + fs/cifs/connect.c | 15 +++++++++++++++ fs/cifs/smb2ops.c | 8 +------- 3 files changed, 17 insertions(+), 7 deletions(-) --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -1524,6 +1524,7 @@ struct mid_q_entry { struct TCP_Server_Info *server; /* server corresponding to this mid */ __u64 mid; /* multiplex id */ __u16 credits; /* number of credits consumed by this mid */ + __u16 credits_received; /* number of credits from the response */ __u32 pid; /* process id */ __u32 sequence_number; /* for CIFS signing */ unsigned long when_alloc; /* when mid was created */ --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -905,6 +905,20 @@ dequeue_mid(struct mid_q_entry *mid, boo spin_unlock(&GlobalMid_Lock); } +static unsigned int +smb2_get_credits_from_hdr(char *buffer, struct TCP_Server_Info *server) +{ + struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buffer; + + /* + * SMB1 does not use credits. + */ + if (server->vals->header_preamble_size) + return 0; + + return le16_to_cpu(shdr->CreditRequest); +} + static void handle_mid(struct mid_q_entry *mid, struct TCP_Server_Info *server, char *buf, int malformed) @@ -912,6 +926,7 @@ handle_mid(struct mid_q_entry *mid, stru if (server->ops->check_trans2 && server->ops->check_trans2(mid, server, buf, malformed)) return; + mid->credits_received = smb2_get_credits_from_hdr(buf, server); mid->resp_buf = buf; mid->large_buf = server->large_buf; /* Was previous buf put in mpx struct for multi-rsp? */ --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -151,13 +151,7 @@ smb2_get_credits_field(struct TCP_Server static unsigned int smb2_get_credits(struct mid_q_entry *mid) { - struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)mid->resp_buf; - - if (mid->mid_state == MID_RESPONSE_RECEIVED - || mid->mid_state == MID_RESPONSE_MALFORMED) - return le16_to_cpu(shdr->CreditRequest); - - return 0; + return mid->credits_received; } static int