Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3941670pxj; Mon, 21 Jun 2021 09:51:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwlA95KNtrIOUxgkn7RWAVJFWu9GFEdnvqvWQqDhILnq4odwwWcFBs+3GTmui2ncMXWmcZ X-Received: by 2002:aa7:c782:: with SMTP id n2mr22938631eds.77.1624294276785; Mon, 21 Jun 2021 09:51:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624294276; cv=none; d=google.com; s=arc-20160816; b=BEb7pKX5EnVVXd08m1O9VYwYMRYnytF12aLCOjrerq1o2TGdo03Hlc7BqMI4aLdg7L ROWUcFoyoJgIf8JgzIpbF7uLf3feCCIxhWfDl6VzP0PrsQkmWdMfu3VQuYYghQSiLs5A Wth6AvGKE9WIDWdfB4e9x5DSWo+wyY8FAlBN3ragl3BzIbt28NUcWPU4HSgTlS45oDyh +A43ADwBF3wUaP1rcGJ96UIF1GbdY401LWNT2l8ZNNVuVEEoD7bu4U5TT5E4sVPk192D 8qzTfRiMHx7hyjjhGnPWVLi8UVMKUjxj7UNv+aKLdhlCI3Q1WRWGNBFiy3qCCmY6EoOD gW4A== 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=0aDLMEzeZFEtvGnKntnHO7cM698LGZYJpUFlU3bvkqQ=; b=KLBD44570FQ9Lt9JyYJrqCLsH1wH50E0kRp+IFVtbNjsQWb7L/+085sxqx3vpXx8dT WVAstjNwxKiRGG/IpSqIf1WAqkasAZ8GOKaem3sGnTMN7OcW9DOWCfwXGXpSSJtNGBAQ THIjS3Dx1L6EiLo2zYqHcwBHxR0NFF6pG8HQjv8P103HJzlJQ9q4l9zxO3nn0tYM9FHb 5nUviIJeIjY0lvB4hRf0+avfs2oYQ9Y7TN2X0HH0ab+cWVFGViiJ6hDhW86YWAKCItZl +YH3dEqPwOVvhZanfGxk7pjwerltsWP2GBOPy3wa/bXDriyphUQ1ujZSKjRp/dickTKz RSuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SE2JKVLy; 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 n6si3429995edd.141.2021.06.21.09.50.54; Mon, 21 Jun 2021 09:51:16 -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=SE2JKVLy; 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 S233142AbhFUQtU (ORCPT + 99 others); Mon, 21 Jun 2021 12:49:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:37916 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233672AbhFUQpL (ORCPT ); Mon, 21 Jun 2021 12:45:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D599D613C8; Mon, 21 Jun 2021 16:32:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624293146; bh=ShYCfW5yDIfh/9e6rHehb8iD1U4Na0+fadOQebrfEDg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SE2JKVLyvlzpnd2smibCQjXSHfaxIlvRnEUS9NjzYCMr4gk8DIpY1kUN1R+Og1XBH GCs2eQPEQrJ0JBrQvbKvU08DEd4WNRqO5ndiJXiLFkd7COi7+brpI82msS9e0JweSL xVgf/Z4SMt/sfEgHEwAtp1WZcnZQ4RDva5lYIKVI= 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.12 115/178] bpf: Inherit expanded/patched seen count from old aux data Date: Mon, 21 Jun 2021 18:15:29 +0200 Message-Id: <20210621154926.689776828@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154921.212599475@linuxfoundation.org> References: <20210621154921.212599475@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 bdf4be10c8cc..0ffe85f22887 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -10820,6 +10820,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; @@ -10840,7 +10841,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