Skip to contentSkip to conversation

kern/sys: Compat sysinfo syscall fix undefined behavior

PATCH In review Scotty Bauer 2 participants 3 messages Sep 4, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kern/sys: Compat sysinfo syscall fix undefined behavior

Fix undefined behavior and compiler warning by replacing right shift 32 with upper_32_bits macro

---
 kernel/sys.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sys.c +1 -1
index ce81291..c78530b 100644
@@ -2135,7 +2135,7 @@ COMPAT_SYSCALL_DEFINE1(sysinfo, struct compat_sysinfo __user *, info)
 	/* Check to see if any memory value is too large for 32-bit and scale
 	 *  down if needed
 	 */
-	if ((s.totalram >> 32) || (s.totalswap >> 32)) {
+	if (upper_32_bits(s.totalram) || upper_32_bits(s.totalswap)) {
 		int bitcount = 0;
 
 		while (s.mem_unit < PAGE_SIZE) {
Signature · 1 line
1.8.3.2
#1 lore raw
Quoted 13 lines · On Thu, 04 Sep 2014 12:46:53 -0600 Scotty Bauer <[email protected]> wrote:

Fix undefined behavior and compiler warning by replacing right shift 32 with upper_32_bits macro

---
 kernel/sys.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sys.c +0 -0
index ce81291..c78530b 100644

kernel/sys.c COMPAT_SYSCALL_DEFINE1(sysinfo, struct compat_sysinfo __user *, info) · line 2141

Quoted 8 lines
kernel/sys.c +1 -1
@@ -2135,7 +2135,7 @@ COMPAT_SYSCALL_DEFINE1(sysinfo, struct compat_sysinfo __user *, info)
 	/* Check to see if any memory value is too large for 32-bit and scale
 	 *  down if needed
 	 */
-	if ((s.totalram >> 32) || (s.totalswap >> 32)) {
+	if (upper_32_bits(s.totalram) || upper_32_bits(s.totalswap)) {
 		int bitcount = 0;
 
 		while (s.mem_unit < PAGE_SIZE) {

Fair enough.

If I'm reading it correctly, this is all dead code because si_meminfo() unconditionally sets sysinfo.mem_unit to PAGE_SIZE.

It could all do with a bit of a cleanup, I suspect.

#2 lore raw
Quoted 1 line · Andrew Morton

If I'm reading it correctly, this is all dead code because si_meminfo() unconditionally sets sysinfo.mem_unit to PAGE_SIZE. It could all do with a bit of a cleanup, I suspect.

I'll do a little more research on this and do further clean up, if required.

-Scotty