Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3726771imu; Mon, 7 Jan 2019 08:22:32 -0800 (PST) X-Google-Smtp-Source: ALg8bN6lcYAr9a72ZixRm8vSCbto39tUfw8YVRVv3zDnnCGp9qztL0BPI398emSTj4fbPN7+52hb X-Received: by 2002:a63:f30d:: with SMTP id l13mr30721464pgh.399.1546878152307; Mon, 07 Jan 2019 08:22:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546878152; cv=none; d=google.com; s=arc-20160816; b=dGEW047R53cQ8lqsfGXkIrxY2gN+AlibFIya/On5+O4F8f6N+FE4mu50w31T+m4JAw 9XYZD4EvNKVCva33iQMvym9onVvOgTQqzfwlX43Be7VJqCOLUfbHHyn2b5btd/QPSgmw BXMSW8/C85fqK2vV/OpTIK7i26TtnvVypK1ftekwNm7FDbbbqd+748D5TI8xAXWlohJ4 qPGcgWKqN4lHBTlUAUGmgVaQhqHzxelycRHGEBk5WFo9GtmsmMry47uzd90v5hhwGAo+ qsCExQxgP1Tsl/FNBCXNT4aNLeZgNOvP75dcHwfpgtNeiUyK21ZzFOaw1OZkbo2eQK4i DVxQ== 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=fxFi4tvxQXFWnkg+ymOvvY6s+7YUYKE8NSondl11UNg=; b=sNMb3KgaNj9kJAmurNthFaVB5l5F/NpR1tsGLppH8GqWGMoiEyWAXsHpg+Bh/35TqY uY+oB6AconNfI/NF/v7DwsJYTtYPWYdkporiqPAwEHtCcPYeGpBOBtiF1a2yS4ubEP4U xPVCO1XQLP1QcuacwvaWrfrNmWpm7m1Ed+Dnq8NOmR/dtF1Bh8aNSaLKTPnzFlPI1EWV 82CV7JPy8/A6f5LDbL0o226fkfg0GVnK2VIA0MVJUtO//CXiIxK4hPOh/SUL4xL3I0lL OsNw7WcgfDI1LvIzAJVVc2mZ5dpJwRdRt+ntmnhINrMPVBH4DHuKi6HDX6BxceLqutco /QlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EWuk1WRN; 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 q140si57155971pfc.20.2019.01.07.08.22.17; Mon, 07 Jan 2019 08:22:32 -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=EWuk1WRN; 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 S1731523AbfAGNGI (ORCPT + 99 others); Mon, 7 Jan 2019 08:06:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:53588 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727252AbfAGNGH (ORCPT ); Mon, 7 Jan 2019 08:06: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 543B021736; Mon, 7 Jan 2019 13:06:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546866366; bh=/cQLdfcbFfz7bxFsx5gOpWgoqOQKLzd3C/yqgA37hbM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EWuk1WRNEUAYbch3+icpR86WYBSa8dhn6+YiJ898pMsFGEL+EuqAC+3ei85eSt/0B 0INd70/0Bhw+yboAXZqlRYlMH5IiXTh0xvlMzKLTF1Hkshbk0zWsrH/qUgMY5tY39n vB3ZPqnnd8hK7li/79e3P1v63yyZRHozz9WIXkpg= 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.9 06/71] ax25: fix a use-after-free in ax25_fillin_cb() Date: Mon, 7 Jan 2019 13:32:35 +0100 Message-Id: <20190107105330.681072921@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190107105330.280153213@linuxfoundation.org> References: <20190107105330.280153213@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.9-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 @@ -654,15 +654,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;