[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20210712164850.GC777994@pc>
Date: Mon, 12 Jul 2021 17:48:50 +0100
From: Salah Triki <salah.triki@...il.com>
To: Joe Perches <joe@...ches.com>
Cc: dan.j.williams@...el.com, vishal.l.verma@...el.com,
dave.jiang@...el.com, nvdimm@...ts.linux.dev,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] dax: replace sprintf() by scnprintf()
On Mon, Jul 12, 2021 at 09:14:53AM -0700, Joe Perches wrote:
> On Mon, 2021-07-12 at 13:26 +0100, Salah Triki wrote:
> > On Sat, Jul 10, 2021 at 10:04:48AM -0700, Joe Perches wrote:
> > > On Sat, 2021-07-10 at 17:46 +0100, Salah Triki wrote:
> > > > Replace sprintf() by scnprintf() in order to avoid buffer overflows.
> > >
> > > OK but also not strictly necessary. DAX_NAME_LEN is 30.
> > >
> > > Are you finding and changing these manually or with a script?
> > >
> > > > diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c
> > > []
> > > > @@ -76,7 +76,7 @@ static ssize_t do_id_store(struct device_driver *drv, const char *buf,
> > > > fields = sscanf(buf, "dax%d.%d", ®ion_id, &id);
> > > > if (fields != 2)
> > > > return -EINVAL;
> > > > - sprintf(devname, "dax%d.%d", region_id, id);
> > > > + scnprintf(devname, DAX_NAME_LEN, "dax%d.%d", region_id, id);
> > > > if (!sysfs_streq(buf, devname))
> > > > return -EINVAL;
> > > >
> > > >
> > >
> > >
> >
> > since region_id and id are unsigned long may be devname should be
> > char[21].
>
> I think you need to look at the code a bit more carefully.
>
> unsigned int region_id, id;
>
> Also the output is %d, so the maximum length of each output
> int is 10 with a possible leading minus sign.
>
> 3 + 10 + 1 + 10 + 1. So 25 not 21 which is too small.
>
> The %d uses could be changed to %u to make it 23.
> But really it hardly matters as 30 is sufficent and the
> function call depth here isn't particularly high.
>
> > I'm finding and changing these manually.
>
> coccinelle could help.
> https://coccinelle.gitlabpages.inria.fr/website/
>
>
Thanx
Powered by blists - more mailing lists