From: Dan Carpenter <dan.carpenter@oracle.com>
To: Oliver Hartkopp <socketcan@hartkopp.net>
Cc: Wolfgang Grandegger <wg@grandegger.com>,
Marc Kleine-Budde <mkl@pengutronix.de>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Leon Romanovsky <leon@kernel.org>,
linux-can@vger.kernel.org, netdev@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH net-next] can: sja1000: fix use after free in ems_pcmcia_add_card()
Date: Wed, 24 Nov 2021 09:56:06 +0300 [thread overview]
Message-ID: <20211124065605.GE6514@kadam> (raw)
In-Reply-To: <72ed48e9-0659-78f9-1b31-be54b118ab76@hartkopp.net>
On Tue, Nov 23, 2021 at 09:42:12PM +0100, Oliver Hartkopp wrote:
> Hello Dan,
>
> On 22.11.21 08:56, Dan Carpenter wrote:
> > In the original code if ems_pcmcia_check_chan() returned false then
> > it called free_sja1000dev(dev) but did not set the error code or jump
> > to the clean up code. This frees "dev" and leads to a use after free.
> >
> > I flipped the ems_pcmcia_check_chan() check around to make the error
> > handling more consistent and readable. That lets us pull the rest of
> > the code in one tab.
> >
> > Fixes: fd734c6f25ae ("can/sja1000: add driver for EMS PCMCIA card")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> I do not think, that you are fixing something here.
>
> The loop
>
> for (i = 0; i < EMS_PCMCIA_MAX_CHAN; i++) { ...
>
> checks with
>
> if (ems_pcmcia_check_chan(priv))
>
> whether this channel is 'available' or not.
>
> As this hardware could come with only ONE channel it is just wrong to tag a
> missing channel as error and finally kill the entire setup process
> (including the potentially working channel we already initialized).
>
> So thanks for the patch but NACK ;-)
There is definitely a use after free bug with the "dev" pointer, but
you're right that it would only affect things if it were the last
channel. The easy solution would be to do something like:
- err = request_irq(dev->irq, &ems_pcmcia_interrupt, IRQF_SHARED,
+ err = request_irq(pdev->irq, &ems_pcmcia_interrupt, IRQF_SHARED,
I'll send a patch for that.
If we were super paranoid, we could add a check for if of the channels
were available.
regards,
dan carpenter
prev parent reply other threads:[~2021-11-24 6:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-22 7:56 [PATCH net-next] can: sja1000: fix use after free in ems_pcmcia_add_card() Dan Carpenter
2021-11-22 8:03 ` Dan Carpenter
2021-11-23 20:42 ` Oliver Hartkopp
2021-11-24 6:56 ` Dan Carpenter [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211124065605.GE6514@kadam \
--to=dan.carpenter@oracle.com \
--cc=davem@davemloft.net \
--cc=kernel-janitors@vger.kernel.org \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=socketcan@hartkopp.net \
--cc=wg@grandegger.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).