Received: by 10.192.165.148 with SMTP id m20csp824157imm; Fri, 27 Apr 2018 08:05:39 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpX7RoaCFgepclFA4LLJIMWcgzITJZVU+1dIprZF20J67lqar03A208ithLH5etG7SnbUgm X-Received: by 10.98.81.197 with SMTP id f188mr2539714pfb.136.1524841539255; Fri, 27 Apr 2018 08:05:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524841539; cv=none; d=google.com; s=arc-20160816; b=rwpIe/O7BFZgPOH6CD5yJce0xuAR3ItyZ1yOt4k81+w+QG2finsD0stfBs7v3WMLEZ 9h7NNNVFbA9MvNs9wuaosMj8h/csT1reX8I7fBw9DY/cf/QcDmnST8DtDpYNRqP+aj7J GQ5Kse2/eZTm9cUroOtjtUXNNBli6L1NK6w63Co9MrieJbOY4EAzlbHQjTxN4BsB992P OcTWEOUqDsl76NndiAMLQUaGNrZDrBxp2a0HomEi1sqVhg3wUrA1IL/2Y0/OBBSX2cay y7SKmY9zulRbJlcSk8nKy6bSXes47TkEqpuSeqWDwQYVy7CDkbE5RpGm19rcWpqAEzxO ppKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dmarc-filter :arc-authentication-results; bh=cZVk5vjlxCyGbJGfnPv+8KPxH26a6gEjb1swRKqBs0Q=; b=nnr8Qwl21HPkkKmn8sx+B9sEdEMKyb3sl6hokylCvElBbeLVIm500MoROl4uFNJ/fb n2wRRnQk11328P/+K+TvPV8HI84wrTLme4LFI1hGof/arjGCUGOPFFPXqjDf4OcYVbu5 iP1Qe9e6LeUFIsV3oFj/ahoyDWTuqshV+Kzz0tOHAHycPgZCe4rMgXfeQ0yFwnPsPAUq 99g+BwxCtWdRGol1NZhXIiK/c1cRIdTwKiecl3FsZ1pTcftqhL5py6mjrzV63TvCQXIf 0AW2NWkX4ekjO0a499Jez7LYYL5y/WswG1DbQAi2pZUuIr/7YAs8fOaWEdbJwt7QU21u NxIA== 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 s2-v6si1360194pge.176.2018.04.27.08.05.24; Fri, 27 Apr 2018 08:05:39 -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 S933856AbeD0OFJ (ORCPT + 99 others); Fri, 27 Apr 2018 10:05:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:51380 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933222AbeD0OFF (ORCPT ); Fri, 27 Apr 2018 10:05:05 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 2E27921890; Fri, 27 Apr 2018 14:05:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2E27921890 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, kernel test robot , Cong Wang , "David S. Miller" Subject: [PATCH 4.9 62/74] llc: fix NULL pointer deref for SOCK_ZAPPED Date: Fri, 27 Apr 2018 15:58:52 +0200 Message-Id: <20180427135712.507232228@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180427135709.899303463@linuxfoundation.org> References: <20180427135709.899303463@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Cong Wang [ Upstream commit 3a04ce7130a7e5dad4e78d45d50313747f8c830f ] For SOCK_ZAPPED socket, we don't need to care about llc->sap, so we should just skip these refcount functions in this case. Fixes: f7e43672683b ("llc: hold llc_sap before release_sock()") Reported-by: kernel test robot Signed-off-by: Cong Wang Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/llc/af_llc.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) --- a/net/llc/af_llc.c +++ b/net/llc/af_llc.c @@ -187,7 +187,6 @@ static int llc_ui_release(struct socket { struct sock *sk = sock->sk; struct llc_sock *llc; - struct llc_sap *sap; if (unlikely(sk == NULL)) goto out; @@ -198,15 +197,19 @@ static int llc_ui_release(struct socket llc->laddr.lsap, llc->daddr.lsap); if (!llc_send_disc(sk)) llc_ui_wait_for_disc(sk, sk->sk_rcvtimeo); - sap = llc->sap; - /* Hold this for release_sock(), so that llc_backlog_rcv() could still - * use it. - */ - llc_sap_hold(sap); - if (!sock_flag(sk, SOCK_ZAPPED)) + if (!sock_flag(sk, SOCK_ZAPPED)) { + struct llc_sap *sap = llc->sap; + + /* Hold this for release_sock(), so that llc_backlog_rcv() + * could still use it. + */ + llc_sap_hold(sap); llc_sap_remove_socket(llc->sap, sk); - release_sock(sk); - llc_sap_put(sap); + release_sock(sk); + llc_sap_put(sap); + } else { + release_sock(sk); + } if (llc->dev) dev_put(llc->dev); sock_put(sk);