Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2242539rdb; Wed, 21 Feb 2024 01:12:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVS3m4KeI52vjvemMkZXyZLumTijzTWN7++sMF5e9ewO5uKV/nYIrCw23z0SCVUf8rpun9PjnZUlkdV+2xHf1Esmmx+NU9rWcnDQ+jKKg== X-Google-Smtp-Source: AGHT+IFr53v3JtiP623qK8a8qo9cNCSBGq7NmuwrN/GPdz6yKWAybRYEvkZO+wxYtpYf39gS7Vz3 X-Received: by 2002:a17:90b:95:b0:299:4cc5:aa25 with SMTP id bb21-20020a17090b009500b002994cc5aa25mr8968582pjb.25.1708506737797; Wed, 21 Feb 2024 01:12:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708506737; cv=pass; d=google.com; s=arc-20160816; b=qcuFNYMlSK84yqI2c70Rq90nHzVY9e5eBSKpzox/y4cUPZ7EUvNpcw4r9UHc9HjygN cuOugF2rNIG7GH46b4xL48TwzWpfAWpryjz+Y6mPGx9NsOr3R/VYX8j955AX3LKO4qgJ YdqzO3E2to36V2z8xAHO5uyMyYNBvggvuJrNt0kl+VIblWRZeR0LV0fu+8EqyUkAyleA N0VuZafopnkeCsKGF6G2u6+pDZlnNQFyBAMOXiSrLssmL+Lg8VpK2UWJBa5y/GwscqNs sUu/Fy95Ag4VeBEivUh7m5vSvHlU8pMYGSDA38x0fb2AhxYSBWEvF+d2VhlNmdKAUjaI QD1A== 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; bh=846p630Yyokf8VdTcF+E3a+zk9z6MDlSbdoHSD0H44s=; fh=KaK1K9J7aucQZTe3E+p4ggsPBI3G7v3SHKonyuzgd/I=; b=OFbZcChCLyAdmxzpS5Ey47+pZi2CJ4qhvmqxDTHsmDOUytTJ9uBuKStbF/VIUYAiof lTawMjMI0RPbHTT3fT42K+nhO1eE3yoyID3BLxpQX1FRiqqr4YF2S1hb1VHLcs118aP5 SI1IkHRyPm7jupd4ymSl3m6Co3zwexXVUGXnYFdQNRq27AonJBSMQkGzwPu/BPSqyDZp GPMrr10wwI46GyDdXMsH27QVuYhDFMUfV5dMdgb50UI8lTXmwfDr4oYH1rsOrgwJG59s KVI3kVckRswiqz/maVaC6p5yf1nxEsJQkMf1mNHnISKZORpNpRihZyAHNXGFOWmh107T GXaw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gondor.apana.org.au dmarc=pass fromdomain=gondor.apana.org.au); spf=pass (google.com: domain of linux-crypto+bounces-2214-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-2214-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=REJECT sp=QUARANTINE dis=NONE) header.from=apana.org.au Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u18-20020a17090ae01200b00299255fb068si7773374pjy.151.2024.02.21.01.12.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 01:12:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto+bounces-2214-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gondor.apana.org.au dmarc=pass fromdomain=gondor.apana.org.au); spf=pass (google.com: domain of linux-crypto+bounces-2214-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-2214-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=REJECT sp=QUARANTINE dis=NONE) header.from=apana.org.au 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 7FC2E280F6C for ; Wed, 21 Feb 2024 09:12:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 930663D961; Wed, 21 Feb 2024 09:07:45 +0000 (UTC) X-Original-To: linux-crypto@vger.kernel.org Received: from abb.hmeau.com (abb.hmeau.com [144.6.53.87]) (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 5CBFF3C6B3; Wed, 21 Feb 2024 09:07:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=144.6.53.87 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708506465; cv=none; b=KI2I4bRh/z3Q7wniEjMtjb0w+I1d+PGvqlbwCP/PVGp7GLsn+5dpSczHt/q3HN2sP37LR+lx8K4XpL6FZX8ob1VfRCnhX45BsfaHdonOgp6xdZT3XHMS3M16Udyvvhiy7s5Oy7SCNZ0MILfxGkkKCtcrNBVW/KWGFxeplkmpq6g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708506465; c=relaxed/simple; bh=Cw0vjSxZd4BozTwPlM6pL0uP35pHBxORm59HXV+iY1U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KGi0PGgmEmyTBH6kwXAk57nq8gXjHjC5mzPoclPoU9MvC0UfiZy1XEptk/mO9JjKdpAb5BesCBFrfVbQ6DnGSqqjbYvUXEHrJB2SF0vUGs4BWsbO9MIt80m2omvOf0Y+bKeKUBGMnVd8rxd0+gkBVqzKPg4HS+NmFAK6AkUQqe4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gondor.apana.org.au; spf=pass smtp.mailfrom=gondor.apana.org.au; arc=none smtp.client-ip=144.6.53.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gondor.apana.org.au Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gondor.apana.org.au Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1rciZd-00G0nc-TZ; Wed, 21 Feb 2024 17:07:30 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Wed, 21 Feb 2024 17:07:44 +0800 Date: Wed, 21 Feb 2024 17:07:44 +0800 From: Herbert Xu To: syzbot Cc: davem@davemloft.net, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Subject: [PATCH] crypto: lskcipher - Copy IV in lskcipher glue code always Message-ID: References: <00000000000097f7f90611d1370c@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: <00000000000097f7f90611d1370c@google.com> The lskcipher glue code for skcipher needs to copy the IV every time rather than only on the first and last request. Otherwise those algorithms that use IV to perform chaining may break, e.g., CBC. This is because crypto_skcipher_import/export do not include the IV as part of the saved state. Reported-by: syzbot+b90b904ef6bdfdafec1d@syzkaller.appspotmail.com Fixes: 662ea18d089b ("crypto: skcipher - Make use of internal state") Signed-off-by: Herbert Xu diff --git a/crypto/lskcipher.c b/crypto/lskcipher.c index 0b6dd8aa21f2..0f1bd7dcde24 100644 --- a/crypto/lskcipher.c +++ b/crypto/lskcipher.c @@ -212,13 +212,12 @@ static int crypto_lskcipher_crypt_sg(struct skcipher_request *req, ivsize = crypto_lskcipher_ivsize(tfm); ivs = PTR_ALIGN(ivs, crypto_skcipher_alignmask(skcipher) + 1); + memcpy(ivs, req->iv, ivsize); flags = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP; if (req->base.flags & CRYPTO_SKCIPHER_REQ_CONT) flags |= CRYPTO_LSKCIPHER_FLAG_CONT; - else - memcpy(ivs, req->iv, ivsize); if (!(req->base.flags & CRYPTO_SKCIPHER_REQ_NOTFINAL)) flags |= CRYPTO_LSKCIPHER_FLAG_FINAL; @@ -234,8 +233,7 @@ static int crypto_lskcipher_crypt_sg(struct skcipher_request *req, flags |= CRYPTO_LSKCIPHER_FLAG_CONT; } - if (flags & CRYPTO_LSKCIPHER_FLAG_FINAL) - memcpy(req->iv, ivs, ivsize); + memcpy(req->iv, ivs, ivsize); return err; } -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt