| 1 |
Index: linux-2.6.18/kernel/vserver/limit.c
|
| 2 |
===================================================================
|
| 3 |
--- linux-2.6.18.orig/kernel/vserver/limit.c
|
| 4 |
+++ linux-2.6.18/kernel/vserver/limit.c
|
| 5 |
@@ -41,31 +41,53 @@ const char *vlimit_name[NUM_LIMITS] = {
|
| 6 |
|
| 7 |
EXPORT_SYMBOL_GPL(vlimit_name);
|
| 8 |
|
| 9 |
+#define MASK_ENTRY(x) (1 << (x))
|
| 10 |
|
| 11 |
-static int is_valid_rlimit(int id)
|
| 12 |
-{
|
| 13 |
- int valid = 0;
|
| 14 |
-
|
| 15 |
- switch (id) {
|
| 16 |
- case RLIMIT_RSS:
|
| 17 |
- case RLIMIT_NPROC:
|
| 18 |
- case RLIMIT_NOFILE:
|
| 19 |
- case RLIMIT_MEMLOCK:
|
| 20 |
- case RLIMIT_AS:
|
| 21 |
- case RLIMIT_LOCKS:
|
| 22 |
- case RLIMIT_MSGQUEUE:
|
| 23 |
-
|
| 24 |
- case VLIMIT_NSOCK:
|
| 25 |
- case VLIMIT_OPENFD:
|
| 26 |
- case VLIMIT_ANON:
|
| 27 |
- case VLIMIT_SHMEM:
|
| 28 |
- case VLIMIT_DENTRY:
|
| 29 |
- valid = 1;
|
| 30 |
- break;
|
| 31 |
- }
|
| 32 |
- return valid;
|
| 33 |
+const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
|
| 34 |
+ /* minimum */
|
| 35 |
+ 0
|
| 36 |
+ , /* softlimit */
|
| 37 |
+ MASK_ENTRY( RLIMIT_RSS ) |
|
| 38 |
+ MASK_ENTRY( VLIMIT_ANON ) |
|
| 39 |
+ 0
|
| 40 |
+ , /* maximum */
|
| 41 |
+ MASK_ENTRY( RLIMIT_RSS ) |
|
| 42 |
+ MASK_ENTRY( RLIMIT_NPROC ) |
|
| 43 |
+ MASK_ENTRY( RLIMIT_NOFILE ) |
|
| 44 |
+ MASK_ENTRY( RLIMIT_MEMLOCK ) |
|
| 45 |
+ MASK_ENTRY( RLIMIT_AS ) |
|
| 46 |
+ MASK_ENTRY( RLIMIT_LOCKS ) |
|
| 47 |
+ MASK_ENTRY( RLIMIT_MSGQUEUE ) |
|
| 48 |
+
|
| 49 |
+ MASK_ENTRY( VLIMIT_NSOCK ) |
|
| 50 |
+ MASK_ENTRY( VLIMIT_OPENFD ) |
|
| 51 |
+ MASK_ENTRY( VLIMIT_ANON ) |
|
| 52 |
+ MASK_ENTRY( VLIMIT_SHMEM ) |
|
| 53 |
+ MASK_ENTRY( VLIMIT_DENTRY ) |
|
| 54 |
+ 0
|
| 55 |
+};
|
| 56 |
+ /* accounting only */
|
| 57 |
+uint32_t account_mask =
|
| 58 |
+ MASK_ENTRY( VLIMIT_SEMARY ) |
|
| 59 |
+ MASK_ENTRY( VLIMIT_NSEMS ) |
|
| 60 |
+ 0;
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+static int is_valid_vlimit(int id)
|
| 64 |
+{
|
| 65 |
+ uint32_t mask = vlimit_mask.minimum |
|
| 66 |
+ vlimit_mask.softlimit | vlimit_mask.maximum;
|
| 67 |
+ return mask & (1 << id);
|
| 68 |
+}
|
| 69 |
+
|
| 70 |
+static int is_accounted_vlimit(int id)
|
| 71 |
+{
|
| 72 |
+ if (is_valid_vlimit(id))
|
| 73 |
+ return 1;
|
| 74 |
+ return account_mask & (1 << id);
|
| 75 |
}
|
| 76 |
|
| 77 |
+
|
| 78 |
static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
|
| 79 |
{
|
| 80 |
rlim_t limit = __rlim_soft(&vxi->limit, id);
|
| 81 |
@@ -81,7 +103,7 @@ static inline uint64_t vc_get_hard(struc
|
| 82 |
static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
|
| 83 |
uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
|
| 84 |
{
|
| 85 |
- if (!is_valid_rlimit(id))
|
| 86 |
+ if (!is_valid_vlimit(id))
|
| 87 |
return -EINVAL;
|
| 88 |
|
| 89 |
if (minimum)
|
| 90 |
@@ -114,7 +136,7 @@ int vc_get_rlimit(struct vx_info *vxi, v
|
| 91 |
static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
|
| 92 |
uint64_t minimum, uint64_t softlimit, uint64_t maximum)
|
| 93 |
{
|
| 94 |
- if (!is_valid_rlimit(id))
|
| 95 |
+ if (!is_valid_vlimit(id))
|
| 96 |
return -EINVAL;
|
| 97 |
|
| 98 |
if (maximum != CRLIM_KEEP)
|
| 99 |
@@ -176,26 +198,7 @@ int vc_get_rlimit_x32(struct vx_info *vx
|
| 100 |
|
| 101 |
int vc_get_rlimit_mask(uint32_t id, void __user *data)
|
| 102 |
{
|
| 103 |
- static struct vcmd_ctx_rlimit_mask_v0 mask = {
|
| 104 |
- /* minimum */
|
| 105 |
- 0
|
| 106 |
- , /* softlimit */
|
| 107 |
- (1 << RLIMIT_RSS) |
|
| 108 |
- (1 << VLIMIT_ANON) |
|
| 109 |
- 0
|
| 110 |
- , /* maximum */
|
| 111 |
- (1 << RLIMIT_RSS) |
|
| 112 |
- (1 << RLIMIT_NPROC) |
|
| 113 |
- (1 << RLIMIT_NOFILE) |
|
| 114 |
- (1 << RLIMIT_MEMLOCK) |
|
| 115 |
- (1 << RLIMIT_LOCKS) |
|
| 116 |
- (1 << RLIMIT_AS) |
|
| 117 |
- (1 << VLIMIT_ANON) |
|
| 118 |
- (1 << VLIMIT_DENTRY) |
|
| 119 |
- 0
|
| 120 |
- };
|
| 121 |
-
|
| 122 |
- if (copy_to_user(data, &mask, sizeof(mask)))
|
| 123 |
+ if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
|
| 124 |
return -EFAULT;
|
| 125 |
return 0;
|
| 126 |
}
|
| 127 |
@@ -231,7 +234,7 @@ int vc_rlimit_stat(struct vx_info *vxi,
|
| 128 |
return -EFAULT;
|
| 129 |
|
| 130 |
id = vc_data.id;
|
| 131 |
- if (!is_valid_rlimit(id))
|
| 132 |
+ if (!is_accounted_vlimit(id))
|
| 133 |
return -EINVAL;
|
| 134 |
|
| 135 |
vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
|