Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3926722pxj; Mon, 21 Jun 2021 09:31:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcPKT5B4K64EkMXW1ui7tTASCtT6nNeT7G2ekasAnizr+bmyv0zvEXm7KFqS5ZLyZACcD/ X-Received: by 2002:a05:6602:20d8:: with SMTP id 24mr9309587ioz.26.1624293119105; Mon, 21 Jun 2021 09:31:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624293119; cv=none; d=google.com; s=arc-20160816; b=PoHlOySW9vskqH+I+QsBdzqL6vfNOEWJQCkr4t8A0M9/4THue1bDXh1Kkk/t+4X/PD XifzTBeHGJdWjNgKTya0lZJea53RkVkwUUH2kc995INH1aPrr0bY9ukPtdbRu2zafylq F72TNt05ozm4sc7TUz/Q+tCBRjBX9sdgaW+V0z/NIyVxw2uZ6+CaaTVQuFMWU/T7I4OO puxuwHurg89ycLI1BsDM6c7JJHiRuM/RlcLWZn42KqJ1cntyqyry0XIKLGtpbtbJP6WP GEU7EghfdNNkYDdQD6tmG3GzyVdj73qyKdMtHkrIJhn3v/cZxCpyU+tgDRkR+NvB3qu7 2RXQ== 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=nygrEw2Tm5Zt7FTSUqb0BDjN6h8JfTCED1mYZTd4D30=; b=jV5RwLQN6V9zxHXjRu4in0e6sj4irZ2eQPfgXta/hhvpVEbV1HXbkeCJtxoy40mkeq FLd/r3Np4ZLyvxNM1E0iF/pb+bOrFiuuSNBgEAFg9hN5pFz3WbsRoFm3vDqoPZ6qN0LN V2nGxKwarmRJixy+DBCyTmq985pNSQqbRWZkEYTkB1olYvT4F4UDmdI8Wa4AMJzN1m/U 2T8YElQBTOS6hFlRJKICgrqAeZfBwrFHIkostzUXGFwhDuVrRXIzSwvbiXf+HfiAGd1a Jc8bywFLwzoz1vhfEMFBExaCQBTX15iCC92VPPVH+SMrzG7oxk4IqDQTIaUmC7xHQt6f uJYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pk22mhBW; 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 i13si15211923ilm.45.2021.06.21.09.31.45; Mon, 21 Jun 2021 09:31:59 -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=pk22mhBW; 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 S231176AbhFUQdb (ORCPT + 99 others); Mon, 21 Jun 2021 12:33:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:48354 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231959AbhFUQaA (ORCPT ); Mon, 21 Jun 2021 12:30:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EF042613C0; Mon, 21 Jun 2021 16:24:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292695; bh=WlC68sZthjWflMpmWXBCqDi4iAudeXEkSFV/uSxmxLc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pk22mhBWvxqFPQkjh5/e/BNCr7OqhY6it50wAu+WFuKu+xTAFmPSkOs8B/SdMyYaj hyEzk9z1G+7EBT36cMOmaeq+sg2DVfFxaUVGPF60yIkFpszd4j4fR8r6oW87zVgfPe E9WkaNTfGqx8dEcfNDKB+xrEuJGewYkFRynM9Lhs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Borkmann , John Fastabend , Benedict Schlueter , Piotr Krysiuk , Alexei Starovoitov , Sasha Levin Subject: [PATCH 5.10 096/146] bpf: Inherit expanded/patched seen count from old aux data Date: Mon, 21 Jun 2021 18:15:26 +0200 Message-Id: <20210621154917.255349343@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154911.244649123@linuxfoundation.org> References: <20210621154911.244649123@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 [ Upstream commit d203b0fd863a2261e5d00b97f3d060c4c2a6db71 ] Instead of relying on current env->pass_cnt, use the seen count from the old aux data in adjust_insn_aux_data(), and expand it to the new range of patched instructions. This change is valid given we always expand 1:n with n>=1, so what applies to the old/original instruction needs to apply for the replacement as well. Not relying on env->pass_cnt is a prerequisite for a later change where we want to avoid marking an instruction seen when verified under speculative execution path. Signed-off-by: Daniel Borkmann Reviewed-by: John Fastabend Reviewed-by: Benedict Schlueter Reviewed-by: Piotr Krysiuk Acked-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- kernel/bpf/verifier.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index da8fc57ff5b2..71ac1da127a6 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -10475,6 +10475,7 @@ static int adjust_insn_aux_data(struct bpf_verifier_env *env, { struct bpf_insn_aux_data *new_data, *old_data = env->insn_aux_data; struct bpf_insn *insn = new_prog->insnsi; + u32 old_seen = old_data[off].seen; u32 prog_len; int i; @@ -10495,7 +10496,8 @@ static int adjust_insn_aux_data(struct bpf_verifier_env *env, memcpy(new_data + off + cnt - 1, old_data + off, sizeof(struct bpf_insn_aux_data) * (prog_len - off - cnt + 1)); for (i = off; i < off + cnt - 1; i++) { - new_data[i].seen = env->pass_cnt; + /* Expand insni[off]'s seen count to the patched range. */ + new_data[i].seen = old_seen; new_data[i].zext_dst = insn_has_def32(env, insn + i); } env->insn_aux_data = new_data; -- 2.30.2