From patchwork Wed Jul 20 08:43:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vegard Nossum X-Patchwork-Id: 9239145 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B25CD60574 for ; Wed, 20 Jul 2016 08:44:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F2C82793D for ; Wed, 20 Jul 2016 08:44:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F30D27AC2; Wed, 20 Jul 2016 08:44:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95B082793D for ; Wed, 20 Jul 2016 08:44:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752006AbcGTIoN (ORCPT ); Wed, 20 Jul 2016 04:44:13 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:49945 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751662AbcGTIoM (ORCPT ); Wed, 20 Jul 2016 04:44:12 -0400 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u6K8hMLb025489 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Jul 2016 08:43:22 GMT Received: from lenuta.oracle.com (dhcp-ukc1-twvpn-1-vpnpool-10-175-163-206.vpn.oracle.com [10.175.163.206]) by userv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u6K8hEmf010566; Wed, 20 Jul 2016 08:43:14 GMT From: Vegard Nossum To: Alexander Aring Cc: linux-wpan@vger.kernel.org, netdev@vger.kernel.org, Vegard Nossum , Lennert Buytenhek , Alexander Aring , Marcel Holtmann , Dmitry Eremin-Solenikov , Sergey Lapin Subject: [PATCH] ieee802154: check device type Date: Wed, 20 Jul 2016 10:43:11 +0200 Message-Id: <1469004191-30920-1-git-send-email-vegard.nossum@oracle.com> X-Mailer: git-send-email 1.9.1 X-Source-IP: userv0022.oracle.com [156.151.31.74] Sender: linux-wpan-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP I've observed a NULL pointer dereference in ieee802154_del_iface() during netlink fuzzing. It's the ->wpan_phy dereference here: phy = dev->ieee802154_ptr->wpan_phy; My bet is that we're not checking that this is an IEEE802154 interface, so let's do what ieee802154_nl_get_dev() is doing. (Maybe we should even be calling this directly?) Cc: Lennert Buytenhek Cc: Alexander Aring Cc: Marcel Holtmann Cc: Dmitry Eremin-Solenikov Cc: Sergey Lapin Signed-off-by: Vegard Nossum Acked-by: Alexander Aring --- net/ieee802154/nl-phy.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/ieee802154/nl-phy.c b/net/ieee802154/nl-phy.c index 77d7301..dc2960b 100644 --- a/net/ieee802154/nl-phy.c +++ b/net/ieee802154/nl-phy.c @@ -286,9 +286,12 @@ int ieee802154_del_iface(struct sk_buff *skb, struct genl_info *info) if (name[nla_len(info->attrs[IEEE802154_ATTR_DEV_NAME]) - 1] != '\0') return -EINVAL; /* name should be null-terminated */ + rc = -ENODEV; dev = dev_get_by_name(genl_info_net(info), name); if (!dev) - return -ENODEV; + return rc; + if (dev->type != ARPHRD_IEEE802154) + goto out; phy = dev->ieee802154_ptr->wpan_phy; BUG_ON(!phy); @@ -342,6 +345,7 @@ nla_put_failure: nlmsg_free(msg); out_dev: wpan_phy_put(phy); +out: if (dev) dev_put(dev);