From patchwork Tue Feb 18 01:42:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangweidong X-Patchwork-Id: 321255 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 4ED262C0091 for ; Tue, 18 Feb 2014 12:43:28 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752735AbaBRBnY (ORCPT ); Mon, 17 Feb 2014 20:43:24 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:35962 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752394AbaBRBnX (ORCPT ); Mon, 17 Feb 2014 20:43:23 -0500 Received: from 172.24.2.119 (EHLO szxeml205-edg.china.huawei.com) ([172.24.2.119]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id AKT38307; Tue, 18 Feb 2014 09:43:20 +0800 (CST) Received: from SZXEML451-HUB.china.huawei.com (10.82.67.194) by szxeml205-edg.china.huawei.com (172.24.2.58) with Microsoft SMTP Server (TLS) id 14.3.158.1; Tue, 18 Feb 2014 09:42:59 +0800 Received: from [127.0.0.1] (10.177.18.75) by szxeml451-hub.china.huawei.com (10.82.67.194) with Microsoft SMTP Server id 14.3.158.1; Tue, 18 Feb 2014 09:42:57 +0800 Message-ID: <5302BAA0.9060905@huawei.com> Date: Tue, 18 Feb 2014 09:42: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: , Daniel Borkmann Subject: [PATCH v2] ethtool: check the ethtool_ops is NULL in dev_ethtool References: <5301F32C.4040704@huawei.com> In-Reply-To: <5301F32C.4040704@huawei.com> 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 to ethtool_ops. So when call the ethtool devx will lead to a 'NULL pointer dereference'. So add a check in dev_ethtool Signed-off-by: Wang Weidong --- Change note: v2: fix a trailing whitespace/tab pointed out by Daniel --- net/core/ethtool.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/core/ethtool.c b/net/core/ethtool.c index 30071de..c8cfd8f 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c @@ -1500,6 +1500,9 @@ int dev_ethtool(struct net *net, struct ifreq *ifr) return -EPERM; } + if (!dev->ethtool_ops) + return -EOPNOTSUPP; + if (dev->ethtool_ops->begin) { rc = dev->ethtool_ops->begin(dev); if (rc < 0)