From: Tetsuo Handa Date: Sat, 26 May 2018 00:59:36 +0000 (+0900) Subject: PM / hibernate: Fix oops at snapshot_write() X-Git-Tag: v4.14.56~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=140eae92cf7023422aec3a1647f78c1e0bdd6bf8;p=platform%2Fkernel%2Flinux-rpi.git PM / hibernate: Fix oops at snapshot_write() commit fc14eebfc20854a38fd9f1d93a42b1783dad4d17 upstream. syzbot is reporting NULL pointer dereference at snapshot_write() [1]. This is because data->handle is zero-cleared by ioctl(SNAPSHOT_FREE). Fix this by checking data_of(data->handle) != NULL before using it. [1] https://syzkaller.appspot.com/bug?id=828a3c71bd344a6de8b6a31233d51a72099f27fd Signed-off-by: Tetsuo Handa Reported-by: syzbot Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- diff --git a/kernel/power/user.c b/kernel/power/user.c index 22df9f7..69017a5 100644 --- a/kernel/power/user.c +++ b/kernel/power/user.c @@ -186,6 +186,11 @@ static ssize_t snapshot_write(struct file *filp, const char __user *buf, res = PAGE_SIZE - pg_offp; } + if (!data_of(data->handle)) { + res = -EINVAL; + goto unlock; + } + res = simple_write_to_buffer(data_of(data->handle), res, &pg_offp, buf, count); if (res > 0)