Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp198183rdb; Thu, 22 Feb 2024 00:19:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVsZkzACrajpEDlltyExpcERmC8kybKhlPiQHK1vCc5723l3MmpKDorUADHtKRPUFeL5edK/WWvsTtqqw0sdLDXd8qu3mqQpDY47mTGgQ== X-Google-Smtp-Source: AGHT+IHycwpQsnRXAUBMJtGOTkbebNtaZEVYthVvT48wwc6hkPvQxeqUQ8BBK1xEtVjNn3WfmnUG X-Received: by 2002:a17:903:40c5:b0:1dc:467b:45ea with SMTP id t5-20020a17090340c500b001dc467b45eamr2028017pld.63.1708589957155; Thu, 22 Feb 2024 00:19:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708589957; cv=pass; d=google.com; s=arc-20160816; b=RWtX4IkozS3GMA7y5xMO4E4h0ufl0yQzqGH8LGhcgXefDh9BEQa4SjK8qBHc9ng3C8 wjd/gtWY/EHHRHarMQWa5izkop3IMA4v74dJwpO3i1JKnLlz0UgQlwUZt+aznPHk8eH5 s7UbX6rRVdPzQ+qaT+12pY+AgAtSzkx/6ORnZIMqGULCb6xeuUQ9jiswtYPq6p7u4D0t 2yFbwWCL91ctDWFRRmT/KWdwvQ2/FJM+RB5eUJiLMERm8pDWjnlrvWMMeY5fxCruVYtR hnFSM5AVsJ4hBCQ3U882WseJnilWydGl/9m8AY7M9cemo7V6v7wZOansLdJsuTn7a7Bt S1xA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=yuTp2NuMxQ3HLCivBzGbe2vGUF9/jcSgMicvuvXS24I=; fh=LUch5+RxdSVAXXjAeeGvRAFe08MdZFSy6rjo9IRYrtc=; b=Dr8JUMMPwyUPWQwdSIfx12FlxKpNvpAqZdwL5H1hg42cHW1DkJMXb8s8UPVmyMe+jR AG7PtUnLnVIpFf+VwtckwEv8CuCeYDtqovmTin6Phto7nsf+gHZp4QFu1ujLzE67b+nQ OS7+3mcPjo/oYqCqBmDW/flIsATpxmtdB/qwfqAslWcHbh7JfYYaA23KZ3JvTGzV2ooK Uf0HbuInU5zl8fmh9kuIhp+uf0NeakmFp/7HssPqgty1JNvSO6ZeFhoKbi9FFTBScSB5 g1iotlM9HUsAzo5aAuldMaUh7qFtXt2azqOmtGuaXrWQWsSmPJzMrNTn29bJH7T1gTlh 2a1Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bvDHYiSr; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-2246-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-2246-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l3-20020a170903244300b001dbe0b2c96csi8106904pls.549.2024.02.22.00.19.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 00:19:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto+bounces-2246-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bvDHYiSr; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-2246-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-2246-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B844F282754 for ; Thu, 22 Feb 2024 08:19:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1550318041; Thu, 22 Feb 2024 08:19:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bvDHYiSr" 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 C45D21B263; Thu, 22 Feb 2024 08:19:11 +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=1708589951; cv=none; b=YN3LevsLojFNlFARXIfCV5aNFuT3a+gST6zpc46xJL/IQqzkjpTvEpdluQe92hDWsfT3AQwhvPL/UmmHdDw8NwGCEo0EWN2DRnfn/RoWfb8LcNYykYAS+dtBXVoCc8mN2t6syb8QC1fL8wFUkWGJEN3FLThW5T0+OijhfcPAWtA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708589951; c=relaxed/simple; bh=vS7S3JhxkbwRX4DFeskeDy6mHgoSepoNa465jqU9o/s=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=V05T4Mrl/syr7ythSiXMHJmsYoGSr5Jc+VKu02SvpKpdjs4jN+tyYMa20usOYMcdp8iD8SWwdprtJkRffO0SIaOa1mlQECREiolPDElhW3MG5yPkSTHc2B9d3qdL88JJ1FOtjfqcBuDUqvqJrtlF+uhJQCVbmQTuVQDOmtA7b20= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bvDHYiSr; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5416BC43394; Thu, 22 Feb 2024 08:19:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708589951; bh=vS7S3JhxkbwRX4DFeskeDy6mHgoSepoNa465jqU9o/s=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=bvDHYiSr7olryX4OEgArbxtV/4R7EOQQuVZBgCQZ5FGKaKZfZlnoHN6/tS4kTmFtD R7V/vSUKQnDxfZntEJt4NLAti4bGLnrYbMClQbEnAgV2JmvgIDEOAe2dK65dElFa3H pradVYpu6RUlIBmfKSodaW7erWbP1hAM47HfGOzhCGR8/nmvxgBKK92QlTmqg49U5a nUEDgwQ/O+jX1VPTZx8Pm3JtLduYhdDa6pESDHWZCVGJBC0QJ8ivPGgnhJL9w1OXRm gNtnbbslL3D/IKGglohwj++r8KtUME24sCyly8IEQepdTz5dnm+F7ftczTBwhDwQIe gnGAKDHir0wbg== Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-512a65cd2c7so6103393e87.0; Thu, 22 Feb 2024 00:19:11 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUjoGJ/bFB/x2+Ox/0IkQCbt0Uh4hsV/GKRhliiX4oTZ4IS0pHgzYBGlha9JmAWNHaxZopiKQbO4toXm3Hi/G7nmICwKdWgTVKnctD/ltOE7cmjgBagPvay//W3WdyHCrpy0kl3 X-Gm-Message-State: AOJu0YxiyipgSuNjpTzhIAyJOGYUWX0DMhi5LBdIFG82L12u1bHWgOXp Niy9PC7xHZlNSMbUkqgwjScfJQPWocszIL7l3TUaqeQeu8fG9ZLAXliRqrVEr9qdxTijdoKhWzM XLDuNOZGd0p9rAketEYKAtUmTrDM= X-Received: by 2002:ac2:544c:0:b0:511:9e5a:922d with SMTP id d12-20020ac2544c000000b005119e5a922dmr12986471lfn.14.1708589949519; Thu, 22 Feb 2024 00:19:09 -0800 (PST) Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240217161151.3987164-2-ardb+git@google.com> <20240222063433.GA37580@sol.localdomain> In-Reply-To: <20240222063433.GA37580@sol.localdomain> From: Ard Biesheuvel Date: Thu, 22 Feb 2024 09:18:56 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] crypto: arm64/neonbs - fix out-of-bounds access on short input To: Eric Biggers Cc: Ard Biesheuvel , linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au, stable@vger.kernel.org, syzbot+f1ceaa1a09ab891e1934@syzkaller.appspotmail.com Content-Type: text/plain; charset="UTF-8" On Thu, 22 Feb 2024 at 07:34, Eric Biggers wrote: > > 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") > Indeed. > > + 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? > Correct. > Otherwise this looks good. > > Reviewed-by: Eric Biggers > I'll respin with these changes. Thanks.