]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
kobject_uevent: remove warning in init_uevent_argv()
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 5 Apr 2021 09:48:52 +0000 (11:48 +0200)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 18 Jun 2021 09:07:35 +0000 (11:07 +0200)
BugLink: https://bugs.launchpad.net/bugs/1931292
commit b4104180a2efb85f55e1ba1407885c9421970338 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>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
lib/kobject_uevent.c

index 7998affa45d49a27b8613931ae3eb81499eef926..c87d5b6a8a55a3c02719ebfde3761f948ec2c35b 100644 (file)
@@ -251,12 +251,13 @@ static int kobj_usermode_filter(struct kobject *kobj)
 
 static int init_uevent_argv(struct kobj_uevent_env *env, const char *subsystem)
 {
+       int buffer_size = sizeof(env->buf) - env->buflen;
        int len;
 
-       len = strlcpy(&env->buf[env->buflen], subsystem,
-                     sizeof(env->buf) - env->buflen);
-       if (len >= (sizeof(env->buf) - env->buflen)) {
-               WARN(1, KERN_ERR "init_uevent_argv: buffer size too small\n");
+       len = strlcpy(&env->buf[env->buflen], subsystem, buffer_size);
+       if (len >= buffer_size) {
+               pr_warn("init_uevent_argv: buffer size of %d too small, needed %d\n",
+                       buffer_size, len);
                return -ENOMEM;
        }