Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2906209pxb; Tue, 24 Aug 2021 10:18:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcJcSjZs49EVsd7abSi+qXOCR+BtFChNFu28ebtHGjxDdrbReaL1SF8gBpHFpqUg8/y1TU X-Received: by 2002:a05:6402:4253:: with SMTP id g19mr44169975edb.31.1629825507193; Tue, 24 Aug 2021 10:18:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629825507; cv=none; d=google.com; s=arc-20160816; b=TfaF1v8OWvPPnS1V1VpYBPU/eTWwphYb+O2DNoMkOZ0pOQ76y/H3IOqeILklvp7ebu FsIzpwANTR1FM58aOrzgHA1mW4zdDaLTchUo104GcFuLWzGLXVabIE49NR4SfEBKYc6Q JbCPP0+tFMZP1m74F5T0hCUfe++IJZEKcIYkeahy2w+HIT2W+03vYYIzOfLkSw0AJnf/ D/+9sKfpe/UjMs1Kb6r26U0zFmCXjddP1ilzrGKI3Kh7RskPELDQnaXqMMX0e3ew0EIh xJa3BeeFjjTHGvjU/IxudDcyRhDnNlDbSUZfSPs1Z/EOOS/qrAKPynX6TVDB+bggJsGt ZPmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=94aHTZ4CPfz0scXP4lKQFFHhj58ywXA2iY6Ipnl8bRw=; b=ft2A5beyiUp0BeM8AhokpUsl2YO3Z/4hSCAOKr+T5xbrOm1lhM8ZzcDTmLjphNrANF 6/8c/CYG+sTlvCZkp0f1b2XKne+Hn0ZWhpaCAO1ny3C3gchGb3pM6Uk5cU4Ps6IeCxEM Apakjf0ygiH3LkAoeUQUCAe636FPOlXUEOiD0v/896AdknUKdLgSoSPRdcOgYS/AAXuk KbTEKoOJVwAeWfmbtUwOMSznmruq7BivRTNbU/CWTbCVSBbPhQPaVgB6aBN+92tmLZYj +5ZNa617mlbdWDF9CK1kt4HJkUTu79Eu9nYVxBjWLHKMQc6h7Zl2pPWcQTU1EMg/2Qrx djjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UDKJWObb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e10si22798943edj.183.2021.08.24.10.18.03; Tue, 24 Aug 2021 10:18:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UDKJWObb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230344AbhHXRRP (ORCPT + 99 others); Tue, 24 Aug 2021 13:17:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:55476 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239587AbhHXROJ (ORCPT ); Tue, 24 Aug 2021 13:14:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 106D461A86; Tue, 24 Aug 2021 17:01:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824497; bh=uDcUEMMDZNHq7x2mjZ0JAwy6btOPoBs2tzjP2NpHr3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UDKJWObbX8x7ungeE9suKP0xX5kHCzwkWVUhfvepCovOAUTRJZ9GV5g1dGbAo+z29 3ltw5C4I/0W045q/lGp7SrD4qnBv+aHaWx9Feo2s7sy3Xz+s4GtzTkFUpIylV2wjke mgNT0KUrnlKkbK3zHq+pPz63EPvrv4CMu0ieKHMZD6UqGA2II9C74XQwGXKbOjPA8i 17uwIIEjTjPoE3ItGDypeRwyFXJvxUHDcaMYoGUJQCvav/3BCTkNAL2OBsCB0V97PP 7CdIh+M7+p/lKS4J2I82Q/swdm0fLR4pbIpRFQTxE6Zs9FCjBZi2FzmpJsfi4z/HK2 n89K29qplAVXg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ilya Leoshkevich , Daniel Borkmann , Sasha Levin Subject: [PATCH 5.4 30/61] bpf: Clear zext_dst of dead insns Date: Tue, 24 Aug 2021 13:00:35 -0400 Message-Id: <20210824170106.710221-31-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824170106.710221-1-sashal@kernel.org> References: <20210824170106.710221-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.4.143-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.4.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.4.143-rc1 X-KernelTest-Deadline: 2021-08-26T17:01+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ilya Leoshkevich [ Upstream commit 45c709f8c71b525b51988e782febe84ce933e7e0 ] "access skb fields ok" verifier test fails on s390 with the "verifier bug. zext_dst is set, but no reg is defined" message. The first insns of the test prog are ... 0: 61 01 00 00 00 00 00 00 ldxw %r0,[%r1+0] 8: 35 00 00 01 00 00 00 00 jge %r0,0,1 10: 61 01 00 08 00 00 00 00 ldxw %r0,[%r1+8] ... and the 3rd one is dead (this does not look intentional to me, but this is a separate topic). sanitize_dead_code() converts dead insns into "ja -1", but keeps zext_dst. When opt_subreg_zext_lo32_rnd_hi32() tries to parse such an insn, it sees this discrepancy and bails. This problem can be seen only with JITs whose bpf_jit_needs_zext() returns true. Fix by clearning dead insns' zext_dst. The commits that contributed to this problem are: 1. 5aa5bd14c5f8 ("bpf: add initial suite for selftests"), which introduced the test with the dead code. 2. 5327ed3d44b7 ("bpf: verifier: mark verified-insn with sub-register zext flag"), which introduced the zext_dst flag. 3. 83a2881903f3 ("bpf: Account for BPF_FETCH in insn_has_def32()"), which introduced the sanity check. 4. 9183671af6db ("bpf: Fix leakage under speculation on mispredicted branches"), which bisect points to. It's best to fix this on stable branches that contain the second one, since that's the point where the inconsistency was introduced. Fixes: 5327ed3d44b7 ("bpf: verifier: mark verified-insn with sub-register zext flag") Signed-off-by: Ilya Leoshkevich Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20210812151811.184086-2-iii@linux.ibm.com Signed-off-by: Sasha Levin --- kernel/bpf/verifier.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 52c2b11a0b47..0b5a446ee59c 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -8586,6 +8586,7 @@ static void sanitize_dead_code(struct bpf_verifier_env *env) if (aux_data[i].seen) continue; memcpy(insn + i, &trap, sizeof(trap)); + aux_data[i].zext_dst = false; } } -- 2.30.2