Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2623606pxj; Mon, 31 May 2021 06:49:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycP4mGfM8O1kqeJe8esaf1wilTGxmTJ+7/JS0e/EvPHX8Shl6w8pmnzJepP5n+8dWsVW69 X-Received: by 2002:a05:6402:220e:: with SMTP id cq14mr24393911edb.57.1622468952921; Mon, 31 May 2021 06:49:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622468952; cv=none; d=google.com; s=arc-20160816; b=nbnF7hyixNfASdiY7iU3D8Crj31ntlp8QHz1k5UyBUqZVvzL09WcQ45zoyv9MxYj7m wP1YRTu9B7KnbIXRY+4wQ3CAGvZhV1gmWChJvwtXDxikNqbC1vAfyKYjeIWthngyD/Uv mBpbpa29erqQEuD5WaJrJojXfIt8aDlP4piTXFCqlCpq9NW8SGkE7/GoS4K/Rann16RG YMMUEkWP5Usq8xUCdwVZ1ym5wJgF7fs7Vu7lXuz5fikuUmn/Ple3V/iLti72DPL4cbnB smdgPasSvRobms2VHNHKc6EoyHrDOBBLhQ8FsVd5Zc/mGJwoxhraZGZyGi3AyjYjXJ3M Xzrw== 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=00QnI5oDkONfXax+J0S5oMSwadaAn7QUy0GGM9V+Evg=; b=jUZMBmhAY31syRbX5N/T1HWGzZnxtKbowTpcNeBw/kGYYxfYsc2LC2/Bcp2poPPe1g G5Ey5dcIxgehXG3ImnngJZJcVgsZRPxc5LQFReGF98vSo0uwPioxC0EDwWkFdz9v/YhO 3zrRJwqMg6fYYCG+yKUvsvKXEiixx9guzRQe+g2C+cdfa4Yu6/QOTLCbHyPHsTsRTQ/F PAYgAUY6BZfN8RrsivaHlbbcz/M37wZaZDWYXrjVhXvmThjB+zYcKB1dDz0qxUFzfatK hkYlCnkNEQ/H5WAaghwT9Ag4qVzDUK4HhS6x1BFAsEjxKCoylo6lnx6KdZA7S2j4wd8m 1Ppw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aVmKYDSH; 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 p5si14044762edi.291.2021.05.31.06.48.50; Mon, 31 May 2021 06:49:12 -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=aVmKYDSH; 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 S232027AbhEaNqO (ORCPT + 99 others); Mon, 31 May 2021 09:46:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:39238 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232357AbhEaNb1 (ORCPT ); Mon, 31 May 2021 09:31:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D02FD61431; Mon, 31 May 2021 13:23:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622467419; bh=7xllVGKvYSZm+yVmXUB3RsUuwf6MEtLyT8D5zyXXl2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aVmKYDSHOYpRVy4rldzsoPN86ltr+4Gy/cCAK/phyrUbZu8v6DhJOsjTEXL8vHQLc xK+JOHAkaYMrt/qF/vkB1KfSG1wMwgkATuWTxwKFWZy/nXZY+UeP/fQJq64n35hQF8 oMxIdROkb/HoNKeNL6bWXBeqWnT/VkT4pb8Ile7M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Daniel Borkmann , Piotr Krysiuk , Alexei Starovoitov , Ovidiu Panait Subject: [PATCH 4.19 058/116] bpf: No need to simulate speculative domain for immediates Date: Mon, 31 May 2021 15:13:54 +0200 Message-Id: <20210531130642.138479899@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130640.131924542@linuxfoundation.org> References: <20210531130640.131924542@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 a7036191277f9fa68d92f2071ddc38c09b1e5ee5 upstream In 801c6058d14a ("bpf: Fix leakage of uninitialized bpf stack under speculation") we replaced masking logic with direct loads of immediates if the register is a known constant. Given in this case we do not apply any masking, there is also no reason for the operation to be truncated under the speculative domain. Therefore, there is also zero reason for the verifier to branch-off and simulate this case, it only needs to do it for unknown but bounded scalars. As a side-effect, this also enables few test cases that were previously rejected due to simulation under zero truncation. Signed-off-by: Daniel Borkmann Reviewed-by: Piotr Krysiuk Acked-by: Alexei Starovoitov Signed-off-by: Ovidiu Panait Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/verifier.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -2874,8 +2874,12 @@ do_sim: /* If we're in commit phase, we're done here given we already * pushed the truncated dst_reg into the speculative verification * stack. + * + * Also, when register is a known constant, we rewrite register-based + * operation to immediate-based, and thus do not need masking (and as + * a consequence, do not need to simulate the zero-truncation either). */ - if (commit_window) + if (commit_window || off_is_imm) return 0; /* Simulate and find potential out-of-bounds access under