Re: [PATCH v2] kobject: return -ENOSPC when add_uevent_var() fails

From: Greg Kroah-Hartman
Date: Wed Jun 19 2019 - 13:31:32 EST


On Tue, Jun 11, 2019 at 06:09:24AM +0900, Masahiro Yamada wrote:
> This function never attempts to allocate memory, so returning -ENOMEM
> looks weird to me. The reason of the failure is there is no more space
> in the given kobj_uevent_env structure.
>
> Let's change the error code to -ENOSPC.
>
> This patch is safe since this function had never failed in reality.
>
> The callers of this function put a fixed number of small strings into
> the buffer.
>
> The buffer is defined to be large enough:
>
> #define UEVENT_NUM_ENVP 32 /* number of env pointers */
> #define UEVENT_BUFFER_SIZE 2048 /* buffer for the variables */
>
> As you see WARN() in the error paths, any failure of this function is
> a software bug.
>
> If such a case had ever happened before, you would have already seen
> a noisy back-trace, then you would have increased UEVENT_NUM_ENVP or
> UEVENT_BUFFER_SIZE.
>
> Nobody has ever increased UEVENT_NUM_ENVP or UEVENT_BUFFER_SIZE since
> their addition, that is, this structure is always large enough.

That implies that we should just drop the WARN() entirely. Especially
given that syzbot runs panic-on-warn, right?

How about doing both things at the same time?

thanks,

greg k-h