linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] udf: avoid uninitialized variable use
@ 2016-01-01 12:47 Arnd Bergmann
  2016-01-01 14:21 ` [PATCH v2] " Arnd Bergmann
  0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2016-01-01 12:47 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-kernel, linux-arm-kernel

A new warning about a real bug has come up from a recent cleanup:

fs/udf/inode.c: In function 'udf_setup_indirect_aext':
fs/udf/inode.c:1927:28: warning: 'adsize' may be used uninitialized in this function [-Wmaybe-uninitialized]

If the alloc_type is neither ICBTAG_FLAG_AD_SHORT nor ICBTAG_FLAG_AD_LONG,
the value of adsize is undefined. This changes the code to use zero for adsize
in that case, which may be the correct solution, though I have not looked
at the code in enough detail to know if it should be something else instead.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: fcea62babc81 ("udf: Factor out code for creating indirect extent")
---
Found on ARM randconfig kernels starting with yesterday's linux-next

diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index 5b83351041a4..a1cc074c656f 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -1890,6 +1890,8 @@ int udf_setup_indirect_aext(struct inode *inode, int block,
 		adsize = sizeof(struct short_ad);
 	else if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_LONG)
 		adsize = sizeof(struct long_ad);
+	else
+		adsize = 0;
 
 	neloc.logicalBlockNum = block;
 	neloc.partitionReferenceNum = epos->block.partitionReferenceNum;


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

* [PATCH v2] udf: avoid uninitialized variable use
  2016-01-01 12:47 [PATCH] udf: avoid uninitialized variable use Arnd Bergmann
@ 2016-01-01 14:21 ` Arnd Bergmann
  2016-01-04  9:56   ` Jan Kara
  0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2016-01-01 14:21 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: Jan Kara, linux-kernel

A new warning about a real bug has come up from a recent cleanup:

fs/udf/inode.c: In function 'udf_setup_indirect_aext':
fs/udf/inode.c:1927:28: warning: 'adsize' may be used uninitialized in this function [-Wmaybe-uninitialized]

If the alloc_type is neither ICBTAG_FLAG_AD_SHORT nor ICBTAG_FLAG_AD_LONG,
the value of adsize is undefined. This changes the code to use zero for adsize
in that case, which may be the correct solution, though I have not looked
at the code in enough detail to know if it should be something else instead.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: fcea62babc81 ("udf: Factor out code for creating indirect extent")
---
sorry for missing another instance the first time around. The warning is
a bit unreliable and it seems in my first configuration I got it only
for one of the two instances that show it in other configuration.

After checking the remaining functions in this file for the same possible
problem, I found that the other functions use either 'BUG()' or 'return -EIO'
in the 'else' path, so I assume the two functions here should one of those
as well, but I don't know which.

diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index 5b83351041a4..42f68dd7e6ef 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -1890,6 +1890,8 @@ int udf_setup_indirect_aext(struct inode *inode, int block,
 		adsize = sizeof(struct short_ad);
 	else if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_LONG)
 		adsize = sizeof(struct long_ad);
+	else
+		adsize = 0;
 
 	neloc.logicalBlockNum = block;
 	neloc.partitionReferenceNum = epos->block.partitionReferenceNum;
@@ -1963,6 +1965,8 @@ int __udf_add_aext(struct inode *inode, struct extent_position *epos,
 		adsize = sizeof(struct short_ad);
 	else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
 		adsize = sizeof(struct long_ad);
+	else
+		adsize = 0;
 
 	if (!epos->bh) {
 		WARN_ON(iinfo->i_lenAlloc !=


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

* Re: [PATCH v2] udf: avoid uninitialized variable use
  2016-01-01 14:21 ` [PATCH v2] " Arnd Bergmann
@ 2016-01-04  9:56   ` Jan Kara
  2016-01-04 10:46     ` Arnd Bergmann
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Kara @ 2016-01-04  9:56 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: linux-arm-kernel, Jan Kara, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2441 bytes --]

On Fri 01-01-16 15:21:54, Arnd Bergmann wrote:
> A new warning about a real bug has come up from a recent cleanup:
> 
> fs/udf/inode.c: In function 'udf_setup_indirect_aext':
> fs/udf/inode.c:1927:28: warning: 'adsize' may be used uninitialized in this function [-Wmaybe-uninitialized]
> 
> If the alloc_type is neither ICBTAG_FLAG_AD_SHORT nor ICBTAG_FLAG_AD_LONG,
> the value of adsize is undefined. This changes the code to use zero for adsize
> in that case, which may be the correct solution, though I have not looked
> at the code in enough detail to know if it should be something else instead.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> Fixes: fcea62babc81 ("udf: Factor out code for creating indirect extent")
> ---
> sorry for missing another instance the first time around. The warning is
> a bit unreliable and it seems in my first configuration I got it only
> for one of the two instances that show it in other configuration.
> 
> After checking the remaining functions in this file for the same possible
> problem, I found that the other functions use either 'BUG()' or 'return -EIO'
> in the 'else' path, so I assume the two functions here should one of those
> as well, but I don't know which.

Callers of these functions make sure alloc_type is one of the two valid
ones. However for future-proofing you're right that probably we should
handle the invalid case as well. Setting adsize to zero is problematic -
not sure what the code would actually do but it wouldn't definitely work.
I'd just return -EIO. Attached is the patch I have merged.

								Honza
