rlimits for both queued signals and POSIX mqueues
Subsystems (10)
cover rlimits for both queued signals and POSIX mqueues
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
PATCH 1/11 add rlimit entry for controlling queued signals
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 =====
include/asm-alpha/resource.h +5 -3
@@ -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 =====
include/asm-arm/resource.h +3 -1
@@ -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 =====
include/asm-arm26/resource.h +3 -1
@@ -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 =====
include/asm-cris/resource.h +5 -3
@@ -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 =====
include/asm-h8300/resource.h +4 -2
@@ -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 =====
include/asm-i386/resource.h +5 -2
@@ -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 =====
include/asm-ia64/resource.h +3 -1
@@ -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 =====
include/asm-m68k/resource.h +4 -2
@@ -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 =====
include/asm-mips/resource.h +3 -1
@@ -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 =====
include/asm-parisc/resource.h +3 -1
@@ -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 =====
include/asm-ppc/resource.h +3 -1
@@ -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 =====
include/asm-ppc64/resource.h +3 -1
@@ -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 =====
include/asm-s390/resource.h +4 -2
@@ -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 =====
include/asm-sh/resource.h +3 -1
@@ -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 =====
include/asm-sparc/resource.h +6 -4
@@ -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 =====
include/asm-sparc64/resource.h +6 -4
@@ -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 =====
include/asm-v850/resource.h +4 -2
@@ -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 =====
include/asm-x86_64/resource.h +4 -2
@@ -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 =====
include/linux/signal.h +3 -0
@@ -7,6 +7,9 @@#include <asm/siginfo.h> #ifdef __KERNEL__ + +#define MAX_SIGPENDING 1024 +/* * Real Time signals may be queued. */
PATCH 2/11 add sigpending field to user_struct
Add sigpending field to user_struct, and make sure it's properly initialized.
===== include/linux/sched.h 1.210 vs edited =====
include/linux/sched.h +1 -0
@@ -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 =====
kernel/user.c +3 -1
@@ -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
PATCH 3/11 pass task_struct in send_signal()
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 =====
kernel/signal.c +4 -3
@@ -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;
PATCH 4/11 add simple get_uid() helper
Add simple helper function to grab a reference to a user_struct.
===== include/linux/sched.h 1.210 vs edited =====
include/linux/sched.h +5 -0
@@ -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 *);
PATCH 5/11 enforce rlimits on queued signals
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 =====
include/linux/signal.h +1 -0
@@ -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 =====
kernel/signal.c +11 -6
@@ -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 :
PATCH 6/11 remove unused queued_signals global accounting
Remove unused queued_signals global accounting.
===== kernel/signal.c 1.115 vs edited =====
kernel/signal.c +0 -3
@@ -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 =====
kernel/sysctl.c +0 -18
@@ -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,
PATCH 7/11 add rlimit entry for POSIX mqueue allocation
Add an rlimit entry to control the maximum number of bytes a user can allocate to a POSIX mqueue.
arch/alpha/kernel/init_task.c renamed from arch/alpha/kernel/init_task.c~mqueue_rlimit +1 -0
@@ -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>
arch/arm/kernel/init_task.c renamed from arch/arm/kernel/init_task.c~mqueue_rlimit +1 -0
@@ -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>
include/asm-arm26/resource.h renamed from include/asm-arm26/resource.h~mqueue_rlimit +3 -1
@@ -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__ */
arch/h8300/kernel/init_task.c renamed from arch/h8300/kernel/init_task.c~mqueue_rlimit +1 -0
@@ -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>
arch/i386/kernel/init_task.c renamed from arch/i386/kernel/init_task.c~mqueue_rlimit +1 -0
@@ -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>
arch/ia64/kernel/init_task.c renamed from arch/ia64/kernel/init_task.c~mqueue_rlimit +1 -0
@@ -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>
arch/m68knommu/kernel/init_task.c renamed from arch/m68knommu/kernel/init_task.c~mqueue_rlimit +1 -0
@@ -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>
arch/mips/kernel/init_task.c renamed from arch/mips/kernel/init_task.c~mqueue_rlimit +1 -0
@@ -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>
arch/parisc/kernel/init_task.c renamed from arch/parisc/kernel/init_task.c~mqueue_rlimit +1 -0
@@ -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>
arch/ppc64/kernel/init_task.c renamed from arch/ppc64/kernel/init_task.c~mqueue_rlimit +1 -0
@@ -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 ;
arch/s390/kernel/init_task.c renamed from arch/s390/kernel/init_task.c~mqueue_rlimit +1 -0
@@ -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>
arch/sh/kernel/init_task.c renamed from arch/sh/kernel/init_task.c~mqueue_rlimit +1 -0
@@ -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>
arch/sparc/kernel/init_task.c renamed from arch/sparc/kernel/init_task.c~mqueue_rlimit +1 -0
@@ -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>
arch/sparc64/kernel/init_task.c renamed from arch/sparc64/kernel/init_task.c~mqueue_rlimit +1 -0
@@ -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>
arch/um/kernel/init_task.c renamed from arch/um/kernel/init_task.c~mqueue_rlimit +1 -0
@@ -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"
arch/v850/kernel/init_task.c renamed from arch/v850/kernel/init_task.c~mqueue_rlimit +1 -0
@@ -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>
arch/x86_64/kernel/init_task.c renamed from arch/x86_64/kernel/init_task.c~mqueue_rlimit +1 -0
@@ -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>
arch/arm26/kernel/init_task.c renamed from arch/arm26/kernel/init_task.c~mqueue_rlimit +1 -0
@@ -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>
include/asm-alpha/resource.h renamed from include/asm-alpha/resource.h~mqueue_rlimit +3 -1
@@ -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__ */
include/asm-arm/resource.h renamed from include/asm-arm/resource.h~mqueue_rlimit +3 -1
@@ -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__ */
include/asm-cris/resource.h renamed from include/asm-cris/resource.h~mqueue_rlimit +3 -1
@@ -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__ */
include/asm-h8300/resource.h renamed from include/asm-h8300/resource.h~mqueue_rlimit +3 -1
@@ -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__ */
include/asm-i386/resource.h renamed from include/asm-i386/resource.h~mqueue_rlimit +3 -1
@@ -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__ */
include/asm-ia64/resource.h renamed from include/asm-ia64/resource.h~mqueue_rlimit +3 -1
@@ -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__ */
include/asm-m68k/resource.h renamed from include/asm-m68k/resource.h~mqueue_rlimit +3 -1
@@ -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__ */
include/asm-mips/resource.h renamed from include/asm-mips/resource.h~mqueue_rlimit +3 -1
@@ -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__ */
include/asm-parisc/resource.h renamed from include/asm-parisc/resource.h~mqueue_rlimit +3 -1
@@ -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__ */
include/asm-ppc/resource.h renamed from include/asm-ppc/resource.h~mqueue_rlimit +3 -1
@@ -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__ */
include/asm-ppc64/resource.h renamed from include/asm-ppc64/resource.h~mqueue_rlimit +3 -1
@@ -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__ */
include/asm-s390/resource.h renamed from include/asm-s390/resource.h~mqueue_rlimit +3 -1
@@ -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__ */
include/asm-sh/resource.h renamed from include/asm-sh/resource.h~mqueue_rlimit +3 -1
@@ -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__ */
include/asm-sparc/resource.h renamed from include/asm-sparc/resource.h~mqueue_rlimit +3 -1
@@ -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__ */
include/asm-sparc64/resource.h renamed from include/asm-sparc64/resource.h~mqueue_rlimit +3 -1
@@ -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__ */
include/asm-v850/resource.h renamed from include/asm-v850/resource.h~mqueue_rlimit +3 -1
@@ -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__ */
include/asm-x86_64/resource.h renamed from include/asm-x86_64/resource.h~mqueue_rlimit +3 -1
@@ -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__ */
include/linux/mqueue.h renamed from include/linux/mqueue.h~mqueue_rlimit +2 -0
@@ -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 819200struct mq_attr {long mq_flags;/* message queue flags */
PATCH 8/11 add mq_bytes to user_struct
Add mq_bytes field to user_struct, and make sure it's properly initialized.
include/linux/sched.h renamed from include/linux/sched.h~mqueue_rlimit +2 -0
@@ -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;
kernel/user.c renamed from kernel/user.c~mqueue_rlimit +3 -0
@@ -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..
PATCH 9/11 add mq_attr_ok() helper
Add helper function mq_attr_ok() to do mq_attr sanity checking, and do some extra overlow checking.
ipc/mqueue.c renamed from ipc/mqueue.c~mqueue_rlimit +23 -10
@@ -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; }
PATCH 10/11 enforce rlimits for POSIX mqueue allocation
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.
ipc/mqueue.c renamed from ipc/mqueue.c~mqueue_rlimit +39 -5
@@ -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); } }
PATCH 11/11 adjust default mqueue sizes
Lower default sizes for POSIX mqueue allocation now that rlimits are in place.
ipc/mqueue.c renamed from ipc/mqueue.c~mqueue_rlimit +3 -3
@@ -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