From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 A3B6030D3FF; Tue, 21 Jul 2026 20:54:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784667245; cv=none; b=GzxFqF0iLFGnzHoIo4vl514McWlWmR2A59970tObjy0t4r3kl2XkPf4FbyJaDUXLmJX8wvLr02LLmqzbVp4laCMNyRK51Yjw4uX9Q7Z5aS2yYSEsLsbPs4YCHYFlKHLA9cOGBNgyxu1a0KH9HI0Ymik029+mtg+nDfkylIxCnXU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784667245; c=relaxed/simple; bh=TaF5CYStGS0tu2kuk9Tjrm7f3M3oBklfATd+z+mWLAM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iRCCkytwx3ZWqxFINvbQZA4a1KOJXTiQnERo1+zEm3nDCrjrBYX4/THXKesBY1VvKWIKHB9zlF1/baJ1xyirQocHjpczcWmsU7m8gBqmuZJMwLuwQvlxtQvT8sQ1vyVWYDTOr+hPJ80L3qvo3NqIeWLZcoyqw6bq8zCtC8EjcGs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=sGCrYXDh; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="sGCrYXDh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 155D61F000E9; Tue, 21 Jul 2026 20:54:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784667244; bh=imIuv3LChIwI74/DFxR9GrBbR6gmH/iI+Neg9OiMNSc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=sGCrYXDhfxB0VSDlSLm5fN8DELl8E9dkFuagO0urx+QiJX4UHlaAVFL8yZsO6ed4x gAOjMDbsqhgiGTN+KPtW9yuqikOsGtoE+EKsXCnjfNIsaJOurO++ItwZ0rh6RY1Hji FEd0I0AhSAiv5q3oryXg+VINDeOn4HIug7q+RUAQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Aaron Tomlin , Thomas Bogendoerfer Subject: [PATCH 6.6 0988/1266] mips: sched: Fix CPUMASK_OFFSTACK memory corruption Date: Tue, 21 Jul 2026 17:23:45 +0200 Message-ID: <20260721152503.944069964@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152441.786066624@linuxfoundation.org> References: <20260721152441.786066624@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Aaron Tomlin commit 98e37db4a34d3af3fb2f4648295c25b5e40b20e3 upstream. This patch addresses a critical memory management flaw. When CONFIG_CPUMASK_OFFSTACK is enabled, cpumask_var_t is a pointer. Consequently, sizeof(new_mask) evaluates to the pointer size, causing copy_from_user() to clobber the mask pointer. Furthermore, the old logic performed copy_from_user() before allocating the mask. Fix this by allocating new_mask first. To handle variable-sized user masks correctly, use cpumask_size() to truncate overly large user masks or pad undersized masks with zeros before copying the data directly into the allocated buffer. Fixes: 295cbf6d63165 ("[MIPS] Move FPU affinity code into separate file.") Cc: stable@vger.kernel.org Signed-off-by: Aaron Tomlin Signed-off-by: Thomas Bogendoerfer Signed-off-by: Greg Kroah-Hartman --- arch/mips/kernel/mips-mt-fpaff.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) --- a/arch/mips/kernel/mips-mt-fpaff.c +++ b/arch/mips/kernel/mips-mt-fpaff.c @@ -70,11 +70,16 @@ asmlinkage long mipsmt_sys_sched_setaffi struct task_struct *p; int retval; - if (len < sizeof(new_mask)) - return -EINVAL; - - if (copy_from_user(&new_mask, user_mask_ptr, sizeof(new_mask))) - return -EFAULT; + if (!alloc_cpumask_var(&new_mask, GFP_KERNEL)) + return -ENOMEM; + if (len < cpumask_size()) + cpumask_clear(new_mask); + else if (len > cpumask_size()) + len = cpumask_size(); + if (copy_from_user(new_mask, user_mask_ptr, len)) { + retval = -EFAULT; + goto out_free_new_mask; + } cpus_read_lock(); rcu_read_lock(); @@ -83,7 +88,8 @@ asmlinkage long mipsmt_sys_sched_setaffi if (!p) { rcu_read_unlock(); cpus_read_unlock(); - return -ESRCH; + retval = -ESRCH; + goto out_free_new_mask; } /* Prevent p going away */ @@ -94,13 +100,9 @@ asmlinkage long mipsmt_sys_sched_setaffi retval = -ENOMEM; goto out_put_task; } - if (!alloc_cpumask_var(&new_mask, GFP_KERNEL)) { - retval = -ENOMEM; - goto out_free_cpus_allowed; - } if (!alloc_cpumask_var(&effective_mask, GFP_KERNEL)) { retval = -ENOMEM; - goto out_free_new_mask; + goto out_free_cpus_allowed; } if (!check_same_owner(p) && !capable(CAP_SYS_NICE)) { retval = -EPERM; @@ -141,13 +143,13 @@ asmlinkage long mipsmt_sys_sched_setaffi } out_unlock: free_cpumask_var(effective_mask); -out_free_new_mask: - free_cpumask_var(new_mask); out_free_cpus_allowed: free_cpumask_var(cpus_allowed); out_put_task: put_task_struct(p); cpus_read_unlock(); +out_free_new_mask: + free_cpumask_var(new_mask); return retval; }