diff options
author | Peter Hurley <peter@hurleysoftware.com> | 2013-04-30 22:14:25 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-05-01 11:12:57 -0400 |
commit | 3d8fa456d5ed22ce8db085a89a037b87568b2b64 (patch) | |
tree | 3e8351d43bea10a10a553f10d1029dcb240a1c39 /ipc | |
parent | 08d76760832993050ad8c25e63b56773ef2ca303 (diff) |
ipc: clamp with min()
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Acked-by: Stanislav Kinsbursky <skinsbursky@parallels.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/msgutil.c | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/ipc/msgutil.c b/ipc/msgutil.c index 5df8e4bf1db0..98b1c2b476cc 100644 --- a/ipc/msgutil.c +++ b/ipc/msgutil.c | |||
@@ -41,8 +41,8 @@ struct msg_msgseg { | |||
41 | /* the next part of the message follows immediately */ | 41 | /* the next part of the message follows immediately */ |
42 | }; | 42 | }; |
43 | 43 | ||
44 | #define DATALEN_MSG (PAGE_SIZE-sizeof(struct msg_msg)) | 44 | #define DATALEN_MSG (int)(PAGE_SIZE-sizeof(struct msg_msg)) |
45 | #define DATALEN_SEG (PAGE_SIZE-sizeof(struct msg_msgseg)) | 45 | #define DATALEN_SEG (int)(PAGE_SIZE-sizeof(struct msg_msgseg)) |
46 | 46 | ||
47 | struct msg_msg *load_msg(const void __user *src, int len) | 47 | struct msg_msg *load_msg(const void __user *src, int len) |
48 | { | 48 | { |
@@ -51,10 +51,7 @@ struct msg_msg *load_msg(const void __user *src, int len) | |||
51 | int err; | 51 | int err; |
52 | int alen; | 52 | int alen; |
53 | 53 | ||
54 | alen = len; | 54 | alen = min(len, DATALEN_MSG); |
55 | if (alen > DATALEN_MSG) | ||
56 | alen = DATALEN_MSG; | ||
57 | |||
58 | msg = kmalloc(sizeof(*msg) + alen, GFP_KERNEL); | 55 | msg = kmalloc(sizeof(*msg) + alen, GFP_KERNEL); |
59 | if (msg == NULL) | 56 | if (msg == NULL) |
60 | return ERR_PTR(-ENOMEM); | 57 | return ERR_PTR(-ENOMEM); |
@@ -72,9 +69,7 @@ struct msg_msg *load_msg(const void __user *src, int len) | |||
72 | pseg = &msg->next; | 69 | pseg = &msg->next; |
73 | while (len > 0) { | 70 | while (len > 0) { |
74 | struct msg_msgseg *seg; | 71 | struct msg_msgseg *seg; |
75 | alen = len; | 72 | alen = min(len, DATALEN_SEG); |
76 | if (alen > DATALEN_SEG) | ||
77 | alen = DATALEN_SEG; | ||
78 | seg = kmalloc(sizeof(*seg) + alen, | 73 | seg = kmalloc(sizeof(*seg) + alen, |
79 | GFP_KERNEL); | 74 | GFP_KERNEL); |
80 | if (seg == NULL) { | 75 | if (seg == NULL) { |
@@ -113,19 +108,14 @@ struct msg_msg *copy_msg(struct msg_msg *src, struct msg_msg *dst) | |||
113 | if (src->m_ts > dst->m_ts) | 108 | if (src->m_ts > dst->m_ts) |
114 | return ERR_PTR(-EINVAL); | 109 | return ERR_PTR(-EINVAL); |
115 | 110 | ||
116 | alen = len; | 111 | alen = min(len, DATALEN_MSG); |
117 | if (alen > DATALEN_MSG) | ||
118 | alen = DATALEN_MSG; | ||
119 | |||
120 | memcpy(dst + 1, src + 1, alen); | 112 | memcpy(dst + 1, src + 1, alen); |
121 | 113 | ||
122 | len -= alen; | 114 | len -= alen; |
123 | dst_pseg = dst->next; | 115 | dst_pseg = dst->next; |
124 | src_pseg = src->next; | 116 | src_pseg = src->next; |
125 | while (len > 0) { | 117 | while (len > 0) { |
126 | alen = len; | 118 | alen = min(len, DATALEN_SEG); |
127 | if (alen > DATALEN_SEG) | ||
128 | alen = DATALEN_SEG; | ||
129 | memcpy(dst_pseg + 1, src_pseg + 1, alen); | 119 | memcpy(dst_pseg + 1, src_pseg + 1, alen); |
130 | dst_pseg = dst_pseg->next; | 120 | dst_pseg = dst_pseg->next; |
131 | len -= alen; | 121 | len -= alen; |
@@ -148,9 +138,7 @@ int store_msg(void __user *dest, struct msg_msg *msg, int len) | |||
148 | int alen; | 138 | int alen; |
149 | struct msg_msgseg *seg; | 139 | struct msg_msgseg *seg; |
150 | 140 | ||
151 | alen = len; | 141 | alen = min(len, DATALEN_MSG); |
152 | if (alen > DATALEN_MSG) | ||
153 | alen = DATALEN_MSG; | ||
154 | if (copy_to_user(dest, msg + 1, alen)) | 142 | if (copy_to_user(dest, msg + 1, alen)) |
155 | return -1; | 143 | return -1; |
156 | 144 | ||
@@ -158,9 +146,7 @@ int store_msg(void __user *dest, struct msg_msg *msg, int len) | |||
158 | dest = ((char __user *)dest) + alen; | 146 | dest = ((char __user *)dest) + alen; |
159 | seg = msg->next; | 147 | seg = msg->next; |
160 | while (len > 0) { | 148 | while (len > 0) { |
161 | alen = len; | 149 | alen = min(len, DATALEN_SEG); |
162 | if (alen > DATALEN_SEG) | ||
163 | alen = DATALEN_SEG; | ||
164 | if (copy_to_user(dest, seg + 1, alen)) | 150 | if (copy_to_user(dest, seg + 1, alen)) |
165 | return -1; | 151 | return -1; |
166 | len -= alen; | 152 | len -= alen; |