From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Kuan-Wei Chiu <visitorckw@gmail.com>, Sasha Levin <sashal@kernel.org>
Subject: Re: [PATCH 5.15.y] scripts/sorttable: fix orc_sort_cmp() to maintain symmetry and transitivity
Date: Tue, 7 Jan 2025 13:10:16 -0500 [thread overview]
Message-ID: <20250107081321-bdeb6457b2dbd8c8@stable.kernel.org> (raw)
In-Reply-To: <20250106175318.3256899-1-visitorckw@gmail.com>
[ Sasha's backport helper bot ]
Hi,
Found matching upstream commit: 0210d251162f4033350a94a43f95b1c39ec84a90
Status in newer kernel trees:
6.12.y | Not found
6.6.y | Not found
6.1.y | Not found
5.15.y | Not found
Note: The patch differs from the upstream commit:
---
1: 0210d251162f ! 1: 02225d4eea29 scripts/sorttable: fix orc_sort_cmp() to maintain symmetry and transitivity
@@ Commit message
The orc_sort_cmp() function, used with qsort(), previously violated the
symmetry and transitivity rules required by the C standard. Specifically,
- when both entries are ORC_TYPE_UNDEFINED, it could result in both a < b
+ when both entries are ORC_REG_UNDEFINED, it could result in both a < b
and b < a, which breaks the required symmetry and transitivity. This can
lead to undefined behavior and incorrect sorting results, potentially
causing memory corruption in glibc implementations [1].
@@ Commit message
Transitivity: If x < y and y < z, then x < z.
Fix the comparison logic to return 0 when both entries are
- ORC_TYPE_UNDEFINED, ensuring compliance with qsort() requirements.
+ ORC_REG_UNDEFINED, ensuring compliance with qsort() requirements.
Link: https://www.qualys.com/2024/01/30/qsort.txt [1]
Link: https://lkml.kernel.org/r/20241226140332.2670689-1-visitorckw@gmail.com
@@ Commit message
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
+ (cherry picked from commit 0210d251162f4033350a94a43f95b1c39ec84a90)
+ Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
## scripts/sorttable.h ##
@@ scripts/sorttable.h: static inline unsigned long orc_ip(const int *ip)
@@ scripts/sorttable.h: static int orc_sort_cmp(const void *_a, const void *_b)
*/
orc_a = g_orc_table + (a - g_orc_ip_table);
+ orc_b = g_orc_table + (b - g_orc_ip_table);
-+ if (orc_a->type == ORC_TYPE_UNDEFINED && orc_b->type == ORC_TYPE_UNDEFINED)
++ if (orc_a->sp_reg == ORC_REG_UNDEFINED && !orc_a->end &&
++ orc_b->sp_reg == ORC_REG_UNDEFINED && !orc_b->end)
+ return 0;
- return orc_a->type == ORC_TYPE_UNDEFINED ? -1 : 1;
+ return orc_a->sp_reg == ORC_REG_UNDEFINED && !orc_a->end ? -1 : 1;
}
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-5.15.y | Success | Success |
prev parent reply other threads:[~2025-01-07 18:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-06 17:53 [PATCH 5.15.y] scripts/sorttable: fix orc_sort_cmp() to maintain symmetry and transitivity Kuan-Wei Chiu
2025-01-07 18:10 ` Sasha Levin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250107081321-bdeb6457b2dbd8c8@stable.kernel.org \
--to=sashal@kernel.org \
--cc=stable@vger.kernel.org \
--cc=visitorckw@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.