Skip to content

Commit

Permalink
ipc/mqueue: improve exception handling in do_mq_notify()
Browse files Browse the repository at this point in the history
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/[email protected]
Signed-off-by: Markus Elfring <[email protected]>
Cc: Davidlohr Bueso <[email protected]>
Cc: Manfred Spraul <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
elfring authored and torvalds committed Sep 26, 2019
1 parent 97b0b1a commit c231740
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions ipc/mqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -1240,15 +1240,14 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification)

/* create the notify skb */
nc = alloc_skb(NOTIFY_COOKIE_LEN, GFP_KERNEL);
if (!nc) {
ret = -ENOMEM;
goto out;
}
if (!nc)
return -ENOMEM;

if (copy_from_user(nc->data,
notification->sigev_value.sival_ptr,
NOTIFY_COOKIE_LEN)) {
ret = -EFAULT;
goto out;
goto free_skb;
}

/* TODO: add a header? */
Expand All @@ -1264,8 +1263,7 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification)
fdput(f);
if (IS_ERR(sock)) {
ret = PTR_ERR(sock);
sock = NULL;
goto out;
goto free_skb;
}

timeo = MAX_SCHEDULE_TIMEOUT;
Expand All @@ -1274,11 +1272,8 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification)
sock = NULL;
goto retry;
}
if (ret) {
sock = NULL;
nc = NULL;
goto out;
}
if (ret)
return ret;
}
}

Expand Down Expand Up @@ -1334,6 +1329,7 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification)
if (sock)
netlink_detachskb(sock, nc);
else
free_skb:
dev_kfree_skb(nc);

return ret;
Expand Down

0 comments on commit c231740

Please sign in to comment.