Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp661198pxb; Tue, 5 Apr 2022 17:44:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3d5hyIeVOAallbMUbWkGKRWTWUiB1Dn8WY7U8d3zKfsdhO4ZFPiFkYhllLq0OFIlCp43+ X-Received: by 2002:a05:6402:26c8:b0:419:2e54:9262 with SMTP id x8-20020a05640226c800b004192e549262mr6165483edd.61.1649205889670; Tue, 05 Apr 2022 17:44:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649205889; cv=none; d=google.com; s=arc-20160816; b=T4fmSgu/cxXTeKI2CyZT+ou8e2DakRcd/tUurxVkIuDmowru0rjhjfsw7KUzx/Hizv GLoablycpvDg48uSYd3uNJ4E+Sv5qpma3RAziuOUDWxDYSbAtfBCJmNnn45VgaN+eyrz IG6ZlCtR+xcVnNgd/8sA9N8NHFlGQmbXxvh6jAA7mOWZKF6uc9jCJ4wMxxJLEh1q4wYt ts4XaVAuMt1RdxngOMY6jiRGdJ5l+R6FMqZ8vf9gEyWipFU3LeySZ2U2RhFlocHgb2wS STWO/UVI0uMze/MM6KF6YTKh26FMfjnLG/RoGGsJK+LBEIE3WB1D1txThmgykbVVMLbG wVWA== 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=As4w45yORY2o7vgYv8jgjbU0FXUe3ZJyOm1dQhoLLuo=; b=Ds3noaL97JatBQKrfZunyg+QWju3CI/IF7tATeSlDMJlX0L37R1ciupmBo2nqqohLN dipDrD0QBc2DqhlBkUndokxpwXZaO4iM6zFqGDA2oIGegtjp2O35MV6Z7w6x4WBaaT4Y wiCz5JBOJqyf7/4v2KF/c0REQNdQ1Yhnd65fAaKsFqaT4AZfJXBSEd4neUjgHZWEQ446 VsWSViXoXmVFRWgqBWU+bbobDaZfZMCCBLgN+IAEnxnQLmeAgdrmdHn9FlJbAIrnNlxL HEVQw3jwhBl3ij43zkmqvM/G5OkcWYhj2FXGr1Gk6YGkJewQ5f/iAjzLN/a36+Cb03WX aXqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="09koD/JT"; 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 k7-20020a17090646c700b006df76385d93si9976735ejs.563.2022.04.05.17.44.22; Tue, 05 Apr 2022 17:44:49 -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="09koD/JT"; 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 S1388241AbiDEOdW (ORCPT + 99 others); Tue, 5 Apr 2022 10:33:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238891AbiDEJdC (ORCPT ); Tue, 5 Apr 2022 05:33:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6162ECF4; Tue, 5 Apr 2022 02:20:37 -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 ams.source.kernel.org (Postfix) with ESMTPS id 11674B81B75; Tue, 5 Apr 2022 09:20:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7BFC8C385A2; Tue, 5 Apr 2022 09:20:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649150434; bh=Utz1YvWbSMLmkIEVCdwmAdUPQ3ARE9UXbQLDcRmNtww=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=09koD/JTbYXOQXStxL8zs1m9nyHJf7dih1HQWLkrviguHaQ8VKcYjTf8TDAaNJy19 uPRDW+o6O/mekfRPf+EtybG1MMiOlYB6O57G5lq9ZCJEPRASLQvxptuJCsyBJws22J UdWLQJ77BGls0CYbkQXN4vC2AFjh/o16kCMOlBeQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Biggers , Jarkko Sakkinen Subject: [PATCH 5.15 055/913] KEYS: fix length validation in keyctl_pkey_params_get_2() Date: Tue, 5 Apr 2022 09:18:37 +0200 Message-Id: <20220405070341.470126690@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@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 c51abd96837f600d8fd940b6ab8e2da578575504 upstream. In many cases, keyctl_pkey_params_get_2() is validating the user buffer lengths against the wrong algorithm properties. Fix it to check against the correct properties. Probably this wasn't noticed before because for all asymmetric keys of the "public_key" subtype, max_data_size == max_sig_size == max_enc_size == max_dec_size. However, this isn't necessarily true for the "asym_tpm" subtype (it should be, but it's not strictly validated). Of course, future key types could have different values as well. Fixes: 00d60fd3b932 ("KEYS: Provide keyctls to drive the new key type ops for asymmetric keys [ver #2]") Cc: # v4.20+ Signed-off-by: Eric Biggers Reviewed-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen Signed-off-by: Greg Kroah-Hartman --- security/keys/keyctl_pkey.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) --- a/security/keys/keyctl_pkey.c +++ b/security/keys/keyctl_pkey.c @@ -135,15 +135,23 @@ static int keyctl_pkey_params_get_2(cons switch (op) { case KEYCTL_PKEY_ENCRYPT: + if (uparams.in_len > info.max_dec_size || + uparams.out_len > info.max_enc_size) + return -EINVAL; + break; case KEYCTL_PKEY_DECRYPT: if (uparams.in_len > info.max_enc_size || uparams.out_len > info.max_dec_size) return -EINVAL; break; case KEYCTL_PKEY_SIGN: + if (uparams.in_len > info.max_data_size || + uparams.out_len > info.max_sig_size) + return -EINVAL; + break; case KEYCTL_PKEY_VERIFY: - if (uparams.in_len > info.max_sig_size || - uparams.out_len > info.max_data_size) + if (uparams.in_len > info.max_data_size || + uparams.in2_len > info.max_sig_size) return -EINVAL; break; default: @@ -151,7 +159,7 @@ static int keyctl_pkey_params_get_2(cons } params->in_len = uparams.in_len; - params->out_len = uparams.out_len; + params->out_len = uparams.out_len; /* Note: same as in2_len */ return 0; }