Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp921968pxj; Thu, 27 May 2021 15:07:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzt6A6tKaAOL8BOujPjA9vZqpHxoHS6JRw+QiFMZ20mBvKFUo4S3LatGIy87oGQoGPsK3z/ X-Received: by 2002:a05:6402:95d:: with SMTP id h29mr6517743edz.233.1622153228137; Thu, 27 May 2021 15:07:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622153228; cv=none; d=google.com; s=arc-20160816; b=T046hUslukqpuAJvq6RNVZawNIqQdRT8tsvSt+716puWGMh3XXvrf7hrKDLYP6TNb5 Ggw/QbfphPyPMr7sV3qyaATghXB4OXRnVx8NDfYj8/iwhLehwAKfGZaH/IhoSFpxg5w4 xuQjau1IKSrXFF47ZeUXGUmoSLZlu/GxVfER8anIHSJfb2qxmKlroLWFkgsSkpT95g3U SRrDJbchZ8b7H2bNcGotxjyJanj6SlIh7K6C9Zd0jxHrsjFAsBX/p9v8Ya2FZCQx30TJ SmjHluY69pvPfRUXkS40uOCclVaBV9zbTxIuB9QTxt/7n6AP/i3cJQ7BcIj95COmj+4j sfew== 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=GiAQGSrsPN/AO4J7NB1CIdGGofVCwruCCLQGCF0u7eo=; b=08EBrkL/UZqH/Qk9pmd/QCy5BKXqGwoFH9MUuLbgGxxeUyXaKovtwH2vFAp408kKyK oODQ4wuLUxZffcectlpLoxty6tUBMfNLSrXbmNQiguYNSCPnd6uA2tKSsWLX+CCD7RxL z/eDyCC0E7xZBX4sCmXMZ/PhT2sDEHxMYAZ7l9f/SYLwjyoyTC1xQ1bx9MDXSDDMworQ mVXkXfrCod3WutMk6xnSBVF69aBb9LuYcF9Mfhe7iST8aRZwqk6ZC5I5vcVL0sC3MsJW RJ0B97oGO9xHpveoRgvq9Ykkvtc8+7A6J8xt9wu5vJdH7IU3+9f9ZVbj0cpxr+2RX1m2 KDMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2ojkSZjt; 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 b11si3385092ejq.727.2021.05.27.15.06.43; Thu, 27 May 2021 15:07:08 -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=2ojkSZjt; 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 S236813AbhE0POp (ORCPT + 99 others); Thu, 27 May 2021 11:14:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:43144 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236886AbhE0POg (ORCPT ); Thu, 27 May 2021 11:14:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A08D2613AF; Thu, 27 May 2021 15:13:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622128383; bh=NYjrMYE3y+cwh5dsoQ4+92RCVtPpsjvRAx4O2m3ox7c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2ojkSZjtLdHCp8fTvrxaEVgBDG4tYzeAWKutwu5jP60sxQmhbazfkZaPU5SrQJrSX fRfBwBlH9wc+Y7EPOR6rfBnXeyHSrY4beGHqHKpr4TJNo/NiPPTQf+TLl9lj3LgUE1 eybMMaYKLTkE6Pg63ZqDM8dVBItbh/YLcjmVB61s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Borkmann , Piotr Krysiuk , Alexei Starovoitov Subject: [PATCH 5.4 3/7] bpf: No need to simulate speculative domain for immediates Date: Thu, 27 May 2021 17:12:45 +0200 Message-Id: <20210527151139.331493090@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210527151139.224619013@linuxfoundation.org> References: <20210527151139.224619013@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: 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 @@ -4408,8 +4408,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