Commit c231740d authored by Markus Elfring's avatar Markus Elfring Committed by Linus Torvalds

ipc/mqueue: improve exception handling in do_mq_notify()

Null pointers were assigned to local variables in a few cases as exception
handling.  The jump target “out” was used where no meaningful data
processing actions should eventually be performed by branches of an if
statement then.  Use an additional jump target for calling dev_kfree_skb()
directly.

Return also directly after error conditions were detected when no extra
clean-up is needed by this function implementation.

Link: http://lkml.kernel.org/r/592ef10e-0b69-72d0-9789-fc48f638fdfd@web.deSigned-off-by: default avatarMarkus Elfring <elfring@users.sourceforge.net>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Manfred Spraul <manfred@colorfullife.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 97b0b1ad
...@@ -1240,15 +1240,14 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification) ...@@ -1240,15 +1240,14 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification)
/* create the notify skb */ /* create the notify skb */
nc = alloc_skb(NOTIFY_COOKIE_LEN, GFP_KERNEL); nc = alloc_skb(NOTIFY_COOKIE_LEN, GFP_KERNEL);
if (!nc) { if (!nc)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
if (copy_from_user(nc->data, if (copy_from_user(nc->data,
notification->sigev_value.sival_ptr, notification->sigev_value.sival_ptr,
NOTIFY_COOKIE_LEN)) { NOTIFY_COOKIE_LEN)) {
ret = -EFAULT; ret = -EFAULT;
goto out; goto free_skb;
} }
/* TODO: add a header? */ /* TODO: add a header? */
...@@ -1264,8 +1263,7 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification) ...@@ -1264,8 +1263,7 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification)
fdput(f); fdput(f);
if (IS_ERR(sock)) { if (IS_ERR(sock)) {
ret = PTR_ERR(sock); ret = PTR_ERR(sock);
sock = NULL; goto free_skb;
goto out;
} }
timeo = MAX_SCHEDULE_TIMEOUT; timeo = MAX_SCHEDULE_TIMEOUT;
...@@ -1274,11 +1272,8 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification) ...@@ -1274,11 +1272,8 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification)
sock = NULL; sock = NULL;
goto retry; goto retry;
} }
if (ret) { if (ret)
sock = NULL; return ret;
nc = NULL;
goto out;
}
} }
} }
...@@ -1334,6 +1329,7 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification) ...@@ -1334,6 +1329,7 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification)
if (sock) if (sock)
netlink_detachskb(sock, nc); netlink_detachskb(sock, nc);
else else
free_skb:
dev_kfree_skb(nc); dev_kfree_skb(nc);
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment