Received: by 10.192.165.148 with SMTP id m20csp760677imm; Fri, 27 Apr 2018 07:07:36 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpNLkIRMqtSOTqENA5gHwKSQpPn54vSjlk/eKxxWUSt8JgFVs+8F1NFOq/D5Pp7rXN2mJYH X-Received: by 2002:a65:414d:: with SMTP id x13-v6mr2313471pgp.223.1524838056428; Fri, 27 Apr 2018 07:07:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524838056; cv=none; d=google.com; s=arc-20160816; b=j+n90p8wUJuTLj7+hvSNDRLtVIpHOdHdwrbqsL4nAO7Lw/BN7DUSBEEKshEzNflU9F DrUUMpXVY9/Rt1nPKhQqr6ZdJtieNyYdg5cBBkgTLXFZ15EYKuJkYFeIbBk92HUST+hI mcXdrabiWFdQQKhVCV+zVrW/7+jyjMl/T8jDSPVtttxrAuKwrax+FI+tjzO+nhSMSeg9 5I73SBX/QSy2Xw1FkmJE/mG5/wFNDEd19NcvwhFZ55czVCywMdrNRq+rWFS7kjJ4ykuZ kb56uxZaSEP4Bfb8h/zZlzM9WaIxJvvWQe014Co4hrb5+T6qTztEdaA5Ao/VnnqIkGqH fBCw== 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=OPN2mBajOyZ7vUf5L1ZXZ8e1czxGOv1ld4FYMPm9WTc=; b=vH2ImmloJ8KqyFexiHvMgbeqzL5BSagUnTHhM8cIRkgyiefi3ASOUaihfLo4RVu+mH bNQNGwTRLpR6Ah5s5Lz8/RlupCQJL4kEG6qhU+86KxjCA88u9WMsZg/I0PReDi+sHvhR msU/tOWe8er+Zx4n6l65FKpHduCCBsF8BwKPw2SSc2DwuxFzEXEL6TNhkk+gli2j+UdI CCKgVjeJxoBbB5JJ+qwT9NFt/yen9+xu+nLmjI/TJpJxB5OMRqFjfa0Nk5RuRQGEfI43 34r3qpH1569b3d9sQcyz1b0BeowJHWiTjXlHTa/JNEee9H1J5Vkqk46aI2QEc8gpLK+M U38w== 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 g33-v6si1352735plb.297.2018.04.27.07.07.22; Fri, 27 Apr 2018 07:07:36 -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 S933869AbeD0OFL (ORCPT + 99 others); Fri, 27 Apr 2018 10:05:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:51330 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933840AbeD0OFC (ORCPT ); Fri, 27 Apr 2018 10:05:02 -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 9FACD21892; Fri, 27 Apr 2018 14:05:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9FACD21892 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.9 61/74] llc: hold llc_sap before release_sock() Date: Fri, 27 Apr 2018 15:58:51 +0200 Message-Id: <20180427135712.468234518@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 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 @@ -187,6 +187,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; @@ -197,9 +198,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);