Skip to content

Commit a30cfa4

Browse files
dfriesgregkh
authored andcommitted
cn: verify msg->len before making callback
The struct cn_msg len field comes from userspace and needs to be validated. More logical to do so here where the cn_msg pointer is pulled out of the sk_buff than the callback which is passed cn_msg * and might assume no validation is needed. Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Acked-by: Evgeniy Polyakov <zbr@ioremap.net> Signed-off-by: David Fries <David@Fries.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 55c4e64 commit a30cfa4

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎drivers/connector/connector.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,18 @@ EXPORT_SYMBOL_GPL(cn_netlink_send);
141141
*/
142142
static int cn_call_callback(struct sk_buff *skb)
143143
{
144+
struct nlmsghdr *nlh;
144145
struct cn_callback_entry *i, *cbq = NULL;
145146
struct cn_dev *dev = &cdev;
146147
struct cn_msg *msg = nlmsg_data(nlmsg_hdr(skb));
147148
struct netlink_skb_parms *nsp = &NETLINK_CB(skb);
148149
int err = -ENODEV;
149150

151+
/* verify msg->len is within skb */
152+
nlh = nlmsg_hdr(skb);
153+
if (nlh->nlmsg_len < NLMSG_HDRLEN + sizeof(struct cn_msg) + msg->len)
154+
return -EINVAL;
155+
150156
spin_lock_bh(&dev->cbdev->queue_lock);
151157
list_for_each_entry(i, &dev->cbdev->queue_list, callback_entry) {
152158
if (cn_cb_equal(&i->id.id, &msg->id)) {

0 commit comments

Comments
 (0)