Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp377759pxy; Fri, 30 Apr 2021 07:21:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8nRB7kYtIVFiKajl4NKw5osDc6iqRdFDi6H7hdrCQhHN5nmzsDYqasC311ToNpLvwbzQi X-Received: by 2002:aa7:8f3b:0:b029:276:93c:6a29 with SMTP id y27-20020aa78f3b0000b0290276093c6a29mr5148939pfr.1.1619792499448; Fri, 30 Apr 2021 07:21:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619792499; cv=none; d=google.com; s=arc-20160816; b=cB0eiyqHgV30tiPT/1aGdrm7kC+dLNZsHWD2iIZ0wlzxacMkpWtjiaBqBW1l0VlAWt VZCgTYMnx6YmTy87y9Z1maVAJt+lmq1HNZj89djuvrr0GCMI9iwoosRYzcmDfpaRfkDC rz+KREhWG95+kgZ72ISLMzVsgZLUL9+zya2CkoRUEEDGlI5xDhWY537FgRn3smx0PZd/ kBpEdswf5Fpz/RCg+n8eXEsSut0csynykmIoJYYgsfmIOb8tBN0SMfiSUvOCku5bBCxY nPPBSXmEqEMiraM3KnDsaMiajdt3T9PPebT2g07Xa0eXJ8LxeIruvHgcOg62WbR4IH0l V4Jw== 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=5w457qs/u9hAUTwP3HbKrUaF+PbCAz5LWfsRv5FaGk0=; b=s4A7P5LiFZXVEMp/alSfbYAiVbgYGfsfz8lBq7+r8sFOpU7bs6zQivAj9hdVBfiBw6 TDTPrhFyn+Lb11uAZx1XxVYOUlSBQP7g4iH0pqxYeP8R09mHilZn29o6oT2dxk5Fpfi8 Ad3QLvUq8iwjJlzZ5NdVB8uQN70dzwOsMBJZpi0wxqAi22UJRoy0uzHduZmw//1PGLeO bwp0FbXSLi6ZYkhdami3nLaOWNcKYBupxboCDzI3SSfQucTLgERRvzQ2BOoy+ALYXE06 7/RFwlncrBAm7bHzK6PW+1V4Duw5TDFZ8/ZswcTS5fWH8bMgZPP+RFToQmWWZzzfq0bY pTbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fEI7AZD4; 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 m8si4076128pgd.18.2021.04.30.07.21.24; Fri, 30 Apr 2021 07:21:39 -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=fEI7AZD4; 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 S230311AbhD3OVP (ORCPT + 99 others); Fri, 30 Apr 2021 10:21:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:57198 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229707AbhD3OVP (ORCPT ); Fri, 30 Apr 2021 10:21:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 08F3B613EA; Fri, 30 Apr 2021 14:20:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1619792425; bh=wjNigdwfj4cbQY3t16dSb7YNrX4MQsXWANz9HVN7Vws=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fEI7AZD4KT/DR3rP43AS1TBwd5qaYb+tvS/doDM6fu5jbdnVOs/z90cqFJDGww4pW 2PJoA0j/VMa1efub2gcjtgh2SIHa3ZOMJWiMuw90Rcz30v8Cx7QAhEhlpbsPf+t3m4 U9S375yQ4sqvahKjX/vUhWZX+IvQAvTAkZEe+adU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , bpf@vger.kernel.org, Daniel Borkmann , John Fastabend , Alexei Starovoitov Subject: [PATCH 5.4 1/8] bpf: Move off_reg into sanitize_ptr_alu Date: Fri, 30 Apr 2021 16:20:15 +0200 Message-Id: <20210430141911.186718631@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210430141911.137473863@linuxfoundation.org> References: <20210430141911.137473863@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore 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 6f55b2f2a1178856c19bbce2f71449926e731914 upstream. 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: Greg Kroah-Hartman --- kernel/bpf/verifier.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -4336,11 +4336,12 @@ static int sanitize_val_alu(struct bpf_v 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; @@ -4474,7 +4475,7 @@ static int adjust_ptr_min_max_vals(struc 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; @@ -4529,7 +4530,7 @@ static int adjust_ptr_min_max_vals(struc } 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;