On Tue, 16 Dec 2025 13:27:49 +0000
David Laight <[email protected]> wrote:

> On Tue, 16 Dec 2025 08:31:27 +0100
> Natanael Copa <[email protected]> wrote:
> 
> > Use a bigger buffer on stack for getmntent_r so we can handle entries
> > with lines longer that 504 chars.
> > 
> > This solves issue when running `mount -o remount,rw ...` in a docker
> > container on Fedora 43.
> > 
> > ref: https://github.com/k0sproject/k0s/issues/6774
> > ref: https://lists.busybox.net/pipermail/busybox/2025-December/091859.html
> > 
> > function                                             old     new   delta
> > mount_main                                          1402    1401      -1
> > ------------------------------------------------------------------------------
> > (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-1)               Total: -1 
> > bytes
> >    text        data     bss     dec     hex filename
> >  824613       14092    1864  840569   cd379 busybox_old
> >  824612       14092    1864  840568   cd378 busybox_unstripped
> > 
> > Signed-off-by: Natanael Copa <[email protected]>
> > ---
> >  util-linux/mount.c | 7 ++++---
> >  1 file changed, 4 insertions(+), 3 deletions(-)
> > 
> > diff --git a/util-linux/mount.c b/util-linux/mount.c
> > index d0f0ae1ad..c0db67ce4 100644
> > --- a/util-linux/mount.c
> > +++ b/util-linux/mount.c
> > @@ -2283,6 +2283,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
> >     unsigned long cmdopt_flags;
> >     unsigned opt;
> >     struct mntent mtpair[2], *mtcur = mtpair;
> > +   char buf[GETMNTENT_BUFSIZE * 2];
> >     IF_NOT_DESKTOP(const int nonroot = 0;)
> >  
> >     IF_DESKTOP(int nonroot = ) sanitize_env_if_suid();
> > @@ -2395,9 +2396,9 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
> >             struct mntent *mtother = (mtcur==mtpair ? mtpair+1 : mtpair);
> >  
> >             // Get next fstab entry
> > -           if (!getmntent_r(fstab, mtcur, getmntent_buf
> > -                                   + (mtcur==mtpair ? GETMNTENT_BUFSIZE/2 
> > : 0),
> > -                           GETMNTENT_BUFSIZE/2)
> > +           if (!getmntent_r(fstab, mtcur, buf
> > +                                   + (mtcur==mtpair ?
> > GETMNTENT_BUFSIZE : 0),
> > +                           GETMNTENT_BUFSIZE)  
> 
> That doesn't look quite enough to me.
> I suspect there is a bit more code that looks at the 'second half' of
> the buffer.

Where would that happen?

> Depending on that code it might be better to do:
>       char pair_buf[GETMNTENT_BUFSIZE];
>       ...
>               if (!getmntent_r(fstab, mtcur, mtcur == mtpair ? pair_buf : 
> getmntent_buf,
>                               GETMNT_ENT_BUFSIZE)

That would probably also work. It would ping-pong between the static
buffer and the buffer on stack.

I did consider use an index for the ping-pong for making the code more
readable, but it increases the size:

char buf[2][GETMNTENT_BUFSIZE];
...
i &= 1;
...
getmntent_r(fstab, &mtpair[i], buf[i], ...);
..
mtcur = &mtpair[1 - i]; // the thing we found last time
...
i++;



 
>       David
> 
> >             ) { // End of fstab/mtab is reached
> >                     mtcur = mtother; // the thing we found last time
> >                     break;  
> 

_______________________________________________
busybox mailing list
[email protected]
https://lists.busybox.net/mailman/listinfo/busybox

Reply via email to