Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp485603pxt; Fri, 6 Aug 2021 06:49:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyglNBELrpSIbKQongpOO6GxZ9+/snFity3Bpbb95l0Bp08sWt/1RVxOYbTZujo+AS3ybeb X-Received: by 2002:a05:6638:6ab:: with SMTP id d11mr10039584jad.33.1628257745272; Fri, 06 Aug 2021 06:49:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628257745; cv=none; d=google.com; s=arc-20160816; b=IQP/ulvhuhgOiLH/MlzsWqS+sENzLyQvpojvreGRDTohVEOBBzGw4rCAzITk6vAcPB fp21OffU8Lt6mM3ckRMSH1EVL5AqdFKkYTEU/RnK9qN7Q+/y5TdGFueWanzh26wzFGCm IgtJMgppOPEDz0cTgA8c0gE3IPXO2NcnD0Co118anpvfYn/SfORjU/kPIMpuCV2tolVq xN/aHRTFXKBlIpGej5+3rKYYxme0Ksnej6ni4jqZ7UVdXe+5ocGzVBPH70cUfI1Ho5M/ TGu6rfZcrQJ8h233d4K2FeBfZQU9ayfbgjRicCZEt76ZODl1ACRjkQhwA5ekX7eY6ePu KrZA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NOS+thoYVcqZiUd/MSLcQzb3FrfTkvPnxid5QNt4hk8=; b=vujDKuXMbqC93obKxNk/p3go8ZDLLNh8LzaZnVSCdjM8BaY2dKqdekbvYcOvJzO8Sj S6XIV6jNqR9X2G+Nrbe4slIZvsMfqJuXbi+jNKhSF2OaQsZThdQUjUwqp4caKdiNMFsx cs2+HknonKEwivTwSMQTteRvR7SpJ7eNpJOiUuZ1Xic1IQFkG+K1FLxuUIRByY0LdxBD MrE48eXHAjllevuadECoPJL+/8dLJpNt0LU8HFTGnoV/eGMeDOrphhHUQ0C/AlnvDfFG WmVMB4gSBDToCsVYZQTx+jnM0xjS9d8SXcsev7L4f2znpK3hvuQNwI5KgTsnV1LVeaAp csIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1bvgsCRX; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q5si1474181ild.1.2021.08.06.06.48.51; Fri, 06 Aug 2021 06:49:05 -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=@linuxfoundation.org header.s=korg header.b=1bvgsCRX; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244082AbhHFIWO (ORCPT + 99 others); Fri, 6 Aug 2021 04:22:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:48014 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244105AbhHFISw (ORCPT ); Fri, 6 Aug 2021 04:18:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 75A9A61241; Fri, 6 Aug 2021 08:18:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628237909; bh=8MgA3rxV71I99YDci/hPYfcfHV0ARvPGiCFPKZtAYLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1bvgsCRXIJf7oYxwNGs8Xw9IugECDAX28ExbmNtM67/xQb80uMZmTRP+GKA3cdkBN X8ByGgDesKmeD0Zo1sRIvVM4TQPUMUnddoANNjcdm0Yem1cPo0fXX7VpS5ax+ipVGr B3JmV1BTtrpayHzpgPB2qpkkJldIWU++VkCuoWKQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Daniel Borkmann , John Fastabend , Benedict Schlueter , Piotr Krysiuk , Alexei Starovoitov , Ovidiu Panait Subject: [PATCH 5.4 19/23] bpf: Do not mark insn as seen under speculative path verification Date: Fri, 6 Aug 2021 10:16:51 +0200 Message-Id: <20210806081112.802430319@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210806081112.104686873@linuxfoundation.org> References: <20210806081112.104686873@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Borkmann commit fe9a5ca7e370e613a9a75a13008a3845ea759d6e upstream ... in such circumstances, we do not want to mark the instruction as seen given the goal is still to jmp-1 rewrite/sanitize dead code, if it is not reachable from the non-speculative path verification. We do however want to verify it for safety regardless. With the patch as-is all the insns that have been marked as seen before the patch will also be marked as seen after the patch (just with a potentially different non-zero count). An upcoming patch will also verify paths that are unreachable in the non-speculative domain, hence this extension is needed. Signed-off-by: Daniel Borkmann Reviewed-by: John Fastabend Reviewed-by: Benedict Schlueter Reviewed-by: Piotr Krysiuk Acked-by: Alexei Starovoitov [OP: - env->pass_cnt is not used in 5.4, so adjust sanitize_mark_insn_seen() to assign "true" instead - drop sanitize_insn_aux_data() comment changes, as the function is not present in 5.4] Signed-off-by: Ovidiu Panait Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/verifier.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -4435,6 +4435,19 @@ do_sim: return !ret ? REASON_STACK : 0; } +static void sanitize_mark_insn_seen(struct bpf_verifier_env *env) +{ + struct bpf_verifier_state *vstate = env->cur_state; + + /* If we simulate paths under speculation, we don't update the + * insn as 'seen' such that when we verify unreachable paths in + * the non-speculative domain, sanitize_dead_code() can still + * rewrite/sanitize them. + */ + if (!vstate->speculative) + env->insn_aux_data[env->insn_idx].seen = true; +} + static int sanitize_err(struct bpf_verifier_env *env, const struct bpf_insn *insn, int reason, const struct bpf_reg_state *off_reg, @@ -7790,7 +7803,7 @@ static int do_check(struct bpf_verifier_ } regs = cur_regs(env); - env->insn_aux_data[env->insn_idx].seen = true; + sanitize_mark_insn_seen(env); prev_insn_idx = env->insn_idx; if (class == BPF_ALU || class == BPF_ALU64) { @@ -8025,7 +8038,7 @@ process_bpf_exit: return err; env->insn_idx++; - env->insn_aux_data[env->insn_idx].seen = true; + sanitize_mark_insn_seen(env); } else { verbose(env, "invalid BPF_LD mode\n"); return -EINVAL;