Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2020622pxa; Mon, 3 Aug 2020 05:34:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfNFxYav2zKzIm4osNvFjIhPhcv0C+Y2nY/uNbTcZn3BVNc3lA++d6q8n3aCRAgvNeAgWd X-Received: by 2002:a17:906:d050:: with SMTP id bo16mr17568272ejb.367.1596458077834; Mon, 03 Aug 2020 05:34:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596458077; cv=none; d=google.com; s=arc-20160816; b=f9ff9jaaqYyRu8+Elo3oWl64vmqpMiHWD0ndahy4R3ZBGCQ5D2YRyFp2asxFxVCGLz KcCCFgYZWF473iIDlVUSKc7Q/wBsVh/kys1t+dLwBbTtwVvbVgqNO/6Nddn8kiTwTDF0 BobJMNx+nqfGJ+ldatwm+ISafdHSQO7k/+XtFOcywNZlGkMUamqoZQSETx/T5DEvgv6e tEIuAgAaWvUFsqLjYB4luBtBA521o19S3BEEr92vQU+jiJP2cRE6NHoIrdTZRvJQYVZ1 adyrkOvTwi6OWr47aCjw4p8QcuPRLLZb/IjUpfo6DY2w1GRCIcOOQC1UoVv/jKDtn3Fd cu2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=a0BY9dkOhsmkrh9VuyIk7yiXYeXo+W3rTnUfStx4yOs=; b=MchmS6QA1qVFuJQvSBNKYs54L6LbJQeCv6qYtDjrQl1vbO2NYyRbqePng3nC7hAGW3 kR4WdnbGgap+gavbR/3Y/UwCHpd7AkDxyhaHBAnl9/VgxpYDQ4puJoR75YsZ2Cgyobtm BVvkJqcwk70RIugoX40bDNGrJsGeUYmU7AeI9+5GL2/mvU3FlRIfUg1TQAP9zu+oxOfR j9WAywbZHqfAdlc4R4VYaWfBvJ3zRYHYpQiyhz/8SGMBJBq/2E0iZ4KiTf2sTdTw+Nwf 3qHUm4M8ZxoKy7DuC3TCn1FArqB4aAxS1hTisba8hXh/D+RtGTWrIz0egTTmXd1C0P8K dP/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=P8ZcQXjx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d11si9821887edh.571.2020.08.03.05.34.15; Mon, 03 Aug 2020 05:34:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=P8ZcQXjx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729005AbgHCMdS (ORCPT + 99 others); Mon, 3 Aug 2020 08:33:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:33062 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729401AbgHCMdO (ORCPT ); Mon, 3 Aug 2020 08:33:14 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 2B9A6204EC; Mon, 3 Aug 2020 12:33:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596457992; bh=UBRBwNUBAkcMQm7k4AI2Gc1Fdp/NT7POSOWwfxAQqok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P8ZcQXjxGpVBoFCjiGGS01JqdaUb0oRJkSAi4+CIUFOoxeRY+qT0vb2brlMoOA76i 2oRdPQ+5Lj+OAJyxvkUlvNiAm/SoJuCbFKm12Kh3a8GqPNLPSm20SQV9HfZwjCYxbX rWq7iGIueJ2Bto3esVG2edTI1yyeHlkJ47mZKCZg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+6db548b615e5aeefdce2@syzkaller.appspotmail.com, YueHaibing , "David S. Miller" Subject: [PATCH 4.19 26/56] net/x25: Fix null-ptr-deref in x25_disconnect Date: Mon, 3 Aug 2020 14:19:41 +0200 Message-Id: <20200803121851.621479441@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200803121850.306734207@linuxfoundation.org> References: <20200803121850.306734207@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: YueHaibing commit 8999dc89497ab1c80d0718828e838c7cd5f6bffe upstream. We should check null before do x25_neigh_put in x25_disconnect, otherwise may cause null-ptr-deref like this: #include #include int main() { int sck_x25; sck_x25 = socket(AF_X25, SOCK_SEQPACKET, 0); close(sck_x25); return 0; } BUG: kernel NULL pointer dereference, address: 00000000000000d8 CPU: 0 PID: 4817 Comm: t2 Not tainted 5.7.0-rc3+ #159 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.9.3- RIP: 0010:x25_disconnect+0x91/0xe0 Call Trace: x25_release+0x18a/0x1b0 __sock_release+0x3d/0xc0 sock_close+0x13/0x20 __fput+0x107/0x270 ____fput+0x9/0x10 task_work_run+0x6d/0xb0 exit_to_usermode_loop+0x102/0x110 do_syscall_64+0x23c/0x260 entry_SYSCALL_64_after_hwframe+0x49/0xb3 Reported-by: syzbot+6db548b615e5aeefdce2@syzkaller.appspotmail.com Fixes: 4becb7ee5b3d ("net/x25: Fix x25_neigh refcnt leak when x25 disconnect") Signed-off-by: YueHaibing Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/x25/x25_subr.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/net/x25/x25_subr.c +++ b/net/x25/x25_subr.c @@ -362,10 +362,12 @@ void x25_disconnect(struct sock *sk, int sk->sk_state_change(sk); sock_set_flag(sk, SOCK_DEAD); } - read_lock_bh(&x25_list_lock); - x25_neigh_put(x25->neighbour); - x25->neighbour = NULL; - read_unlock_bh(&x25_list_lock); + if (x25->neighbour) { + read_lock_bh(&x25_list_lock); + x25_neigh_put(x25->neighbour); + x25->neighbour = NULL; + read_unlock_bh(&x25_list_lock); + } } /*