Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3661410pxb; Mon, 24 Jan 2022 14:44:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJzsrqlcIGXeT5iD1wHv+JmMFOkm9KUwJKznq3q4Pi3d+tFHNNIUvuLbUIsxX+lk3mONQbNh X-Received: by 2002:a17:90b:180e:: with SMTP id lw14mr515719pjb.94.1643064262512; Mon, 24 Jan 2022 14:44:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643064262; cv=none; d=google.com; s=arc-20160816; b=c06w5SI1Raj36ozuScwyk6GPkBGPvGCwI1/N7088XgXYXGV5QnNKg5Rw7DhKEXyfQt QzLEI07Iw0/XOhmUmjLQeHxk/kKD/xCLkbkzB/grSRJW9oYS7BNiP2fU/IUQzgr5tpRL VACaDkYwoowQOHJ+wQREYglQdAJcyMkdgv15kXqWgOx1DqV1pGoXqx0fjO+uamfWfDTG rCQ7oRZN7SWjoRJ7QvptJq7h3Mottr2sHUAC+u2TrszA+D8WtnIBQhMGGNnGiwL1wPXZ DNRj0/yNWKTL+XtZxwyACuH5kGgABZQ+IYWmZwmHeQqqZvSlrnd7WvK8nnWUZyR1xO+T 1ESg== 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=IcOALySATPh2Vx0BruHek5Cp96OMgauj3YiT0QHfUTs=; b=wruaiZeBtuVRocOrPtnX8dNqURwYEhBzhiqYzfGQIILU9+FEk5XeJD90BHkLd+2D2u gSjbAENsxFJ8IyBXz4NNgGgkM2Gy/E5iv8aQ5EWxxNKTkyG2oHJ5Qi0Arqq4I1Xl4Xh1 kDBA1BIGica0Nn9Cu8cMaSN6E7HoeHjICqPqRQOUdx+KMbXfaWe0UijGoO0+SVwbIzqg Qht0KCR6n+o0krn/TzhJLM2H/HwaCrcmFyj8IwZQ+6agOqc99v9Cl13vWKlEHM1drHIX oscaJEUTQLRtKkCA0RGjOlxKX+ZCbWMC75OjK3Yyde7By2vRDT6WBjNhqYZRPRJPtJ3A lDuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="dYi/gA8f"; 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 d1si13133390pll.28.2022.01.24.14.44.09; Mon, 24 Jan 2022 14:44:22 -0800 (PST) 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="dYi/gA8f"; 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 S1836860AbiAXWlB (ORCPT + 99 others); Mon, 24 Jan 2022 17:41:01 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:60054 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1457624AbiAXVl6 (ORCPT ); Mon, 24 Jan 2022 16:41:58 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1567F61320; Mon, 24 Jan 2022 21:41:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCEE6C340E4; Mon, 24 Jan 2022 21:41:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643060517; bh=G9DGqFM3J6+IZWyQueHkSzbTE2a7MnnhPz7w4RWVOFs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dYi/gA8fAKu+CuU3AxAi8uUf2AxbxW/hvcahtnnN1vlZ5MXqYCVPzhkJN6tJ1kqGX 4AhVJrjkt3lC1qPosNo0Z1iUCKnCWOgmGy7EKAX76C52ObP4XhfiGYhW+P4JxIAEKb 4K1AR5jfby/RRxKZ1oSquR73UsaLG2zAM34p4LNg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Borkmann , John Fastabend , Alexei Starovoitov Subject: [PATCH 5.16 0942/1039] bpf: Mark PTR_TO_FUNC register initially with zero offset Date: Mon, 24 Jan 2022 19:45:31 +0100 Message-Id: <20220124184156.957782600@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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 d400a6cf1c8a57cdf10f35220ead3284320d85ff upstream. Similar as with other pointer types where we use ldimm64, clear the register content to zero first, and then populate the PTR_TO_FUNC type and subprogno number. Currently this is not done, and leads to reuse of stale register tracking data. Given for special ldimm64 cases we always clear the register offset, make it common for all cases, so it won't be forgotten in future. Fixes: 69c087ba6225 ("bpf: Add bpf_for_each_map_elem() helper") Signed-off-by: Daniel Borkmann Acked-by: John Fastabend Acked-by: Alexei Starovoitov Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/verifier.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -9389,9 +9389,13 @@ static int check_ld_imm(struct bpf_verif return 0; } - if (insn->src_reg == BPF_PSEUDO_BTF_ID) { - mark_reg_known_zero(env, regs, insn->dst_reg); + /* All special src_reg cases are listed below. From this point onwards + * we either succeed and assign a corresponding dst_reg->type after + * zeroing the offset, or fail and reject the program. + */ + mark_reg_known_zero(env, regs, insn->dst_reg); + if (insn->src_reg == BPF_PSEUDO_BTF_ID) { dst_reg->type = aux->btf_var.reg_type; switch (dst_reg->type) { case PTR_TO_MEM: @@ -9429,7 +9433,6 @@ static int check_ld_imm(struct bpf_verif } map = env->used_maps[aux->map_index]; - mark_reg_known_zero(env, regs, insn->dst_reg); dst_reg->map_ptr = map; if (insn->src_reg == BPF_PSEUDO_MAP_VALUE ||