> 
> diff --git a/fs/udf/inode.c b/fs/udf/inode.c
> index 5b83351041a4..42f68dd7e6ef 100644
> --- a/fs/udf/inode.c
> +++ b/fs/udf/inode.c
> @@ -1890,6 +1890,8 @@ int udf_setup_indirect_aext(struct inode *inode, int block,
>  		adsize = sizeof(struct short_ad);
>  	else if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_LONG)
>  		adsize = sizeof(struct long_ad);
> +	else
> +		adsize = 0;
>  
>  	neloc.logicalBlockNum = block;
>  	neloc.partitionReferenceNum = epos->block.partitionReferenceNum;
> @@ -1963,6 +1965,8 @@ int __udf_add_aext(struct inode *inode, struct extent_position *epos,
>  		adsize = sizeof(struct short_ad);
>  	else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
>  		adsize = sizeof(struct long_ad);
> +	else
> +		adsize = 0;
>  
>  	if (!epos->bh) {
>  		WARN_ON(iinfo->i_lenAlloc !=
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

[-- Attachment #2: 0001-udf-avoid-uninitialized-variable-use.patch --]
[-- Type: text/x-patch, Size: 1746 bytes --]

>From 4f1b1519f7bec44ded3c2c4d46a2594c01446dc8 Mon Sep 17 00:00:00 2001
From: Arnd Bergmann <arnd@arndb.de>
Date: Fri, 1 Jan 2016 15:21:54 +0100
Subject: [PATCH] udf: avoid uninitialized variable use

A new warning has come up from a recent cleanup:

fs/udf/inode.c: In function 'udf_setup_indirect_aext':
fs/udf/inode.c:1927:28: warning: 'adsize' may be used uninitialized in this function [-Wmaybe-uninitialized]

If the alloc_type is neither ICBTAG_FLAG_AD_SHORT nor
ICBTAG_FLAG_AD_LONG, the value of adsize is undefined. Currently,
callers of these functions make sure alloc_type is one of the two valid
ones but for future proofing make sure we handle the case of invalid
alloc type as well.  This changes the code to return -EIOin that case.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: fcea62babc81 ("udf: Factor out code for creating indirect extent")
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/udf/inode.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index 846294891925..91d8fa9d87a4 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -1889,6 +1889,8 @@ int udf_setup_indirect_aext(struct inode *inode, int block,
 		adsize = sizeof(struct short_ad);
 	else if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_LONG)
 		adsize = sizeof(struct long_ad);
+	else
+		return -EIO;
 
 	neloc.logicalBlockNum = block;
 	neloc.partitionReferenceNum = epos->block.partitionReferenceNum;
@@ -1962,6 +1964,8 @@ int __udf_add_aext(struct inode *inode, struct extent_position *epos,
 		adsize = sizeof(struct short_ad);
 	else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
 		adsize = sizeof(struct long_ad);
+	else
+		return -EIO;
 
 	if (!epos->bh) {
 		WARN_ON(iinfo->i_lenAlloc !=
-- 
2.6.2


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

* Re: [PATCH v2] udf: avoid uninitialized variable use
  2016-01-04  9:56   ` Jan Kara
@ 2016-01-04 10:46     ` Arnd Bergmann
  0 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2016-01-04 10:46 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-arm-kernel, linux-kernel

On Monday 04 January 2016 10:56:05 Jan Kara wrote:
> On Fri 01-01-16 15:21:54, Arnd Bergmann wrote:
> > A new warning about a real bug has come up from a recent cleanup:
> > 
> > fs/udf/inode.c: In function 'udf_setup_indirect_aext':
> > fs/udf/inode.c:1927:28: warning: 'adsize' may be used uninitialized in this function [-Wmaybe-uninitialized]
> > 
> > If the alloc_type is neither ICBTAG_FLAG_AD_SHORT nor ICBTAG_FLAG_AD_LONG,
> > the value of adsize is undefined. This changes the code to use zero for adsize
> > in that case, which may be the correct solution, though I have not looked
> > at the code in enough detail to know if it should be something else instead.
> > 
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > Fixes: fcea62babc81 ("udf: Factor out code for creating indirect extent")
> > ---
> > sorry for missing another instance the first time around. The warning is
> > a bit unreliable and it seems in my first configuration I got it only
> > for one of the two instances that show it in other configuration.
> > 
> > After checking the remaining functions in this file for the same possible
> > problem, I found that the other functions use either 'BUG()' or 'return -EIO'
> > in the 'else' path, so I assume the two functions here should one of those
> > as well, but I don't know which.
> 
> Callers of these functions make sure alloc_type is one of the two valid
> ones. However for future-proofing you're right that probably we should
> handle the invalid case as well. Setting adsize to zero is problematic -
> not sure what the code would actually do but it wouldn't definitely work.
> I'd just return -EIO. Attached is the patch I have merged.
> 
> 

Looks good, thanks!

	Arnd

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

end of thread, other threads:[~2016-01-04 10:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-01 12:47 [PATCH] udf: avoid uninitialized variable use Arnd Bergmann
2016-01-01 14:21 ` [PATCH v2] " Arnd Bergmann
2016-01-04  9:56   ` Jan Kara
2016-01-04 10:46     ` Arnd Bergmann

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).