All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: Suggestion on "int len" sanity
@ 2005-06-02  7:28 XIAO Gang
  2005-06-02  8:48 ` Jörn Engel
  0 siblings, 1 reply; 22+ messages in thread
From: XIAO Gang @ 2005-06-02  7:28 UTC (permalink / raw)
  To: linux-kernel

Willy Tarreau wrote:

>> On the other hand, when a variable is named "len" or "length", it is 
>> usually used for length and never should go negative. So could I suggest 
>> that the declarations of these variables to be uniformized to "size_t", 
>> via a gradual but sysmatic cleanup?

> Probably true for most cases, but be careful of code which would use
> -1 to report some errors if such thing exists.

I agree that they are probably not all replaceable, and care must be taken.

Examples:

1. In the types of sys_[gs]ethostname, sys_[gs]etdomainname, "int len" could be replaced
by "unsigned int" or "size_t" and sanity check simplified.

2. In mm/shmem.c, shmem_symlink(), we have "len = strlen(symname) + 1;". Although it is highly
improbable that strlen(symname) overflows, it is more correct to declare "size_t len;".

3. The similar situation occurs in fs/namei.c, vfs_readlink(). Here it does not matter if len
is declared to be unsigned, but for size_t, we have to take care about the size of size_t.

-- 

XIAO Gang (~{P$8U~})                          xiao@unice.fr
          home page: pcmath126.unice.fr/xiao.html 




^ permalink raw reply	[flat|nested] 22+ messages in thread
* Suggestion on "int len" sanity
@ 2005-06-01  7:06 XIAO Gang
  2005-06-01 13:46 ` Jörn Engel
  2005-06-01 20:39 ` Willy Tarreau
  0 siblings, 2 replies; 22+ messages in thread
From: XIAO Gang @ 2005-06-01  7:06 UTC (permalink / raw)
  To: linux-kernel


I would like to make a security suggestion.

There are many length variables in the kernel, locally declared as "len" 
or "length", either as "int", "unsigned int" or "size_t". However, 
declaring a length as "int" leads easily to an erroneous situation, as 
the author (or even a code checker) might make the implicite hypothesis 
that the length is positive, so that it is enough to make a sanity check 
of the kind

if (length > limit) ERROR;

which is not enough.

On the other hand, when a variable is named "len" or "length", it is 
usually used for length and never should go negative. So could I suggest 
that the declarations of these variables to be uniformized to "size_t", 
via a gradual but sysmatic cleanup?

-- 

XIAO Gang (~{P$8U~})                          xiao@unice.fr
          home page: pcmath126.unice.fr/xiao.html 




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

end of thread, other threads:[~2005-06-04 17:11 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-02  7:28 Suggestion on "int len" sanity XIAO Gang
2005-06-02  8:48 ` Jörn Engel
2005-06-02  9:12   ` XIAO Gang
2005-06-02  9:47     ` Jörn Engel
2005-06-03  9:45   ` Geert Uytterhoeven
2005-06-03 12:20     ` Al Viro
2005-06-03 14:19       ` Jörn Engel
2005-06-03 12:28     ` Andreas Schwab
2005-06-03 12:43       ` Geert Uytterhoeven
2005-06-03 14:38         ` Andreas Schwab
2005-06-03 18:04           ` randy_dunlap
2005-06-03 18:09             ` Lars Marowsky-Bree
2005-06-03 18:16               ` randy_dunlap
2005-06-04 11:28             ` Christoph Hellwig
2005-06-04 16:58               ` randy_dunlap
2005-06-04 17:07                 ` Jörn Engel
2005-06-04 17:11                   ` randy_dunlap
  -- strict thread matches above, loose matches on Subject: below --
2005-06-01  7:06 XIAO Gang
2005-06-01 13:46 ` Jörn Engel
2005-06-01 20:39 ` Willy Tarreau
2005-06-03  9:42   ` Geert Uytterhoeven
2005-06-03 12:47     ` Takashi Iwai

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.