Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3407796imu; Sat, 24 Nov 2018 04:17:50 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xc1qJ4eYGPPv/1zJLUVgBFKFIXVqhAntTSCGe+g+k5zW5YxgUJ/mUofD07Io43STStp2yA X-Received: by 2002:a17:902:9f93:: with SMTP id g19mr19301842plq.195.1543061870403; Sat, 24 Nov 2018 04:17:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543061870; cv=none; d=google.com; s=arc-20160816; b=k/q4f80AX+cEA74o/YmZC23dubRFg3u5ZlTChAIA276/k3AOUAz2zXbjCC0kzYwp86 pEql3ey07Jliw5wAx/NeAo+v+DBSvYIWp/kVQ9VRnbr5X/uXN0lHHDwRhHg3ByG/xk8b RPU2lQ7pYCPHnkSeVBpribn8Ltiv7gHI7ywJSIoq11atF+cx5cIPhdMnF9qVrcQcOVSM 3MtVTRhLHfWxKyGKH1/V6nDuWLfcRwI2/R+uQI45lyWXA2JsFddH2SeRg8Nw9lcuHOvt aWGlKDzg3oYGnNEPLFPp7oh6bE9huXVJ5zdaOHqUASSUjA80brsoQd4gwip+ubMNZQTJ kZ3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=NkLBZqZCBrvlh/HCL2fPpBzZ9Wu31qlJsikEisuvYyI=; b=0Y5oBUNkZrMmGWNP1kE5F84gM/BEBj0PlCTu0zXjAZF5RZZFpz19yYwEpBCmAsMlpW EFNDpSzDoKDHHuVgOvcBFDmWiw6PrOccBZxuaf4Ki1fhgjsxPB2IQ9esoi4BMKt0nZmR IpIikN25l4u8SltRMTbK/Pa7wm4Tjw+7WQRRiGcAvHyODsUjiYG5/uowkiowG1C4105P 6RlLlfHO5Jr2TdeHbNyMRikdieCddnV8Rbuv9dgBu+grzrrXfVyZ60NnF3usrOl0fOho pZkU9iWQrrsATJBJutj3FtkDdFmjNK/dUvVe8iGlGvxeJBF8ZvodcqjpJCEa1VBo1Zun 9JYg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x191si12648430pfd.220.2018.11.24.04.17.15; Sat, 24 Nov 2018 04:17:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726319AbeKXXEO (ORCPT + 99 others); Sat, 24 Nov 2018 18:04:14 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:35272 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726031AbeKXXEO (ORCPT ); Sat, 24 Nov 2018 18:04:14 -0500 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1gQWql-0003Oi-Qr; Sat, 24 Nov 2018 12:15:51 +0000 From: Colin King To: Roopa Prabhu , Nikolay Aleksandrov , "David S . Miller" , bridge@lists.linux-foundation.org, netdev@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] net: bridge: check for a null p->dev before dereferencing it Date: Sat, 24 Nov 2018 12:15:51 +0000 Message-Id: <20181124121551.6942-1-colin.king@canonical.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King A recent change added a null check on p->dev after p->dev was being dereferenced by the ns_capable check on p->dev. Fix this by performing the p->dev sanity check before it is dereferenced. Detected by CoverityScan, CID#751490 ("Dereference before null check") Fixes: a5f3ea54f3cc ("net: bridge: add support for raw sysfs port options") Signed-off-by: Colin Ian King --- net/bridge/br_sysfs_if.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c index 7c87a2fe5248..aab8aa17cccf 100644 --- a/net/bridge/br_sysfs_if.c +++ b/net/bridge/br_sysfs_if.c @@ -314,15 +314,15 @@ static ssize_t brport_store(struct kobject *kobj, unsigned long val; char *endp; + if (!p->dev || !p->br) + return -EINVAL; + if (!ns_capable(dev_net(p->dev)->user_ns, CAP_NET_ADMIN)) return -EPERM; if (!rtnl_trylock()) return restart_syscall(); - if (!p->dev || !p->br) - goto out_unlock; - if (brport_attr->store_raw) { char *buf_copy; -- 2.19.1