* [PATCH 0/11] rlimits for both queued signals and POSIX mqueues @ 2004-05-11 8:42 Chris Wright 2004-05-11 8:45 ` [PATCH 1/11] add rlimit entry for controlling queued signals Chris Wright 0 siblings, 1 reply; 12+ messages in thread From: Chris Wright @ 2004-05-11 8:42 UTC (permalink / raw) To: linux-kernel; +Cc: akpm, torvalds, marcelo.tosatti The following patches introduce per user rlimits for both queued signals and POSIX message queues. The changes touch all the arches resource.h files as well as init_task.c to get the rlimit defaults setup. Both require caching the user_struct to avoid problems with setuid(). The signal changes makes some small changes to send_signal() to pass along the task being signalled to get proper accounting for signals initiated in interrupt. Patches are relative to 2.6.6-bk. Thanks to Marcelo for getting this one going. thanks, -chris ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 1/11] add rlimit entry for controlling queued signals 2004-05-11 8:42 [PATCH 0/11] rlimits for both queued signals and POSIX mqueues Chris Wright @ 2004-05-11 8:45 ` Chris Wright 2004-05-11 8:46 ` [PATCH 2/11] add sigpending field to user_struct Chris Wright 0 siblings, 1 reply; 12+ messages in thread From: Chris Wright @ 2004-05-11 8:45 UTC (permalink / raw) To: linux-kernel; +Cc: akpm, torvalds, marcelo.tosatti Add an rlimit entry to control the maximum number of pending signals a user may have. This is essentially just the resource.h changes. ===== include/asm-alpha/resource.h 1.1 vs edited ===== --- 1.1/include/asm-alpha/resource.h Tue Feb 5 09:39:46 2002 +++ edited/include/asm-alpha/resource.h Mon May 10 18:24:25 2004 @@ -15,9 +15,10 @@ #define RLIMIT_AS 7 /* address space limit(?) */ #define RLIMIT_NPROC 8 /* max number of processes */ #define RLIMIT_MEMLOCK 9 /* max locked-in-memory address space */ -#define RLIMIT_LOCKS 10 /* maximum file locks held */ +#define RLIMIT_LOCKS 10 /* maximum file locks held */ +#define RLIMIT_SIGPENDING 11 /* max number of pending signals */ -#define RLIM_NLIMITS 11 +#define RLIM_NLIMITS 12 /* * SuS says limits have to be unsigned. Fine, it's unsigned, but @@ -40,7 +41,8 @@ {LONG_MAX, LONG_MAX}, /* RLIMIT_AS */ \ {LONG_MAX, LONG_MAX}, /* RLIMIT_NPROC */ \ {LONG_MAX, LONG_MAX}, /* RLIMIT_MEMLOCK */ \ - {LONG_MAX, LONG_MAX}, /* RLIMIT_LOCKS */ \ + {LONG_MAX, LONG_MAX}, /* RLIMIT_LOCKS */ \ + {MAX_SIGPENDING, MAX_SIGPENDING}, /* RLIMIT_SIGPENDING */ \ } #endif /* __KERNEL__ */ ===== include/asm-arm/resource.h 1.1 vs edited ===== --- 1.1/include/asm-arm/resource.h Tue Feb 5 09:39:52 2002 +++ edited/include/asm-arm/resource.h Mon May 10 18:22:10 2004 @@ -16,8 +16,9 @@ #define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ +#define RLIMIT_SIGPENDING 11 /* max number of pending signals */ -#define RLIM_NLIMITS 11 +#define RLIM_NLIMITS 12 #ifdef __KERNEL__ @@ -40,6 +41,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ + { MAX_SIGPENDING, MAX_SIGPENDING}, \ } #endif /* __KERNEL__ */ ===== include/asm-arm26/resource.h 1.1 vs edited ===== --- 1.1/include/asm-arm26/resource.h Wed Jun 4 04:14:10 2003 +++ edited/include/asm-arm26/resource.h Mon May 10 18:22:10 2004 @@ -16,8 +16,9 @@ #define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ +#define RLIMIT_SIGPENDING 11 /* max number of pending signals */ -#define RLIM_NLIMITS 11 +#define RLIM_NLIMITS 12 #ifdef __KERNEL__ @@ -40,6 +41,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ + { MAX_SIGPENDING, MAX_SIGPENDING}, \ } #endif /* __KERNEL__ */ ===== include/asm-cris/resource.h 1.1 vs edited ===== --- 1.1/include/asm-cris/resource.h Tue Feb 5 09:56:43 2002 +++ edited/include/asm-cris/resource.h Mon May 10 18:25:50 2004 @@ -15,9 +15,10 @@ #define RLIMIT_NOFILE 7 /* max number of open files */ #define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ #define RLIMIT_AS 9 /* address space limit */ -#define RLIMIT_LOCKS 10 /* maximum file locks held */ +#define RLIMIT_LOCKS 10 /* maximum file locks held */ +#define RLIMIT_SIGPENDING 11 /* max number of pending signals */ -#define RLIM_NLIMITS 11 +#define RLIM_NLIMITS 12 /* * SuS says limits have to be unsigned. @@ -38,8 +39,9 @@ { 0, 0 }, \ { INR_OPEN, INR_OPEN }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ - { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ + { RLIM_INFINITY, RLIM_INFINITY }, \ + { MAX_SIGPENDING, MAX_SIGPENDING }, \ } #endif /* __KERNEL__ */ ===== include/asm-h8300/resource.h 1.1 vs edited ===== --- 1.1/include/asm-h8300/resource.h Sun Feb 16 16:01:58 2003 +++ edited/include/asm-h8300/resource.h Mon May 10 18:26:57 2004 @@ -16,8 +16,9 @@ #define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ +#define RLIMIT_SIGPENDING 11 /* max number of pending signals */ -#define RLIM_NLIMITS 11 +#define RLIM_NLIMITS 12 /* * SuS says limits have to be unsigned. @@ -39,7 +40,8 @@ { INR_OPEN, INR_OPEN }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ - { RLIM_INFINITY, RLIM_INFINITY }, \ + { RLIM_INFINITY, RLIM_INFINITY }, \ + { MAX_SIGPENDING, MAX_SIGPENDING }, \ } #endif /* __KERNEL__ */ ===== include/asm-i386/resource.h 1.1 vs edited ===== --- 1.1/include/asm-i386/resource.h Tue Feb 5 09:39:44 2002 +++ edited/include/asm-i386/resource.h Mon May 10 18:22:10 2004 @@ -16,8 +16,10 @@ #define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ +#define RLIMIT_SIGPENDING 11 /* max number of pending signals */ + +#define RLIM_NLIMITS 12 -#define RLIM_NLIMITS 11 /* * SuS says limits have to be unsigned. @@ -39,7 +41,8 @@ { INR_OPEN, INR_OPEN }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ - { RLIM_INFINITY, RLIM_INFINITY }, \ + { RLIM_INFINITY, RLIM_INFINITY }, \ + { MAX_SIGPENDING, MAX_SIGPENDING }, \ } #endif /* __KERNEL__ */ ===== include/asm-ia64/resource.h 1.3 vs edited ===== --- 1.3/include/asm-ia64/resource.h Fri Jan 23 10:52:25 2004 +++ edited/include/asm-ia64/resource.h Mon May 10 18:22:10 2004 @@ -23,8 +23,9 @@ #define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ +#define RLIMIT_SIGPENDING 11 /* max number of pending signals */ -#define RLIM_NLIMITS 11 +#define RLIM_NLIMITS 12 /* * SuS says limits have to be unsigned. @@ -47,6 +48,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ + { MAX_SIGPENDING, MAX_SIGPENDING }, \ } # endif /* __KERNEL__ */ ===== include/asm-m68k/resource.h 1.2 vs edited ===== --- 1.2/include/asm-m68k/resource.h Fri Nov 9 05:47:28 2001 +++ edited/include/asm-m68k/resource.h Mon May 10 18:22:10 2004 @@ -16,8 +16,9 @@ #define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ +#define RLIMIT_SIGPENDING 11 /* max number of pending signals */ -#define RLIM_NLIMITS 11 +#define RLIM_NLIMITS 12 /* * SuS says limits have to be unsigned. @@ -39,7 +40,8 @@ { INR_OPEN, INR_OPEN }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ - { RLIM_INFINITY, RLIM_INFINITY }, \ + { RLIM_INFINITY, RLIM_INFINITY }, \ + { MAX_SIGPENDING, MAX_SIGPENDING }, \ } #endif /* __KERNEL__ */ ===== include/asm-mips/resource.h 1.3 vs edited ===== --- 1.3/include/asm-mips/resource.h Mon Jul 28 04:57:50 2003 +++ edited/include/asm-mips/resource.h Mon May 10 18:22:10 2004 @@ -23,8 +23,9 @@ #define RLIMIT_NPROC 8 /* max number of processes */ #define RLIMIT_MEMLOCK 9 /* max locked-in-memory address space */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ +#define RLIMIT_SIGPENDING 11 /* max number of pending signals */ -#define RLIM_NLIMITS 11 /* Number of limit flavors. */ +#define RLIM_NLIMITS 12 /* Number of limit flavors. */ #ifdef __KERNEL__ @@ -54,6 +55,7 @@ { 0, 0 }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ + { MAX_SIGPENDING, MAX_SIGPENDING }, \ } #endif /* __KERNEL__ */ ===== include/asm-parisc/resource.h 1.1 vs edited ===== --- 1.1/include/asm-parisc/resource.h Tue Feb 5 09:39:57 2002 +++ edited/include/asm-parisc/resource.h Mon May 10 18:22:10 2004 @@ -16,8 +16,9 @@ #define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ +#define RLIMIT_SIGPENDING 11 /* max number of pending signals */ -#define RLIM_NLIMITS 11 +#define RLIM_NLIMITS 12 /* * SuS says limits have to be unsigned. @@ -40,6 +41,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ + { MAX_SIGPENDING, MAX_SIGPENDING }, \ } #endif /* __KERNEL__ */ ===== include/asm-ppc/resource.h 1.3 vs edited ===== --- 1.3/include/asm-ppc/resource.h Sun Sep 15 21:52:06 2002 +++ edited/include/asm-ppc/resource.h Mon May 10 18:22:10 2004 @@ -12,8 +12,9 @@ #define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ #define RLIMIT_AS 9 /* address space limit(?) */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ +#define RLIMIT_SIGPENDING 11 /* max number of pending signals */ -#define RLIM_NLIMITS 11 +#define RLIM_NLIMITS 12 #ifdef __KERNEL__ @@ -37,6 +38,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ + { MAX_SIGPENDING, MAX_SIGPENDING }, \ } #endif /* __KERNEL__ */ ===== include/asm-ppc64/resource.h 1.1 vs edited ===== --- 1.1/include/asm-ppc64/resource.h Thu Feb 14 04:14:36 2002 +++ edited/include/asm-ppc64/resource.h Mon May 10 18:22:10 2004 @@ -21,8 +21,9 @@ #define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ #define RLIMIT_AS 9 /* address space limit(?) */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ +#define RLIMIT_SIGPENDING 11 /* max number of pending signals */ -#define RLIM_NLIMITS 11 +#define RLIM_NLIMITS 12 #ifdef __KERNEL__ @@ -46,6 +47,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ + { MAX_SIGPENDING, MAX_SIGPENDING }, \ } #endif /* __KERNEL__ */ ===== include/asm-s390/resource.h 1.2 vs edited ===== --- 1.2/include/asm-s390/resource.h Mon Feb 4 23:37:28 2002 +++ edited/include/asm-s390/resource.h Mon May 10 18:22:10 2004 @@ -24,8 +24,9 @@ #define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ - -#define RLIM_NLIMITS 11 +#define RLIMIT_SIGPENDING 11 /* max number of pending signals */ + +#define RLIM_NLIMITS 12 /* * SuS says limits have to be unsigned. @@ -48,6 +49,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ + { MAX_SIGPENDING, MAX_SIGPENDING }, \ } #endif /* __KERNEL__ */ ===== include/asm-sh/resource.h 1.1 vs edited ===== --- 1.1/include/asm-sh/resource.h Tue Feb 5 09:39:53 2002 +++ edited/include/asm-sh/resource.h Mon May 10 18:22:10 2004 @@ -16,8 +16,9 @@ #define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ +#define RLIMIT_SIGPENDING 11 /* max number of pending signals */ -#define RLIM_NLIMITS 11 +#define RLIM_NLIMITS 12 #ifdef __KERNEL__ @@ -40,6 +41,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ + { MAX_SIGPENDING, MAX_SIGPENDING }, \ } #endif /* __KERNEL__ */ ===== include/asm-sparc/resource.h 1.1 vs edited ===== --- 1.1/include/asm-sparc/resource.h Tue Feb 5 09:39:47 2002 +++ edited/include/asm-sparc/resource.h Mon May 10 18:32:32 2004 @@ -19,11 +19,12 @@ #define RLIMIT_RSS 5 /* max resident set size */ #define RLIMIT_NOFILE 6 /* max number of open files */ #define RLIMIT_NPROC 7 /* max number of processes */ -#define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ -#define RLIMIT_AS 9 /* address space limit */ +#define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ +#define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ +#define RLIMIT_SIGPENDING 11 /* max number of pending signals */ -#define RLIM_NLIMITS 11 +#define RLIM_NLIMITS 12 /* * SuS says limits have to be unsigned. @@ -44,7 +45,8 @@ {INR_OPEN, INR_OPEN}, {0, 0}, \ {RLIM_INFINITY, RLIM_INFINITY}, \ {RLIM_INFINITY, RLIM_INFINITY}, \ - {RLIM_INFINITY, RLIM_INFINITY} \ + {RLIM_INFINITY, RLIM_INFINITY}, \ + {MAX_SIGPENDING, MAX_SIGPENDING}, \ } #endif /* __KERNEL__ */ ===== include/asm-sparc64/resource.h 1.1 vs edited ===== --- 1.1/include/asm-sparc64/resource.h Tue Feb 5 09:39:50 2002 +++ edited/include/asm-sparc64/resource.h Mon May 10 18:33:39 2004 @@ -19,11 +19,12 @@ #define RLIMIT_RSS 5 /* max resident set size */ #define RLIMIT_NOFILE 6 /* max number of open files */ #define RLIMIT_NPROC 7 /* max number of processes */ -#define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ -#define RLIMIT_AS 9 /* address space limit */ +#define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ +#define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ +#define RLIMIT_SIGPENDING 11 /* max number of pending signals */ -#define RLIM_NLIMITS 11 +#define RLIM_NLIMITS 12 /* * SuS says limits have to be unsigned. @@ -43,7 +44,8 @@ {INR_OPEN, INR_OPEN}, {0, 0}, \ {RLIM_INFINITY, RLIM_INFINITY}, \ {RLIM_INFINITY, RLIM_INFINITY}, \ - {RLIM_INFINITY, RLIM_INFINITY} \ + {RLIM_INFINITY, RLIM_INFINITY}, \ + {MAX_SIGPENDING, MAX_SIGPENDING}, \ } #endif /* __KERNEL__ */ ===== include/asm-v850/resource.h 1.1 vs edited ===== --- 1.1/include/asm-v850/resource.h Fri Nov 1 08:38:12 2002 +++ edited/include/asm-v850/resource.h Mon May 10 18:34:44 2004 @@ -16,8 +16,9 @@ #define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ +#define RLIMIT_SIGPENDING 11 /* max number of pending signals */ -#define RLIM_NLIMITS 11 +#define RLIM_NLIMITS 12 /* * SuS says limits have to be unsigned. @@ -39,7 +40,8 @@ { INR_OPEN, INR_OPEN }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ - { RLIM_INFINITY, RLIM_INFINITY }, \ + { RLIM_INFINITY, RLIM_INFINITY }, \ + { MAX_SIGPENDING, MAX_SIGPENDING }, \ } #endif /* __KERNEL__ */ ===== include/asm-x86_64/resource.h 1.1 vs edited ===== --- 1.1/include/asm-x86_64/resource.h Thu Feb 7 02:55:27 2002 +++ edited/include/asm-x86_64/resource.h Mon May 10 18:22:10 2004 @@ -16,8 +16,9 @@ #define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ +#define RLIMIT_SIGPENDING 11 /* max number of pending signals */ -#define RLIM_NLIMITS 11 +#define RLIM_NLIMITS 12 /* * SuS says limits have to be unsigned. @@ -39,7 +40,8 @@ { INR_OPEN, INR_OPEN }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ - { RLIM_INFINITY, RLIM_INFINITY }, \ + { RLIM_INFINITY, RLIM_INFINITY }, \ + { MAX_SIGPENDING, MAX_SIGPENDING }, \ } #endif /* __KERNEL__ */ ===== include/linux/signal.h 1.15 vs edited ===== --- 1.15/include/linux/signal.h Thu Jan 15 12:40:33 2004 +++ edited/include/linux/signal.h Mon May 10 18:22:10 2004 @@ -7,6 +7,9 @@ #include <asm/siginfo.h> #ifdef __KERNEL__ + +#define MAX_SIGPENDING 1024 + /* * Real Time signals may be queued. */ ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 2/11] add sigpending field to user_struct 2004-05-11 8:45 ` [PATCH 1/11] add rlimit entry for controlling queued signals Chris Wright @ 2004-05-11 8:46 ` Chris Wright 2004-05-11 8:48 ` [PATCH 3/11] pass task_struct in send_signal() Chris Wright 0 siblings, 1 reply; 12+ messages in thread From: Chris Wright @ 2004-05-11 8:46 UTC (permalink / raw) To: linux-kernel; +Cc: akpm, torvalds, marcelo.tosatti Add sigpending field to user_struct, and make sure it's properly initialized. ===== include/linux/sched.h 1.210 vs edited ===== --- 1.210/include/linux/sched.h Mon May 10 04:25:34 2004 +++ edited/include/linux/sched.h Mon May 10 18:22:10 2004 @@ -314,6 +314,7 @@ atomic_t __count; /* reference count */ atomic_t processes; /* How many processes does this user have? */ atomic_t files; /* How many open files does this user have? */ + atomic_t sigpending; /* How many pending signals does this user have? */ /* Hash table maintenance information */ struct list_head uidhash_list; ===== kernel/user.c 1.9 vs edited ===== --- 1.9/kernel/user.c Mon May 10 04:25:43 2004 +++ edited/kernel/user.c Mon May 10 18:22:10 2004 @@ -30,7 +30,8 @@ struct user_struct root_user = { .__count = ATOMIC_INIT(1), .processes = ATOMIC_INIT(1), - .files = ATOMIC_INIT(0) + .files = ATOMIC_INIT(0), + .sigpending = ATOMIC_INIT(0), }; /* @@ -108,6 +109,7 @@ atomic_set(&new->__count, 1); atomic_set(&new->processes, 0); atomic_set(&new->files, 0); + atomic_set(&new->sigpending, 0); /* * Before adding this, check whether we raced ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 3/11] pass task_struct in send_signal() 2004-05-11 8:46 ` [PATCH 2/11] add sigpending field to user_struct Chris Wright @ 2004-05-11 8:48 ` Chris Wright 2004-05-11 8:50 ` [PATCH 4/11] add simple get_uid() helper Chris Wright 0 siblings, 1 reply; 12+ messages in thread From: Chris Wright @ 2004-05-11 8:48 UTC (permalink / raw) To: linux-kernel; +Cc: akpm, torvalds, marcelo.tosatti Update send_signal() api to allow passing the task receiving the signal. This is necessary to ensure signals generated out of process context can be charged to the correct user. ===== kernel/signal.c 1.115 vs edited ===== --- 1.115/kernel/signal.c Mon May 10 03:04:00 2004 +++ edited/kernel/signal.c Mon May 10 16:16:13 2004 @@ -698,7 +698,8 @@ } } -static int send_signal(int sig, struct siginfo *info, struct sigpending *signals) +static int send_signal(int sig, struct siginfo *info, struct task_struct *t, + struct sigpending *signals) { struct sigqueue * q = NULL; int ret = 0; @@ -797,7 +798,7 @@ if (LEGACY_QUEUE(&t->pending, sig)) goto out; - ret = send_signal(sig, info, &t->pending); + ret = send_signal(sig, info, t, &t->pending); if (!ret && !sigismember(&t->blocked, sig)) signal_wake_up(t, sig == SIGKILL); out: @@ -998,7 +999,7 @@ * We always use the shared queue for process-wide signals, * to avoid several races. */ - ret = send_signal(sig, info, &p->signal->shared_pending); + ret = send_signal(sig, info, p, &p->signal->shared_pending); if (unlikely(ret)) return ret; ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 4/11] add simple get_uid() helper 2004-05-11 8:48 ` [PATCH 3/11] pass task_struct in send_signal() Chris Wright @ 2004-05-11 8:50 ` Chris Wright 2004-05-11 8:52 ` [PATCH 5/11] enforce rlimits on queued signals Chris Wright 0 siblings, 1 reply; 12+ messages in thread From: Chris Wright @ 2004-05-11 8:50 UTC (permalink / raw) To: linux-kernel; +Cc: akpm, torvalds, marcelo.tosatti Add simple helper function to grab a reference to a user_struct. ===== include/linux/sched.h 1.210 vs edited ===== --- 1.210/include/linux/sched.h Mon May 10 04:25:34 2004 +++ edited/include/linux/sched.h Mon May 10 18:22:10 2004 @@ -714,6 +714,11 @@ /* per-UID process charging. */ extern struct user_struct * alloc_uid(uid_t); +static inline struct user_struct *get_uid(struct user_struct *u) +{ + atomic_inc(&u->__count); + return u; +} extern void free_uid(struct user_struct *); extern void switch_uid(struct user_struct *); ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 5/11] enforce rlimits on queued signals 2004-05-11 8:50 ` [PATCH 4/11] add simple get_uid() helper Chris Wright @ 2004-05-11 8:52 ` Chris Wright 2004-05-11 8:53 ` [PATCH 6/11] remove unused queued_signals global accounting Chris Wright 0 siblings, 1 reply; 12+ messages in thread From: Chris Wright @ 2004-05-11 8:52 UTC (permalink / raw) To: linux-kernel; +Cc: akpm, torvalds, marcelo.tosatti Add a user_struct to the sigqueue structure. Charge sigqueue allocation and destruction to the user_struct rather than a global pool. This per user rlimit accounting obsoletes the global queued_signals accouting. ===== include/linux/signal.h 1.15 vs edited ===== --- 1.15/include/linux/signal.h Thu Jan 15 12:40:33 2004 +++ edited/include/linux/signal.h Mon May 10 16:16:13 2004 @@ -19,6 +19,7 @@ spinlock_t *lock; int flags; siginfo_t info; + struct user_struct *user; }; /* flags values. */ ===== kernel/signal.c 1.115 vs edited ===== --- 1.115/kernel/signal.c Mon May 10 03:04:00 2004 +++ edited/kernel/signal.c Mon May 10 16:16:13 2004 @@ -264,17 +264,19 @@ return sig; } -struct sigqueue *__sigqueue_alloc(void) +static struct sigqueue *__sigqueue_alloc(void) { struct sigqueue *q = 0; - if (atomic_read(&nr_queued_signals) < max_queued_signals) + if (atomic_read(¤t->user->sigpending) < + current->rlim[RLIMIT_SIGPENDING].rlim_cur) q = kmem_cache_alloc(sigqueue_cachep, GFP_ATOMIC); if (q) { - atomic_inc(&nr_queued_signals); INIT_LIST_HEAD(&q->list); q->flags = 0; q->lock = 0; + q->user = get_uid(current->user); + atomic_inc(&q->user->sigpending); } return(q); } @@ -283,8 +285,9 @@ { if (q->flags & SIGQUEUE_PREALLOC) return; + atomic_dec(&q->user->sigpending); + free_uid(q->user); kmem_cache_free(sigqueue_cachep, q); - atomic_dec(&nr_queued_signals); } static void flush_sigqueue(struct sigpending *queue) @@ -719,12 +722,14 @@ make sure at least one signal gets delivered and don't pass on the info struct. */ - if (atomic_read(&nr_queued_signals) < max_queued_signals) + if (atomic_read(&t->user->sigpending) < + t->rlim[RLIMIT_SIGPENDING].rlim_cur) q = kmem_cache_alloc(sigqueue_cachep, GFP_ATOMIC); if (q) { - atomic_inc(&nr_queued_signals); q->flags = 0; + q->user = get_uid(t->user); + atomic_inc(&q->user->sigpending); list_add_tail(&q->list, &signals->list); switch ((unsigned long) info) { case 0: ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 6/11] remove unused queued_signals global accounting 2004-05-11 8:52 ` [PATCH 5/11] enforce rlimits on queued signals Chris Wright @ 2004-05-11 8:53 ` Chris Wright 2004-05-11 8:56 ` [PATCH 7/11] add rlimit entry for POSIX mqueue allocation Chris Wright 0 siblings, 1 reply; 12+ messages in thread From: Chris Wright @ 2004-05-11 8:53 UTC (permalink / raw) To: linux-kernel; +Cc: akpm, torvalds, marcelo.tosatti Remove unused queued_signals global accounting. ===== kernel/signal.c 1.115 vs edited ===== --- 1.115/kernel/signal.c Mon May 10 03:04:00 2004 +++ edited/kernel/signal.c Mon May 10 16:16:13 2004 @@ -31,9 +31,6 @@ static kmem_cache_t *sigqueue_cachep; -atomic_t nr_queued_signals; -int max_queued_signals = 1024; - /* * In POSIX a signal is sent either to a specific thread (Linux task) * or to the process as a whole (Linux thread group). How the signal ===== kernel/sysctl.c 1.72 vs edited ===== --- 1.72/kernel/sysctl.c Mon May 10 04:25:53 2004 +++ edited/kernel/sysctl.c Mon May 10 16:16:13 2004 @@ -53,8 +53,6 @@ extern int sysctl_overcommit_memory; extern int sysctl_overcommit_ratio; extern int max_threads; -extern atomic_t nr_queued_signals; -extern int max_queued_signals; extern int sysrq_enabled; extern int core_uses_pid; extern char core_pattern[]; @@ -429,22 +427,6 @@ .proc_handler = &proc_dointvec, }, #endif - { - .ctl_name = KERN_RTSIGNR, - .procname = "rtsig-nr", - .data = &nr_queued_signals, - .maxlen = sizeof(int), - .mode = 0444, - .proc_handler = &proc_dointvec, - }, - { - .ctl_name = KERN_RTSIGMAX, - .procname = "rtsig-max", - .data = &max_queued_signals, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = &proc_dointvec, - }, #ifdef CONFIG_SYSVIPC { .ctl_name = KERN_SHMMAX, ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 7/11] add rlimit entry for POSIX mqueue allocation 2004-05-11 8:53 ` [PATCH 6/11] remove unused queued_signals global accounting Chris Wright @ 2004-05-11 8:56 ` Chris Wright 2004-05-11 8:58 ` [PATCH 8/11] add mq_bytes to user_struct Chris Wright 0 siblings, 1 reply; 12+ messages in thread From: Chris Wright @ 2004-05-11 8:56 UTC (permalink / raw) To: linux-kernel; +Cc: akpm, torvalds, marcelo.tosatti Add an rlimit entry to control the maximum number of bytes a user can allocate to a POSIX mqueue. --- 2.6-rlimit/arch/alpha/kernel/init_task.c~mqueue_rlimit 2004-05-10 23:16:44.734764544 -0700 +++ 2.6-rlimit/arch/alpha/kernel/init_task.c 2004-05-10 23:16:44.736764240 -0700 @@ -4,6 +4,7 @@ #include <linux/init.h> #include <linux/init_task.h> #include <linux/fs.h> +#include <linux/mqueue.h> #include <asm/uaccess.h> --- 2.6-rlimit/arch/arm/kernel/init_task.c~mqueue_rlimit 2004-05-10 23:16:44.856746000 -0700 +++ 2.6-rlimit/arch/arm/kernel/init_task.c 2004-05-10 23:16:44.859745544 -0700 @@ -7,6 +7,7 @@ #include <linux/sched.h> #include <linux/init.h> #include <linux/init_task.h> +#include <linux/mqueue.h> #include <asm/uaccess.h> #include <asm/pgtable.h> --- 2.6-rlimit/include/asm-arm26/resource.h~mqueue_rlimit 2004-05-10 23:01:16.256914632 -0700 +++ 2.6-rlimit/include/asm-arm26/resource.h 2004-05-10 23:16:46.769455224 -0700 @@ -17,8 +17,9 @@ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ #define RLIMIT_SIGPENDING 11 /* max number of pending signals */ +#define RLIMIT_MSGQUEUE 12 /* maximum bytes in POSIX mqueues */ -#define RLIM_NLIMITS 12 +#define RLIM_NLIMITS 13 #ifdef __KERNEL__ @@ -42,6 +43,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { MAX_SIGPENDING, MAX_SIGPENDING}, \ + { MQ_BYTES_MAX, MQ_BYTES_MAX}, \ } #endif /* __KERNEL__ */ --- 2.6-rlimit/arch/h8300/kernel/init_task.c~mqueue_rlimit 2004-05-10 23:16:44.994725024 -0700 +++ 2.6-rlimit/arch/h8300/kernel/init_task.c 2004-05-10 23:16:44.996724720 -0700 @@ -7,6 +7,7 @@ #include <linux/init.h> #include <linux/init_task.h> #include <linux/fs.h> +#include <linux/mqueue.h> #include <asm/uaccess.h> #include <asm/pgtable.h> --- 2.6-rlimit/arch/i386/kernel/init_task.c~mqueue_rlimit 2004-05-10 23:16:44.199845864 -0700 +++ 2.6-rlimit/arch/i386/kernel/init_task.c 2004-05-10 23:16:44.201845560 -0700 @@ -4,6 +4,7 @@ #include <linux/init.h> #include <linux/init_task.h> #include <linux/fs.h> +#include <linux/mqueue.h> #include <asm/uaccess.h> #include <asm/pgtable.h> --- 2.6-rlimit/arch/ia64/kernel/init_task.c~mqueue_rlimit 2004-05-10 23:16:45.128704656 -0700 +++ 2.6-rlimit/arch/ia64/kernel/init_task.c 2004-05-10 23:16:45.130704352 -0700 @@ -11,6 +11,7 @@ #include <linux/module.h> #include <linux/sched.h> #include <linux/init_task.h> +#include <linux/mqueue.h> #include <asm/uaccess.h> #include <asm/pgtable.h> --- 2.6-rlimit/arch/m68knommu/kernel/init_task.c~mqueue_rlimit 2004-05-10 23:16:45.265683832 -0700 +++ 2.6-rlimit/arch/m68knommu/kernel/init_task.c 2004-05-10 23:16:45.268683376 -0700 @@ -7,6 +7,7 @@ #include <linux/init.h> #include <linux/init_task.h> #include <linux/fs.h> +#include <linux/mqueue.h> #include <asm/uaccess.h> #include <asm/pgtable.h> --- 2.6-rlimit/arch/mips/kernel/init_task.c~mqueue_rlimit 2004-05-10 23:16:45.404662704 -0700 +++ 2.6-rlimit/arch/mips/kernel/init_task.c 2004-05-10 23:16:45.406662400 -0700 @@ -3,6 +3,7 @@ #include <linux/sched.h> #include <linux/init_task.h> #include <linux/fs.h> +#include <linux/mqueue.h> #include <asm/thread_info.h> #include <asm/uaccess.h> --- 2.6-rlimit/arch/parisc/kernel/init_task.c~mqueue_rlimit 2004-05-10 23:16:45.535642792 -0700 +++ 2.6-rlimit/arch/parisc/kernel/init_task.c 2004-05-10 23:16:45.538642336 -0700 @@ -27,6 +27,7 @@ #include <linux/sched.h> #include <linux/init.h> #include <linux/init_task.h> +#include <linux/mqueue.h> #include <asm/uaccess.h> #include <asm/pgtable.h> --- 2.6-rlimit/arch/ppc64/kernel/init_task.c~mqueue_rlimit 2004-05-10 23:16:45.681620600 -0700 +++ 2.6-rlimit/arch/ppc64/kernel/init_task.c 2004-05-10 23:16:45.683620296 -0700 @@ -4,6 +4,7 @@ #include <linux/init.h> #include <linux/init_task.h> #include <linux/fs.h> +#include <linux/mqueue.h> #include <asm/uaccess.h> static struct fs_struct init_fs = INIT_FS; --- 2.6-rlimit/arch/s390/kernel/init_task.c~mqueue_rlimit 2004-05-10 23:16:45.793603576 -0700 +++ 2.6-rlimit/arch/s390/kernel/init_task.c 2004-05-10 23:16:45.795603272 -0700 @@ -10,6 +10,7 @@ #include <linux/module.h> #include <linux/sched.h> #include <linux/init_task.h> +#include <linux/mqueue.h> #include <asm/uaccess.h> #include <asm/pgtable.h> --- 2.6-rlimit/arch/sh/kernel/init_task.c~mqueue_rlimit 2004-05-10 23:16:45.935581992 -0700 +++ 2.6-rlimit/arch/sh/kernel/init_task.c 2004-05-10 23:16:45.937581688 -0700 @@ -2,6 +2,7 @@ #include <linux/module.h> #include <linux/sched.h> #include <linux/init_task.h> +#include <linux/mqueue.h> #include <asm/uaccess.h> #include <asm/pgtable.h> --- 2.6-rlimit/arch/sparc/kernel/init_task.c~mqueue_rlimit 2004-05-10 23:16:46.075560712 -0700 +++ 2.6-rlimit/arch/sparc/kernel/init_task.c 2004-05-10 23:16:46.078560256 -0700 @@ -2,6 +2,7 @@ #include <linux/module.h> #include <linux/sched.h> #include <linux/init_task.h> +#include <linux/mqueue.h> #include <asm/pgtable.h> #include <asm/uaccess.h> --- 2.6-rlimit/arch/sparc64/kernel/init_task.c~mqueue_rlimit 2004-05-10 23:16:46.204541104 -0700 +++ 2.6-rlimit/arch/sparc64/kernel/init_task.c 2004-05-10 23:16:46.206540800 -0700 @@ -2,6 +2,7 @@ #include <linux/module.h> #include <linux/sched.h> #include <linux/init_task.h> +#include <linux/mqueue.h> #include <asm/pgtable.h> #include <asm/uaccess.h> --- 2.6-rlimit/arch/um/kernel/init_task.c~mqueue_rlimit 2004-05-10 23:16:46.339520584 -0700 +++ 2.6-rlimit/arch/um/kernel/init_task.c 2004-05-10 23:16:46.341520280 -0700 @@ -9,6 +9,7 @@ #include "linux/sched.h" #include "linux/init_task.h" #include "linux/version.h" +#include "linux/mqueue.h" #include "asm/uaccess.h" #include "asm/pgtable.h" #include "user_util.h" --- 2.6-rlimit/arch/v850/kernel/init_task.c~mqueue_rlimit 2004-05-10 23:16:46.477499608 -0700 +++ 2.6-rlimit/arch/v850/kernel/init_task.c 2004-05-10 23:16:46.479499304 -0700 @@ -15,6 +15,7 @@ #include <linux/init.h> #include <linux/init_task.h> #include <linux/fs.h> +#include <linux/mqueue.h> #include <asm/uaccess.h> #include <asm/pgtable.h> --- 2.6-rlimit/arch/x86_64/kernel/init_task.c~mqueue_rlimit 2004-05-10 23:16:46.613478936 -0700 +++ 2.6-rlimit/arch/x86_64/kernel/init_task.c 2004-05-10 23:16:46.615478632 -0700 @@ -4,6 +4,7 @@ #include <linux/init.h> #include <linux/init_task.h> #include <linux/fs.h> +#include <linux/mqueue.h> #include <asm/uaccess.h> #include <asm/pgtable.h> --- 2.6-rlimit/arch/arm26/kernel/init_task.c~mqueue_rlimit 2004-05-10 23:16:46.742459328 -0700 +++ 2.6-rlimit/arch/arm26/kernel/init_task.c 2004-05-10 23:16:46.746458720 -0700 @@ -10,6 +10,7 @@ #include <linux/sched.h> #include <linux/init.h> #include <linux/init_task.h> +#include <linux/mqueue.h> #include <asm/uaccess.h> #include <asm/pgtable.h> --- 2.6-rlimit/include/asm-alpha/resource.h~mqueue_rlimit 2004-05-10 23:01:16.253915088 -0700 +++ 2.6-rlimit/include/asm-alpha/resource.h 2004-05-10 23:16:46.747458568 -0700 @@ -17,8 +17,9 @@ #define RLIMIT_MEMLOCK 9 /* max locked-in-memory address space */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ #define RLIMIT_SIGPENDING 11 /* max number of pending signals */ +#define RLIMIT_MSGQUEUE 12 /* maximum bytes in POSIX mqueues */ -#define RLIM_NLIMITS 12 +#define RLIM_NLIMITS 13 /* * SuS says limits have to be unsigned. Fine, it's unsigned, but @@ -43,6 +44,7 @@ {LONG_MAX, LONG_MAX}, /* RLIMIT_MEMLOCK */ \ {LONG_MAX, LONG_MAX}, /* RLIMIT_LOCKS */ \ {MAX_SIGPENDING, MAX_SIGPENDING}, /* RLIMIT_SIGPENDING */ \ + {MQ_BYTES_MAX, MQ_BYTES_MAX}, /* RLIMIT_MSGQUEUE */ \ } #endif /* __KERNEL__ */ --- 2.6-rlimit/include/asm-arm/resource.h~mqueue_rlimit 2004-05-10 23:01:16.255914784 -0700 +++ 2.6-rlimit/include/asm-arm/resource.h 2004-05-10 23:16:46.749458264 -0700 @@ -17,8 +17,9 @@ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ #define RLIMIT_SIGPENDING 11 /* max number of pending signals */ +#define RLIMIT_MSGQUEUE 12 /* maximum bytes in POSIX mqueues */ -#define RLIM_NLIMITS 12 +#define RLIM_NLIMITS 13 #ifdef __KERNEL__ @@ -42,6 +43,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { MAX_SIGPENDING, MAX_SIGPENDING}, \ + { MQ_BYTES_MAX, MQ_BYTES_MAX}, \ } #endif /* __KERNEL__ */ --- 2.6-rlimit/include/asm-cris/resource.h~mqueue_rlimit 2004-05-10 23:01:16.258914328 -0700 +++ 2.6-rlimit/include/asm-cris/resource.h 2004-05-10 23:16:46.750458112 -0700 @@ -17,8 +17,9 @@ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ #define RLIMIT_SIGPENDING 11 /* max number of pending signals */ +#define RLIMIT_MSGQUEUE 12 /* maximum bytes in POSIX mqueues */ -#define RLIM_NLIMITS 12 +#define RLIM_NLIMITS 13 /* * SuS says limits have to be unsigned. @@ -42,6 +43,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { MAX_SIGPENDING, MAX_SIGPENDING }, \ + { MQ_BYTES_MAX, MQ_BYTES_MAX }, \ } #endif /* __KERNEL__ */ --- 2.6-rlimit/include/asm-h8300/resource.h~mqueue_rlimit 2004-05-10 23:01:16.259914176 -0700 +++ 2.6-rlimit/include/asm-h8300/resource.h 2004-05-10 23:16:46.751457960 -0700 @@ -17,8 +17,9 @@ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ #define RLIMIT_SIGPENDING 11 /* max number of pending signals */ +#define RLIMIT_MSGQUEUE 12 /* maximum bytes in POSIX mqueues */ -#define RLIM_NLIMITS 12 +#define RLIM_NLIMITS 13 /* * SuS says limits have to be unsigned. @@ -42,6 +43,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { MAX_SIGPENDING, MAX_SIGPENDING }, \ + { MQ_BYTES_MAX, MQ_BYTES_MAX }, \ } #endif /* __KERNEL__ */ --- 2.6-rlimit/include/asm-i386/resource.h~mqueue_rlimit 2004-05-10 23:01:39.674354640 -0700 +++ 2.6-rlimit/include/asm-i386/resource.h 2004-05-10 23:16:46.752457808 -0700 @@ -17,8 +17,9 @@ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ #define RLIMIT_SIGPENDING 11 /* max number of pending signals */ +#define RLIMIT_MSGQUEUE 12 /* maximum bytes in POSIX mqueues */ -#define RLIM_NLIMITS 12 +#define RLIM_NLIMITS 13 /* @@ -43,6 +44,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { MAX_SIGPENDING, MAX_SIGPENDING }, \ + { MQ_BYTES_MAX, MQ_BYTES_MAX }, \ } #endif /* __KERNEL__ */ --- 2.6-rlimit/include/asm-ia64/resource.h~mqueue_rlimit 2004-05-10 23:01:16.262913720 -0700 +++ 2.6-rlimit/include/asm-ia64/resource.h 2004-05-10 23:16:46.754457504 -0700 @@ -24,8 +24,9 @@ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ #define RLIMIT_SIGPENDING 11 /* max number of pending signals */ +#define RLIMIT_MSGQUEUE 12 /* maximum bytes in POSIX mqueues */ -#define RLIM_NLIMITS 12 +#define RLIM_NLIMITS 13 /* * SuS says limits have to be unsigned. @@ -49,6 +50,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { MAX_SIGPENDING, MAX_SIGPENDING }, \ + { MQ_BYTES_MAX, MQ_BYTES_MAX }, \ } # endif /* __KERNEL__ */ --- 2.6-rlimit/include/asm-m68k/resource.h~mqueue_rlimit 2004-05-10 23:01:16.263913568 -0700 +++ 2.6-rlimit/include/asm-m68k/resource.h 2004-05-10 23:16:46.755457352 -0700 @@ -17,8 +17,9 @@ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ #define RLIMIT_SIGPENDING 11 /* max number of pending signals */ +#define RLIMIT_MSGQUEUE 12 /* maximum bytes in POSIX mqueues */ -#define RLIM_NLIMITS 12 +#define RLIM_NLIMITS 13 /* * SuS says limits have to be unsigned. @@ -42,6 +43,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { MAX_SIGPENDING, MAX_SIGPENDING }, \ + { MQ_BYTES_MAX, MQ_BYTES_MAX }, \ } #endif /* __KERNEL__ */ --- 2.6-rlimit/include/asm-mips/resource.h~mqueue_rlimit 2004-05-10 23:01:16.265913264 -0700 +++ 2.6-rlimit/include/asm-mips/resource.h 2004-05-10 23:16:46.756457200 -0700 @@ -24,8 +24,9 @@ #define RLIMIT_MEMLOCK 9 /* max locked-in-memory address space */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ #define RLIMIT_SIGPENDING 11 /* max number of pending signals */ +#define RLIMIT_MSGQUEUE 12 /* maximum bytes in POSIX mqueues */ -#define RLIM_NLIMITS 12 /* Number of limit flavors. */ +#define RLIM_NLIMITS 13 /* Number of limit flavors. */ #ifdef __KERNEL__ @@ -56,6 +57,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { MAX_SIGPENDING, MAX_SIGPENDING }, \ + { MQ_BYTES_MAX, MQ_BYTES_MAX }, \ } #endif /* __KERNEL__ */ --- 2.6-rlimit/include/asm-parisc/resource.h~mqueue_rlimit 2004-05-10 23:01:16.266913112 -0700 +++ 2.6-rlimit/include/asm-parisc/resource.h 2004-05-10 23:16:46.758456896 -0700 @@ -17,8 +17,9 @@ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ #define RLIMIT_SIGPENDING 11 /* max number of pending signals */ +#define RLIMIT_MSGQUEUE 12 /* maximum bytes in POSIX mqueues */ -#define RLIM_NLIMITS 12 +#define RLIM_NLIMITS 13 /* * SuS says limits have to be unsigned. @@ -42,6 +43,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { MAX_SIGPENDING, MAX_SIGPENDING }, \ + { MQ_BYTES_MAX, MQ_BYTES_MAX }, \ } #endif /* __KERNEL__ */ --- 2.6-rlimit/include/asm-ppc/resource.h~mqueue_rlimit 2004-05-10 23:01:16.267912960 -0700 +++ 2.6-rlimit/include/asm-ppc/resource.h 2004-05-10 23:16:46.759456744 -0700 @@ -13,8 +13,9 @@ #define RLIMIT_AS 9 /* address space limit(?) */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ #define RLIMIT_SIGPENDING 11 /* max number of pending signals */ +#define RLIMIT_MSGQUEUE 12 /* maximum bytes in POSIX mqueues */ -#define RLIM_NLIMITS 12 +#define RLIM_NLIMITS 13 #ifdef __KERNEL__ @@ -39,6 +40,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { MAX_SIGPENDING, MAX_SIGPENDING }, \ + { MQ_BYTES_MAX, MQ_BYTES_MAX }, \ } #endif /* __KERNEL__ */ --- 2.6-rlimit/include/asm-ppc64/resource.h~mqueue_rlimit 2004-05-10 23:01:16.269912656 -0700 +++ 2.6-rlimit/include/asm-ppc64/resource.h 2004-05-10 23:16:46.760456592 -0700 @@ -22,8 +22,9 @@ #define RLIMIT_AS 9 /* address space limit(?) */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ #define RLIMIT_SIGPENDING 11 /* max number of pending signals */ +#define RLIMIT_MSGQUEUE 12 /* maximum bytes in POSIX mqueues */ -#define RLIM_NLIMITS 12 +#define RLIM_NLIMITS 13 #ifdef __KERNEL__ @@ -48,6 +49,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { MAX_SIGPENDING, MAX_SIGPENDING }, \ + { MQ_BYTES_MAX, MQ_BYTES_MAX }, \ } #endif /* __KERNEL__ */ --- 2.6-rlimit/include/asm-s390/resource.h~mqueue_rlimit 2004-05-10 23:01:16.270912504 -0700 +++ 2.6-rlimit/include/asm-s390/resource.h 2004-05-10 23:16:46.761456440 -0700 @@ -25,8 +25,9 @@ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ #define RLIMIT_SIGPENDING 11 /* max number of pending signals */ +#define RLIMIT_MSGQUEUE 12 /* maximum bytes in POSIX mqueues */ -#define RLIM_NLIMITS 12 +#define RLIM_NLIMITS 13 /* * SuS says limits have to be unsigned. @@ -50,6 +51,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { MAX_SIGPENDING, MAX_SIGPENDING }, \ + { MQ_BYTES_MAX, MQ_BYTES_MAX }, \ } #endif /* __KERNEL__ */ --- 2.6-rlimit/include/asm-sh/resource.h~mqueue_rlimit 2004-05-10 23:01:16.271912352 -0700 +++ 2.6-rlimit/include/asm-sh/resource.h 2004-05-10 23:16:46.763456136 -0700 @@ -17,8 +17,9 @@ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ #define RLIMIT_SIGPENDING 11 /* max number of pending signals */ +#define RLIMIT_MSGQUEUE 12 /* maximum bytes in POSIX mqueues */ -#define RLIM_NLIMITS 12 +#define RLIM_NLIMITS 13 #ifdef __KERNEL__ @@ -42,6 +43,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { MAX_SIGPENDING, MAX_SIGPENDING }, \ + { MQ_BYTES_MAX, MQ_BYTES_MAX }, \ } #endif /* __KERNEL__ */ --- 2.6-rlimit/include/asm-sparc/resource.h~mqueue_rlimit 2004-05-10 23:01:16.273912048 -0700 +++ 2.6-rlimit/include/asm-sparc/resource.h 2004-05-10 23:16:46.764455984 -0700 @@ -23,8 +23,9 @@ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ #define RLIMIT_SIGPENDING 11 /* max number of pending signals */ +#define RLIMIT_MSGQUEUE 12 /* maximum bytes in POSIX mqueues */ -#define RLIM_NLIMITS 12 +#define RLIM_NLIMITS 13 /* * SuS says limits have to be unsigned. @@ -47,6 +48,7 @@ {RLIM_INFINITY, RLIM_INFINITY}, \ {RLIM_INFINITY, RLIM_INFINITY}, \ {MAX_SIGPENDING, MAX_SIGPENDING}, \ + {MQ_BYTES_MAX, MQ_BYTES_MAX}, \ } #endif /* __KERNEL__ */ --- 2.6-rlimit/include/asm-sparc64/resource.h~mqueue_rlimit 2004-05-10 23:01:16.274911896 -0700 +++ 2.6-rlimit/include/asm-sparc64/resource.h 2004-05-10 23:16:46.765455832 -0700 @@ -23,8 +23,9 @@ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ #define RLIMIT_SIGPENDING 11 /* max number of pending signals */ +#define RLIMIT_MSGQUEUE 12 /* maximum bytes in POSIX mqueues */ -#define RLIM_NLIMITS 12 +#define RLIM_NLIMITS 13 /* * SuS says limits have to be unsigned. @@ -46,6 +47,7 @@ {RLIM_INFINITY, RLIM_INFINITY}, \ {RLIM_INFINITY, RLIM_INFINITY}, \ {MAX_SIGPENDING, MAX_SIGPENDING}, \ + {MQ_BYTES_MAX, MQ_BYTES_MAX}, \ } #endif /* __KERNEL__ */ --- 2.6-rlimit/include/asm-v850/resource.h~mqueue_rlimit 2004-05-10 23:01:16.276911592 -0700 +++ 2.6-rlimit/include/asm-v850/resource.h 2004-05-10 23:16:46.767455528 -0700 @@ -17,8 +17,9 @@ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ #define RLIMIT_SIGPENDING 11 /* max number of pending signals */ +#define RLIMIT_MSGQUEUE 12 /* maximum bytes in POSIX mqueues */ -#define RLIM_NLIMITS 12 +#define RLIM_NLIMITS 13 /* * SuS says limits have to be unsigned. @@ -42,6 +43,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { MAX_SIGPENDING, MAX_SIGPENDING }, \ + { MQ_BYTES_MAX, MQ_BYTES_MAX }, \ } #endif /* __KERNEL__ */ --- 2.6-rlimit/include/asm-x86_64/resource.h~mqueue_rlimit 2004-05-10 23:01:16.277911440 -0700 +++ 2.6-rlimit/include/asm-x86_64/resource.h 2004-05-10 23:16:46.768455376 -0700 @@ -17,8 +17,9 @@ #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ #define RLIMIT_SIGPENDING 11 /* max number of pending signals */ +#define RLIMIT_MSGQUEUE 12 /* maximum bytes in POSIX mqueues */ -#define RLIM_NLIMITS 12 +#define RLIM_NLIMITS 13 /* * SuS says limits have to be unsigned. @@ -42,6 +43,7 @@ { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ { MAX_SIGPENDING, MAX_SIGPENDING }, \ + { MQ_BYTES_MAX, MQ_BYTES_MAX }, \ } #endif /* __KERNEL__ */ --- 2.6-rlimit/include/linux/mqueue.h~mqueue_rlimit 2004-05-10 23:01:16.278911288 -0700 +++ 2.6-rlimit/include/linux/mqueue.h 2004-05-10 23:16:46.771454920 -0700 @@ -21,6 +21,8 @@ #include <linux/types.h> #define MQ_PRIO_MAX 32768 +/* per-uid limit of kernel memory used by mqueue, in bytes */ +#define MQ_BYTES_MAX 819200 struct mq_attr { long mq_flags; /* message queue flags */ ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 8/11] add mq_bytes to user_struct 2004-05-11 8:56 ` [PATCH 7/11] add rlimit entry for POSIX mqueue allocation Chris Wright @ 2004-05-11 8:58 ` Chris Wright 2004-05-11 9:00 ` [PATCH 9/11] add mq_attr_ok() helper Chris Wright 0 siblings, 1 reply; 12+ messages in thread From: Chris Wright @ 2004-05-11 8:58 UTC (permalink / raw) To: linux-kernel; +Cc: akpm, torvalds, marcelo.tosatti Add mq_bytes field to user_struct, and make sure it's properly initialized. --- 2.6-rlimit/include/linux/sched.h~mqueue_rlimit 2004-05-10 22:29:32.558320808 -0700 +++ 2.6-rlimit/include/linux/sched.h 2004-05-10 22:30:44.527379848 -0700 @@ -315,6 +315,8 @@ atomic_t processes; /* How many processes does this user have? */ atomic_t files; /* How many open files does this user have? */ atomic_t sigpending; /* How many pending signals does this user have? */ + /* protected by mq_lock */ + unsigned long mq_bytes; /* How many bytes can be allocated to mqueue? */ /* Hash table maintenance information */ struct list_head uidhash_list; --- 2.6-rlimit/kernel/user.c~mqueue_rlimit 2004-05-10 22:29:03.741701600 -0700 +++ 2.6-rlimit/kernel/user.c 2004-05-10 22:30:44.531379240 -0700 @@ -32,6 +32,7 @@ .processes = ATOMIC_INIT(1), .files = ATOMIC_INIT(0), .sigpending = ATOMIC_INIT(0), + .mq_bytes = 0 }; /* @@ -111,6 +112,8 @@ atomic_set(&new->files, 0); atomic_set(&new->sigpending, 0); + new->mq_bytes = 0; + /* * Before adding this, check whether we raced * on adding the same user already.. ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 9/11] add mq_attr_ok() helper 2004-05-11 8:58 ` [PATCH 8/11] add mq_bytes to user_struct Chris Wright @ 2004-05-11 9:00 ` Chris Wright 2004-05-11 9:02 ` [PATCH 10/11] enforce rlimits for POSIX mqueue allocation Chris Wright 0 siblings, 1 reply; 12+ messages in thread From: Chris Wright @ 2004-05-11 9:00 UTC (permalink / raw) To: linux-kernel; +Cc: akpm, torvalds, marcelo.tosatti Add helper function mq_attr_ok() to do mq_attr sanity checking, and do some extra overlow checking. --- 2.6-rlimit/ipc/mqueue.c~mqueue_rlimit 2004-05-10 22:28:43.137833864 -0700 +++ 2.6-rlimit/ipc/mqueue.c 2004-05-10 22:30:44.530379392 -0700 @@ -534,6 +534,28 @@ info->notify_owner = 0; } +static int mq_attr_ok(struct mq_attr *attr) +{ + if (attr->mq_maxmsg <= 0 || attr->mq_msgsize <= 0) + return 0; + if (capable(CAP_SYS_RESOURCE)) { + if (attr->mq_maxmsg > HARD_MSGMAX) + return 0; + } else { + if (attr->mq_maxmsg > msg_max || + attr->mq_msgsize > msgsize_max) + return 0; + } + /* check for overflow */ + if (attr->mq_msgsize > ULONG_MAX/attr->mq_maxmsg) + return 0; + if ((unsigned long)(attr->mq_maxmsg * attr->mq_msgsize) + + (attr->mq_maxmsg * sizeof (struct msg_msg *)) < + (unsigned long)(attr->mq_maxmsg * attr->mq_msgsize)) + return 0; + return 1; +} + /* * Invoked when creating a new queue via sys_mq_open */ @@ -547,17 +569,8 @@ if (u_attr != NULL) { if (copy_from_user(&attr, u_attr, sizeof(attr))) return ERR_PTR(-EFAULT); - - if (attr.mq_maxmsg <= 0 || attr.mq_msgsize <= 0) + if (!mq_attr_ok(&attr)) return ERR_PTR(-EINVAL); - if (capable(CAP_SYS_RESOURCE)) { - if (attr.mq_maxmsg > HARD_MSGMAX) - return ERR_PTR(-EINVAL); - } else { - if (attr.mq_maxmsg > msg_max || - attr.mq_msgsize > msgsize_max) - return ERR_PTR(-EINVAL); - } /* store for use during create */ dentry->d_fsdata = &attr; } ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 10/11] enforce rlimits for POSIX mqueue allocation 2004-05-11 9:00 ` [PATCH 9/11] add mq_attr_ok() helper Chris Wright @ 2004-05-11 9:02 ` Chris Wright 2004-05-11 9:04 ` [PATCH 11/11] adjust default mqueue sizes Chris Wright 0 siblings, 1 reply; 12+ messages in thread From: Chris Wright @ 2004-05-11 9:02 UTC (permalink / raw) To: linux-kernel; +Cc: akpm, torvalds, marcelo.tosatti Add a user_struct to the mq_inode_info structure. Charge the maximum number of bytes that could be allocated to a mqueue to the user who creates the mqueue. This is checked against the per user rlimit. --- 2.6-rlimit/ipc/mqueue.c~mqueue_rlimit 2004-05-10 22:28:43.137833864 -0700 +++ 2.6-rlimit/ipc/mqueue.c 2004-05-10 22:30:44.530379392 -0700 @@ -67,6 +66,7 @@ struct sigevent notify; pid_t notify_owner; + struct user_struct *user; /* user who created, for accouting */ struct sock *notify_sock; struct sk_buff *notify_cookie; @@ -114,6 +114,9 @@ if (S_ISREG(mode)) { struct mqueue_inode_info *info; + struct task_struct *p = current; + struct user_struct *u = p->user; + unsigned long mq_bytes, mq_msg_tblsz; inode->i_fop = &mqueue_file_operations; inode->i_size = FILENT_SIZE; @@ -123,8 +126,10 @@ init_waitqueue_head(&info->wait_q); INIT_LIST_HEAD(&info->e_wait_q[0].list); INIT_LIST_HEAD(&info->e_wait_q[1].list); + info->messages = NULL; info->notify_owner = 0; info->qsize = 0; + info->user = NULL; /* set when all is ok */ memset(&info->attr, 0, sizeof(info->attr)); info->attr.mq_maxmsg = DFLT_MSGMAX; info->attr.mq_msgsize = DFLT_MSGSIZEMAX; @@ -132,12 +137,29 @@ info->attr.mq_maxmsg = attr->mq_maxmsg; info->attr.mq_msgsize = attr->mq_msgsize; } - info->messages = kmalloc(info->attr.mq_maxmsg * sizeof(struct msg_msg *), GFP_KERNEL); + mq_msg_tblsz = info->attr.mq_maxmsg * sizeof(struct msg_msg *); + mq_bytes = (mq_msg_tblsz + + (info->attr.mq_maxmsg * info->attr.mq_msgsize)); + + spin_lock(&mq_lock); + if (u->mq_bytes + mq_bytes < u->mq_bytes || + u->mq_bytes + mq_bytes > + p->rlim[RLIMIT_MSGQUEUE].rlim_cur) { + spin_unlock(&mq_lock); + goto out_inode; + } + u->mq_bytes += mq_bytes; + spin_unlock(&mq_lock); + + info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL); if (!info->messages) { - make_bad_inode(inode); - iput(inode); - inode = NULL; + spin_lock(&mq_lock); + u->mq_bytes -= mq_bytes; + spin_unlock(&mq_lock); + goto out_inode; } + /* all is ok */ + info->user = get_uid(u); } else if (S_ISDIR(mode)) { inode->i_nlink++; /* Some things misbehave if size == 0 on a directory */ @@ -147,6 +169,10 @@ } } return inode; +out_inode: + make_bad_inode(inode); + iput(inode); + return NULL; } static int mqueue_fill_super(struct super_block *sb, void *data, int silent) @@ -205,6 +231,8 @@ static void mqueue_delete_inode(struct inode *inode) { struct mqueue_inode_info *info; + struct user_struct *user; + unsigned long mq_bytes; int i; if (S_ISDIR(inode->i_mode)) { @@ -220,10 +248,15 @@ clear_inode(inode); - if (info->messages) { + mq_bytes = (info->attr.mq_maxmsg * sizeof(struct msg_msg *) + + (info->attr.mq_maxmsg * info->attr.mq_msgsize)); + user = info->user; + if (user) { spin_lock(&mq_lock); + user->mq_bytes -= mq_bytes; queues_count--; spin_unlock(&mq_lock); + free_uid(user); } } ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 11/11] adjust default mqueue sizes 2004-05-11 9:02 ` [PATCH 10/11] enforce rlimits for POSIX mqueue allocation Chris Wright @ 2004-05-11 9:04 ` Chris Wright 0 siblings, 0 replies; 12+ messages in thread From: Chris Wright @ 2004-05-11 9:04 UTC (permalink / raw) To: linux-kernel; +Cc: akpm, torvalds, marcelo.tosatti Lower default sizes for POSIX mqueue allocation now that rlimits are in place. --- 2.6-rlimit/ipc/mqueue.c~mqueue_rlimit 2004-05-10 22:28:43.137833864 -0700 +++ 2.6-rlimit/ipc/mqueue.c 2004-05-10 22:30:44.530379392 -0700 @@ -43,10 +43,10 @@ #define CTL_MSGSIZEMAX 4 /* default values */ -#define DFLT_QUEUESMAX 64 /* max number of message queues */ -#define DFLT_MSGMAX 40 /* max number of messages in each queue */ +#define DFLT_QUEUESMAX 256 /* max number of message queues */ +#define DFLT_MSGMAX 10 /* max number of messages in each queue */ #define HARD_MSGMAX (131072/sizeof(void*)) -#define DFLT_MSGSIZEMAX 16384 /* max message size */ +#define DFLT_MSGSIZEMAX 8192 /* max message size */ #define NOTIFY_COOKIE_LEN 32 ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2004-05-11 9:16 UTC | newest] Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2004-05-11 8:42 [PATCH 0/11] rlimits for both queued signals and POSIX mqueues Chris Wright 2004-05-11 8:45 ` [PATCH 1/11] add rlimit entry for controlling queued signals Chris Wright 2004-05-11 8:46 ` [PATCH 2/11] add sigpending field to user_struct Chris Wright 2004-05-11 8:48 ` [PATCH 3/11] pass task_struct in send_signal() Chris Wright 2004-05-11 8:50 ` [PATCH 4/11] add simple get_uid() helper Chris Wright 2004-05-11 8:52 ` [PATCH 5/11] enforce rlimits on queued signals Chris Wright 2004-05-11 8:53 ` [PATCH 6/11] remove unused queued_signals global accounting Chris Wright 2004-05-11 8:56 ` [PATCH 7/11] add rlimit entry for POSIX mqueue allocation Chris Wright 2004-05-11 8:58 ` [PATCH 8/11] add mq_bytes to user_struct Chris Wright 2004-05-11 9:00 ` [PATCH 9/11] add mq_attr_ok() helper Chris Wright 2004-05-11 9:02 ` [PATCH 10/11] enforce rlimits for POSIX mqueue allocation Chris Wright 2004-05-11 9:04 ` [PATCH 11/11] adjust default mqueue sizes Chris Wright
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®