Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3698320imu; Mon, 7 Jan 2019 07:57:27 -0800 (PST) X-Google-Smtp-Source: AFSGD/WaoYIK3cH17g7xdeNehej8mCSJ+/Gr0wp6T4fQyuzIlx41EPaL8correKdT2V/DzmSzjdI X-Received: by 2002:a62:db41:: with SMTP id f62mr64590539pfg.123.1546876647705; Mon, 07 Jan 2019 07:57:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546876647; cv=none; d=google.com; s=arc-20160816; b=xGPLkLK7WaceZAW/+SPPPM9WfVKuX0rrLM3feL/+XULDV8kIWu768D7XYhvZHT6kbz weFME06bA82tZObCA4VQy+re5BYor/URogrBRTl7O5WD48UeLOnwr4KGv6z7DeqsNqkA icpL/kQaWMoXIwYgdYoaHFbq7sZyFQjWNMlKe0U8Rx7e3pxT3p1rtVNA7Q4xNdNBqPfH /WUAvOmBKbUYVkCXp8vZkC78ni74ktzFOusiBbGh4KHVbAGl4rv7y0+jZgLUmiDub+Oe nMonOTW7cCmFiEb6spNdEFSfq4QIeoAsiRzWmrfG3iNzyB++vlziVYZ5x1Vx7cqWFHB8 4H7w== 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=uVSSidTBYO756ap1bAjHc4ZOaFZ+agfxzgbriK8srLo=; b=AHNpXUhFL4pFgB0v8oj7AO4tiVZwBOX+TIfiTHUdifG+6440UPzLKB6h5MinhhTgkm jSwP7OK6m4J+HnEmCSJdFrxqtbtzzRilr7IkiMlmzKwXYFKzQOR0XBK7rrr1/5cdUGpH 23aUaQ9CYxMsXJYEwp54a0ToIsW2PtAtkGKps3KbScxeQZV4ZFeGb2KX31odQ7q1xLOy NsrX6Cm1ltPdTeHyWuwvtOJMjQoxjC+612Fwi6Tdb8uPG2Y4DPiE7EiLdIzdxyuNAHs5 oxz5wbQtOr2oFj3whrD1toeee97y1+A4JtVOdquFwmVwSC80ICBAd1CnHT8a4GkcFd73 n1Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JVoUBTmv; 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 u186si24341586pgd.131.2019.01.07.07.57.12; Mon, 07 Jan 2019 07:57:27 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=JVoUBTmv; 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 S1727128AbfAGMeL (ORCPT + 99 others); Mon, 7 Jan 2019 07:34:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:45962 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727073AbfAGMeH (ORCPT ); Mon, 7 Jan 2019 07:34:07 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 10C852173C; Mon, 7 Jan 2019 12:34:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546864447; bh=h6nDnIYTXrM+YhmqgUVohd9wHBsYv14p+gOYTA5FaOk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JVoUBTmvCIchGXs6rkutLuPjwz0fe/64pl7OqKchZp/6Y2V4gpf2Gdx8zGXYEsLPz RI89e+9qNRxRAn2L8+LAuP1NUf7zoCbnM6OVbNHqopNg/8ZFHXhIazLGHN0QBG8O26 sM34D5wxxxbCfWrWz6WYUkA8md00cz9EfJ5T9fw8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Cong Wang , "David S. Miller" , syzbot+ae6bb869cbed29b29040@syzkaller.appspotmail.com Subject: [PATCH 4.20 006/145] ax25: fix a use-after-free in ax25_fillin_cb() Date: Mon, 7 Jan 2019 13:30:43 +0100 Message-Id: <20190107104438.142798465@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190107104437.308206189@linuxfoundation.org> References: <20190107104437.308206189@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Cong Wang [ Upstream commit c433570458e49bccea5c551df628d058b3526289 ] There are multiple issues here: 1. After freeing dev->ax25_ptr, we need to set it to NULL otherwise we may use a dangling pointer. 2. There is a race between ax25_setsockopt() and device notifier as reported by syzbot. Close it by holding RTNL lock. 3. We need to test if dev->ax25_ptr is NULL before using it. Reported-and-tested-by: syzbot+ae6bb869cbed29b29040@syzkaller.appspotmail.com Signed-off-by: Cong Wang Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ax25/af_ax25.c | 11 +++++++++-- net/ax25/ax25_dev.c | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) --- a/net/ax25/af_ax25.c +++ b/net/ax25/af_ax25.c @@ -653,15 +653,22 @@ static int ax25_setsockopt(struct socket break; } - dev = dev_get_by_name(&init_net, devname); + rtnl_lock(); + dev = __dev_get_by_name(&init_net, devname); if (!dev) { + rtnl_unlock(); res = -ENODEV; break; } ax25->ax25_dev = ax25_dev_ax25dev(dev); + if (!ax25->ax25_dev) { + rtnl_unlock(); + res = -ENODEV; + break; + } ax25_fillin_cb(ax25, ax25->ax25_dev); - dev_put(dev); + rtnl_unlock(); break; default: --- a/net/ax25/ax25_dev.c +++ b/net/ax25/ax25_dev.c @@ -116,6 +116,7 @@ void ax25_dev_device_down(struct net_dev if ((s = ax25_dev_list) == ax25_dev) { ax25_dev_list = s->next; spin_unlock_bh(&ax25_dev_lock); + dev->ax25_ptr = NULL; dev_put(dev); kfree(ax25_dev); return; @@ -125,6 +126,7 @@ void ax25_dev_device_down(struct net_dev if (s->next == ax25_dev) { s->next = ax25_dev->next; spin_unlock_bh(&ax25_dev_lock); + dev->ax25_ptr = NULL; dev_put(dev); kfree(ax25_dev); return;