diff mbox series

Fix the size of the header read buffer.

Message ID 20220128220156.4057446-1-jmeurin@google.com
State Changes Requested
Headers show
Series Fix the size of the header read buffer. | expand

Commit Message

Jean-Marc Eurin Jan. 28, 2022, 10:01 p.m. UTC
The read buffer size depends on the MTDOOPS_HEADER_SIZE.

Tested: Changed the header size, it doesn't panic, header is still
read/written correctly.

Signed-off-by: Jean-Marc Eurin <jmeurin@google.com>
---
 drivers/mtd/mtdoops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Miquel Raynal Jan. 31, 2022, 10 a.m. UTC | #1
Hi Jean-Marc,

jmeurin@google.com wrote on Fri, 28 Jan 2022 14:01:56 -0800:

> The read buffer size depends on the MTDOOPS_HEADER_SIZE.
> 
> Tested: Changed the header size, it doesn't panic, header is still
> read/written correctly.

On what Linux kernel version are you? It looks like we don't share the
same code base, are we?

> 
> Signed-off-by: Jean-Marc Eurin <jmeurin@google.com>
> ---
>  drivers/mtd/mtdoops.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
> index 227df24387df..09a26747f490 100644
> --- a/drivers/mtd/mtdoops.c
> +++ b/drivers/mtd/mtdoops.c
> @@ -223,7 +223,7 @@ static void find_next_position(struct mtdoops_context *cxt)
>  {
>  	struct mtd_info *mtd = cxt->mtd;
>  	int ret, page, maxpos = 0;
> -	u32 count[2], maxcount = 0xffffffff;
> +	u32 count[MTDOOPS_HEADER_SIZE/sizeof(u32)], maxcount = 0xffffffff;
>  	size_t retlen;
>  
>  	for (page = 0; page < cxt->oops_pages; page++) {


Thanks,
Miquèl
Jean-Marc Eurin Feb. 4, 2022, 1:53 a.m. UTC | #2
On Mon, Jan 31, 2022 at 2:00 AM Miquel Raynal <miquel.raynal@bootlin.com> wrote:
>
> Hi Jean-Marc,
>
> jmeurin@google.com wrote on Fri, 28 Jan 2022 14:01:56 -0800:
>
> > The read buffer size depends on the MTDOOPS_HEADER_SIZE.
> >
> > Tested: Changed the header size, it doesn't panic, header is still
> > read/written correctly.
>
> On what Linux kernel version are you? It looks like we don't share the
> same code base, are we?

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/mtd/mtdoops.c?h=v5.17-rc2
has that bug.  If you try to increase the MTDOOPS_HEADER_SIZE,
find_next_position() will try to do an mtd_read() of
MTDOOPS_HEADER_SIZE bytes in a count buffer that is fixed to only 8
bytes.

Thanks,

Jean-Marc

>
> >
> > Signed-off-by: Jean-Marc Eurin <jmeurin@google.com>
> > ---
> >  drivers/mtd/mtdoops.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
> > index 227df24387df..09a26747f490 100644
> > --- a/drivers/mtd/mtdoops.c
> > +++ b/drivers/mtd/mtdoops.c
> > @@ -223,7 +223,7 @@ static void find_next_position(struct mtdoops_context *cxt)
> >  {
> >       struct mtd_info *mtd = cxt->mtd;
> >       int ret, page, maxpos = 0;
> > -     u32 count[2], maxcount = 0xffffffff;
> > +     u32 count[MTDOOPS_HEADER_SIZE/sizeof(u32)], maxcount = 0xffffffff;
> >       size_t retlen;
> >
> >       for (page = 0; page < cxt->oops_pages; page++) {
>
>
> Thanks,
> Miquèl
Miquel Raynal Feb. 7, 2022, 3:34 p.m. UTC | #3
Hi Jean-Marc,

It looks like you changed the title when answering to my question, I
thought this was a v2 and could not find it in patchwork. That is
because the v2 does not actually exist?

jmeurin@google.com wrote on Thu, 3 Feb 2022 17:53:47
-0800:

> On Mon, Jan 31, 2022 at 2:00 AM Miquel Raynal <miquel.raynal@bootlin.com> wrote:
> >
> > Hi Jean-Marc,
> >
> > jmeurin@google.com wrote on Fri, 28 Jan 2022 14:01:56 -0800:
> >  
> > > The read buffer size depends on the MTDOOPS_HEADER_SIZE.
> > >
> > > Tested: Changed the header size, it doesn't panic, header is still
> > > read/written correctly.  
> >
> > On what Linux kernel version are you? It looks like we don't share the
> > same code base, are we?  
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/mtd/mtdoops.c?h=v5.17-rc2
> has that bug.  If you try to increase the MTDOOPS_HEADER_SIZE,
> find_next_position() will try to do an mtd_read() of
> MTDOOPS_HEADER_SIZE bytes in a count buffer that is fixed to only 8
> bytes.

I might have checked another function then. Indeed the fix looks legit.

Can you please send a v2 with:
- Your two patches in the same series (formatted with git-format-patch
  to get the dependency/order right)
- In the other commit, drop the reference pointing to (I believe) a
  commit hash that is local to your tree only.
- Use the right prefix ("mtd: mtdoops:").

And we should be good.

> 
> Thanks,
> 
> Jean-Marc
> 
> >  
> > >
> > > Signed-off-by: Jean-Marc Eurin <jmeurin@google.com>
> > > ---
> > >  drivers/mtd/mtdoops.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
> > > index 227df24387df..09a26747f490 100644
> > > --- a/drivers/mtd/mtdoops.c
> > > +++ b/drivers/mtd/mtdoops.c
> > > @@ -223,7 +223,7 @@ static void find_next_position(struct mtdoops_context *cxt)
> > >  {
> > >       struct mtd_info *mtd = cxt->mtd;
> > >       int ret, page, maxpos = 0;
> > > -     u32 count[2], maxcount = 0xffffffff;
> > > +     u32 count[MTDOOPS_HEADER_SIZE/sizeof(u32)], maxcount = 0xffffffff;
> > >       size_t retlen;
> > >
> > >       for (page = 0; page < cxt->oops_pages; page++) {  
> >
> >
> > Thanks,
> > Miquèl  


Thanks,
Miquèl
diff mbox series

Patch

diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
index 227df24387df..09a26747f490 100644
--- a/drivers/mtd/mtdoops.c
+++ b/drivers/mtd/mtdoops.c
@@ -223,7 +223,7 @@  static void find_next_position(struct mtdoops_context *cxt)
 {
 	struct mtd_info *mtd = cxt->mtd;
 	int ret, page, maxpos = 0;
-	u32 count[2], maxcount = 0xffffffff;
+	u32 count[MTDOOPS_HEADER_SIZE/sizeof(u32)], maxcount = 0xffffffff;
 	size_t retlen;
 
 	for (page = 0; page < cxt->oops_pages; page++) {