Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp738914pxj; Thu, 27 May 2021 10:29:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxn3bidzXvzLX9TazYF785lH8ca2n0e7Qzkl1kH9iReDDJVgUWLFyzMkolqsNEcy1Su5NM1 X-Received: by 2002:a17:906:a00e:: with SMTP id p14mr5181451ejy.66.1622136577864; Thu, 27 May 2021 10:29:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622136577; cv=none; d=google.com; s=arc-20160816; b=XXICr8tflIbnpjb7c1w16qQwRMXyBjzzDVOFsAGHV0UQRIGt5ZR+NK5E7HpgU2fkOa gqQpaGoM69OYQgaZKRYO+R4W815vULdw6oFaH0ZSdHSTiai0m+qvae2pvDfOiXHRuFVZ KrqoYy7dIPzWToWwhMgTWgeERnki1mIWADszWdWvNVLKBzNCnpOv/U84yx8AN6A9MOW8 l3Jm/Y6w2MdyHxjSscDDePxnAgABSlfT4rP45RBsvujhXIffKhmJw8Lkz8I88nq6bYd/ PpgesZDLPTihFwBv9QFLn60oQ79s3uCPqFssviY08av+bceFmc65zISGbBM/2LwU5xC8 JQqg== 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=66LU1xhL80TVWC0aW4mjI453DEnLnnnPZMKdQfT1Vmg=; b=lS6rbHnm2b0Osbt1r+hQXkQIDKZIz82vfcTvFR1Arg4tRpBsjZTCrDBYNoiAzYMvk4 QJUOOIx8WWOWx68Ai7cUlT+VhHmDB9KweEdH5jrGTJKS7QLO6+usgY0xt0eZgENcilJm rWlrRzBXy7oTrmLjpDL7LKKM08+42amCWcezd7Siy+CUqGIe/h0+vhii4VB+kxYEtizt Dfy/YR6cI8MxmjxAS9bm9FuR8qrKDnUu+KUfcwsUeQZQu+Hi5BHsvUsZWwmQgfqmytMm 6lSpOicE8vweJWOYxSh4fJbmbCHPU/ozZ/Nbr6IGy4osDI64oGH/f6bYwYMZ2huRtY5P kuKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CBgHgLhM; 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 d19si1864948edj.577.2021.05.27.10.29.14; Thu, 27 May 2021 10:29:37 -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=CBgHgLhM; 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 S237075AbhE0PQG (ORCPT + 99 others); Thu, 27 May 2021 11:16:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:43814 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237025AbhE0PPQ (ORCPT ); Thu, 27 May 2021 11:15:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8031B613BA; Thu, 27 May 2021 15:13:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622128423; bh=yPDcRABYHxKEMWjTFyGXfsO77B84tjA7QsGTFE3thQ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CBgHgLhMcmjEkn4JA6GNdkxjgLYIbtuaXu3Z64uVUIwgLIyYohvrDfp84Cddj7agi efmmLEaA2nHWj9DjtKjGjet/AxY9tjieJg8FHsTqSM1veb8FvBtBLp1ir8mwz/0ep+ KLUp3IBImmvARNnrp9ECkvkuc/wf/QBWRlcB+eTI= 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.12 3/7] bpf: No need to simulate speculative domain for immediates Date: Thu, 27 May 2021 17:13:04 +0200 Message-Id: <20210527151139.354476579@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210527151139.241267495@linuxfoundation.org> References: <20210527151139.241267495@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 @@ -5999,8 +5999,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