[glsdk/meta-ti-glsdk.git] / recipes-kernel / linux / linux-ti33x-psp-3.2 / 3.2.7 / 0013-relay-prevent-integer-overflow-in-relay_open.patch
1 From a0cbc2da8ed19f3affb50a249dc16a04d5d6f42f Mon Sep 17 00:00:00 2001
2 From: Dan Carpenter <dan.carpenter@oracle.com>
3 Date: Fri, 10 Feb 2012 09:03:58 +0100
4 Subject: [PATCH 13/30] relay: prevent integer overflow in relay_open()
6 commit f6302f1bcd75a042df69866d98b8d775a668f8f1 upstream.
8 "subbuf_size" and "n_subbufs" come from the user and they need to be
9 capped to prevent an integer overflow.
11 Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
12 Signed-off-by: Jens Axboe <axboe@kernel.dk>
13 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
14 ---
15 kernel/relay.c | 10 ++++++++--
16 1 files changed, 8 insertions(+), 2 deletions(-)
18 diff --git a/kernel/relay.c b/kernel/relay.c
19 index 226fade..b6f803a 100644
20 --- a/kernel/relay.c
21 +++ b/kernel/relay.c
22 @@ -164,10 +164,14 @@ depopulate:
23 */
24 static struct rchan_buf *relay_create_buf(struct rchan *chan)
25 {
26 - struct rchan_buf *buf = kzalloc(sizeof(struct rchan_buf), GFP_KERNEL);
27 - if (!buf)
28 + struct rchan_buf *buf;
29 +
30 + if (chan->n_subbufs > UINT_MAX / sizeof(size_t *))
31 return NULL;
33 + buf = kzalloc(sizeof(struct rchan_buf), GFP_KERNEL);
34 + if (!buf)
35 + return NULL;
36 buf->padding = kmalloc(chan->n_subbufs * sizeof(size_t *), GFP_KERNEL);
37 if (!buf->padding)
38 goto free_buf;
39 @@ -574,6 +578,8 @@ struct rchan *relay_open(const char *base_filename,
41 if (!(subbuf_size && n_subbufs))
42 return NULL;
43 + if (subbuf_size > UINT_MAX / n_subbufs)
44 + return NULL;
46 chan = kzalloc(sizeof(struct rchan), GFP_KERNEL);
47 if (!chan)
48 --
49 1.7.7.4