Skip to content

Commit c386907

Browse files
committed
kobject_uevent: remove warning in init_uevent_argv()
commit b410418 upstream. syzbot can trigger the WARN() in init_uevent_argv() which isn't the nicest as the code does properly recover and handle the error. So change the WARN() call to pr_warn() and provide some more information on what the buffer size that was needed. Link: https://lore.kernel.org/r/20201107082206.GA19079@kroah.com Cc: "Rafael J. Wysocki" <rafael@kernel.org> Cc: linux-kernel@vger.kernel.org Reported-by: syzbot+92340f7b2b4789907fdb@syzkaller.appspotmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://lore.kernel.org/r/20210405094852.1348499-1-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a252d05 commit c386907

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/kobject_uevent.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,13 @@ static int kobj_usermode_filter(struct kobject *kobj)
271271

272272
static int init_uevent_argv(struct kobj_uevent_env *env, const char *subsystem)
273273
{
274+
int buffer_size = sizeof(env->buf) - env->buflen;
274275
int len;
275276

276-
len = strlcpy(&env->buf[env->buflen], subsystem,
277-
sizeof(env->buf) - env->buflen);
278-
if (len >= (sizeof(env->buf) - env->buflen)) {
279-
WARN(1, KERN_ERR "init_uevent_argv: buffer size too small\n");
277+
len = strlcpy(&env->buf[env->buflen], subsystem, buffer_size);
278+
if (len >= buffer_size) {
279+
pr_warn("init_uevent_argv: buffer size of %d too small, needed %d\n",
280+
buffer_size, len);
280281
return -ENOMEM;
281282
}
282283

0 commit comments

Comments
 (0)