Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5133616imu; Tue, 13 Nov 2018 01:32:05 -0800 (PST) X-Google-Smtp-Source: AJdET5e8Cm2f9s6WpNzooUY7/kW6K2Dae96kviQeM64Ux2TJ+DgmS+Il8v4mldNua950T0Ipq6g2 X-Received: by 2002:a62:65c3:: with SMTP id z186-v6mr4483309pfb.206.1542101525297; Tue, 13 Nov 2018 01:32:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542101525; cv=none; d=google.com; s=arc-20160816; b=WGuvqJNzn53TdZLLm+U75d1uRmI0rs1pgdpTDsDWHzSqEOYrkundxKvMxHQdNpr/yE 89os9r68fQKJw5Ret7tX7F5ROT2ZcXlV10P8niByX/H7beRKOt294e4plB6idmxCKDve PwJTxizFNyhuLKh42Au+IpusINFA0nne/U6kANXJTmQxmkTwYC/ZOytJknoQ1Xm0PB0N DlLiN1/TGvkwMTgBcBnE5dhQR4FeqPQPNIDFW7h7rAQDRyhILlPUBXPOgXCSKo8WQU9U xjRNR5JfnKzY7Kk7DlDI8F8UPoJu9XXsO+QgNz0BZs7QhTFgLC4ewZb0bGOclSlCRM3U bmdQ== 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=aHjS9Sf7HxVVnv/ykpX+shWwPM+CkbFLNeHHRvWNyVc=; b=lrr5PbrwNbiP6Q3r0yU5ry6oUM4/r7QqoP7dVGdDEuTWfyaBrV2VwVKehvRdGhjiE6 ELAUu7BaLspQ0p/zaLgCEiAOHq0UZmVGR4BChtZlkL4VeDwU05k7JiUzO2i4FX83oRqp sB8jsHI2gsI96L4/UMCSIdcP8zCs5roaD1DwH6JK75N6JMFYSGrbng7s8Xf6hXuWPaTe k1EUGRoqkmDK/ExFoa3uCBhbok2u37nSwwxXEESsAoF6vK+BfXYSUu85U9a32+GFJapg RsYqFTuSkHTigUGzF+vJ864vwlfOKH3RjedEFzT+z+76tJVUaEEucQMWk2JOwfYqBNJd gmqw== 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 z21-v6si19671948plo.89.2018.11.13.01.31.50; Tue, 13 Nov 2018 01:32:05 -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 S1731558AbeKMT0o (ORCPT + 99 others); Tue, 13 Nov 2018 14:26:44 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:41476 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731476AbeKMT0o (ORCPT ); Tue, 13 Nov 2018 14:26:44 -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 1gMV0h-0004qR-9H; Tue, 13 Nov 2018 09:29:27 +0000 From: Colin King To: Alexei Starovoitov , Daniel Borkmann , netdev@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][bpf-next] bpf: fix null pointer dereference on pointer offload Date: Tue, 13 Nov 2018 09:29:26 +0000 Message-Id: <20181113092926.27081-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 Pointer offload is being null checked however the following statement dereferences the potentially null pointer offload when assigning offload->dev_state. Fix this by only assigning it if offload is not null. Detected by CoverityScan, CID#1475437 ("Dereference after null check") Fixes: 00db12c3d141 ("bpf: call verifier_prep from its callback in struct bpf_offload_dev") Signed-off-by: Colin Ian King --- kernel/bpf/offload.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/offload.c b/kernel/bpf/offload.c index 52c5617e3716..54cf2b9c44a4 100644 --- a/kernel/bpf/offload.c +++ b/kernel/bpf/offload.c @@ -130,9 +130,10 @@ int bpf_prog_offload_verifier_prep(struct bpf_prog *prog) down_read(&bpf_devs_lock); offload = prog->aux->offload; - if (offload) + if (offload) { ret = offload->offdev->ops->prepare(prog); - offload->dev_state = !ret; + offload->dev_state = !ret; + } up_read(&bpf_devs_lock); return ret; -- 2.19.1