Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2673566pxb; Mon, 19 Apr 2021 10:57:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSkvzgvoB+LTXFKK8Bvyb0h1RTsNe3NMG7Eg246ghXsENDzge67KWb/+AVmPZU4MhSXQrT X-Received: by 2002:a63:d70f:: with SMTP id d15mr13245549pgg.397.1618855026635; Mon, 19 Apr 2021 10:57:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618855026; cv=none; d=google.com; s=arc-20160816; b=FVqeSpxdKuqRlNeqGqubMBS+QbUuZ114/zz++UCAo2BFmr6+GJ5gvaXMVStSfBspGC TKze/OGL7jNSfeaWknQ1JM2Joeh7khRf8pFJNAiWZTWMfd9SW/rk++llZdP8YfvzVDzw a6jIismcjbGp/ISr7diXfXRKeZSeMmATscSnCkUTVWQCdYP+uZHyZVKMnevlCzgRT6KQ h/tzlUZdymcaw4CjZ76CRJI/PlChiyTjBHxk9iageZZJdIsQ7HBb9XpRVHEyVSr7coWg jsPJcu4WkfJPyxbsMWlo8JByBNoe8VlwN5mJ7vDdIdxiRtr2gELWOoCfHjY1vU6XFar7 mdVg== 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=jwB5/uDxfgfyvqSrHlRSGh2/4ruCegeQDNXnHht2Qes=; b=djUrPFmyw6Rzoo0aUkT0JmVQ2TR9OSedZPCt0OQv/bs/agSeyTA6wbXLgppqDs2DBD ewYSwR4Mh1sLp1/3GdEpndf6Rdy1kiHScuGMcwzed/gcBBHW8uoxq22IQqofvkOYryUG UPq1UBUbhkhZM0qKEKR2suh4wC2GTRS/nAEoAd9y3NXaolWKKMYrkVpZX2fXdoVl1DME zGFpNqLv2BiRkp/cJD4qxXrwQl4VgaA07IkfxmC8DECSnkYltwSwlT9099GJwCCFOROz MN8H6iY9cEcnJ7C6yVhhxLYDOxYA94CU5IhyAo1QkKP0/cA/9BzwXRgCawwcBv1ccp6V MWHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YBpdYqDV; 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 u16si19414816plg.10.2021.04.19.10.56.53; Mon, 19 Apr 2021 10:57:06 -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=YBpdYqDV; 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 S242874AbhDSNaL (ORCPT + 99 others); Mon, 19 Apr 2021 09:30:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:56986 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240664AbhDSNVA (ORCPT ); Mon, 19 Apr 2021 09:21:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 308D2613F7; Mon, 19 Apr 2021 13:17:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618838255; bh=UMriKm81P/67QXxaKl0Vg7J5ff/ci0TXWFpSSlR5OeA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YBpdYqDV6E9YloYrhutS108eLg/P5zNaBHHSsOA3nGERRCImOEWenov+ZzZu5uAQp wFsfrHoGwERjyRzuRTvg/cq5ra+NrZj6hCfTiUwPOZacyXcckkgEp/pRdFp1PNoj3E iIeHcQWWW5tTV/xtPAG0RWAzW9F15yifnMW111C8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Borkmann , John Fastabend , Alexei Starovoitov , Sasha Levin Subject: [PATCH 5.10 098/103] bpf: Move off_reg into sanitize_ptr_alu Date: Mon, 19 Apr 2021 15:06:49 +0200 Message-Id: <20210419130531.152446942@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210419130527.791982064@linuxfoundation.org> References: <20210419130527.791982064@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 6f55b2f2a1178856c19bbce2f71449926e731914 ] Small refactor to drag off_reg into sanitize_ptr_alu(), so we later on can use off_reg for generalizing some of the checks for all pointer types. Signed-off-by: Daniel Borkmann Reviewed-by: John Fastabend Acked-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- kernel/bpf/verifier.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index a2a74b7ed2c6..6b562828dd49 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -5407,11 +5407,12 @@ static int sanitize_val_alu(struct bpf_verifier_env *env, static int sanitize_ptr_alu(struct bpf_verifier_env *env, struct bpf_insn *insn, const struct bpf_reg_state *ptr_reg, - struct bpf_reg_state *dst_reg, - bool off_is_neg) + const struct bpf_reg_state *off_reg, + struct bpf_reg_state *dst_reg) { struct bpf_verifier_state *vstate = env->cur_state; struct bpf_insn_aux_data *aux = cur_aux(env); + bool off_is_neg = off_reg->smin_value < 0; bool ptr_is_dst_reg = ptr_reg == dst_reg; u8 opcode = BPF_OP(insn->code); u32 alu_state, alu_limit; @@ -5546,7 +5547,7 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env, switch (opcode) { case BPF_ADD: - ret = sanitize_ptr_alu(env, insn, ptr_reg, dst_reg, smin_val < 0); + ret = sanitize_ptr_alu(env, insn, ptr_reg, off_reg, dst_reg); if (ret < 0) { verbose(env, "R%d tried to add from different maps, paths, or prohibited types\n", dst); return ret; @@ -5601,7 +5602,7 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env, } break; case BPF_SUB: - ret = sanitize_ptr_alu(env, insn, ptr_reg, dst_reg, smin_val < 0); + ret = sanitize_ptr_alu(env, insn, ptr_reg, off_reg, dst_reg); if (ret < 0) { verbose(env, "R%d tried to sub from different maps, paths, or prohibited types\n", dst); return ret; -- 2.30.2