* [PATCH] xfs: fix stack contents leakage in the v1 bulkstat/inumbers ioctls
@ 2019-07-24 15:35 Darrick J. Wong
2019-07-24 20:19 ` Eric Sandeen
2019-07-25 6:52 ` Dan Carpenter
0 siblings, 2 replies; 5+ messages in thread
From: Darrick J. Wong @ 2019-07-24 15:35 UTC (permalink / raw)
To: linux-xfs; +Cc: Dan Carpenter
From: Darrick J. Wong <darrick.wong@oracle.com>
Explicitly initialize the onstack structures to zero so we don't leak
kernel memory into userspace when converting the in-core structure to
the v1 ioctl structure.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
fs/xfs/xfs_ioctl.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index f193f7b288ca..44e1a290f053 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -719,7 +719,7 @@ xfs_fsbulkstat_one_fmt(
struct xfs_ibulk *breq,
const struct xfs_bulkstat *bstat)
{
- struct xfs_bstat bs1;
+ struct xfs_bstat bs1 = { 0 };
xfs_bulkstat_to_bstat(breq->mp, &bs1, bstat);
if (copy_to_user(breq->ubuffer, &bs1, sizeof(bs1)))
@@ -732,7 +732,7 @@ xfs_fsinumbers_fmt(
struct xfs_ibulk *breq,
const struct xfs_inumbers *igrp)
{
- struct xfs_inogrp ig1;
+ struct xfs_inogrp ig1 = { 0 };
xfs_inumbers_to_inogrp(&ig1, igrp);
if (copy_to_user(breq->ubuffer, &ig1, sizeof(struct xfs_inogrp)))
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] xfs: fix stack contents leakage in the v1 bulkstat/inumbers ioctls
2019-07-24 15:35 [PATCH] xfs: fix stack contents leakage in the v1 bulkstat/inumbers ioctls Darrick J. Wong
@ 2019-07-24 20:19 ` Eric Sandeen
2019-07-24 20:27 ` Eric Sandeen
2019-07-25 6:52 ` Dan Carpenter
1 sibling, 1 reply; 5+ messages in thread
From: Eric Sandeen @ 2019-07-24 20:19 UTC (permalink / raw)
To: Darrick J. Wong, linux-xfs; +Cc: Dan Carpenter
On 7/24/19 10:35 AM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
>
> Explicitly initialize the onstack structures to zero so we don't leak
> kernel memory into userspace when converting the in-core structure to
> the v1 ioctl structure.
>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
> fs/xfs/xfs_ioctl.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> index f193f7b288ca..44e1a290f053 100644
> --- a/fs/xfs/xfs_ioctl.c
> +++ b/fs/xfs/xfs_ioctl.c
> @@ -719,7 +719,7 @@ xfs_fsbulkstat_one_fmt(
> struct xfs_ibulk *breq,
> const struct xfs_bulkstat *bstat)
> {
> - struct xfs_bstat bs1;
> + struct xfs_bstat bs1 = { 0 };
>
> xfs_bulkstat_to_bstat(breq->mp, &bs1, bstat);
Confused. the first thing xfs_bulkstat_to_bstat does is...
void
xfs_bulkstat_to_bstat(
struct xfs_mount *mp,
struct xfs_bstat *bs1,
const struct xfs_bulkstat *bstat)
{
memset(bs1, 0, sizeof(struct xfs_bstat));
so what's leaking here?
> if (copy_to_user(breq->ubuffer, &bs1, sizeof(bs1)))
> @@ -732,7 +732,7 @@ xfs_fsinumbers_fmt(
> struct xfs_ibulk *breq,
> const struct xfs_inumbers *igrp)
> {
> - struct xfs_inogrp ig1;
> + struct xfs_inogrp ig1 = { 0 };
>
> xfs_inumbers_to_inogrp(&ig1, igrp);
... and this function initializes all elements of xfs_inogrp ig1 AFAICT.
Maybe I need more coffee?
-Eric
> if (copy_to_user(breq->ubuffer, &ig1, sizeof(struct xfs_inogrp)))
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] xfs: fix stack contents leakage in the v1 bulkstat/inumbers ioctls
2019-07-24 20:19 ` Eric Sandeen
@ 2019-07-24 20:27 ` Eric Sandeen
0 siblings, 0 replies; 5+ messages in thread
From: Eric Sandeen @ 2019-07-24 20:27 UTC (permalink / raw)
To: Darrick J. Wong, linux-xfs; +Cc: Dan Carpenter
On 7/24/19 3:19 PM, Eric Sandeen wrote:
> On 7/24/19 10:35 AM, Darrick J. Wong wrote:
>> From: Darrick J. Wong <darrick.wong@oracle.com>
>>
>> Explicitly initialize the onstack structures to zero so we don't leak
>> kernel memory into userspace when converting the in-core structure to
>> the v1 ioctl structure.
>>
>> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
>> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
>
>> ---
>> fs/xfs/xfs_ioctl.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
>> index f193f7b288ca..44e1a290f053 100644
>> --- a/fs/xfs/xfs_ioctl.c
>> +++ b/fs/xfs/xfs_ioctl.c
>> @@ -719,7 +719,7 @@ xfs_fsbulkstat_one_fmt(
>> struct xfs_ibulk *breq,
>> const struct xfs_bulkstat *bstat)
>> {
>> - struct xfs_bstat bs1;
>> + struct xfs_bstat bs1 = { 0 };
>>
>> xfs_bulkstat_to_bstat(breq->mp, &bs1, bstat);
>
> Confused. the first thing xfs_bulkstat_to_bstat does is...
>
> void
> xfs_bulkstat_to_bstat(
> struct xfs_mount *mp,
> struct xfs_bstat *bs1,
> const struct xfs_bulkstat *bstat)
> {
> memset(bs1, 0, sizeof(struct xfs_bstat));
>
> so what's leaking here?
>
>> if (copy_to_user(breq->ubuffer, &bs1, sizeof(bs1)))
>> @@ -732,7 +732,7 @@ xfs_fsinumbers_fmt(
>> struct xfs_ibulk *breq,
>> const struct xfs_inumbers *igrp)
>> {
>> - struct xfs_inogrp ig1;
>> + struct xfs_inogrp ig1 = { 0 };
>>
>> xfs_inumbers_to_inogrp(&ig1, igrp);
>
> ... and this function initializes all elements of xfs_inogrp ig1 AFAICT.
>
> Maybe I need more coffee?
or I need to read mail in order. o_O Ok, struct packing/ hole issues.
But let's be consistent, do we zero it out in the conversion function or
rely on the caller? (I prefer the former, as is done in xfs_bulkstat_to_bstat,
but we surely don't need to do both).
Also, Fixes: tag please?
-Eric
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] xfs: fix stack contents leakage in the v1 bulkstat/inumbers ioctls
2019-07-24 15:35 [PATCH] xfs: fix stack contents leakage in the v1 bulkstat/inumbers ioctls Darrick J. Wong
2019-07-24 20:19 ` Eric Sandeen
@ 2019-07-25 6:52 ` Dan Carpenter
2019-07-25 17:02 ` Darrick J. Wong
1 sibling, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2019-07-25 6:52 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: linux-xfs
On Wed, Jul 24, 2019 at 08:35:45AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
>
> Explicitly initialize the onstack structures to zero so we don't leak
> kernel memory into userspace when converting the in-core structure to
> the v1 ioctl structure.
>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
> fs/xfs/xfs_ioctl.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> index f193f7b288ca..44e1a290f053 100644
> --- a/fs/xfs/xfs_ioctl.c
> +++ b/fs/xfs/xfs_ioctl.c
> @@ -719,7 +719,7 @@ xfs_fsbulkstat_one_fmt(
> struct xfs_ibulk *breq,
> const struct xfs_bulkstat *bstat)
> {
> - struct xfs_bstat bs1;
> + struct xfs_bstat bs1 = { 0 };
This sort of initialization is potentially problematic because some
versions of GCC will change it as a series of assignments (which doesn't
clear the struct hole). It's not clear to me the rules where GCC does
this and also I wish there were an option to disable that feature.
[ I am still out of office until the end of the month ]
regards,
dan carpenter
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] xfs: fix stack contents leakage in the v1 bulkstat/inumbers ioctls
2019-07-25 6:52 ` Dan Carpenter
@ 2019-07-25 17:02 ` Darrick J. Wong
0 siblings, 0 replies; 5+ messages in thread
From: Darrick J. Wong @ 2019-07-25 17:02 UTC (permalink / raw)
To: Dan Carpenter; +Cc: linux-xfs
On Thu, Jul 25, 2019 at 09:52:17AM +0300, Dan Carpenter wrote:
> On Wed, Jul 24, 2019 at 08:35:45AM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> >
> > Explicitly initialize the onstack structures to zero so we don't leak
> > kernel memory into userspace when converting the in-core structure to
> > the v1 ioctl structure.
> >
> > Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> > fs/xfs/xfs_ioctl.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> > index f193f7b288ca..44e1a290f053 100644
> > --- a/fs/xfs/xfs_ioctl.c
> > +++ b/fs/xfs/xfs_ioctl.c
> > @@ -719,7 +719,7 @@ xfs_fsbulkstat_one_fmt(
> > struct xfs_ibulk *breq,
> > const struct xfs_bulkstat *bstat)
> > {
> > - struct xfs_bstat bs1;
> > + struct xfs_bstat bs1 = { 0 };
>
> This sort of initialization is potentially problematic because some
> versions of GCC will change it as a series of assignments (which doesn't
> clear the struct hole). It's not clear to me the rules where GCC does
> this and also I wish there were an option to disable that feature.
And poor maintainers like me didn't even /know/ that.... ok, I'll go
with an explicit memset like Eric suggested in the patch review.
--D
> [ I am still out of office until the end of the month ]
>
> regards,
> dan carpenter
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-07-25 17:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-24 15:35 [PATCH] xfs: fix stack contents leakage in the v1 bulkstat/inumbers ioctls Darrick J. Wong
2019-07-24 20:19 ` Eric Sandeen
2019-07-24 20:27 ` Eric Sandeen
2019-07-25 6:52 ` Dan Carpenter
2019-07-25 17:02 ` Darrick J. Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).