* [Linux-kernel-mentees] [PATCH] drm/bufs: Prevent kernel-infoleak in copy_one_buf()
@ 2020-07-28 1:43 ` Peilin Ye
0 siblings, 0 replies; 18+ messages in thread
From: Peilin Ye @ 2020-07-28 1:43 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann
Cc: Arnd Bergmann, David Airlie, Greg Kroah-Hartman, linux-kernel,
dri-devel, linux-kernel-mentees, Peilin Ye, Dan Carpenter
copy_one_buf() is copying uninitialized stack memory to userspace due to
the compiler not initializing holes in statically allocated structures.
Fix it by initializing `v` with memset().
Cc: stable@vger.kernel.org
Fixes: 5c7640ab6258 ("switch compat_drm_infobufs() to drm_ioctl_kernel()")
Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
---
drivers/gpu/drm/drm_bufs.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
index a0735fbc144b..f99cd4a3f951 100644
--- a/drivers/gpu/drm/drm_bufs.c
+++ b/drivers/gpu/drm/drm_bufs.c
@@ -1349,10 +1349,14 @@ static int copy_one_buf(void *data, int count, struct drm_buf_entry *from)
{
struct drm_buf_info *request = data;
struct drm_buf_desc __user *to = &request->list[count];
- struct drm_buf_desc v = {.count = from->buf_count,
- .size = from->buf_size,
- .low_mark = from->low_mark,
- .high_mark = from->high_mark};
+ struct drm_buf_desc v;
+
+ memset(&v, 0, sizeof(v));
+
+ v.count = from->buf_count;
+ v.size = from->buf_size;
+ v.low_mark = from->low_mark;
+ v.high_mark = from->high_mark;
if (copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags)))
return -EFAULT;
--
2.25.1
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [Linux-kernel-mentees] [PATCH] drm/bufs: Prevent kernel-infoleak in copy_one_buf()
@ 2020-07-28 1:43 ` Peilin Ye
0 siblings, 0 replies; 18+ messages in thread
From: Peilin Ye @ 2020-07-28 1:43 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann
Cc: Arnd Bergmann, David Airlie, linux-kernel, dri-devel,
Daniel Vetter, linux-kernel-mentees, Peilin Ye, Dan Carpenter
copy_one_buf() is copying uninitialized stack memory to userspace due to
the compiler not initializing holes in statically allocated structures.
Fix it by initializing `v` with memset().
Cc: stable@vger.kernel.org
Fixes: 5c7640ab6258 ("switch compat_drm_infobufs() to drm_ioctl_kernel()")
Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
---
drivers/gpu/drm/drm_bufs.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
index a0735fbc144b..f99cd4a3f951 100644
--- a/drivers/gpu/drm/drm_bufs.c
+++ b/drivers/gpu/drm/drm_bufs.c
@@ -1349,10 +1349,14 @@ static int copy_one_buf(void *data, int count, struct drm_buf_entry *from)
{
struct drm_buf_info *request = data;
struct drm_buf_desc __user *to = &request->list[count];
- struct drm_buf_desc v = {.count = from->buf_count,
- .size = from->buf_size,
- .low_mark = from->low_mark,
- .high_mark = from->high_mark};
+ struct drm_buf_desc v;
+
+ memset(&v, 0, sizeof(v));
+
+ v.count = from->buf_count;
+ v.size = from->buf_size;
+ v.low_mark = from->low_mark;
+ v.high_mark = from->high_mark;
if (copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags)))
return -EFAULT;
--
2.25.1
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH] drm/bufs: Prevent kernel-infoleak in copy_one_buf()
2020-07-28 1:43 ` Peilin Ye
(?)
@ 2020-07-28 8:11 ` Arnd Bergmann
-1 siblings, 0 replies; 18+ messages in thread
From: Arnd Bergmann @ 2020-07-28 8:11 UTC (permalink / raw)
To: Peilin Ye
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Daniel Vetter, Dan Carpenter, Greg Kroah-Hartman,
linux-kernel-mentees, dri-devel, linux-kernel
On Tue, Jul 28, 2020 at 3:45 AM Peilin Ye <yepeilin.cs@gmail.com> wrote:
>
> copy_one_buf() is copying uninitialized stack memory to userspace due to
> the compiler not initializing holes in statically allocated structures.
> Fix it by initializing `v` with memset().
I would add 'potentially' somewhere in that description: it is architecture
dependent whether there are holes in this structure as 'enum' types
and 'long' are both dependent on the ABI, and even if there is a hole,
it is undefined behavior whether the hold gets initialized.
Other than that, the patch looks good.
> Cc: stable@vger.kernel.org
> Fixes: 5c7640ab6258 ("switch compat_drm_infobufs() to drm_ioctl_kernel()")
> Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
> ---
> drivers/gpu/drm/drm_bufs.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
> index a0735fbc144b..f99cd4a3f951 100644
> --- a/drivers/gpu/drm/drm_bufs.c
> +++ b/drivers/gpu/drm/drm_bufs.c
> @@ -1349,10 +1349,14 @@ static int copy_one_buf(void *data, int count, struct drm_buf_entry *from)
> {
> struct drm_buf_info *request = data;
> struct drm_buf_desc __user *to = &request->list[count];
> - struct drm_buf_desc v = {.count = from->buf_count,
> - .size = from->buf_size,
> - .low_mark = from->low_mark,
> - .high_mark = from->high_mark};
> + struct drm_buf_desc v;
> +
> + memset(&v, 0, sizeof(v));
> +
> + v.count = from->buf_count;
> + v.size = from->buf_size;
> + v.low_mark = from->low_mark;
> + v.high_mark = from->high_mark;
>
> if (copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags)))
> return -EFAULT;
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH] drm/bufs: Prevent kernel-infoleak in copy_one_buf()
@ 2020-07-28 8:11 ` Arnd Bergmann
0 siblings, 0 replies; 18+ messages in thread
From: Arnd Bergmann @ 2020-07-28 8:11 UTC (permalink / raw)
To: Peilin Ye
Cc: Thomas Zimmermann, David Airlie, Greg Kroah-Hartman,
linux-kernel, dri-devel, linux-kernel-mentees, Dan Carpenter
On Tue, Jul 28, 2020 at 3:45 AM Peilin Ye <yepeilin.cs@gmail.com> wrote:
>
> copy_one_buf() is copying uninitialized stack memory to userspace due to
> the compiler not initializing holes in statically allocated structures.
> Fix it by initializing `v` with memset().
I would add 'potentially' somewhere in that description: it is architecture
dependent whether there are holes in this structure as 'enum' types
and 'long' are both dependent on the ABI, and even if there is a hole,
it is undefined behavior whether the hold gets initialized.
Other than that, the patch looks good.
> Cc: stable@vger.kernel.org
> Fixes: 5c7640ab6258 ("switch compat_drm_infobufs() to drm_ioctl_kernel()")
> Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
> ---
> drivers/gpu/drm/drm_bufs.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
> index a0735fbc144b..f99cd4a3f951 100644
> --- a/drivers/gpu/drm/drm_bufs.c
> +++ b/drivers/gpu/drm/drm_bufs.c
> @@ -1349,10 +1349,14 @@ static int copy_one_buf(void *data, int count, struct drm_buf_entry *from)
> {
> struct drm_buf_info *request = data;
> struct drm_buf_desc __user *to = &request->list[count];
> - struct drm_buf_desc v = {.count = from->buf_count,
> - .size = from->buf_size,
> - .low_mark = from->low_mark,
> - .high_mark = from->high_mark};
> + struct drm_buf_desc v;
> +
> + memset(&v, 0, sizeof(v));
> +
> + v.count = from->buf_count;
> + v.size = from->buf_size;
> + v.low_mark = from->low_mark;
> + v.high_mark = from->high_mark;
>
> if (copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags)))
> return -EFAULT;
> --
> 2.25.1
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH] drm/bufs: Prevent kernel-infoleak in copy_one_buf()
@ 2020-07-28 8:11 ` Arnd Bergmann
0 siblings, 0 replies; 18+ messages in thread
From: Arnd Bergmann @ 2020-07-28 8:11 UTC (permalink / raw)
To: Peilin Ye
Cc: Thomas Zimmermann, David Airlie, Maarten Lankhorst, linux-kernel,
Maxime Ripard, dri-devel, Daniel Vetter, linux-kernel-mentees,
Dan Carpenter
On Tue, Jul 28, 2020 at 3:45 AM Peilin Ye <yepeilin.cs@gmail.com> wrote:
>
> copy_one_buf() is copying uninitialized stack memory to userspace due to
> the compiler not initializing holes in statically allocated structures.
> Fix it by initializing `v` with memset().
I would add 'potentially' somewhere in that description: it is architecture
dependent whether there are holes in this structure as 'enum' types
and 'long' are both dependent on the ABI, and even if there is a hole,
it is undefined behavior whether the hold gets initialized.
Other than that, the patch looks good.
> Cc: stable@vger.kernel.org
> Fixes: 5c7640ab6258 ("switch compat_drm_infobufs() to drm_ioctl_kernel()")
> Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
> ---
> drivers/gpu/drm/drm_bufs.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
> index a0735fbc144b..f99cd4a3f951 100644
> --- a/drivers/gpu/drm/drm_bufs.c
> +++ b/drivers/gpu/drm/drm_bufs.c
> @@ -1349,10 +1349,14 @@ static int copy_one_buf(void *data, int count, struct drm_buf_entry *from)
> {
> struct drm_buf_info *request = data;
> struct drm_buf_desc __user *to = &request->list[count];
> - struct drm_buf_desc v = {.count = from->buf_count,
> - .size = from->buf_size,
> - .low_mark = from->low_mark,
> - .high_mark = from->high_mark};
> + struct drm_buf_desc v;
> +
> + memset(&v, 0, sizeof(v));
> +
> + v.count = from->buf_count;
> + v.size = from->buf_size;
> + v.low_mark = from->low_mark;
> + v.high_mark = from->high_mark;
>
> if (copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags)))
> return -EFAULT;
> --
> 2.25.1
>
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH] drm/bufs: Prevent kernel-infoleak in copy_one_buf()
2020-07-28 8:11 ` Arnd Bergmann
(?)
@ 2020-07-28 11:15 ` Peilin Ye
-1 siblings, 0 replies; 18+ messages in thread
From: Peilin Ye @ 2020-07-28 11:15 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Daniel Vetter, Dan Carpenter, Greg Kroah-Hartman,
linux-kernel-mentees, dri-devel, linux-kernel
On Tue, Jul 28, 2020 at 10:11:09AM +0200, Arnd Bergmann wrote:
> On Tue, Jul 28, 2020 at 3:45 AM Peilin Ye <yepeilin.cs@gmail.com> wrote:
> >
> > copy_one_buf() is copying uninitialized stack memory to userspace due to
> > the compiler not initializing holes in statically allocated structures.
> > Fix it by initializing `v` with memset().
>
> I would add 'potentially' somewhere in that description: it is architecture
> dependent whether there are holes in this structure as 'enum' types
> and 'long' are both dependent on the ABI, and even if there is a hole,
> it is undefined behavior whether the hold gets initialized.
I see. I will fix that up. Thank you for the advice!
Peilin Ye
> Other than that, the patch looks good.
>
> > Cc: stable@vger.kernel.org
> > Fixes: 5c7640ab6258 ("switch compat_drm_infobufs() to drm_ioctl_kernel()")
> > Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
> > Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
>
> Acked-by: Arnd Bergmann <arnd@arndb.de>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH] drm/bufs: Prevent kernel-infoleak in copy_one_buf()
@ 2020-07-28 11:15 ` Peilin Ye
0 siblings, 0 replies; 18+ messages in thread
From: Peilin Ye @ 2020-07-28 11:15 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Thomas Zimmermann, David Airlie, Greg Kroah-Hartman,
linux-kernel, dri-devel, linux-kernel-mentees, Dan Carpenter
On Tue, Jul 28, 2020 at 10:11:09AM +0200, Arnd Bergmann wrote:
> On Tue, Jul 28, 2020 at 3:45 AM Peilin Ye <yepeilin.cs@gmail.com> wrote:
> >
> > copy_one_buf() is copying uninitialized stack memory to userspace due to
> > the compiler not initializing holes in statically allocated structures.
> > Fix it by initializing `v` with memset().
>
> I would add 'potentially' somewhere in that description: it is architecture
> dependent whether there are holes in this structure as 'enum' types
> and 'long' are both dependent on the ABI, and even if there is a hole,
> it is undefined behavior whether the hold gets initialized.
I see. I will fix that up. Thank you for the advice!
Peilin Ye
> Other than that, the patch looks good.
>
> > Cc: stable@vger.kernel.org
> > Fixes: 5c7640ab6258 ("switch compat_drm_infobufs() to drm_ioctl_kernel()")
> > Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
> > Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
>
> Acked-by: Arnd Bergmann <arnd@arndb.de>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH] drm/bufs: Prevent kernel-infoleak in copy_one_buf()
@ 2020-07-28 11:15 ` Peilin Ye
0 siblings, 0 replies; 18+ messages in thread
From: Peilin Ye @ 2020-07-28 11:15 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Thomas Zimmermann, David Airlie, Maarten Lankhorst, linux-kernel,
Maxime Ripard, dri-devel, Daniel Vetter, linux-kernel-mentees,
Dan Carpenter
On Tue, Jul 28, 2020 at 10:11:09AM +0200, Arnd Bergmann wrote:
> On Tue, Jul 28, 2020 at 3:45 AM Peilin Ye <yepeilin.cs@gmail.com> wrote:
> >
> > copy_one_buf() is copying uninitialized stack memory to userspace due to
> > the compiler not initializing holes in statically allocated structures.
> > Fix it by initializing `v` with memset().
>
> I would add 'potentially' somewhere in that description: it is architecture
> dependent whether there are holes in this structure as 'enum' types
> and 'long' are both dependent on the ABI, and even if there is a hole,
> it is undefined behavior whether the hold gets initialized.
I see. I will fix that up. Thank you for the advice!
Peilin Ye
> Other than that, the patch looks good.
>
> > Cc: stable@vger.kernel.org
> > Fixes: 5c7640ab6258 ("switch compat_drm_infobufs() to drm_ioctl_kernel()")
> > Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
> > Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
>
> Acked-by: Arnd Bergmann <arnd@arndb.de>
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Linux-kernel-mentees] [PATCH v2] drm/bufs: Prevent kernel-infoleak in copy_one_buf()
2020-07-28 1:43 ` Peilin Ye
(?)
@ 2020-07-28 11:52 ` Peilin Ye
-1 siblings, 0 replies; 18+ messages in thread
From: Peilin Ye @ 2020-07-28 11:52 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann
Cc: Peilin Ye, David Airlie, Daniel Vetter, Dan Carpenter,
Arnd Bergmann, Greg Kroah-Hartman, linux-kernel-mentees,
dri-devel, linux-kernel
Currently `struct drm_buf_desc` is defined as follows:
struct drm_buf_desc {
int count;
int size;
int low_mark;
int high_mark;
enum {
_DRM_PAGE_ALIGN = 0x01,
_DRM_AGP_BUFFER = 0x02,
_DRM_SG_BUFFER = 0x04,
_DRM_FB_BUFFER = 0x08,
_DRM_PCI_BUFFER_RO = 0x10
} flags;
unsigned long agp_start;
};
copy_one_buf() is potentially copying uninitialized kernel stack memory
to userspace, since the compiler may leave such "holes" (around `.flags`
and `.agp_start` fields) in this statically allocated structure. Prevent
it by initializing `v` with memset().
Cc: stable@vger.kernel.org
Fixes: 5c7640ab6258 ("switch compat_drm_infobufs() to drm_ioctl_kernel()")
Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
---
Change in v2:
- Improve commit description. (Suggested by Arnd Bergmann
<arnd@arndb.de>)
drivers/gpu/drm/drm_bufs.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
index a0735fbc144b..f99cd4a3f951 100644
--- a/drivers/gpu/drm/drm_bufs.c
+++ b/drivers/gpu/drm/drm_bufs.c
@@ -1349,10 +1349,14 @@ static int copy_one_buf(void *data, int count, struct drm_buf_entry *from)
{
struct drm_buf_info *request = data;
struct drm_buf_desc __user *to = &request->list[count];
- struct drm_buf_desc v = {.count = from->buf_count,
- .size = from->buf_size,
- .low_mark = from->low_mark,
- .high_mark = from->high_mark};
+ struct drm_buf_desc v;
+
+ memset(&v, 0, sizeof(v));
+
+ v.count = from->buf_count;
+ v.size = from->buf_size;
+ v.low_mark = from->low_mark;
+ v.high_mark = from->high_mark;
if (copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags)))
return -EFAULT;
--
2.25.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [Linux-kernel-mentees] [PATCH v2] drm/bufs: Prevent kernel-infoleak in copy_one_buf()
@ 2020-07-28 11:52 ` Peilin Ye
0 siblings, 0 replies; 18+ messages in thread
From: Peilin Ye @ 2020-07-28 11:52 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann
Cc: Arnd Bergmann, David Airlie, Greg Kroah-Hartman, linux-kernel,
dri-devel, linux-kernel-mentees, Peilin Ye, Dan Carpenter
Currently `struct drm_buf_desc` is defined as follows:
struct drm_buf_desc {
int count;
int size;
int low_mark;
int high_mark;
enum {
_DRM_PAGE_ALIGN = 0x01,
_DRM_AGP_BUFFER = 0x02,
_DRM_SG_BUFFER = 0x04,
_DRM_FB_BUFFER = 0x08,
_DRM_PCI_BUFFER_RO = 0x10
} flags;
unsigned long agp_start;
};
copy_one_buf() is potentially copying uninitialized kernel stack memory
to userspace, since the compiler may leave such "holes" (around `.flags`
and `.agp_start` fields) in this statically allocated structure. Prevent
it by initializing `v` with memset().
Cc: stable@vger.kernel.org
Fixes: 5c7640ab6258 ("switch compat_drm_infobufs() to drm_ioctl_kernel()")
Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
---
Change in v2:
- Improve commit description. (Suggested by Arnd Bergmann
<arnd@arndb.de>)
drivers/gpu/drm/drm_bufs.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
index a0735fbc144b..f99cd4a3f951 100644
--- a/drivers/gpu/drm/drm_bufs.c
+++ b/drivers/gpu/drm/drm_bufs.c
@@ -1349,10 +1349,14 @@ static int copy_one_buf(void *data, int count, struct drm_buf_entry *from)
{
struct drm_buf_info *request = data;
struct drm_buf_desc __user *to = &request->list[count];
- struct drm_buf_desc v = {.count = from->buf_count,
- .size = from->buf_size,
- .low_mark = from->low_mark,
- .high_mark = from->high_mark};
+ struct drm_buf_desc v;
+
+ memset(&v, 0, sizeof(v));
+
+ v.count = from->buf_count;
+ v.size = from->buf_size;
+ v.low_mark = from->low_mark;
+ v.high_mark = from->high_mark;
if (copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags)))
return -EFAULT;
--
2.25.1
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [Linux-kernel-mentees] [PATCH v2] drm/bufs: Prevent kernel-infoleak in copy_one_buf()
@ 2020-07-28 11:52 ` Peilin Ye
0 siblings, 0 replies; 18+ messages in thread
From: Peilin Ye @ 2020-07-28 11:52 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann
Cc: Arnd Bergmann, David Airlie, linux-kernel, dri-devel,
Daniel Vetter, linux-kernel-mentees, Peilin Ye, Dan Carpenter
Currently `struct drm_buf_desc` is defined as follows:
struct drm_buf_desc {
int count;
int size;
int low_mark;
int high_mark;
enum {
_DRM_PAGE_ALIGN = 0x01,
_DRM_AGP_BUFFER = 0x02,
_DRM_SG_BUFFER = 0x04,
_DRM_FB_BUFFER = 0x08,
_DRM_PCI_BUFFER_RO = 0x10
} flags;
unsigned long agp_start;
};
copy_one_buf() is potentially copying uninitialized kernel stack memory
to userspace, since the compiler may leave such "holes" (around `.flags`
and `.agp_start` fields) in this statically allocated structure. Prevent
it by initializing `v` with memset().
Cc: stable@vger.kernel.org
Fixes: 5c7640ab6258 ("switch compat_drm_infobufs() to drm_ioctl_kernel()")
Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
---
Change in v2:
- Improve commit description. (Suggested by Arnd Bergmann
<arnd@arndb.de>)
drivers/gpu/drm/drm_bufs.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
index a0735fbc144b..f99cd4a3f951 100644
--- a/drivers/gpu/drm/drm_bufs.c
+++ b/drivers/gpu/drm/drm_bufs.c
@@ -1349,10 +1349,14 @@ static int copy_one_buf(void *data, int count, struct drm_buf_entry *from)
{
struct drm_buf_info *request = data;
struct drm_buf_desc __user *to = &request->list[count];
- struct drm_buf_desc v = {.count = from->buf_count,
- .size = from->buf_size,
- .low_mark = from->low_mark,
- .high_mark = from->high_mark};
+ struct drm_buf_desc v;
+
+ memset(&v, 0, sizeof(v));
+
+ v.count = from->buf_count;
+ v.size = from->buf_size;
+ v.low_mark = from->low_mark;
+ v.high_mark = from->high_mark;
if (copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags)))
return -EFAULT;
--
2.25.1
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply related [flat|nested] 18+ messages in thread
* RE: [Linux-kernel-mentees] [PATCH v2] drm/bufs: Prevent kernel-infoleak in copy_one_buf()
2020-07-28 11:52 ` Peilin Ye
(?)
@ 2020-07-28 12:35 ` David Laight
-1 siblings, 0 replies; 18+ messages in thread
From: David Laight @ 2020-07-28 12:35 UTC (permalink / raw)
To: 'Peilin Ye', Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann
Cc: David Airlie, Daniel Vetter, Dan Carpenter, Arnd Bergmann,
Greg Kroah-Hartman, linux-kernel-mentees, dri-devel,
linux-kernel
From: Peilin Ye
> Sent: 28 July 2020 12:52
> Currently `struct drm_buf_desc` is defined as follows:
>
> struct drm_buf_desc {
> int count;
> int size;
> int low_mark;
> int high_mark;
> enum {
> _DRM_PAGE_ALIGN = 0x01,
> _DRM_AGP_BUFFER = 0x02,
> _DRM_SG_BUFFER = 0x04,
> _DRM_FB_BUFFER = 0x08,
> _DRM_PCI_BUFFER_RO = 0x10
> } flags;
> unsigned long agp_start;
> };
>
> copy_one_buf() is potentially copying uninitialized kernel stack memory
> to userspace, since the compiler may leave such "holes" (around `.flags`
> and `.agp_start` fields) in this statically allocated structure. Prevent
> it by initializing `v` with memset().
>
> Cc: stable@vger.kernel.org
> Fixes: 5c7640ab6258 ("switch compat_drm_infobufs() to drm_ioctl_kernel()")
> Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
> Acked-by: Arnd Bergmann <arnd@arndb.de>
> Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
> ---
> Change in v2:
> - Improve commit description. (Suggested by Arnd Bergmann
> <arnd@arndb.de>)
>
> drivers/gpu/drm/drm_bufs.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
> index a0735fbc144b..f99cd4a3f951 100644
> --- a/drivers/gpu/drm/drm_bufs.c
> +++ b/drivers/gpu/drm/drm_bufs.c
> @@ -1349,10 +1349,14 @@ static int copy_one_buf(void *data, int count, struct drm_buf_entry *from)
> {
> struct drm_buf_info *request = data;
> struct drm_buf_desc __user *to = &request->list[count];
> - struct drm_buf_desc v = {.count = from->buf_count,
> - .size = from->buf_size,
> - .low_mark = from->low_mark,
> - .high_mark = from->high_mark};
> + struct drm_buf_desc v;
> +
> + memset(&v, 0, sizeof(v));
> +
> + v.count = from->buf_count;
> + v.size = from->buf_size;
> + v.low_mark = from->low_mark;
> + v.high_mark = from->high_mark;
>
> if (copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags)))
> return -EFAULT;
The memset() isn't needed.
The copy_to_user() stops after the 4 'int' values so no 'random'
kernel stack can get copied.
Quite why it is 'right' to leave the remaining part of each
userspace structure unchanged is another matter.
David.
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
^ permalink raw reply [flat|nested] 18+ messages in thread
* RE: [Linux-kernel-mentees] [PATCH v2] drm/bufs: Prevent kernel-infoleak in copy_one_buf()
@ 2020-07-28 12:35 ` David Laight
0 siblings, 0 replies; 18+ messages in thread
From: David Laight @ 2020-07-28 12:35 UTC (permalink / raw)
To: 'Peilin Ye', Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann
Cc: Arnd Bergmann, David Airlie, Greg Kroah-Hartman, linux-kernel,
dri-devel, linux-kernel-mentees, Dan Carpenter
From: Peilin Ye
> Sent: 28 July 2020 12:52
> Currently `struct drm_buf_desc` is defined as follows:
>
> struct drm_buf_desc {
> int count;
> int size;
> int low_mark;
> int high_mark;
> enum {
> _DRM_PAGE_ALIGN = 0x01,
> _DRM_AGP_BUFFER = 0x02,
> _DRM_SG_BUFFER = 0x04,
> _DRM_FB_BUFFER = 0x08,
> _DRM_PCI_BUFFER_RO = 0x10
> } flags;
> unsigned long agp_start;
> };
>
> copy_one_buf() is potentially copying uninitialized kernel stack memory
> to userspace, since the compiler may leave such "holes" (around `.flags`
> and `.agp_start` fields) in this statically allocated structure. Prevent
> it by initializing `v` with memset().
>
> Cc: stable@vger.kernel.org
> Fixes: 5c7640ab6258 ("switch compat_drm_infobufs() to drm_ioctl_kernel()")
> Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
> Acked-by: Arnd Bergmann <arnd@arndb.de>
> Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
> ---
> Change in v2:
> - Improve commit description. (Suggested by Arnd Bergmann
> <arnd@arndb.de>)
>
> drivers/gpu/drm/drm_bufs.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
> index a0735fbc144b..f99cd4a3f951 100644
> --- a/drivers/gpu/drm/drm_bufs.c
> +++ b/drivers/gpu/drm/drm_bufs.c
> @@ -1349,10 +1349,14 @@ static int copy_one_buf(void *data, int count, struct drm_buf_entry *from)
> {
> struct drm_buf_info *request = data;
> struct drm_buf_desc __user *to = &request->list[count];
> - struct drm_buf_desc v = {.count = from->buf_count,
> - .size = from->buf_size,
> - .low_mark = from->low_mark,
> - .high_mark = from->high_mark};
> + struct drm_buf_desc v;
> +
> + memset(&v, 0, sizeof(v));
> +
> + v.count = from->buf_count;
> + v.size = from->buf_size;
> + v.low_mark = from->low_mark;
> + v.high_mark = from->high_mark;
>
> if (copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags)))
> return -EFAULT;
The memset() isn't needed.
The copy_to_user() stops after the 4 'int' values so no 'random'
kernel stack can get copied.
Quite why it is 'right' to leave the remaining part of each
userspace structure unchanged is another matter.
David.
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH v2] drm/bufs: Prevent kernel-infoleak in copy_one_buf()
@ 2020-07-28 12:35 ` David Laight
0 siblings, 0 replies; 18+ messages in thread
From: David Laight @ 2020-07-28 12:35 UTC (permalink / raw)
To: 'Peilin Ye', Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann
Cc: Arnd Bergmann, David Airlie, linux-kernel, dri-devel,
Daniel Vetter, linux-kernel-mentees, Dan Carpenter
From: Peilin Ye
> Sent: 28 July 2020 12:52
> Currently `struct drm_buf_desc` is defined as follows:
>
> struct drm_buf_desc {
> int count;
> int size;
> int low_mark;
> int high_mark;
> enum {
> _DRM_PAGE_ALIGN = 0x01,
> _DRM_AGP_BUFFER = 0x02,
> _DRM_SG_BUFFER = 0x04,
> _DRM_FB_BUFFER = 0x08,
> _DRM_PCI_BUFFER_RO = 0x10
> } flags;
> unsigned long agp_start;
> };
>
> copy_one_buf() is potentially copying uninitialized kernel stack memory
> to userspace, since the compiler may leave such "holes" (around `.flags`
> and `.agp_start` fields) in this statically allocated structure. Prevent
> it by initializing `v` with memset().
>
> Cc: stable@vger.kernel.org
> Fixes: 5c7640ab6258 ("switch compat_drm_infobufs() to drm_ioctl_kernel()")
> Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
> Acked-by: Arnd Bergmann <arnd@arndb.de>
> Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
> ---
> Change in v2:
> - Improve commit description. (Suggested by Arnd Bergmann
> <arnd@arndb.de>)
>
> drivers/gpu/drm/drm_bufs.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
> index a0735fbc144b..f99cd4a3f951 100644
> --- a/drivers/gpu/drm/drm_bufs.c
> +++ b/drivers/gpu/drm/drm_bufs.c
> @@ -1349,10 +1349,14 @@ static int copy_one_buf(void *data, int count, struct drm_buf_entry *from)
> {
> struct drm_buf_info *request = data;
> struct drm_buf_desc __user *to = &request->list[count];
> - struct drm_buf_desc v = {.count = from->buf_count,
> - .size = from->buf_size,
> - .low_mark = from->low_mark,
> - .high_mark = from->high_mark};
> + struct drm_buf_desc v;
> +
> + memset(&v, 0, sizeof(v));
> +
> + v.count = from->buf_count;
> + v.size = from->buf_size;
> + v.low_mark = from->low_mark;
> + v.high_mark = from->high_mark;
>
> if (copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags)))
> return -EFAULT;
The memset() isn't needed.
The copy_to_user() stops after the 4 'int' values so no 'random'
kernel stack can get copied.
Quite why it is 'right' to leave the remaining part of each
userspace structure unchanged is another matter.
David.
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH v2] drm/bufs: Prevent kernel-infoleak in copy_one_buf()
2020-07-28 12:35 ` David Laight
(?)
@ 2020-07-28 12:50 ` Peilin Ye
-1 siblings, 0 replies; 18+ messages in thread
From: Peilin Ye @ 2020-07-28 12:50 UTC (permalink / raw)
To: David Laight
Cc: David Airlie, Daniel Vetter, Dan Carpenter, Arnd Bergmann,
Greg Kroah-Hartman, linux-kernel-mentees, dri-devel,
linux-kernel
On Tue, Jul 28, 2020 at 12:35:17PM +0000, David Laight wrote:
> From: Peilin Ye
> > Sent: 28 July 2020 12:52
> > Currently `struct drm_buf_desc` is defined as follows:
> >
> > struct drm_buf_desc {
> > int count;
> > int size;
> > int low_mark;
> > int high_mark;
> > enum {
> > _DRM_PAGE_ALIGN = 0x01,
> > _DRM_AGP_BUFFER = 0x02,
> > _DRM_SG_BUFFER = 0x04,
> > _DRM_FB_BUFFER = 0x08,
> > _DRM_PCI_BUFFER_RO = 0x10
> > } flags;
> > unsigned long agp_start;
> > };
> >
> > copy_one_buf() is potentially copying uninitialized kernel stack memory
> > to userspace, since the compiler may leave such "holes" (around `.flags`
> > and `.agp_start` fields) in this statically allocated structure. Prevent
> > it by initializing `v` with memset().
> >
> > Cc: stable@vger.kernel.org
> > Fixes: 5c7640ab6258 ("switch compat_drm_infobufs() to drm_ioctl_kernel()")
> > Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
> > Acked-by: Arnd Bergmann <arnd@arndb.de>
> > Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
> > ---
> > Change in v2:
> > - Improve commit description. (Suggested by Arnd Bergmann
> > <arnd@arndb.de>)
> >
> > drivers/gpu/drm/drm_bufs.c | 12 ++++++++----
> > 1 file changed, 8 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
> > index a0735fbc144b..f99cd4a3f951 100644
> > --- a/drivers/gpu/drm/drm_bufs.c
> > +++ b/drivers/gpu/drm/drm_bufs.c
> > @@ -1349,10 +1349,14 @@ static int copy_one_buf(void *data, int count, struct drm_buf_entry *from)
> > {
> > struct drm_buf_info *request = data;
> > struct drm_buf_desc __user *to = &request->list[count];
> > - struct drm_buf_desc v = {.count = from->buf_count,
> > - .size = from->buf_size,
> > - .low_mark = from->low_mark,
> > - .high_mark = from->high_mark};
> > + struct drm_buf_desc v;
> > +
> > + memset(&v, 0, sizeof(v));
> > +
> > + v.count = from->buf_count;
> > + v.size = from->buf_size;
> > + v.low_mark = from->low_mark;
> > + v.high_mark = from->high_mark;
> >
> > if (copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags)))
> > return -EFAULT;
>
> The memset() isn't needed.
> The copy_to_user() stops after the 4 'int' values so no 'random'
> kernel stack can get copied.
You are right, I overlooked that. Thank you for pointing this out!
Peilin Ye
> Quite why it is 'right' to leave the remaining part of each
> userspace structure unchanged is another matter.
>
> David.
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH v2] drm/bufs: Prevent kernel-infoleak in copy_one_buf()
@ 2020-07-28 12:50 ` Peilin Ye
0 siblings, 0 replies; 18+ messages in thread
From: Peilin Ye @ 2020-07-28 12:50 UTC (permalink / raw)
To: David Laight
Cc: Arnd Bergmann, David Airlie, Greg Kroah-Hartman, linux-kernel,
dri-devel, linux-kernel-mentees, Dan Carpenter
On Tue, Jul 28, 2020 at 12:35:17PM +0000, David Laight wrote:
> From: Peilin Ye
> > Sent: 28 July 2020 12:52
> > Currently `struct drm_buf_desc` is defined as follows:
> >
> > struct drm_buf_desc {
> > int count;
> > int size;
> > int low_mark;
> > int high_mark;
> > enum {
> > _DRM_PAGE_ALIGN = 0x01,
> > _DRM_AGP_BUFFER = 0x02,
> > _DRM_SG_BUFFER = 0x04,
> > _DRM_FB_BUFFER = 0x08,
> > _DRM_PCI_BUFFER_RO = 0x10
> > } flags;
> > unsigned long agp_start;
> > };
> >
> > copy_one_buf() is potentially copying uninitialized kernel stack memory
> > to userspace, since the compiler may leave such "holes" (around `.flags`
> > and `.agp_start` fields) in this statically allocated structure. Prevent
> > it by initializing `v` with memset().
> >
> > Cc: stable@vger.kernel.org
> > Fixes: 5c7640ab6258 ("switch compat_drm_infobufs() to drm_ioctl_kernel()")
> > Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
> > Acked-by: Arnd Bergmann <arnd@arndb.de>
> > Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
> > ---
> > Change in v2:
> > - Improve commit description. (Suggested by Arnd Bergmann
> > <arnd@arndb.de>)
> >
> > drivers/gpu/drm/drm_bufs.c | 12 ++++++++----
> > 1 file changed, 8 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
> > index a0735fbc144b..f99cd4a3f951 100644
> > --- a/drivers/gpu/drm/drm_bufs.c
> > +++ b/drivers/gpu/drm/drm_bufs.c
> > @@ -1349,10 +1349,14 @@ static int copy_one_buf(void *data, int count, struct drm_buf_entry *from)
> > {
> > struct drm_buf_info *request = data;
> > struct drm_buf_desc __user *to = &request->list[count];
> > - struct drm_buf_desc v = {.count = from->buf_count,
> > - .size = from->buf_size,
> > - .low_mark = from->low_mark,
> > - .high_mark = from->high_mark};
> > + struct drm_buf_desc v;
> > +
> > + memset(&v, 0, sizeof(v));
> > +
> > + v.count = from->buf_count;
> > + v.size = from->buf_size;
> > + v.low_mark = from->low_mark;
> > + v.high_mark = from->high_mark;
> >
> > if (copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags)))
> > return -EFAULT;
>
> The memset() isn't needed.
> The copy_to_user() stops after the 4 'int' values so no 'random'
> kernel stack can get copied.
You are right, I overlooked that. Thank you for pointing this out!
Peilin Ye
> Quite why it is 'right' to leave the remaining part of each
> userspace structure unchanged is another matter.
>
> David.
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH v2] drm/bufs: Prevent kernel-infoleak in copy_one_buf()
@ 2020-07-28 12:50 ` Peilin Ye
0 siblings, 0 replies; 18+ messages in thread
From: Peilin Ye @ 2020-07-28 12:50 UTC (permalink / raw)
To: David Laight
Cc: Arnd Bergmann, David Airlie, linux-kernel, dri-devel,
Daniel Vetter, linux-kernel-mentees, Dan Carpenter
On Tue, Jul 28, 2020 at 12:35:17PM +0000, David Laight wrote:
> From: Peilin Ye
> > Sent: 28 July 2020 12:52
> > Currently `struct drm_buf_desc` is defined as follows:
> >
> > struct drm_buf_desc {
> > int count;
> > int size;
> > int low_mark;
> > int high_mark;
> > enum {
> > _DRM_PAGE_ALIGN = 0x01,
> > _DRM_AGP_BUFFER = 0x02,
> > _DRM_SG_BUFFER = 0x04,
> > _DRM_FB_BUFFER = 0x08,
> > _DRM_PCI_BUFFER_RO = 0x10
> > } flags;
> > unsigned long agp_start;
> > };
> >
> > copy_one_buf() is potentially copying uninitialized kernel stack memory
> > to userspace, since the compiler may leave such "holes" (around `.flags`
> > and `.agp_start` fields) in this statically allocated structure. Prevent
> > it by initializing `v` with memset().
> >
> > Cc: stable@vger.kernel.org
> > Fixes: 5c7640ab6258 ("switch compat_drm_infobufs() to drm_ioctl_kernel()")
> > Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
> > Acked-by: Arnd Bergmann <arnd@arndb.de>
> > Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
> > ---
> > Change in v2:
> > - Improve commit description. (Suggested by Arnd Bergmann
> > <arnd@arndb.de>)
> >
> > drivers/gpu/drm/drm_bufs.c | 12 ++++++++----
> > 1 file changed, 8 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
> > index a0735fbc144b..f99cd4a3f951 100644
> > --- a/drivers/gpu/drm/drm_bufs.c
> > +++ b/drivers/gpu/drm/drm_bufs.c
> > @@ -1349,10 +1349,14 @@ static int copy_one_buf(void *data, int count, struct drm_buf_entry *from)
> > {
> > struct drm_buf_info *request = data;
> > struct drm_buf_desc __user *to = &request->list[count];
> > - struct drm_buf_desc v = {.count = from->buf_count,
> > - .size = from->buf_size,
> > - .low_mark = from->low_mark,
> > - .high_mark = from->high_mark};
> > + struct drm_buf_desc v;
> > +
> > + memset(&v, 0, sizeof(v));
> > +
> > + v.count = from->buf_count;
> > + v.size = from->buf_size;
> > + v.low_mark = from->low_mark;
> > + v.high_mark = from->high_mark;
> >
> > if (copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags)))
> > return -EFAULT;
>
> The memset() isn't needed.
> The copy_to_user() stops after the 4 'int' values so no 'random'
> kernel stack can get copied.
You are right, I overlooked that. Thank you for pointing this out!
Peilin Ye
> Quite why it is 'right' to leave the remaining part of each
> userspace structure unchanged is another matter.
>
> David.
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
>
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply [flat|nested] 18+ messages in thread