Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp161549rdb; Wed, 21 Feb 2024 22:34:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXeZOAyRSLWrihhMRwlj177njKELduw8JNQCBOL80Kixr0seb4drMgTql1Qv62kCsVLYKeLBiW3HVmIkeJmYa/CUbp3lxjWv9CE3qfQYw== X-Google-Smtp-Source: AGHT+IFjI41pC8Od8zXgxxiyx0PFK3BhMmioucFjkItfR0e6m6Jqx6umvxDkUHR3UCRXpX2LaZ6f X-Received: by 2002:a0c:e086:0:b0:68f:5d8f:7c14 with SMTP id l6-20020a0ce086000000b0068f5d8f7c14mr13108010qvk.19.1708583679603; Wed, 21 Feb 2024 22:34:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708583679; cv=pass; d=google.com; s=arc-20160816; b=nsuJU9rwzG2B5mybScJjFp9VSfWXqkIq0Ygc8mVXYE4h8br5+9wOxMe21Uh4L+QFiN GiBk+/gwvDBCMBpaAOyOWlM+4I5DJDKk7PBg9x8ZJ6WnRJVNJpOnYEWGdsIDgRTu0whq 4kv2WSM/ZwwBcnyaS5WZAAYhiwGcSz29BdkQS9pK3k71n7/XFER9xeh7S0M1OYDKe/nM YxvgEdJzE22fjvYZdePjLJf6m94ghp4SinWBVjCHneyX1yAtOj0vh9yqUKlQezdOyXje cr9ajaFgWtAvgsAZ7vH62+3PFS7UwDxaUVdQwbGy11x38X42DpG0OTJcW8c4O/CkITpx sKrw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=wOKBQl4Jz6eJ/OBAcJYui14WggpYgk42N58/0NJocNg=; fh=xW2EuhGTUmY2T9bQx0XpNkrdAGphcVLtZtvmnzuCqDw=; b=uEcG5eGTVzqQLuvFNn+SJb3QxVwPte0YUxpra7kgnSXrp3ldY8MHdtbFlGwX6L8kQ2 8k+K6BFNA+KpodV6Ps2QrJRtNrctI443n3eC+Ovo6tMMsCXA5Hv0nRr8WnbdJvlhqmJ4 bnHaCA4n7io6QL417DerrVW0BEHT4hxTLMp8K3vY8SB5mZUF/u4tDbKb/CYNpqGzw7oU bQ2rRPhMqmQJ5Ykah+GjnGA/atB2ldWI2GEQVfG6rLnB9KrIaiOjFcIGiAGVWPnP3ko1 fDOswcdNR/2/djiApqwe2NJGh7AG9W7JPY1WXp30Z02OgXIaFY6PD6qksZTIrcTwsZlw SJsQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sZLZenrS; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-2242-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-2242-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id o3-20020a0562140e4300b00681955e64bcsi12525701qvc.604.2024.02.21.22.34.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 22:34:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto+bounces-2242-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sZLZenrS; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-2242-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-2242-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 57C801C2191E for ; Thu, 22 Feb 2024 06:34:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AD749D533; Thu, 22 Feb 2024 06:34:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sZLZenrS" X-Original-To: linux-crypto@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68976A3F; Thu, 22 Feb 2024 06:34:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708583675; cv=none; b=gHm8Tlw8EcxSlJFGyYkNdUEOHoeCk5qcyEz47bLp4p9s2SXlYXiaMGw/HxZtwdipPd5uvIl7RrWpqmdj6EGsNIXRqcX9VS1fD4tCblvc6V/1Bo1PiqtyKUrDS5g8V3TiyKEK+c6uthw6Tp0Yje4Wm3kWTLtxArjRB7gjxsWa6sY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708583675; c=relaxed/simple; bh=utVGYA1jsUbTdSF23TVfYNwr3Dv1enzZmeupdecEtGQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=c7cSOZGpzoahL1PRY2wpAOmi20fR9YcOQDRW2dWFsq+q51vYettn9T8OWPuhC1vJAsFYq8uC07hDoQk8VpE/Ab3uCm7LtJCv/rduHrjh0R+2ZHvjp8qmShtVelQO/p7Gic4R4yY1X1N60clXFvHz1vZaxmJBrlQbHl2OvXGS0cY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sZLZenrS; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00E47C433C7; Thu, 22 Feb 2024 06:34:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708583675; bh=utVGYA1jsUbTdSF23TVfYNwr3Dv1enzZmeupdecEtGQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=sZLZenrSVbyJviQNkgxmlnf/7S1zEl2jTPaWA4SLmKis08BO3WMzPodwBt0ae30fT S/4teASk2F3zV8283yPvHZJTcz/hwhMRlW45sEnuC9QAqw56KcO5ySFF2z4kWMT0Sn xjnqbcy9c0dKIxGCtdqW8QSbAk0g22pJUT1bLsbJw/exxm/bHQCZx9vpVMPna5gV79 TrRRr0k60LFvvO/BcJcHYA5aytnHerMHQlrXL5zabTTo2zvFrgv+KjrIOMzF42dfPA 6Xr6jcpkdJWyIo67pD1b4/7C5ydQThpL+OMM2RrnetEPT/fPy3XNbBmN5fLLtzdJwj AkUR/vBYsSdCQ== Date: Wed, 21 Feb 2024 22:34:33 -0800 From: Eric Biggers To: Ard Biesheuvel Cc: linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au, Ard Biesheuvel , stable@vger.kernel.org, syzbot+f1ceaa1a09ab891e1934@syzkaller.appspotmail.com Subject: Re: [PATCH] crypto: arm64/neonbs - fix out-of-bounds access on short input Message-ID: <20240222063433.GA37580@sol.localdomain> References: <20240217161151.3987164-2-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240217161151.3987164-2-ardb+git@google.com> On Sat, Feb 17, 2024 at 05:11:52PM +0100, Ard Biesheuvel wrote: > From: Ard Biesheuvel > > The bit-sliced implementation of AES-CTR operates on blocks of 128 > bytes, and will fall back to the plain NEON version for tail blocks or > inputs that are shorter than 128 bytes to begin with. > > It will call straight into the plain NEON asm helper, which performs all > memory accesses in granules of 16 bytes (the size of a NEON register). > For this reason, the associated plain NEON glue code will copy inputs > shorter than 16 bytes into a temporary buffer, given that this is a rare > occurrence and it is not worth the effort to work around this in the asm > code. > > The fallback from the bit-sliced NEON version fails to take this into > account, potentially resulting in out-of-bounds accesses. So clone the > same workaround, and use a temp buffer for short in/outputs. > > Cc: > Reported-by: syzbot+f1ceaa1a09ab891e1934@syzkaller.appspotmail.com > Tested-by: syzbot+f1ceaa1a09ab891e1934@syzkaller.appspotmail.com > Signed-off-by: Ard Biesheuvel Looks like this could use: Fixes: fc074e130051 ("crypto: arm64/aes-neonbs-ctr - fallback to plain NEON for final chunk") > + if (unlikely(nbytes < AES_BLOCK_SIZE)) > + src = dst = memcpy(buf + sizeof(buf) - nbytes, > + src, nbytes); > + > neon_aes_ctr_encrypt(dst, src, ctx->enc, ctx->key.rounds, > nbytes, walk.iv); > + > + if (unlikely(nbytes < AES_BLOCK_SIZE)) > + memcpy(d, buf + sizeof(buf) - nbytes, nbytes); The second one could use 'dst' instead of 'buf + sizeof(buf) - nbytes', right? Otherwise this looks good. Reviewed-by: Eric Biggers - Eric