From patchwork Mon Feb 17 11:31:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangweidong X-Patchwork-Id: 320941 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 991AA2C00CC for ; Mon, 17 Feb 2014 22:32:14 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752149AbaBQLcJ (ORCPT ); Mon, 17 Feb 2014 06:32:09 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:25353 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751555AbaBQLcI (ORCPT ); Mon, 17 Feb 2014 06:32:08 -0500 Received: from 172.24.2.119 (EHLO szxeml205-edg.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BPX80853; Mon, 17 Feb 2014 19:31:59 +0800 (CST) Received: from SZXEML424-HUB.china.huawei.com (10.82.67.163) by szxeml205-edg.china.huawei.com (172.24.2.58) with Microsoft SMTP Server (TLS) id 14.3.158.1; Mon, 17 Feb 2014 19:31:58 +0800 Received: from [127.0.0.1] (10.177.18.75) by szxeml424-hub.china.huawei.com (10.82.67.163) with Microsoft SMTP Server id 14.3.158.1; Mon, 17 Feb 2014 19:31:58 +0800 Message-ID: <5301F32C.4040704@huawei.com> Date: Mon, 17 Feb 2014 19:31:56 +0800 From: Wang Weidong User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 MIME-Version: 1.0 To: David Miller CC: Subject: [PATCH] ethtool: check the ethtool_ops is NULL in dev_ethtool X-Originating-IP: [10.177.18.75] X-CFilter-Loop: Reflected Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org some drivers maybe not implement the ethtool_ops with only set NULL. So when call the ethtool cmds will lead to a 'NULL pointer dereference'. So add a checking in dev_ethtool. Signed-off-by: Wang Weidong --- net/core/ethtool.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/core/ethtool.c b/net/core/ethtool.c index 30071de..f418dcb 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c @@ -1499,6 +1499,9 @@ int dev_ethtool(struct net *net, struct ifreq *ifr) if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) return -EPERM; } + + if (!dev->ethtool_ops) + return -EOPNOTSUPP; if (dev->ethtool_ops->begin) { rc = dev->ethtool_ops->begin(dev);