Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20501C433EF for ; Mon, 13 Dec 2021 09:54:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236973AbhLMJyL (ORCPT ); Mon, 13 Dec 2021 04:54:11 -0500 Received: from sin.source.kernel.org ([145.40.73.55]:40050 "EHLO sin.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234587AbhLMJsd (ORCPT ); Mon, 13 Dec 2021 04:48:33 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id B6609CE0B20; Mon, 13 Dec 2021 09:48:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C4ABC00446; Mon, 13 Dec 2021 09:48:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1639388909; bh=qDXaSaxmEZateudXlrVulZq1YeE+yl3kbgOZBcV7Xho=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OixnI00TDOpsm+lKOll9pzBEVNBuZ9klu2nUl7O9Yo5RM6DHy+O1XaNvqMM11BM+h kLvf22JhJ1fadnVv/II/vhS28NuQxxu3Xrd94bdb/JPyTq3BLFK9NVGvC1l854WPBH laxuHPJEf3BgR8a72Og7Rzzp8zJeUrBHWxrmjG6o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Oliver Hartkopp , Marc Kleine-Budde Subject: [PATCH 5.10 019/132] can: sja1000: fix use after free in ems_pcmcia_add_card() Date: Mon, 13 Dec 2021 10:29:20 +0100 Message-Id: <20211213092939.745279660@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211213092939.074326017@linuxfoundation.org> References: <20211213092939.074326017@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: Dan Carpenter commit 3ec6ca6b1a8e64389f0212b5a1b0f6fed1909e45 upstream. If the last channel is not available then "dev" is freed. Fortunately, we can just use "pdev->irq" instead. Also we should check if at least one channel was set up. Fixes: fd734c6f25ae ("can/sja1000: add driver for EMS PCMCIA card") Link: https://lore.kernel.org/all/20211124145041.GB13656@kili Cc: stable@vger.kernel.org Signed-off-by: Dan Carpenter Acked-by: Oliver Hartkopp Tested-by: Oliver Hartkopp Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- drivers/net/can/sja1000/ems_pcmcia.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/drivers/net/can/sja1000/ems_pcmcia.c +++ b/drivers/net/can/sja1000/ems_pcmcia.c @@ -235,7 +235,12 @@ static int ems_pcmcia_add_card(struct pc free_sja1000dev(dev); } - err = request_irq(dev->irq, &ems_pcmcia_interrupt, IRQF_SHARED, + if (!card->channels) { + err = -ENODEV; + goto failure_cleanup; + } + + err = request_irq(pdev->irq, &ems_pcmcia_interrupt, IRQF_SHARED, DRV_NAME, card); if (!err) return 0;