From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 609E2C27C79 for ; Mon, 17 Jun 2024 18:23:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=k0EhHphcOCAhjYithQSIO46/DHdY6e1ko/vam/X6iSg=; b=KDVJZzQn0gKdzwy+txtcMLpfNE Txd7cXZTcIQP7f2jiPROTOC9Gwa35nE9/YxoZ+rzC3Gsu7mdaqjpXSQ0yHZnolTNyeUjLblCNoPLI qchNjlCw+PUvFWX3FWbYEgqRe5L9ah/6f2BsnTwjn1voixneL/7gbQ7TEHSvhjMPR50cNBq37k+OY ufTKj6UoXaBD9ys+DywWfQ3QrTqONFcmCJEpyfnQKig5K1ytN4NRdENSxjoJ3UxvQWSPkxTrPlmhm 0AiEfHQPBn4BVS4nN8uXNrkvmQc4YI4yVofxUvzIhXkf9vTw7StO6ue40uGNZ6o5WY1sr7H+hbYo4 HDsUppdw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJH0R-0000000C9O3-3kuT; Mon, 17 Jun 2024 18:23:03 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJH0L-0000000C9MU-0FCD for linux-arm-kernel@lists.infradead.org; Mon, 17 Jun 2024 18:23:02 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 3AC3861445; Mon, 17 Jun 2024 18:22:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7838C2BD10; Mon, 17 Jun 2024 18:22:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718648575; bh=NCfs8+3fHX5/tKNCnEGfSHtJp8L4wyAuoa/GOOiGtoo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OYTKNQDkBo4oTu9itBH1S+qnTg9b9i6GMOgnDPStEM6Pa/BynSfWqQ3mgzbBtNcZ1 bhHhT78ngG45kzg9IIAZESHxq+jnZwKuJC4lP1pYyMV0t1ilAraGndXeTiFEdnpsHH vT/vRStrwMYfu9Zxn1IkG1tK4uU4Fvj4vmdS1PVOLLSOKDGKi+laFMAMs1iqvDx9E/ GPCUHFVkoS1Unx6OZXfJJ1Vq+IE0rbmT2G6OQeHLi65iKl6JdERAaZ1bJRXF2hz22S vl7GtpyBXdLLSFjhYQXmOrdVVgh7WwStO1Q0JZSINGTAwXILEhWJyEz2tU0p3/lfOl KroXUSvl1cGKA== Date: Mon, 17 Jun 2024 11:22:55 -0700 From: Kees Cook To: Mark Rutland Cc: Yuntao Liu , x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, linux-hardening@vger.kernel.org, catalin.marinas@arm.com, will@kernel.org, hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, borntraeger@linux.ibm.com, svens@linux.ibm.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, gustavoars@kernel.org, arnd@arndb.de, leobras@redhat.com, broonie@kernel.org, imbrenda@linux.ibm.com, pawan.kumar.gupta@linux.intel.com Subject: Re: [PATCH] remove AND operation in choose_random_kstack_offset() Message-ID: <202406171122.B5FDA6A@keescook> References: <20240617133721.377540-1-liuyuntao12@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240617_112257_178980_E18F62E1 X-CRM114-Status: GOOD ( 14.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Jun 17, 2024 at 04:52:15PM +0100, Mark Rutland wrote: > On Mon, Jun 17, 2024 at 01:37:21PM +0000, Yuntao Liu wrote: > > Since the offset would be bitwise ANDed with 0x3FF in > > add_random_kstack_offset(), so just remove AND operation here. > > > > Signed-off-by: Yuntao Liu > > The comments in arm64 and x86 say that they're deliberately capping the > offset at fewer bits than the result of KSTACK_OFFSET_MAX() masking the > value with 0x3FF. > > Maybe it's ok to expand that, but if that's the case the commit message > needs to explain why it's safe add extra bits (2 on arm64, 3 on s39 and > x86), and those comments need to be updated accordingly. > > As-is, I do not think this patch is ok. Yeah, I agree: the truncation is intentional and tuned to the architecture. -- Kees Cook