From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796381536; b=ytRBT0lKaqKPDJAcmYDd52KoqigQQ6q/q6kyEbDf5Q5b9Bdi1Npf+x/wUaAwEaoR6LQi ylS/ijqZHYc+2v7AIFno01jExhGETP+GID1/gvteZyPvb/FKwgbIpRrYRZRleNjZU4I2b nCHVutLJkFHP++RmtOiZgDpWuPjnYMTCd+io0gtKBVDIxc/+GTxGUZZcK6zNxTkc5WfIA eSSM01VGlAOVMNUe3p2WQdIsfH3pubOqXYNp3prU7ZyS18u9AhSsb3RYXQvPo3G6FvFFR DNkrBGKJTvZA09rHvyhw+Jz5BaXAv51eMZHIX16myEOoRAsbMV/SFMXJ5r2oxZ3jwng== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381536; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=GYvyIuxQPSRDN42l+GQNsnTZYIts+9C+bYQ21QjFg+k=; b=Rz/5y4lC5iq67c/4J+itFcBo1t33Prg5q0btg2gnkeNPQ+RidsVBUxKZkOlmXsnEVINb uvSy7aoe19wmamTDPZJcipCB3NjvakxXWX9ps9xFxSkDs9agN/iV5a9Cl9Haj7Jd31e7N vrdT2SXtYOJUt4l67OKr8pwVKyr8T7RmdDaRyQAb0uwYutooJKrSIn6Q9TKjsCOaHkzza aIJSISG1NM/gYruuqCid30fr68n8tzOFG88pi9CuwerIMSWTbgyTTcDAXSbT6klvycE2G UBuHhjZ/Vmk4qje0duPG/zk0MnD1yXKW++94j/+he4t4JliHebBP8Do9IFzDK76koLQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=XyjBkVoN; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3A00606A681; Fri, 4 Dec 2026 10:52:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=XyjBkVoN Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27F171F000CE; Fri, 4 Dec 2026 10:52:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381536; bh=GYvyIuxQPSRDN42l+GQNsnTZYIts+9C+bYQ21QjFg+k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=XyjBkVoNQXpTnmqBkFqMXxZE+sptt1LTOAto1VA1m7F+S88+Jo0kCDZFBVGxfpK3F uRHX6ewjjIQR48q3SF075nYW2PDMD/QS9OmfsEIFAyayOTqukKGrOPF4tNv1qJpO7S DihabjxQ058Q/EmFgXLty0A4cVRwrM23l6JikMBc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Guicai Ma , Jarkko Sakkinen Subject: [PATCH 7.3 707/742] KEYS: Fix userspace buffer overflow in keyctl_pkey_e_d_s() Date: Fri, 4 Dec 2026 19:09:31 +0900 Message-ID: <20261204100653.839336391@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Guicai Ma commit 484dc27f031229b374446cf038fa9c7a84d0f725 upstream. Commit cb481e59ea6c ("KEYS: fix overflow in keyctl_pkey_params_get_2()") changed keyctl_pkey_params_get_2() to set params->out_len to the maximum output size of the operation instead of uparams.out_len, so that the kernel buffer allocated in keyctl_pkey_e_d_s() is large enough. Because uparams.out_len is no longer kept, keyctl_pkey_e_d_s() copies ret bytes to _out without checking whether the result fits in the caller's buffer. If a smaller out_len was passed, copy_to_user() writes past the end of _out instead of failing with -EOVERFLOW. uparams.out_len cannot simply be required to be at least the maximum output size in keyctl_pkey_params_get_2(), since KEYCTL_PKEY_DECRYPT with enc=pkcs1 can return a plaintext shorter than max_dec_size into a matching smaller buffer. Pass uparams.out_len back to keyctl_pkey_e_d_s() and return -EOVERFLOW before copy_to_user() if ret exceeds it. Cc: stable@vger.kernel.org # v7.2+ Fixes: cb481e59ea6c ("KEYS: fix overflow in keyctl_pkey_params_get_2()") Signed-off-by: Guicai Ma Reviewed-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen Signed-off-by: Greg Kroah-Hartman --- security/keys/keyctl_pkey.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) --- a/security/keys/keyctl_pkey.c +++ b/security/keys/keyctl_pkey.c @@ -113,7 +113,8 @@ static int keyctl_pkey_params_get(key_se static int keyctl_pkey_params_get_2(const struct keyctl_pkey_params __user *_params, const char __user *_info, int op, - struct kernel_pkey_params *params) + struct kernel_pkey_params *params, + u32 *user_out_len) { struct keyctl_pkey_params uparams; struct kernel_pkey_query info; @@ -183,6 +184,8 @@ static int keyctl_pkey_params_get_2(cons } params->in_len = uparams.in_len; + if (user_out_len) + *user_out_len = uparams.out_len; switch (op) { case KEYCTL_PKEY_VERIFY: @@ -264,10 +267,12 @@ long keyctl_pkey_e_d_s(int op, void __user *_out) { struct kernel_pkey_params params; + u32 user_out_len; void *in, *out; long ret; - ret = keyctl_pkey_params_get_2(_params, _info, op, ¶ms); + ret = keyctl_pkey_params_get_2(_params, _info, op, ¶ms, + &user_out_len); if (ret < 0) goto error_params; @@ -310,6 +315,10 @@ out_up_key_sem: if (ret < 0) goto error_out; + if (ret > user_out_len) { + ret = -EOVERFLOW; + goto error_out; + } if (copy_to_user(_out, out, ret) != 0) ret = -EFAULT; @@ -349,7 +358,7 @@ long keyctl_pkey_verify(const struct key long ret; ret = keyctl_pkey_params_get_2(_params, _info, KEYCTL_PKEY_VERIFY, - ¶ms); + ¶ms, NULL); if (ret < 0) goto out_free_params;