Skip to content

Commit 9bf76ca

Browse files
miniplitorvalds
authored andcommitted
ipc, msg: forbid negative values for "msg{max,mnb,mni}"
Negative message lengths make no sense -- so don't do negative queue lenghts or identifier counts. Prevent them from getting negative. Also change the underlying data types to be unsigned to avoid hairy surprises with sign extensions in cases where those variables get evaluated in unsigned expressions with bigger data types, e.g size_t. In case a user still wants to have "unlimited" sizes she could just use INT_MAX instead. Signed-off-by: Mathias Krause <minipli@googlemail.com> Cc: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9dc8c89 commit 9bf76ca

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

‎include/linux/ipc_namespace.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ struct ipc_namespace {
3434
int sem_ctls[4];
3535
int used_sems;
3636

37-
int msg_ctlmax;
38-
int msg_ctlmnb;
39-
int msg_ctlmni;
37+
unsigned int msg_ctlmax;
38+
unsigned int msg_ctlmnb;
39+
unsigned int msg_ctlmni;
4040
atomic_t msg_bytes;
4141
atomic_t msg_hdrs;
4242
int auto_msgmni;

‎ipc/ipc_sysctl.c‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
6262
return err;
6363
}
6464

65-
static int proc_ipc_callback_dointvec(ctl_table *table, int write,
65+
static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
6666
void __user *buffer, size_t *lenp, loff_t *ppos)
6767
{
6868
struct ctl_table ipc_table;
@@ -72,7 +72,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
7272
memcpy(&ipc_table, table, sizeof(ipc_table));
7373
ipc_table.data = get_ipc(table);
7474

75-
rc = proc_dointvec(&ipc_table, write, buffer, lenp, ppos);
75+
rc = proc_dointvec_minmax(&ipc_table, write, buffer, lenp, ppos);
7676

7777
if (write && !rc && lenp_bef == *lenp)
7878
/*
@@ -152,15 +152,13 @@ static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
152152
#define proc_ipc_dointvec NULL
153153
#define proc_ipc_dointvec_minmax NULL
154154
#define proc_ipc_dointvec_minmax_orphans NULL
155-
#define proc_ipc_callback_dointvec NULL
155+
#define proc_ipc_callback_dointvec_minmax NULL
156156
#define proc_ipcauto_dointvec_minmax NULL
157157
#endif
158158

159159
static int zero;
160160
static int one = 1;
161-
#ifdef CONFIG_CHECKPOINT_RESTORE
162161
static int int_max = INT_MAX;
163-
#endif
164162

165163
static struct ctl_table ipc_kern_table[] = {
166164
{
@@ -198,21 +196,27 @@ static struct ctl_table ipc_kern_table[] = {
198196
.data = &init_ipc_ns.msg_ctlmax,
199197
.maxlen = sizeof (init_ipc_ns.msg_ctlmax),
200198
.mode = 0644,
201-
.proc_handler = proc_ipc_dointvec,
199+
.proc_handler = proc_ipc_dointvec_minmax,
200+
.extra1 = &zero,
201+
.extra2 = &int_max,
202202
},
203203
{
204204
.procname = "msgmni",
205205
.data = &init_ipc_ns.msg_ctlmni,
206206
.maxlen = sizeof (init_ipc_ns.msg_ctlmni),
207207
.mode = 0644,
208-
.proc_handler = proc_ipc_callback_dointvec,
208+
.proc_handler = proc_ipc_callback_dointvec_minmax,
209+
.extra1 = &zero,
210+
.extra2 = &int_max,
209211
},
210212
{
211213
.procname = "msgmnb",
212214
.data = &init_ipc_ns.msg_ctlmnb,
213215
.maxlen = sizeof (init_ipc_ns.msg_ctlmnb),
214216
.mode = 0644,
215-
.proc_handler = proc_ipc_dointvec,
217+
.proc_handler = proc_ipc_dointvec_minmax,
218+
.extra1 = &zero,
219+
.extra2 = &int_max,
216220
},
217221
{
218222
.procname = "sem",

0 commit comments

Comments
 (0)