Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp663791pxb; Tue, 5 Apr 2022 17:51:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrQBhZQn0A+ZfNDRzMHORaJ9PAIK+SeG+gH7P/Kf0qYBxPWDJ/Q4kHrQm+eHWCN0B9HIww X-Received: by 2002:a05:6402:5cb:b0:419:14d8:4106 with SMTP id n11-20020a05640205cb00b0041914d84106mr6296908edx.140.1649206304868; Tue, 05 Apr 2022 17:51:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649206304; cv=none; d=google.com; s=arc-20160816; b=Q6qQy9RhZF6rJ0A11Ssxurn9wR0xNTYjhMI1ppx1H4oTULgraR58I8KoJJAkdzc1Jq XZ0ORZYw0/sPNNtFEczqFgmjpHlnMshxUDZ+hG5tuxDus49pi8ie9fo5kKNwVmgEXRFa 2vl2fe9ObS5OKbBeE234nldQ6k3I2VF3BePEobyV9Y22smpHASVbQ24OCbTcKk2h4GLc I+6bNCUMsz7ZoP72w2Wd6NABEp0Mf79SZU+s8ZKYCJzRJ1XBPX9OuTPEzr63Q8Q7XFlZ 0P9J0V7Wejyg5XaN0YQjpejJTNus2yNirUBg7xUnNTuNKTM/of2m4y8VwchXFy0R80FN 5PGw== 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=/Lx54BsLdNwzMrIyYU+nMCoUGJd5Mhc1JQmfBz5UvJk=; b=n3Y6KHO//zkKo+QXFaEl2yA3t74DlQwkrf2G95CMiMf9pzJcUuIR+pQmV2ui01hlfC Jk3zOQ6LPPJa+93rQPd0ujVSm2b1Yo3/2IG2svDJ9gAmy42Opsx7Fa+Y7IEsJ28jg5Vd wJw55wDb13PgW/VUaZWRoRoulrTdD48iHOql4Mb9rnO2chl2zY0hRBDxJnaQMfXLArvD Paeb6WxiruuDvPVDakaRl4jTmMSugoMb56edHRaXAbLW18OmRE1bg5lbkIyPFScrUXQq DlXA4BzxfL78wuqM9g8mid+8R5RKHP0tpdXcVwtoQvQHe4dFkHGorOFl4wU4H7R7Ln6p 4sug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SY+nsTZg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id la18-20020a170907781200b006df76385c5asi10794801ejc.250.2022.04.05.17.51.15; Tue, 05 Apr 2022 17:51:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SY+nsTZg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S235287AbiDEH7e (ORCPT + 99 others); Tue, 5 Apr 2022 03:59:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233587AbiDEHsE (ORCPT ); Tue, 5 Apr 2022 03:48:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B4E828C; Tue, 5 Apr 2022 00:46:06 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0777C616BF; Tue, 5 Apr 2022 07:46:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19458C340EE; Tue, 5 Apr 2022 07:46:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649144765; bh=+3MwjoxU6y9Rz147dPjjPlPFEMsY7UQgaL93494ZQ1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SY+nsTZgM2QbSo7v085aolKZL7DrwAzA+haDNKK4U2VJ0xE1IsYSZFU1LJvXntzp8 xuAx5BYZVI4ZX2vFB+nGehmUsk+4Rb4GvTTgzjCKNljPBqhVnOO4DDnnD+4j+mrB3+ 0mtJzoms1UKr1E74fSxXCtTnNwxCOslRT9V1bbPg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tadeusz Struk , Eric Biggers , Herbert Xu Subject: [PATCH 5.17 0163/1126] crypto: rsa-pkcs1pad - fix buffer overread in pkcs1pad_verify_complete() Date: Tue, 5 Apr 2022 09:15:10 +0200 Message-Id: <20220405070412.379079190@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Biggers commit a24611ea356c7f3f0ec926da11b9482ac1f414fd upstream. Before checking whether the expected digest_info is present, we need to check that there are enough bytes remaining. Fixes: a49de377e051 ("crypto: Add hash param to pkcs1pad") Cc: # v4.6+ Cc: Tadeusz Struk Signed-off-by: Eric Biggers Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- crypto/rsa-pkcs1pad.c | 2 ++ 1 file changed, 2 insertions(+) --- a/crypto/rsa-pkcs1pad.c +++ b/crypto/rsa-pkcs1pad.c @@ -476,6 +476,8 @@ static int pkcs1pad_verify_complete(stru pos++; if (digest_info) { + if (digest_info->size > dst_len - pos) + goto done; if (crypto_memneq(out_buf + pos, digest_info->data, digest_info->size)) goto done;