[PATCH] Re: 2.4.0test - uid_hash_find()

From: Dan Aloni (karrde@callisto.yi.org)
Date: Sun Oct 08 2000 - 23:43:38 EDT

  • Next message: Dan Aloni: "[PATCH correction] Re: 2.4.0test - uid_hash_find()"

    On Sun, 8 Oct 2000, Mitchell Blank Jr wrote:

    > Dan Aloni wrote:
    > >
    > > I've been touring around the kernel sources when I stumbled
    > > across the uid_hash_find() function (kernel/user.c):
    > >
    > > static inline struct user_struct *uid_hash_find(unsigned short uid, unsigned int hashent)
    >
    > Is it just me, or should that be "uid_t" not "unsigned short"? Now THAT
    > looks like a bug.
    >

    You are right, that was the original function. The bug will typically show
    in a system with more than a few tens of thousands of users.

    So here's the complete patch for test9's kernel/user.c, including the
    removal of the unnecessery initialization:

    --- linux-2.4.0-test9/kernel/user.c Mon Oct 9 01:37:35 2000
    +++ linux.vanilla/kernel/user.c Sun Oct 8 22:33:55 2000
    @@ -51,22 +51,18 @@
             *up->pprev = up->next;
     }
     
    -static inline struct user_struct *uid_hash_find(uid_t uid, unsigned int hashent)
    +static inline struct user_struct *uid_hash_find(unsigned short uid, unsigned int hashent)
     {
    - struct user_struct *up, *next;
    + struct user_struct *up;
     
    - next = uidhash[hashent];
    - for (;;) {
    - up = next;
    - if (next) {
    - next = up->next;
    - if (up->uid != uid)
    - continue;
    - atomic_inc(&up->__count);
    + for (up = uidhash[hashent]; up ; up = up->next)
    + if (up->uid == uid)
    + {
    + atomic_inc(&up->__count)
    + return up;
                     }
    - break;
    - }
    - return up;
    +
    + return NULL;
     }
     
     /*
    @@ -136,16 +132,11 @@
     
     static int __init uid_cache_init(void)
     {
    - int i;
    -
             uid_cachep = kmem_cache_create("uid_cache", sizeof(struct user_struct),
                                            0,
                                            SLAB_HWCACHE_ALIGN, NULL, NULL);
             if(!uid_cachep)
                     panic("Cannot create uid taskcount SLAB cache\n");
    -
    - for(i = 0; i < UIDHASH_SZ; i++)
    - uidhash[i] = 0;
     
             /* Insert the root user immediately - init already runs with this */
             uid_hash_insert(&root_user, uidhashfn(0));
     

    -- 
    Dan Aloni 
    dax@karrde.org
    

    - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org Please read the FAQ at http://www.tux.org/lkml/



    This archive was generated by hypermail 2b29 : Sun Oct 08 2000 - 19:46:57 EDT