public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] setrlimit incorrectly allows hard limits to exceed soft limits
@ 2002-11-11  4:10 Kingsley Cheung
  2002-11-11  4:59 ` Kingsley Cheung
  0 siblings, 1 reply; 2+ messages in thread
From: Kingsley Cheung @ 2002-11-11  4:10 UTC (permalink / raw)
  To: linux-kernel; +Cc: trivial

Hi,

In 2.4.19 (also 2.5.46) setrlimit code only ever makes a comparison to
check the old soft limit with the new soft limit and the new hard
limit with the old hard limit.  There is never a check to ensure the
new soft limit never exceeds the new hard limit. 

Just try "ulimit -H -m 10000" for memory limits that were not
previously set.  You end up with (hard limit = 10000) < (soft limit =
unlimited).

Fix is trivial.

--- sys.c       Sat Aug  3 10:39:46 2002
+++ edited.sys.c        Mon Nov 11 14:49:19 2002
@@ -1118,6 +1118,8 @@
 
        if (resource >= RLIM_NLIMITS)
                return -EINVAL;
+       if (new_rlim.rlim_cur > new_rlim.rlim_max)
+               return -EINVAL;
        if(copy_from_user(&new_rlim, rlim, sizeof(*rlim)))
                return -EFAULT;
        old_rlim = current->rlim + resource;

--
			Kingsley

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

* Re: [PATCH] setrlimit incorrectly allows hard limits to exceed soft limits
  2002-11-11  4:10 [PATCH] setrlimit incorrectly allows hard limits to exceed soft limits Kingsley Cheung
@ 2002-11-11  4:59 ` Kingsley Cheung
  0 siblings, 0 replies; 2+ messages in thread
From: Kingsley Cheung @ 2002-11-11  4:59 UTC (permalink / raw)
  To: linux-kernel; +Cc: trivial

Oops, should be after the copy :-(

--- sys.c       Sat Aug  3 10:39:46 2002
+++ edited.sys.c        Mon Nov 11 15:56:51 2002
@@ -1120,6 +1120,8 @@
                return -EINVAL;
        if(copy_from_user(&new_rlim, rlim, sizeof(*rlim)))
                return -EFAULT;
+       if (new_rlim.rlim_cur > new_rlim.rlim_max)
+               return -EINVAL;
        old_rlim = current->rlim + resource;
        if (((new_rlim.rlim_cur > old_rlim->rlim_max) ||
             (new_rlim.rlim_max > old_rlim->rlim_max)) &&


On Mon, Nov 11, 2002 at 03:10:05PM +1100, Kingsley Cheung wrote:
> Hi,
> 
> In 2.4.19 (also 2.5.46) setrlimit code only ever makes a comparison to
> check the old soft limit with the new soft limit and the new hard
> limit with the old hard limit.  There is never a check to ensure the
> new soft limit never exceeds the new hard limit. 
> 
> Just try "ulimit -H -m 10000" for memory limits that were not
> previously set.  You end up with (hard limit = 10000) < (soft limit =
> unlimited).
> 
> Fix is trivial.
> 
> --- sys.c       Sat Aug  3 10:39:46 2002
> +++ edited.sys.c        Mon Nov 11 14:49:19 2002
> @@ -1118,6 +1118,8 @@
>  
>         if (resource >= RLIM_NLIMITS)
>                 return -EINVAL;
> +       if (new_rlim.rlim_cur > new_rlim.rlim_max)
> +               return -EINVAL;
>         if(copy_from_user(&new_rlim, rlim, sizeof(*rlim)))
>                 return -EFAULT;
>         old_rlim = current->rlim + resource;
> 

-- 
		Kingsley

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

end of thread, other threads:[~2002-11-11  4:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-11  4:10 [PATCH] setrlimit incorrectly allows hard limits to exceed soft limits Kingsley Cheung
2002-11-11  4:59 ` Kingsley Cheung

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox