From patchwork Wed Nov 30 14:03:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schmidt X-Patchwork-Id: 9454403 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 8C9396071C for ; Wed, 30 Nov 2016 14:03:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8166E281E1 for ; Wed, 30 Nov 2016 14:03:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 759082843B; Wed, 30 Nov 2016 14:03:45 +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 38B4B281E1 for ; Wed, 30 Nov 2016 14:03:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757327AbcK3ODi (ORCPT ); Wed, 30 Nov 2016 09:03:38 -0500 Received: from proxima.lasnet.de ([78.47.171.185]:52065 "EHLO proxima.lasnet.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750922AbcK3ODh (ORCPT ); Wed, 30 Nov 2016 09:03:37 -0500 Received: from workmachine.Speedport_W_724V_09011603_00_023 (p20030048092FF3679A8389FFFE20FF3F.dip0.t-ipconnect.de [IPv6:2003:48:92f:f367:9a83:89ff:fe20:ff3f]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: stefan@sostec.de) by proxima.lasnet.de (Postfix) with ESMTPSA id C5A04C5320; Wed, 30 Nov 2016 15:03:34 +0100 (CET) From: Stefan Schmidt To: marcel@holtmann.org Cc: linux-wpan@vger.kernel.org, Alexander Aring , "vegard.nossum@oracle.com" , Lennert Buytenhek , Alexander Aring , Dmitry Eremin-Solenikov , Sergey Lapin , Stefan Schmidt Subject: [PATCH bluetooth-next 1/5] ieee802154: check device type Date: Wed, 30 Nov 2016 15:03:21 +0100 Message-Id: <1480514605-30926-2-git-send-email-stefan@osg.samsung.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1480514605-30926-1-git-send-email-stefan@osg.samsung.com> References: <1480514605-30926-1-git-send-email-stefan@osg.samsung.com> 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 From: "vegard.nossum@oracle.com" 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 Signed-off-by: Stefan Schmidt --- 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 @@ int ieee802154_del_iface(struct sk_buff *skb, struct genl_info *info) nlmsg_free(msg); out_dev: wpan_phy_put(phy); +out: if (dev) dev_put(dev);