lkml.org 
[lkml]   [2023]   [Oct]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] execve.2: execve also returns E2BIG if a string is too long
Hi Matthew,

On Wed, Oct 11, 2023 at 09:44:29AM -0400, Matthew House wrote:
>
> To expand on this, there are basically two separate byte limits in
> fs/exec.c, one for each individual argv/envp string, and another for all
> strings and all pointers to them as a whole. To put the whole thing in
> pseudocode, the checks work effectively like this, assuming I haven't made
> any errors:
>
> int argc, envc;
> unsigned long bytes, limit;
>
> /* assume that argv has already been adjusted to add an empty argv[0] */
> argc = 0, envc = 0, bytes = 0;
> for (char **a = argv; *a != NULL; a++, argc++) {
> if (strlen(*a) >= MAX_ARG_STRLEN)
> return -E2BIG;
> bytes += strlen(*a) + 1;
> }
> for (char **e = envp; *e != NULL; e++, envc++) {
> if (strlen(*e) >= MAX_ARG_STRLEN)
> return -E2BIG;
> bytes += strlen(*e) + 1;
> }
>
> if (argc > MAX_ARG_STRINGS || envc > MAX_ARG_STRINGS)
> return -E2BIG;
> bytes += (argc + envc) * sizeof(void *);
>
> limit = max(min(_STK_LIM / 4 * 3, rlim_stack.rlim_cur / 4), ARG_MAX);
> if (bytes > limit)
> return -E2BIG;
>
> Thank you,
> Matthew House

Thanks!

This thing would be useful in the commit message. An example program
demonstrating it would be even better.

Cheers,
Alex

--
<https://www.alejandro-colomar.es/>
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2023-10-11 16:45    [W:0.058 / U:1.364 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site