Thread (7 messages) 7 messages, 4 authors, 2014-10-22

Re: [PATCH] mm, hugetlb: correct bit shift in hstate_sizelog

From: Andrey Ryabinin <hidden>
Date: 2014-10-22 05:42:51
Also in: lkml

On 10/21/2014 10:15 PM, Sasha Levin wrote:
hstate_sizelog() would shift left an int rather than long, triggering
undefined behaviour and passing an incorrect value when the requested
page size was more than 4GB, thus breaking >4GB pages.
quoted hunk ↗ jump to hunk
Signed-off-by: Sasha Levin <redacted>
---
 include/linux/hugetlb.h |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 65e12a2..57e0dfd 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -312,7 +312,8 @@ static inline struct hstate *hstate_sizelog(int page_size_log)
 {
 	if (!page_size_log)
 		return &default_hstate;
-	return size_to_hstate(1 << page_size_log);
+
+	return size_to_hstate(1UL << page_size_log);
That still could be undefined on 32-bits. Either use 1ULL or reduce SHM_HUGE_MASK on 32bits.

 }
 
 static inline struct hstate *hstate_vma(struct vm_area_struct *vma)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help