From: Ciju Rajan K <ciju@linux.vnet.ibm.com>
To: William Lee Irwin III <wli@holomorphy.com>
Cc: aglitke <agl@us.ibm.com>, linux-kernel@vger.kernel.org
Subject: Re: [RFC] [PATCH] hugetlbfs :shmget with SHM_HUGETLB only works as root
Date: Fri, 30 Nov 2007 00:02:32 +0530 [thread overview]
Message-ID: <474F05C0.9040002@linux.vnet.ibm.com> (raw)
In-Reply-To: <20071114220038.GD1806@holomorphy.com>
Hi Wli,
I tested your patch. But that is not solving the problem.
If the code change to user_shm_lock() is not a good solution, could
you please suggest a method so that the normal user is able to allocate
the huge pages, if his gid is added to /proc/sys/vm/hugetlb_shm_group
Thanks
Ciju
William Lee Irwin III wrote:
> On Wed, Nov 14, 2007 at 09:31:41AM -0600, aglitke wrote:
>> ... if the user's locked limit (ulimit -l) is set to unlimited, allowed
>> (above) is set to 1. In that case, the second part of that if() is
>> bypassed, and the function grants permission. Therefore, the easy
>> solution is to make sure your user's lock_limit is RLIM_INFINITY.
>
> This function deserves a minor cleanup and a bit more commenting.
>
> Reading user->locked_shm within shmlock_user_lock would be nice, too.
>
> Maybe something like this (untested, uncompiled) would do.
>
>
> -- wli
>
>
> diff --git a/mm/mlock.c b/mm/mlock.c
> index 7b26560..5f51792 100644
> --- a/mm/mlock.c
> +++ b/mm/mlock.c
> @@ -234,6 +234,12 @@ asmlinkage long sys_munlockall(void)
> /*
> * Objects with different lifetime than processes (SHM_LOCK and SHM_HUGETLB
> * shm segments) get accounted against the user_struct instead.
> + * First, user_shm_lock() checks that the user has permission to lock
> + * enough memory; then if so, the locked shm is accounted to the user's
> + * system-wide state. shmlock_user_lock protects the per-user field
> + * tracking how much locked_shm is in use within the struct user_struct.
> + * shmlock_user_lock is taken early to guard the read-only check that
> + * user->locked_shm is in-bounds against updates to user->locked_shm.
> */
> static DEFINE_SPINLOCK(shmlock_user_lock);
>
> @@ -242,19 +248,22 @@ int user_shm_lock(size_t size, struct user_struct *user)
> unsigned long lock_limit, locked;
> int allowed = 0;
>
> + spin_lock(&shmlock_user_lock);
> locked = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
> lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
> if (lock_limit == RLIM_INFINITY)
> allowed = 1;
> - lock_limit >>= PAGE_SHIFT;
> - spin_lock(&shmlock_user_lock);
> - if (!allowed &&
> - locked + user->locked_shm > lock_limit && !capable(CAP_IPC_LOCK))
> - goto out;
> - get_uid(user);
> - user->locked_shm += locked;
> - allowed = 1;
> -out:
> + else {
> + lock_limit >>= PAGE_SHIFT;
> + if (locked + user->locked_shm <= lock_limit)
> + allowed = 1;
> + else if (capable(CAP_IPC_LOCK))
> + allowed = 1;
> + }
> + if (allowed) {
> + get_uid(user);
> + user->locked_shm += locked;
> + }
> spin_unlock(&shmlock_user_lock);
> return allowed;
> }
next prev parent reply other threads:[~2007-11-29 18:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-14 14:15 [RFC] [PATCH] hugetlbfs :shmget with SHM_HUGETLB only works as root Ciju Rajan K
2007-11-14 15:31 ` aglitke
2007-11-14 22:00 ` William Lee Irwin III
2007-11-29 18:32 ` Ciju Rajan K [this message]
2007-11-29 23:11 ` William Lee Irwin III
2008-01-29 14:58 ` Ciju Rajan K
2008-01-30 9:32 ` Ciju Rajan K
2007-11-16 13:59 ` Ciju Rajan K
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=474F05C0.9040002@linux.vnet.ibm.com \
--to=ciju@linux.vnet.ibm.com \
--cc=agl@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=wli@holomorphy.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.