misc: xilinx_sdfec: Fix a couple small information leaks
PATCH 1/4 misc: xilinx_sdfec: Fix a couple small information leaks
These structs have holes in them so we end up disclosing a few bytes of uninitialized stack data.
drivers/misc/xilinx_sdfec.c:305 xsdfec_get_status() warn: check that 'status' doesn't leak information (struct has a hole after 'activity') drivers/misc/xilinx_sdfec.c:449 xsdfec_get_turbo() warn: check that 'turbo_params' doesn't leak information (struct has a hole after 'scale')
We need to zero out the holes with memset().
--- drivers/misc/xilinx_sdfec.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/misc/xilinx_sdfec.c +2 -0
@@ -295,6 +295,7 @@ static int xsdfec_get_status(struct xsdfec_dev *xsdfec, void __user *arg)struct xsdfec_status status;int err; +memset (&status,0 ,sizeof (status));spin_lock_irqsave (&xsdfec->error_data_lock, xsdfec->flags); status.state = xsdfec->state; xsdfec->state_updated = false;
@@ -440,6 +441,7 @@ static int xsdfec_get_turbo(struct xsdfec_dev *xsdfec, void __user *arg)if (xsdfec->config.code =XSDFEC_LDPC_CODE )return -EIO ; +memset (&turbo_params,0 ,sizeof (turbo_params)); reg_value =xsdfec_regread (xsdfec,XSDFEC_TURBO_ADDR ); turbo_params.scale = (reg_value & XSDFEC_TURBO_SCALE_MASK) >>
Signature · 1 line
2.20.1
PATCH 2/4 misc: xilinx_sdfec: Return -EFAULT if copy_from_user() fails
The copy_from_user() funciton returns the number of bytes remaining to be copied but we want to return -EFAULT to the user.
--- drivers/misc/xilinx_sdfec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/misc/xilinx_sdfec.c +3 -2
@@ -651,9 +651,10 @@ static int xsdfec_add_ldpc(struct xsdfec_dev *xsdfec, void __user *arg)if (!ldpc)return -ENOMEM ; - ret =copy_from_user (ldpc, arg,sizeof (*ldpc)); -if (ret) +if (copy_from_user (ldpc, arg,sizeof (*ldpc))) { + ret = -EFAULT ; goto err_out; + }if (xsdfec->config.code =XSDFEC_TURBO_CODE ) { ret = -EIO ;
Signature · 1 line
2.20.1
PATCH 3/4 misc: xilinx_sdfec: Prevent a divide by zero in xsdfec_reg0_write()
In reply to Dan CarpenterThe "psize" value comes from the user so we need to verify that it's non-zero before we check if "n % psize" or it will crash.
---
The parentheses in this condition are a no-op. They're just confusing. Perhaps something else was intended?
drivers/misc/xilinx_sdfec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/xilinx_sdfec.c +1 -1
@@ -460,7 +460,7 @@ static int xsdfec_reg0_write(struct xsdfec_dev *xsdfec, u32 n, u32 k, u32 psize, {u32 wdata; -if (n <XSDFEC_REG0_N_MIN || n >XSDFEC_REG0_N_MAX || +if (n <XSDFEC_REG0_N_MIN || n >XSDFEC_REG0_N_MAX || psize =0 || (n >XSDFEC_REG0_N_MUL_P * psize) || n <= k || ((n % psize) !=0 )) {dev_dbg (xsdfec->dev,"N value is not in range" );return -EINVAL ;
Signature · 1 line
2.20.1
PATCH 4/4 misc: xilinx_sdfec: Prevent integer overflow in xsdfec_table_write()
In reply to Dan CarpenterThe checking here needs to handle integer overflows because "offset" and "len" come from the user.
--- drivers/misc/xilinx_sdfec.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/misc/xilinx_sdfec.c +3 -1
@@ -611,7 +611,9 @@ static int xsdfec_table_write(struct xsdfec_dev *xsdfec, u32 offset,* Writes that go beyond the length of * Shared Scale(SC) table should fail */ -if ((XSDFEC_REG_WIDTH_JUMP * (offset + len)) > depth) { +if (offset > depth /XSDFEC_REG_WIDTH_JUMP || + len > depth /XSDFEC_REG_WIDTH_JUMP || + offset + len > depth /XSDFEC_REG_WIDTH_JUMP ) {dev_dbg (xsdfec->dev,"Write exceeds SC table length" );return -EINVAL ; }
Signature · 1 line
2.20.1
Hi Dan,
Quoted 5 lines · Dan Carpenter
These structs have holes in them so we end up disclosing a few bytes of uninitialized stack data.
drivers/misc/xilinx_sdfec.c:305xsdfec_get_status()warn: check that 'status' doesn't leak information (struct has a hole after 'activity')drivers/misc/xilinx_sdfec.c:449xsdfec_get_turbo()warn: check that 'turbo_params' doesn't leak information (struct has a hole after 'scale')
Who is generating these warnings? Is this any new GCC or different tool? I see that 3byte padding but never seen these warnings.
Quoted 22 lines
We need to zero out the holes with
memset().Fixes 6bd6a690c2e7 ("misc: xilinx_sdfec: Add stats & status ioctls")Signed-off-by Dan Carpenter <[email protected]>--- drivers/misc/xilinx_sdfec.c | 2 ++ 1 file changed, 2 insertions(+)drivers/misc/xilinx_sdfec.c +1
-0@@ -295,6 +295,7 @@ static int xsdfec_get_status(struct xsdfec_dev *xsdfec, void __user *arg)struct xsdfec_status status;int err; +memset (&status,0 ,sizeof (status));spin_lock_irqsave (&xsdfec->error_data_lock, xsdfec->flags); status.state = xsdfec->state; xsdfec->state_updated = false;
drivers/misc/xilinx_sdfec.c static int xsdfec_get_turbo(struct xsdfec_dev *xsdfec, void __user *arg) · line 447
Quoted 7 lines
drivers/misc/xilinx_sdfec.c +1
-0@@ -440,6 +441,7 @@ static int xsdfec_get_turbo(struct xsdfec_dev *xsdfec, void __user *arg)if (xsdfec->config.code =XSDFEC_LDPC_CODE )return -EIO ; +memset (&turbo_params,0 ,sizeof (turbo_params)); reg_value =xsdfec_regread (xsdfec,XSDFEC_TURBO_ADDR ); turbo_params.scale = (reg_value & XSDFEC_TURBO_SCALE_MASK) >>
Thanks,
Michal
Re: [PATCH 2/4] misc: xilinx_sdfec: Return -EFAULT if copy_from_user() fails
In reply to Dan CarpenterQuoted 1 line · Dan Carpenter
The
copy_from_user()funciton returns the number of bytes remaining to
typo here.
Quoted 16 lines
be copied but we want to return
-EFAULTto the user.Fixes 20ec628e8007 ("misc: xilinx_sdfec: Add ability to configure LDPC")Signed-off-by Dan Carpenter <[email protected]>--- drivers/misc/xilinx_sdfec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/misc/xilinx_sdfec.c +0
-0@@ -651,9 +651,10 @@ static int xsdfec_add_ldpc(struct xsdfec_dev *xsdfec, void __user *arg)if (!ldpc)return -ENOMEM ;
drivers/misc/xilinx_sdfec.c static int xsdfec_add_ldpc(struct xsdfec_dev *xsdfec, void __user *arg) · line 660
Quoted 10 lines
drivers/misc/xilinx_sdfec.c +3
-2- ret =copy_from_user (ldpc, arg,sizeof (*ldpc)); -if (ret) +if (copy_from_user (ldpc, arg,sizeof (*ldpc))) { + ret = -EFAULT ; goto err_out; + }if (xsdfec->config.code =XSDFEC_TURBO_CODE ) { ret = -EIO ;
When typo fixed feel free to add my
Thanks,
Michal
Re: [PATCH 3/4] misc: xilinx_sdfec: Prevent a divide by zero in xsdfec_reg0_write()
In reply to Dan CarpenterQuoted 18 lines · Dan Carpenter
The "psize" value comes from the user so we need to verify that it's non-zero before we check if "n % psize" or it will crash.
Fixes 20ec628e8007 ("misc: xilinx_sdfec: Add ability to configure LDPC")Signed-off-by Dan Carpenter <[email protected]>---
The parentheses in this condition are a no-op. They're just confusing. Perhaps something else was intended?drivers/misc/xilinx_sdfec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/misc/xilinx_sdfec.c +0
-0
drivers/misc/xilinx_sdfec.c static int xsdfec_reg0_write(struct xsdfec_dev *xsdfec, u32 n, u32 k, u32 psize, · line 466
Quoted 8 lines
drivers/misc/xilinx_sdfec.c +1
-1@@ -460,7 +460,7 @@ static int xsdfec_reg0_write(struct xsdfec_dev *xsdfec, u32 n, u32 k, u32 psize, {u32 wdata; -if (n <XSDFEC_REG0_N_MIN || n >XSDFEC_REG0_N_MAX || +if (n <XSDFEC_REG0_N_MIN || n >XSDFEC_REG0_N_MAX || psize =0 || (n >XSDFEC_REG0_N_MUL_P * psize) || n <= k || ((n % psize) !=0 )) {dev_dbg (xsdfec->dev,"N value is not in range" );return -EINVAL ;
Thanks,
Michal
Re: [PATCH 4/4] misc: xilinx_sdfec: Prevent integer overflow in xsdfec_table_write()
In reply to Dan CarpenterQuoted 15 lines · Dan Carpenter
The checking here needs to handle integer overflows because "offset" and "len" come from the user.
Fixes 20ec628e8007 ("misc: xilinx_sdfec: Add ability to configure LDPC")Signed-off-by Dan Carpenter <[email protected]>--- drivers/misc/xilinx_sdfec.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/misc/xilinx_sdfec.c +0
-0
drivers/misc/xilinx_sdfec.c static int xsdfec_table_write(struct xsdfec_dev *xsdfec, u32 offset, · line 619
Quoted 10 lines
drivers/misc/xilinx_sdfec.c +3
-1@@ -611,7 +611,9 @@ static int xsdfec_table_write(struct xsdfec_dev *xsdfec, u32 offset,* Writes that go beyond the length of * Shared Scale(SC) table should fail */ -if ((XSDFEC_REG_WIDTH_JUMP * (offset + len)) > depth) { +if (offset > depth /XSDFEC_REG_WIDTH_JUMP || + len > depth /XSDFEC_REG_WIDTH_JUMP || + offset + len > depth /XSDFEC_REG_WIDTH_JUMP ) {dev_dbg (xsdfec->dev,"Write exceeds SC table length" );return -EINVAL ; }
Thanks,
Michal
Quoted 11 lines · Michal Simek
Hi Dan,
Quoted 5 lines · Dan Carpenter
These structs have holes in them so we end up disclosing a few bytes of uninitialized stack data.
drivers/misc/xilinx_sdfec.c:305xsdfec_get_status()warn: check that 'status' doesn't leak information (struct has a hole after 'activity')drivers/misc/xilinx_sdfec.c:449xsdfec_get_turbo()warn: check that 'turbo_params' doesn't leak information (struct has a hole after 'scale')Who is generating these warnings? Is this any new GCC or different tool? I see that 3byte padding but never seen these warnings.
This is a Smatch check.
regards,
dan carpenter
PATCH v2 2/4 misc: xilinx_sdfec: Return -EFAULT if copy_from_user() fails
In reply to Dan CarpenterThe copy_from_user() function returns the number of bytes remaining to be copied but we want to return -EFAULT to the user.
---
v2: Fix a typo in the commit message. funciton --> function
drivers/misc/xilinx_sdfec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/misc/xilinx_sdfec.c +3 -2
@@ -651,9 +651,10 @@ static int xsdfec_add_ldpc(struct xsdfec_dev *xsdfec, void __user *arg)if (!ldpc)return -ENOMEM ; - ret =copy_from_user (ldpc, arg,sizeof (*ldpc)); -if (ret) +if (copy_from_user (ldpc, arg,sizeof (*ldpc))) { + ret = -EFAULT ; goto err_out; + }if (xsdfec->config.code =XSDFEC_TURBO_CODE ) { ret = -EIO ;
Signature · 1 line
2.20.1
Quoted 7 lines · Dan Carpenter
Quoted 6 lines · Michal Simek
Hi Dan,
Quoted 3 lines · Dan Carpenter
These structs have holes in them so we end up disclosing a few bytes of uninitialized stack data.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
drivers/misc/xilinx_sdfec.c:305xsdfec_get_status()warn: check that 'status' doesn't leak information (struct has a hole after 'activity')drivers/misc/xilinx_sdfec.c:449xsdfec_get_turbo()warn: check that 'turbo_params' doesn't leak information (struct has a hole after 'scale')Who is generating these warnings? Is this any new GCC or different tool? I see that 3byte padding but never seen these warnings.
This is a Smatch check.
ok. It looks like I need to update it to latest version. My version is not showing these.
Anyway thanks for patches,
Michal
Hi Dan,
Quoted 44 lines
-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Wednesday 21 August 2019 08:06
To: Derek Kiernan <[email protected]>; Dragan Cvetic <[email protected]>
Cc: Arnd Bergmann <[email protected]>; Greg Kroah-Hartman <[email protected]>; Michal Simek <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH 1/4] misc:xilinx_sdfec: Fix a couple small information leaksThese structs have holes in them so we end up disclosing a few bytes of uninitialized stack data.
drivers/misc/xilinx_sdfec.c:305xsdfec_get_status()warn: check that 'status' doesn't leak information (struct has a hole after 'activity')drivers/misc/xilinx_sdfec.c:449xsdfec_get_turbo()warn: check that 'turbo_params' doesn't leak information (struct has a hole after 'scale')We need to zero out the holes with
memset().Fixes 6bd6a690c2e7 ("misc: xilinx_sdfec: Add stats & status ioctls")Signed-off-by Dan Carpenter <[email protected]>--- drivers/misc/xilinx_sdfec.c | 2 ++ 1 file changed, 2 insertions(+)drivers/misc/xilinx_sdfec.c +2
-1@@ -295,6 +295,7 @@ static int xsdfec_get_status(struct xsdfec_dev *xsdfec, void __user *arg)struct xsdfec_status status;int err; +memset (&status,0 ,sizeof (status));spin_lock_irqsave (&xsdfec->error_data_lock, xsdfec->flags); status.state = xsdfec->state; xsdfec->state_updated = false;@@ -440,6 +441,7 @@ static int xsdfec_get_turbo(struct xsdfec_dev *xsdfec, void __user *arg)if (xsdfec->config.code ==XSDFEC_LDPC_CODE )return -EIO ; +memset (&turbo_params,0 ,sizeof (turbo_params)); reg_value =xsdfec_regread (xsdfec,XSDFEC_TURBO_ADDR ); turbo_params.scale = (reg_value & XSDFEC_TURBO_SCALE_MASK) >> --
Quoted 1 line
2.20.1
Thanks,
Dragan
RE: [PATCH 2/4] misc: xilinx_sdfec: Return -EFAULT if copy_from_user() fails
In reply to Dan CarpenterHi Dan,
Quoted 35 lines
-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Wednesday 21 August 2019 08:07
To: Derek Kiernan <[email protected]>; Dragan Cvetic <[email protected]>
Cc: Arnd Bergmann <[email protected]>; Greg Kroah-Hartman <[email protected]>; Michal Simek <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH 2/4] misc:xilinx_sdfec: Return-EFAULTifcopy_from_user()failsThe
copy_from_user()funciton returns the number of bytes remaining to be copied but we want to return-EFAULTto the user.Fixes 20ec628e8007 ("misc: xilinx_sdfec: Add ability to configure LDPC")Signed-off-by Dan Carpenter <[email protected]>--- drivers/misc/xilinx_sdfec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/misc/xilinx_sdfec.c +3
-3@@ -651,9 +651,10 @@ static int xsdfec_add_ldpc(struct xsdfec_dev *xsdfec, void __user *arg)if (!ldpc)return -ENOMEM ; - ret =copy_from_user (ldpc, arg,sizeof (*ldpc)); -if (ret) +if (copy_from_user (ldpc, arg,sizeof (*ldpc))) { + ret = -EFAULT ; goto err_out; + }if (xsdfec->config.code ==XSDFEC_TURBO_CODE ) { ret = -EIO ; --
Quoted 1 line
2.20.1
Thanks,
Dragan
RE: [PATCH 4/4] misc: xilinx_sdfec: Prevent integer overflow in xsdfec_table_write()
In reply to Dan CarpenterHi Dan,
Quoted 10 lines
-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Wednesday 21 August 2019 08:11
To: Derek Kiernan <[email protected]>; Dragan Cvetic <[email protected]>
Cc: Arnd Bergmann <[email protected]>; Greg Kroah-Hartman <[email protected]>; Michal Simek <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH 4/4] misc:xilinx_sdfec: Prevent integer overflow inxsdfec_table_write()The checking here needs to handle integer overflows because "offset" and "len" come from the user.
Good catch, thanks.
Quoted 23 lines
Fixes 20ec628e8007 ("misc: xilinx_sdfec: Add ability to configure LDPC")Signed-off-by Dan Carpenter <[email protected]>--- drivers/misc/xilinx_sdfec.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/misc/xilinx_sdfec.c +3
-2@@ -611,7 +611,9 @@ static int xsdfec_table_write(struct xsdfec_dev *xsdfec, u32 offset,* Writes that go beyond the length of * Shared Scale(SC) table should fail */ -if ((XSDFEC_REG_WIDTH_JUMP * (offset + len)) > depth) { +if (offset > depth /XSDFEC_REG_WIDTH_JUMP || + len > depth /XSDFEC_REG_WIDTH_JUMP || + offset + len > depth /XSDFEC_REG_WIDTH_JUMP ) {dev_dbg (xsdfec->dev,"Write exceeds SC table length" );return -EINVAL ; } --
Quoted 1 line
2.20.1
Thanks
Dragan
RE: [PATCH 3/4] misc: xilinx_sdfec: Prevent a divide by zero in xsdfec_reg0_write()
In reply to Dan CarpenterHi Dan,
Quoted 34 lines
-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Wednesday 21 August 2019 08:10
To: Derek Kiernan <[email protected]>; Dragan Cvetic <[email protected]>
Cc: Arnd Bergmann <[email protected]>; Greg Kroah-Hartman <[email protected]>; Michal Simek <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH 3/4] misc:xilinx_sdfec: Prevent a divide by zero inxsdfec_reg0_write()The "psize" value comes from the user so we need to verify that it's non-zero before we check if "n % psize" or it will crash.
Fixes 20ec628e8007 ("misc: xilinx_sdfec: Add ability to configure LDPC")Signed-off-by Dan Carpenter <[email protected]>---
The parentheses in this condition are a no-op. They're just confusing. Perhaps something else was intended?drivers/misc/xilinx_sdfec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/misc/xilinx_sdfec.c +1
-2@@ -460,7 +460,7 @@ static int xsdfec_reg0_write(struct xsdfec_dev *xsdfec, u32 n, u32 k, u32 psize, {u32 wdata; -if (n <XSDFEC_REG0_N_MIN || n >XSDFEC_REG0_N_MAX || +if (n <XSDFEC_REG0_N_MIN || n >XSDFEC_REG0_N_MAX || psize ==0 || (n >XSDFEC_REG0_N_MUL_P * psize) || n <= k || ((n % psize) !=0 )) {dev_dbg (xsdfec->dev,"N value is not in range" );return -EINVAL ; --
Quoted 1 line
2.20.1
Thanks,
Dragan