Linux Security Modules development
 help / color / mirror / Atom feed
* [PATCH V3] lockdown: Initialize array before use
@ 2025-01-05  7:05 Tanya Agarwal
  2025-01-05 10:42 ` Kuan-Wei Chiu
  2025-01-05 17:48 ` [PATCH v3] " Paul Moore
  0 siblings, 2 replies; 4+ messages in thread
From: Tanya Agarwal @ 2025-01-05  7:05 UTC (permalink / raw)
  To: paul, jmorris, serge
  Cc: kees, yuehaibing, linux-security-module, linux-kernel,
	matthewgarrett, skhan, anupnewsmail, tanyaagarwal25699

From: Tanya Agarwal <tanyaagarwal25699@gmail.com>

The static code analysis tool "Coverity Scan" pointed the following
details out for further development considerations:
CID 1486102: Uninitialized scalar variable (UNINIT)
uninit_use_in_call: Using uninitialized value *temp when calling
strlen.

Conclusion:
Initialize array before use in lockdown_read() to satisfy the static
analyzer.

Fixes: 000d388ed3bb ("security: Add a static lockdown policy LSM")
Signed-off-by: Tanya Agarwal <tanyaagarwal25699@gmail.com>
---
V2: add Fixes tag and reword commit description
V3: use "" initialization instead of {}

Coverity Link:
https://scan7.scan.coverity.com/#/project-view/52849/11354?selectedIssue=1486102


 security/lockdown/lockdown.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/security/lockdown/lockdown.c b/security/lockdown/lockdown.c
index f2bdbd55aa2b..cf83afa1d879 100644
--- a/security/lockdown/lockdown.c
+++ b/security/lockdown/lockdown.c
@@ -96,7 +96,7 @@ static int __init lockdown_lsm_init(void)
 static ssize_t lockdown_read(struct file *filp, char __user *buf, size_t count,
 			     loff_t *ppos)
 {
-	char temp[80];
+	char temp[80] = "";
 	int i, offset = 0;
 
 	for (i = 0; i < ARRAY_SIZE(lockdown_levels); i++) {
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH V3] lockdown: Initialize array before use
  2025-01-05  7:05 [PATCH V3] lockdown: Initialize array before use Tanya Agarwal
@ 2025-01-05 10:42 ` Kuan-Wei Chiu
  2025-01-05 17:48 ` [PATCH v3] " Paul Moore
  1 sibling, 0 replies; 4+ messages in thread
From: Kuan-Wei Chiu @ 2025-01-05 10:42 UTC (permalink / raw)
  To: Tanya Agarwal
  Cc: paul, jmorris, serge, kees, yuehaibing, linux-security-module,
	linux-kernel, matthewgarrett, skhan, anupnewsmail

Hi Tanya,

On Sun, Jan 05, 2025 at 12:35:38PM +0530, Tanya Agarwal wrote:
> From: Tanya Agarwal <tanyaagarwal25699@gmail.com>
> 
> The static code analysis tool "Coverity Scan" pointed the following
> details out for further development considerations:
> CID 1486102: Uninitialized scalar variable (UNINIT)
> uninit_use_in_call: Using uninitialized value *temp when calling
> strlen.
> 
> Conclusion:
> Initialize array before use in lockdown_read() to satisfy the static
> analyzer.
> 
> Fixes: 000d388ed3bb ("security: Add a static lockdown policy LSM")
> Signed-off-by: Tanya Agarwal <tanyaagarwal25699@gmail.com>

I don't believe this is a real bug. The lockdown_reasons array is a
non-empty constant, so temp is guaranteed to be written to by sprintf
before being passed to strlen.

When submitting patches in the future, could you also include an
analysis of the conditions that might lead to the bug, along with the
coverity scan report?

Regards,
Kuan-Wei

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] lockdown: Initialize array before use
  2025-01-05  7:05 [PATCH V3] lockdown: Initialize array before use Tanya Agarwal
  2025-01-05 10:42 ` Kuan-Wei Chiu
@ 2025-01-05 17:48 ` Paul Moore
  2025-01-05 17:52   ` Tanya Agarwal
  1 sibling, 1 reply; 4+ messages in thread
From: Paul Moore @ 2025-01-05 17:48 UTC (permalink / raw)
  To: Tanya Agarwal, jmorris, serge
  Cc: kees, yuehaibing, linux-security-module, linux-kernel,
	matthewgarrett, skhan, anupnewsmail, tanyaagarwal25699

On Jan  5, 2025 Tanya Agarwal <tanyaagarwal25699@gmail.com> wrote:
> 
> The static code analysis tool "Coverity Scan" pointed the following
> details out for further development considerations:
> CID 1486102: Uninitialized scalar variable (UNINIT)
> uninit_use_in_call: Using uninitialized value *temp when calling
> strlen.
> 
> Conclusion:
> Initialize array before use in lockdown_read() to satisfy the static
> analyzer.
> 
> Fixes: 000d388ed3bb ("security: Add a static lockdown policy LSM")
> Signed-off-by: Tanya Agarwal <tanyaagarwal25699@gmail.com>

I removed the 'Fixes:' tag as the code isn't actually broken as we
discussed in previous iterations of this patch.  I also edited the
subject line and commit description a bit, but otherwise this is
fine.  Merged into lsm/dev.

--
paul-moore.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] lockdown: Initialize array before use
  2025-01-05 17:48 ` [PATCH v3] " Paul Moore
@ 2025-01-05 17:52   ` Tanya Agarwal
  0 siblings, 0 replies; 4+ messages in thread
From: Tanya Agarwal @ 2025-01-05 17:52 UTC (permalink / raw)
  To: Paul Moore
  Cc: jmorris, serge, kees, yuehaibing, linux-security-module,
	linux-kernel, matthewgarrett, skhan, anupnewsmail

On Sun, Jan 5, 2025 at 11:18 PM Paul Moore <paul@paul-moore.com> wrote:
>
> On Jan  5, 2025 Tanya Agarwal <tanyaagarwal25699@gmail.com> wrote:
> >
> > The static code analysis tool "Coverity Scan" pointed the following
> > details out for further development considerations:
> > CID 1486102: Uninitialized scalar variable (UNINIT)
> > uninit_use_in_call: Using uninitialized value *temp when calling
> > strlen.
> >
> > Conclusion:
> > Initialize array before use in lockdown_read() to satisfy the static
> > analyzer.
> >
> > Fixes: 000d388ed3bb ("security: Add a static lockdown policy LSM")
> > Signed-off-by: Tanya Agarwal <tanyaagarwal25699@gmail.com>
>
> I removed the 'Fixes:' tag as the code isn't actually broken as we
> discussed in previous iterations of this patch.  I also edited the
> subject line and commit description a bit, but otherwise this is
> fine.  Merged into lsm/dev.
>
> --
> paul-moore.com


Thank you, Paul.

Regards,
Tanya

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-01-05 17:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-05  7:05 [PATCH V3] lockdown: Initialize array before use Tanya Agarwal
2025-01-05 10:42 ` Kuan-Wei Chiu
2025-01-05 17:48 ` [PATCH v3] " Paul Moore
2025-01-05 17:52   ` Tanya Agarwal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox