Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp672645pxb; Mon, 25 Oct 2021 16:22:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwamk5B1lwNm4tFfMn7uuBU2GpyasS/WPdbmWmPV6c5FvZE7No5hQCh3+6t/64pyKhhPszC X-Received: by 2002:a17:907:8a06:: with SMTP id sc6mr15712932ejc.372.1635204134842; Mon, 25 Oct 2021 16:22:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635204134; cv=none; d=google.com; s=arc-20160816; b=Gq4/udOvlg3umyUK3g6QtUSCHW2emgAUEpKHKauW7Rv6ru7G+Zv0tTQwjyXXJh/H2I sKdxB4z2v+hpLIyl5FgcegRw8Cn7FwDecgG/7qkir+n+Xo2pn4Q+48p4EIwhE5HAe/TA PTNycF2mBJ9maYS9SKAa46kLm0YDRvZdzyii5SzAHoicsDExylWF05rSrNKoJsDvA3A5 6fw3lAWp0MnHGEtS1jmAufgsGqixZNHWNWOihu/QPNJ7pHUTRZ14yKqOtWg/gVnwopNv /CCP02B65rBZxuAJ1/VbeBJn0D2mnakRODkuMPcgMxmhvqkhpIJii/+FiLUIeizJ1FW/ Rwpg== 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=YEZJWshrFLCGsaOrb2qkU6nmgC8c9GrDueJc/ON5OtQ=; b=MAKRe+aG8XD5Xw3g4Z0cpVAYhuSpFgZjpOVSi4QQqiNhCVWVx9H3sriluyUCNZXPL4 RdW9GEggHVY3MiUh1sxqaM0Kgh3P2Qpsv1FeD1XFtlEEibRD7yoex5fxqT3bF0dxKHGH kYLkkXk4PywY8MkRsCx3Ahx/1emnM58eST5YLWkAvYNjKm68yNauVbb80zgA4d81JcwL 4ZkJUfbnsyXBeX/SjdQvzfx+suqBrs62a/ezso4uNVr9I/MHZedx0THEX8wMeWHO/uqg hd5nUjCNAN1ShW66X2BprB3oKxR6LJSTkF9G8ZDz8kznrd+WuZsaS7qc9WEhvsyB3psr vRHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K91BLmpD; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o17si39139825edc.228.2021.10.25.16.21.51; Mon, 25 Oct 2021 16:22:14 -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=@linuxfoundation.org header.s=korg header.b=K91BLmpD; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234946AbhJYT0O (ORCPT + 99 others); Mon, 25 Oct 2021 15:26:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:38608 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234790AbhJYTYE (ORCPT ); Mon, 25 Oct 2021 15:24:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A5DE1610A5; Mon, 25 Oct 2021 19:21:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635189701; bh=cmk0RP38NN1vE0MQXQVLilmNUQCYQAVw/M+Ouy94bZg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K91BLmpD5zBL1vLOsFh1UIKduxSQLT9jIhycW4lLOk5NmtBXQBXRJJgWeGxcJ1e31 dgNSgcFGt/l6I7nPLQZSRR3PDH4fNSiBs6kWAyOr84zaYhwjT9ReJ2pmCOjz2cepQx Tj/THCEjLMlcbub1n/XrvyvOt6XrpTY1iVsyGPnc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zheyu Ma , Marc Kleine-Budde Subject: [PATCH 4.14 10/30] can: peak_pci: peak_pci_remove(): fix UAF Date: Mon, 25 Oct 2021 21:14:30 +0200 Message-Id: <20211025190925.473771236@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211025190922.089277904@linuxfoundation.org> References: <20211025190922.089277904@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zheyu Ma commit 949fe9b35570361bc6ee2652f89a0561b26eec98 upstream. When remove the module peek_pci, referencing 'chan' again after releasing 'dev' will cause UAF. Fix this by releasing 'dev' later. The following log reveals it: [ 35.961814 ] BUG: KASAN: use-after-free in peak_pci_remove+0x16f/0x270 [peak_pci] [ 35.963414 ] Read of size 8 at addr ffff888136998ee8 by task modprobe/5537 [ 35.965513 ] Call Trace: [ 35.965718 ] dump_stack_lvl+0xa8/0xd1 [ 35.966028 ] print_address_description+0x87/0x3b0 [ 35.966420 ] kasan_report+0x172/0x1c0 [ 35.966725 ] ? peak_pci_remove+0x16f/0x270 [peak_pci] [ 35.967137 ] ? trace_irq_enable_rcuidle+0x10/0x170 [ 35.967529 ] ? peak_pci_remove+0x16f/0x270 [peak_pci] [ 35.967945 ] __asan_report_load8_noabort+0x14/0x20 [ 35.968346 ] peak_pci_remove+0x16f/0x270 [peak_pci] [ 35.968752 ] pci_device_remove+0xa9/0x250 Fixes: e6d9c80b7ca1 ("can: peak_pci: add support of some new PEAK-System PCI cards") Link: https://lore.kernel.org/all/1634192913-15639-1-git-send-email-zheyuma97@gmail.com Cc: stable@vger.kernel.org Signed-off-by: Zheyu Ma Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- drivers/net/can/sja1000/peak_pci.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) --- a/drivers/net/can/sja1000/peak_pci.c +++ b/drivers/net/can/sja1000/peak_pci.c @@ -739,16 +739,15 @@ static void peak_pci_remove(struct pci_d struct net_device *prev_dev = chan->prev_dev; dev_info(&pdev->dev, "removing device %s\n", dev->name); + /* do that only for first channel */ + if (!prev_dev && chan->pciec_card) + peak_pciec_remove(chan->pciec_card); unregister_sja1000dev(dev); free_sja1000dev(dev); dev = prev_dev; - if (!dev) { - /* do that only for first channel */ - if (chan->pciec_card) - peak_pciec_remove(chan->pciec_card); + if (!dev) break; - } priv = netdev_priv(dev); chan = priv->priv; }