Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3776054imu; Mon, 7 Jan 2019 09:13:13 -0800 (PST) X-Google-Smtp-Source: ALg8bN6kYSzjXvdrXZSO8LFDH6ikMmFkToscd69j26IxFO2xKmfnjAGxZACHdc4yQYfVX9Wz7jwA X-Received: by 2002:a17:902:b40d:: with SMTP id x13mr63105696plr.237.1546881193145; Mon, 07 Jan 2019 09:13:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546881193; cv=none; d=google.com; s=arc-20160816; b=ZPC6YI5eV5hvf7WhaE6nBzA03KdqtDcZBqvO+A8StPJqSo6i9yUQTtOVezSrtSab7i h3OJqh28JuPB2DYPCF/tcrmJZMMCXGFTGqrDHo3Zchj8jGU7Qe1NqrFZBsAFTtTfFPXl H42QYj/ztpRu64H24P4wVjL5WJUlRY9r6ap6S4VrJn2QCDMxb9Gz8ln06rkufcIsCv1b miAsDwHxLW/lpIjm2x0uVN19wN85Eq/KBLV8SbOemzm5ZVcfayWq/grnCHlOibgzTL1X k5AxSjxiF5xmgM+ocJs/hifKy8FyAyfBFnyV0usGJyqa8u5vtflCjoB2CrpzpCHkot3z j9Iw== 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=XbtsjJt5MZWRPXVFDu+QkkQvpmQCFOogrU0G40R3qBQ=; b=rJm8QETLYV7btTlG7GIkpg7+tcqvoVjC7YrKt+qbRL7j7+lZn8dZ2nQ3zPM4bWhESf hPPjNRU/PbqDd2G6EOs6XiF/pD9YJfO2y+TWQEszgd4oN4JHgZW0LKLwVN3l47W4idUU dYmW1Btq95Wrk0bAWNNMRUBW4jzY65GjMGG6RH6AjG0BBIu+m8h7YlZVTAuHi9ZdKf3k Fxw4jEub5K7/QaOpyl9rm5j3mCUXFE5PMjsbPpt7i/+D2c0hy0a5P2AgdIkfMojKPUAE iT59LiU/Exoc6k+PbKd6GburePA7z30/doZ908s3u6DN2CksWGwk6jERvn47GYGTwDAx tWbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kwN0H4xp; 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 a19si37403567pgj.429.2019.01.07.09.12.56; Mon, 07 Jan 2019 09:13:13 -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=kwN0H4xp; 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 S1730616AbfAGNB0 (ORCPT + 99 others); Mon, 7 Jan 2019 08:01:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:48866 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730603AbfAGNBY (ORCPT ); Mon, 7 Jan 2019 08:01:24 -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 D8A822089F; Mon, 7 Jan 2019 13:01:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546866083; bh=gYMaFGlo4avxR8ogDUvyGqIwKgwgMNO8BwLuDgOkxCc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kwN0H4xpAcDuDDQ5SUM9qnfGGGoALAJsCkOjmBuZX1QjWJVmrtHSmqRibV5lXJif8 Z5XInA97mptOBpjQuZ1xDHyfBqY37VP5xv34ZvHv3VZY3cDQmyztX3EpKCCTzFfxTl CNRhcEmhs644Ob2umH3BWVUOllToxT5YdyMan4TM= 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.14 005/101] ax25: fix a use-after-free in ax25_fillin_cb() Date: Mon, 7 Jan 2019 13:31:53 +0100 Message-Id: <20190107105330.725325137@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190107105330.372621917@linuxfoundation.org> References: <20190107105330.372621917@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.14-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;