Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

David Fries and committed by
Greg Kroah-Hartman
a30cfa47 55c4e640

+6
+6
drivers/connector/connector.c
··· 141 141 */ 142 142 static int cn_call_callback(struct sk_buff *skb) 143 143 { 144 + struct nlmsghdr *nlh; 144 145 struct cn_callback_entry *i, *cbq = NULL; 145 146 struct cn_dev *dev = &cdev; 146 147 struct cn_msg *msg = nlmsg_data(nlmsg_hdr(skb)); 147 148 struct netlink_skb_parms *nsp = &NETLINK_CB(skb); 148 149 int err = -ENODEV; 150 + 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; 149 155 150 156 spin_lock_bh(&dev->cbdev->queue_lock); 151 157 list_for_each_entry(i, &dev->cbdev->queue_list, callback_entry) {