stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kernfs: fix off by one error.
@ 2014-03-05 16:10 Richard Cochran
  2014-03-05 17:11 ` Eric W. Biederman
  2014-03-05 18:30 ` Greg Kroah-Hartman
  0 siblings, 2 replies; 4+ messages in thread
From: Richard Cochran @ 2014-03-05 16:10 UTC (permalink / raw)
  To: linux-kernel; +Cc: Greg Kroah-Hartman, Eric Biederman, Tejun Heo, stable

The hash values 0 and 1 are reserved for magic directory entries, but
the code only prevents names hashing to 0. This patch fixes the test
to also prevent hash value 1.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Cc: <stable@vger.kernel.org>
---
 fs/kernfs/dir.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index bd6e18b..39c0143 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -37,7 +37,7 @@ static unsigned int kernfs_name_hash(const char *name, const void *ns)
 	hash = (end_name_hash(hash) ^ hash_ptr((void *)ns, 31));
 	hash &= 0x7fffffffU;
 	/* Reserve hash numbers 0, 1 and INT_MAX for magic directory entries */
-	if (hash < 1)
+	if (hash < 2)
 		hash += 2;
 	if (hash >= INT_MAX)
 		hash = INT_MAX - 1;
-- 
1.7.10.4


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

* Re: [PATCH] kernfs: fix off by one error.
  2014-03-05 16:10 [PATCH] kernfs: fix off by one error Richard Cochran
@ 2014-03-05 17:11 ` Eric W. Biederman
  2014-03-05 18:30 ` Greg Kroah-Hartman
  1 sibling, 0 replies; 4+ messages in thread
From: Eric W. Biederman @ 2014-03-05 17:11 UTC (permalink / raw)
  To: Richard Cochran; +Cc: linux-kernel, Greg Kroah-Hartman, Tejun Heo, stable

Richard Cochran <richardcochran@gmail.com> writes:

> The hash values 0 and 1 are reserved for magic directory entries, but
> the code only prevents names hashing to 0. This patch fixes the test
> to also prevent hash value 1.
>
Reviewed-by: "Eric W. Biederman" <ebiederm@xmission.com>
> Signed-off-by: Richard Cochran <richardcochran@gmail.com>
> Cc: <stable@vger.kernel.org>
> ---
>  fs/kernfs/dir.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
> index bd6e18b..39c0143 100644
> --- a/fs/kernfs/dir.c
> +++ b/fs/kernfs/dir.c
> @@ -37,7 +37,7 @@ static unsigned int kernfs_name_hash(const char *name, const void *ns)
>  	hash = (end_name_hash(hash) ^ hash_ptr((void *)ns, 31));
>  	hash &= 0x7fffffffU;
>  	/* Reserve hash numbers 0, 1 and INT_MAX for magic directory entries */
> -	if (hash < 1)
> +	if (hash < 2)
>  		hash += 2;
>  	if (hash >= INT_MAX)
>  		hash = INT_MAX - 1;

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

* Re: [PATCH] kernfs: fix off by one error.
  2014-03-05 16:10 [PATCH] kernfs: fix off by one error Richard Cochran
  2014-03-05 17:11 ` Eric W. Biederman
@ 2014-03-05 18:30 ` Greg Kroah-Hartman
  2014-03-05 18:34   ` Eric W. Biederman
  1 sibling, 1 reply; 4+ messages in thread
From: Greg Kroah-Hartman @ 2014-03-05 18:30 UTC (permalink / raw)
  To: Richard Cochran; +Cc: linux-kernel, Eric Biederman, Tejun Heo, stable

On Wed, Mar 05, 2014 at 05:10:52PM +0100, Richard Cochran wrote:
> The hash values 0 and 1 are reserved for magic directory entries, but
> the code only prevents names hashing to 0. This patch fixes the test
> to also prevent hash value 1.
> 
> Signed-off-by: Richard Cochran <richardcochran@gmail.com>
> Cc: <stable@vger.kernel.org>
> ---
>  fs/kernfs/dir.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Is this for 3.14-final or 3.15-rc1?

thanks,

greg k-h

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

* Re: [PATCH] kernfs: fix off by one error.
  2014-03-05 18:30 ` Greg Kroah-Hartman
@ 2014-03-05 18:34   ` Eric W. Biederman
  0 siblings, 0 replies; 4+ messages in thread
From: Eric W. Biederman @ 2014-03-05 18:34 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Richard Cochran, linux-kernel, Tejun Heo, stable

Greg Kroah-Hartman <gregkh@linuxfoundation.org> writes:

> On Wed, Mar 05, 2014 at 05:10:52PM +0100, Richard Cochran wrote:
>> The hash values 0 and 1 are reserved for magic directory entries, but
>> the code only prevents names hashing to 0. This patch fixes the test
>> to also prevent hash value 1.
>> 
>> Signed-off-by: Richard Cochran <richardcochran@gmail.com>
>> Cc: <stable@vger.kernel.org>
>> ---
>>  fs/kernfs/dir.c |    2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> Is this for 3.14-final or 3.15-rc1?

The bug has existed since I added that hash function in 3.4-rc1.  It was
named sysfs_name_hash then but the code has otherwise been unchanged.

It is a very minor bug.

commit 4e4d6d860b9393c5395ba5920edb5b4c5d43a3a3
Author: Eric W. Biederman <ebiederm@xmission.com>
Date:   Sun Dec 18 20:05:43 2011 -0800

    sysfs: Add s_hash to sysfs_dirent and order directory entries by hash
    
    Compute a 31 bit hash of directory entries (that can fit in a signed
    32bit off_t) and index the sysfs directory entries by that hash,
    replacing the per directory indexes by name and by inode.  Because we
    now only use a single rbtree this reduces the size of sysfs_dirent by 2
    pointers.  Because we have fewer cases to deal with the code is now
    simpler.
    
    For now I use the simple hash that the dcache uses as that is easy to
    use and seems simple enough.
    
    In addition to makeing the code simpler using a hash for the file
    position in readdir brings sysfs in line with other filesystems that
    have non-trivial directory structures.
    
    Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

Eric


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

end of thread, other threads:[~2014-03-05 18:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-05 16:10 [PATCH] kernfs: fix off by one error Richard Cochran
2014-03-05 17:11 ` Eric W. Biederman
2014-03-05 18:30 ` Greg Kroah-Hartman
2014-03-05 18:34   ` Eric W. Biederman

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