All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4: prevent very high s_inode_readahead_blks
@ 2019-02-11 18:44 ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2019-02-11 18:44 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: Andreas Dilger, linux-ext4, kernel-janitors

My static checker complains that "arg" can be negative.  That does seem
possible.  I don't know if it causes an issue at run time but it seems
safest to allow negatives.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 fs/ext4/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 60da0a6e4d86..4e0845708c52 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1838,7 +1838,7 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
 	} else if (token == Opt_min_batch_time) {
 		sbi->s_min_batch_time = arg;
 	} else if (token == Opt_inode_readahead_blks) {
-		if (arg && (arg > (1 << 30) || !is_power_of_2(arg))) {
+		if (arg && (arg > (1U << 30) || !is_power_of_2(arg))) {
 			ext4_msg(sb, KERN_ERR,
 				 "EXT4-fs: inode_readahead_blks must be "
 				 "0 or a power of 2 smaller than 2^31");
-- 
2.17.1


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

* [PATCH] ext4: prevent very high s_inode_readahead_blks
@ 2019-02-11 18:44 ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2019-02-11 18:44 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: Andreas Dilger, linux-ext4, kernel-janitors

My static checker complains that "arg" can be negative.  That does seem
possible.  I don't know if it causes an issue at run time but it seems
safest to allow negatives.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 fs/ext4/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 60da0a6e4d86..4e0845708c52 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1838,7 +1838,7 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
 	} else if (token = Opt_min_batch_time) {
 		sbi->s_min_batch_time = arg;
 	} else if (token = Opt_inode_readahead_blks) {
-		if (arg && (arg > (1 << 30) || !is_power_of_2(arg))) {
+		if (arg && (arg > (1U << 30) || !is_power_of_2(arg))) {
 			ext4_msg(sb, KERN_ERR,
 				 "EXT4-fs: inode_readahead_blks must be "
 				 "0 or a power of 2 smaller than 2^31");
-- 
2.17.1

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

* Re: [PATCH] ext4: prevent very high s_inode_readahead_blks
  2019-02-11 18:44 ` Dan Carpenter
@ 2019-02-11 20:38   ` Andreas Dilger
  -1 siblings, 0 replies; 4+ messages in thread
From: Andreas Dilger @ 2019-02-11 20:38 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Theodore Ts'o, Ext4 Developers List, kernel-janitors

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

On Feb 11, 2019, at 11:44 AM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> 
> My static checker complains that "arg" can be negative.  That does seem
> possible.  I don't know if it causes an issue at run time but it seems
> safest to allow negatives.

The option declaration requires that "arg" be greater than zero:

        {Opt_inode_readahead_blks, 2, MOPT_GTE0},

and this is checked earlier in handle_mount_opt():

        if (args->from && (m->flags & MOPT_GTE0) && (arg < 0))
                return -1;

but I agree that having false static checking warnings is annoying
and potentially also hides other issues.

> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> fs/ext4/super.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 60da0a6e4d86..4e0845708c52 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -1838,7 +1838,7 @@ static int handle_mount_opt(struct super_block *sb,
> 	} else if (token == Opt_min_batch_time) {
> 		sbi->s_min_batch_time = arg;
> 	} else if (token == Opt_inode_readahead_blks) {
> -		if (arg && (arg > (1 << 30) || !is_power_of_2(arg))) {
> +		if (arg && (arg > (1U << 30) || !is_power_of_2(arg))) {

This may "fix" the problem by virtue of implicitly forcing an unsigned
comparison, but doesn't necessarily make the issue more obvious to the
reader.

That said, it doesn't look like _any_ use of "arg" allows a negative
value, regardless of whether MOPT_GTE0 is set or not, so we should
just declare arg as an unsigned int or explicitly refuse all negatives:

	if (args->from && !(m->flags & MOPT_STRING)) {
		if (match_int(args, &arg))
			return -1;
		if (arg < 0)
			return -1;
	}

This should keep the static checker happy, since the only place that
"arg" is set away from zero it is also verified not to be negative.
At that point it would also be possible to remove MOPT_GTE0 completely.

Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]

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

* Re: [PATCH] ext4: prevent very high s_inode_readahead_blks
@ 2019-02-11 20:38   ` Andreas Dilger
  0 siblings, 0 replies; 4+ messages in thread
From: Andreas Dilger @ 2019-02-11 20:38 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Theodore Ts'o, Ext4 Developers List, kernel-janitors

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

On Feb 11, 2019, at 11:44 AM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> 
> My static checker complains that "arg" can be negative.  That does seem
> possible.  I don't know if it causes an issue at run time but it seems
> safest to allow negatives.

The option declaration requires that "arg" be greater than zero:

        {Opt_inode_readahead_blks, 2, MOPT_GTE0},

and this is checked earlier in handle_mount_opt():

        if (args->from && (m->flags & MOPT_GTE0) && (arg < 0))
                return -1;

but I agree that having false static checking warnings is annoying
and potentially also hides other issues.

> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> fs/ext4/super.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 60da0a6e4d86..4e0845708c52 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -1838,7 +1838,7 @@ static int handle_mount_opt(struct super_block *sb,
> 	} else if (token == Opt_min_batch_time) {
> 		sbi->s_min_batch_time = arg;
> 	} else if (token == Opt_inode_readahead_blks) {
> -		if (arg && (arg > (1 << 30) || !is_power_of_2(arg))) {
> +		if (arg && (arg > (1U << 30) || !is_power_of_2(arg))) {

This may "fix" the problem by virtue of implicitly forcing an unsigned
comparison, but doesn't necessarily make the issue more obvious to the
reader.

That said, it doesn't look like _any_ use of "arg" allows a negative
value, regardless of whether MOPT_GTE0 is set or not, so we should
just declare arg as an unsigned int or explicitly refuse all negatives:

	if (args->from && !(m->flags & MOPT_STRING)) {
		if (match_int(args, &arg))
			return -1;
		if (arg < 0)
			return -1;
	}

This should keep the static checker happy, since the only place that
"arg" is set away from zero it is also verified not to be negative.
At that point it would also be possible to remove MOPT_GTE0 completely.

Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]

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

end of thread, other threads:[~2019-02-11 20:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-11 18:44 [PATCH] ext4: prevent very high s_inode_readahead_blks Dan Carpenter
2019-02-11 18:44 ` Dan Carpenter
2019-02-11 20:38 ` Andreas Dilger
2019-02-11 20:38   ` Andreas Dilger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.