Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3171194pxp; Mon, 14 Mar 2022 12:26:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGPDR/sLMP1NI6ZDjdoDLk6vRvgPJ32WmUKN7GwTuTCVfGxs7snomU0uBglvnTsEnZKgc+ X-Received: by 2002:a05:6402:430c:b0:416:c695:7c23 with SMTP id m12-20020a056402430c00b00416c6957c23mr18254323edc.367.1647286017080; Mon, 14 Mar 2022 12:26:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647286017; cv=none; d=google.com; s=arc-20160816; b=lqWFsEMo1mKb8PkEUbIyrpC2xh80YcRnx19jVin7bhoL2NMzy6QSNC/mL4KxSi6M8/ 0Qx0OJCn2uOGXDtx7l0aR4oJQgGecfaCOhQ00fSCY+KfRKTx+MReYgtnQR9QDmp+hb4z BHNrtLitDX4FUqF/o3VZZPuHMj1ebH0dQlN+svlx5+GQd8Jlh/0Wi890EyggvWbb6Oc2 9Xe4ujd+zLorzdcOIe+WB04/l640d3WkOB7wb/sUeZsUVCjDBhu6gpKDOol4JCCJUNjH Fmv1s7XIsgpqPO+F6cndctuqFKHNJ+GsaqsHxo+UzXhbLWNHYy8A9E35gpBoBi9kxUtB MiAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hwZ4f077Z2npLBieLH8SaD70FGkDBhiGuy6sfQvF6rs=; b=JVgeVYPpLg/SQjFphCul23LNKjnM1MhVk7u6kl/7Huw2Mb1e27gRAQiAesMbdxR/4/ THBJe6JF5AHiamVm6IbYXkAbA8b1OYZ5rE8Xc6iXcaJfalca7A9A75v8Y8hIQBhn/S/K Y5rT89zcuKBnJn5ddtEZD2A+7n1rrOOJfKp9GzYXKxcsq82MOXqCI7C/CPIOECEge9UZ N4N2ArhLmxIi5lrrIHhxuN+BVeDS2ibPmZo9DgCQoBZek9ls8uRLSj4x7yE1shd/KG3L BaQj/24HhTtEjgpdOxwuCqzqjNdzbM1G39eOZ2hRD4ZUx6O0O6xq+QB1oThEulFf2iKn yYOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pEndiGnz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o15-20020a509b0f000000b00415d59918cesi13874188edi.81.2022.03.14.12.26.24; Mon, 14 Mar 2022 12:26:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pEndiGnz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241349AbiCNMNN (ORCPT + 99 others); Mon, 14 Mar 2022 08:13:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242610AbiCNMKV (ORCPT ); Mon, 14 Mar 2022 08:10:21 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C5DE2B242; Mon, 14 Mar 2022 05:09:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id A100DCE1269; Mon, 14 Mar 2022 12:09:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2DE7C340E9; Mon, 14 Mar 2022 12:09:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647259749; bh=HWox8W0DnIRCyYED+rSsjxVe2Di18lInjdfTY3Byvck=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pEndiGnzLmuL78zoj4hA64cznU5fGUkMqDW+A+wtialVnLX+25n+/buJYVy0XxV6L ssg8X7JO78C9/eEgFxDnHEDHjYL07rx5XENVCB32J/6N1JEChtPtpIHz8jaVtOr/5U VE4DHIdgNv6kIyEnDL+3HgPcKKXeQPN1z4okhqx8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Osterried , Duoming Zhou , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 039/110] ax25: Fix NULL pointer dereference in ax25_kill_by_device Date: Mon, 14 Mar 2022 12:53:41 +0100 Message-Id: <20220314112744.129475785@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314112743.029192918@linuxfoundation.org> References: <20220314112743.029192918@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Duoming Zhou [ Upstream commit 71171ac8eb34ce7fe6b3267dce27c313ab3cb3ac ] When two ax25 devices attempted to establish connection, the requester use ax25_create(), ax25_bind() and ax25_connect() to initiate connection. The receiver use ax25_rcv() to accept connection and use ax25_create_cb() in ax25_rcv() to create ax25_cb, but the ax25_cb->sk is NULL. When the receiver is detaching, a NULL pointer dereference bug caused by sock_hold(sk) in ax25_kill_by_device() will happen. The corresponding fail log is shown below: =============================================================== BUG: KASAN: null-ptr-deref in ax25_device_event+0xfd/0x290 Call Trace: ... ax25_device_event+0xfd/0x290 raw_notifier_call_chain+0x5e/0x70 dev_close_many+0x174/0x220 unregister_netdevice_many+0x1f7/0xa60 unregister_netdevice_queue+0x12f/0x170 unregister_netdev+0x13/0x20 mkiss_close+0xcd/0x140 tty_ldisc_release+0xc0/0x220 tty_release_struct+0x17/0xa0 tty_release+0x62d/0x670 ... This patch add condition check in ax25_kill_by_device(). If s->sk is NULL, it will goto if branch to kill device. Fixes: 4e0f718daf97 ("ax25: improve the incomplete fix to avoid UAF and NPD bugs") Reported-by: Thomas Osterried Signed-off-by: Duoming Zhou Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ax25/af_ax25.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c index ea3431ac46a1..735f29512163 100644 --- a/net/ax25/af_ax25.c +++ b/net/ax25/af_ax25.c @@ -87,6 +87,13 @@ static void ax25_kill_by_device(struct net_device *dev) ax25_for_each(s, &ax25_list) { if (s->ax25_dev == ax25_dev) { sk = s->sk; + if (!sk) { + spin_unlock_bh(&ax25_list_lock); + s->ax25_dev = NULL; + ax25_disconnect(s, ENETUNREACH); + spin_lock_bh(&ax25_list_lock); + goto again; + } sock_hold(sk); spin_unlock_bh(&ax25_list_lock); lock_sock(sk); -- 2.34.1