Commit 0acbf09b authored by Tetsuo Handa's avatar Tetsuo Handa Committed by Kleber Sacilotto de Souza

loop: remember whether sysfs_create_group() was done

BugLink: https://bugs.launchpad.net/bugs/1790620

commit d3349b6b upstream.

syzbot is hitting WARN() triggered by memory allocation fault
injection [1] because loop module is calling sysfs_remove_group()
when sysfs_create_group() failed.
Fix this by remembering whether sysfs_create_group() succeeded.

[1] https://syzkaller.appspot.com/bug?id=3f86c0edf75c86d2633aeb9dd69eccc70bc7e90bSigned-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Reported-by: default avatarsyzbot <syzbot+9f03168400f56df89dbc6f1751f4458fe739ff29@syzkaller.appspotmail.com>
Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>

Renamed sysfs_ready -> sysfs_inited.
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 4f86306b
...@@ -878,14 +878,15 @@ static struct attribute_group loop_attribute_group = { ...@@ -878,14 +878,15 @@ static struct attribute_group loop_attribute_group = {
.attrs= loop_attrs, .attrs= loop_attrs,
}; };
static int loop_sysfs_init(struct loop_device *lo) static void loop_sysfs_init(struct loop_device *lo)
{ {
return sysfs_create_group(&disk_to_dev(lo->lo_disk)->kobj, lo->sysfs_inited = !sysfs_create_group(&disk_to_dev(lo->lo_disk)->kobj,
&loop_attribute_group); &loop_attribute_group);
} }
static void loop_sysfs_exit(struct loop_device *lo) static void loop_sysfs_exit(struct loop_device *lo)
{ {
if (lo->sysfs_inited)
sysfs_remove_group(&disk_to_dev(lo->lo_disk)->kobj, sysfs_remove_group(&disk_to_dev(lo->lo_disk)->kobj,
&loop_attribute_group); &loop_attribute_group);
} }
......
...@@ -59,6 +59,7 @@ struct loop_device { ...@@ -59,6 +59,7 @@ struct loop_device {
struct kthread_worker worker; struct kthread_worker worker;
struct task_struct *worker_task; struct task_struct *worker_task;
bool use_dio; bool use_dio;
bool sysfs_inited;
struct request_queue *lo_queue; struct request_queue *lo_queue;
struct blk_mq_tag_set tag_set; struct blk_mq_tag_set tag_set;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment