Received: by 10.192.165.148 with SMTP id m20csp784205imm; Fri, 27 Apr 2018 07:28:43 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoCOW78V/9cGqxhO+KDxbI7/zcrhYgF/xhdUr+ObgGRaIgkTJ3/5NGInmBQLHuA+IAnfGdA X-Received: by 2002:a17:902:598d:: with SMTP id p13-v6mr2513686pli.191.1524839323506; Fri, 27 Apr 2018 07:28:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524839323; cv=none; d=google.com; s=arc-20160816; b=zBMZ+m5Cz/WswJzmqnYlAIf4WxLNvcwPhyEWR2M0Qn74rEn7iG2agz1yZlE3t+t9MV NhiCL1o4rP+SE1V7ewzu6L4wqQxGrTZkTmKDhYRu04PSJCZG9rIed6fRI5ua/JUr8hBz nN4ldjbCguOWGvCdiGWUdKulHnQfaR1kKkEqoJSnucOh0qSmRhWcLoDBVqqONsGcRi2d Y3GQ71pRTn8ggdydCBVuUX6IVQG3MajZ2l1IMbRwRCjSjzt4pPFRAMAS8nrsfZoxMJzF HW9HWhrE44cprI8HEwZgrz5/d1E5MDBfhkHlaM3vgfquCaOGofZBilxclsN6WBTtfbeB d6zA== 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=fZl6E5pSAIuGc0+P4wBiZ0uTpwQ3uVuzqyjSeQde/6I=; b=Q8YQWosAvHt9fu7ShvPxMthVbqxiJ0bvDdsKWH+rvxfnKbPdoHYuaFl0o05THqv2Gd Us9TmsK6S+fLZTg76fsNFki6CPgBaWcrputv4AWJX6ntdJ5SQlfJ7UT4NGM7Jnhj8tc9 09sUJPykoibmObx8bq3Mpzb6dUtBgKiWzCy+qzxZFx5Vtv46GUNK3/rIj1VMFU0ZKBe0 BHeIi/9wCiCYmbsPvjuZalf/Rj054y3hlmBRdGQgPIBSe4F7uGbg29sxz8V+oW/lnSg1 j8E6X3JZmcO6qHKHdKYOdXgzkj0E47OP+m5cxQWeYT7z9WSkBM4xx2IxCYvB8qEb3/Eo OUfg== 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 t144-v6si1288628pgb.94.2018.04.27.07.28.29; Fri, 27 Apr 2018 07:28:43 -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 S935015AbeD0OL0 (ORCPT + 99 others); Fri, 27 Apr 2018 10:11:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:56144 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934986AbeD0OLQ (ORCPT ); Fri, 27 Apr 2018 10:11:16 -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 A54B82189E; Fri, 27 Apr 2018 14:11:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A54B82189E 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.16 45/81] llc: hold llc_sap before release_sock() Date: Fri, 27 Apr 2018 15:58:47 +0200 Message-Id: <20180427135745.814415328@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180427135743.216853156@linuxfoundation.org> References: <20180427135743.216853156@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.16-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);