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=1796384193; b=FUJqqw6kcik9BVvibTjB8DoMsLyrRJLS6CCgQ7UN1OsbEufC3lo5ltA3JU7bpvOmp0BI H1okr2h3kGzUoD1vJRQdkHtnC+irEbohi0tlfHfxm4Zu2fzPRWnUyybOEM+EY7Uh47doS XdHmeMQ3xVlhZ4SMV9aa1Fe89Nzm4JMXleLJlJy+cM89ks/9naZI0yew5opFPhk1T97AW cHwlg0inNeEsd8mV7pkoboELnD1fG6bSb/8bHUw1id/l12lgq2nhTIUx9XNnsi6c0Ecmu CQ3Xoam09hzTzkj6iA8RaCuyUMVJq00IpiNW6ugv5ZDjsZgOVK4gl+dw+gWfuRY9Ojw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384193; 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=BOOReE20645DZSwvGuw2wgdPIHkIyKH54DItWDkpb44=; b=DKi74iUiXFce8fcZrZ5MzI9gwqob4jKHEvkPsXBAAxHAWZh09dRZwlrf0USfAz1UKB0Q hbk3xO62aSZ63k1TtYRqBB2JjmEMUDvtnhD2mxG9ukVBJhztS9bMouCGAEwzJKUDEW9wL Fc7JZidin152/lO3Eo70OVdM7kuaEet97zpGVF9xqrUTkEgEGHGBY1bExNgqnMCxmsHFj aLcAJ/YRwuvhjRrkArdrFH+7Tt2hNTwO8iCYnkSFtPbD985/2cYvg//aLiKhVtGGKeGwz Ru/6p0B30FiWfaa1/lS9SyakSHtI6O9da+Rz6olW21w9xH0jpQhsf11fECnmKHOdfaA== 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="CTvvtw/E"; 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 58F31606A32D; Fri, 4 Dec 2026 11:36:33 +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=CTvvtw/E Received: by smtp.kernel.org (Postfix) with ESMTPSA id C82151F000C2; Fri, 4 Dec 2026 11:36:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384193; bh=BOOReE20645DZSwvGuw2wgdPIHkIyKH54DItWDkpb44=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CTvvtw/El4TuwEUE/ShqcBFTW5tAQQnEcj+FfTGQDugUK65ZutvVy/eu64+/5E4F3 ca8N0JTeiYZuTUktG1493Pi2q/Fg4x/kL/pd8sk6KXRHt2PalDaynJEFB9KENb9qgZ 3PmYvnQQOPsiP7vxeeHLe27WbEQCQhYs/hNtYSAg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Guicai Ma , Jarkko Sakkinen Subject: [PATCH 6.12 535/555] KEYS: Fix userspace buffer overflow in keyctl_pkey_e_d_s() Date: Fri, 4 Dec 2026 19:09:38 +0900 Message-ID: <20261204100629.040057845@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-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;