procfs: fix a locking bug in a vmcore_add_device_dump() error path
authorBart Van Assche <bvanassche@acm.org>
Wed, 29 Jan 2025 22:20:03 +0000 (14:20 -0800)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 18 Feb 2025 06:40:00 +0000 (22:40 -0800)
Unlock vmcore_mutex when returning -EBUSY.

Link: https://lkml.kernel.org/r/20250129222003.1495713-1-bvanassche@acm.org
Fixes: 0f3b1c40c652 ("fs/proc/vmcore: disallow vmcore modifications while the vmcore is open")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Baoquan he <bhe@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/proc/vmcore.c

index a00120a3c0994c18504a100c277d1f059489a175..10d01eb09c43d792afc0d30ecb7a1a1b7c6f7632 100644 (file)
@@ -1524,7 +1524,7 @@ int vmcore_add_device_dump(struct vmcoredd_data *data)
                pr_warn_once("Unexpected adding of device dump\n");
        if (vmcore_open) {
                ret = -EBUSY;
-               goto out_err;
+               goto unlock;
        }
 
        list_add_tail(&dump->list, &vmcoredd_list);
@@ -1532,6 +1532,9 @@ int vmcore_add_device_dump(struct vmcoredd_data *data)
        mutex_unlock(&vmcore_mutex);
        return 0;
 
+unlock:
+       mutex_unlock(&vmcore_mutex);
+
 out_err:
        vfree(buf);
        vfree(dump);