Received: by 10.192.165.148 with SMTP id m20csp762772imm; Fri, 27 Apr 2018 07:09:24 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoxhG/RR83pvZLrjncBW4V27xP/oqtChhAmCzteDmMrjb4oFdJ4VdItkjGbhAnRUBpnUum2 X-Received: by 2002:a65:5b4d:: with SMTP id y13-v6mr2295176pgr.152.1524838164072; Fri, 27 Apr 2018 07:09:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524838164; cv=none; d=google.com; s=arc-20160816; b=BkrTCt6zJEthuPQy0rGfCl3rDUidVNvQt7ozrEiGeuwMuSgDtcF4IR0Y8hkqR94XUG eOUebskCyK8u/ae0hVm4JMD/1ikvnGYpD3LWvCLUAnsrvKnfFI2E9F5jPWCe1Q2cCyLw 5ctChx4NBhg5wwaME8pJ1sFwwzAMId/ARRQjxVWYpLFVKCt+ptfPoyT5xL1QX76dPQpf sUVSYHeszGZeDjniV13aMBUp3tjMOiglesPNHXpIExLBmydXzmRHR81P5mcHIkVu4lwJ +XTGpLbRWqUcgduKi9qrBAfWTpGMNGc1f20rFNfE69rfnH2Ji073vxPtPu5YT1etFIlZ qGhQ== 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=Peu7w3ukaqAAJgRwT4smkl6heC/9leGRtvCK8Juft80=; b=yffNZK3DXFk4C5R/wIOGMiHRzAWTPcP8OvNX2cRVSS0884V0AMjEcNoOVxurK+Vft9 TzSvtFc86ANi0gHInP6tc3ts5aZ8ahs5mJegitIskb2KAJJeA598OqgE9BNImRKrv541 WlIuy8ooDj2vcDBx6XGG7MlDDwaVciyfFg2xmb9sBsUcwBgtim/mYmPB2iJt8wQPR/XO nq7MNKx7lLz9OPMHylHmXwfZaaCg2u0iPAQ7cJuMx60nx0IUHkqye+pBp7KPFkgqaoEI yy5Y3KIE5SHj+ioq51BHhUJ7V6fvjZq+IWp73HBAJH/tV/9WAU+2HzuG9rrk/SWXBchQ V9QQ== 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 g2-v6si1283783pgu.212.2018.04.27.07.09.09; Fri, 27 Apr 2018 07:09:24 -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 S934421AbeD0OID (ORCPT + 99 others); Fri, 27 Apr 2018 10:08:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:53720 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934104AbeD0OIB (ORCPT ); Fri, 27 Apr 2018 10:08:01 -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 1C57E21864; Fri, 27 Apr 2018 14:07:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1C57E21864 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, syzbot+6e181fc95081c2cf9051@syzkaller.appspotmail.com, Cong Wang , "David S. Miller" Subject: [PATCH 4.14 36/80] llc: hold llc_sap before release_sock() Date: Fri, 27 Apr 2018 15:58:29 +0200 Message-Id: <20180427135734.793915209@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180427135732.928644313@linuxfoundation.org> References: <20180427135732.928644313@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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Cong Wang [ Upstream commit f7e43672683b097bb074a8fe7af9bc600a23f231 ] syzbot reported we still access llc->sap in llc_backlog_rcv() after it is freed in llc_sap_remove_socket(): Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0x1b9/0x294 lib/dump_stack.c:113 print_address_description+0x6c/0x20b mm/kasan/report.c:256 kasan_report_error mm/kasan/report.c:354 [inline] kasan_report.cold.7+0x242/0x2fe mm/kasan/report.c:412 __asan_report_load1_noabort+0x14/0x20 mm/kasan/report.c:430 llc_conn_ac_send_sabme_cmd_p_set_x+0x3a8/0x460 net/llc/llc_c_ac.c:785 llc_exec_conn_trans_actions net/llc/llc_conn.c:475 [inline] llc_conn_service net/llc/llc_conn.c:400 [inline] llc_conn_state_process+0x4e1/0x13a0 net/llc/llc_conn.c:75 llc_backlog_rcv+0x195/0x1e0 net/llc/llc_conn.c:891 sk_backlog_rcv include/net/sock.h:909 [inline] __release_sock+0x12f/0x3a0 net/core/sock.c:2335 release_sock+0xa4/0x2b0 net/core/sock.c:2850 llc_ui_release+0xc8/0x220 net/llc/af_llc.c:204 llc->sap is refcount'ed and llc_sap_remove_socket() is paired with llc_sap_add_socket(). This can be amended by holding its refcount before llc_sap_remove_socket() and releasing it after release_sock(). Reported-by: Signed-off-by: Cong Wang Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/llc/af_llc.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/net/llc/af_llc.c +++ b/net/llc/af_llc.c @@ -189,6 +189,7 @@ 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; @@ -199,9 +200,15 @@ 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)) llc_sap_remove_socket(llc->sap, sk); release_sock(sk); + llc_sap_put(sap); if (llc->dev) dev_put(llc->dev); sock_put(sk);