Skip to content

Commit 52f657e

Browse files
committed
x86: shadow stacks: proper error handling for mmap lock
김영민 reports that shstk_pop_sigframe() doesn't check for errors from mmap_read_lock_killable(), which is a silly oversight, and also shows that we haven't marked those functions with "__must_check", which would have immediately caught it. So let's fix both issues. Reported-by: 김영민 <osori@hspace.io> Acked-by: Oleg Nesterov <oleg@redhat.com> Acked-by: Dave Hansen <dave.hansen@intel.com> Acked-by: Rick Edgecombe <rick.p.edgecombe@intel.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 3036cd0 commit 52f657e

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

arch/x86/kernel/shstk.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ static int shstk_pop_sigframe(unsigned long *ssp)
351351
need_to_check_vma = PAGE_ALIGN(*ssp) == *ssp;
352352

353353
if (need_to_check_vma)
354-
mmap_read_lock_killable(current->mm);
354+
if (mmap_read_lock_killable(current->mm))
355+
return -EINTR;
355356

356357
err = get_shstk_data(&token_addr, (unsigned long __user *)*ssp);
357358
if (unlikely(err))

include/linux/mmap_lock.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ static inline void mmap_write_lock_nested(struct mm_struct *mm, int subclass)
546546
__mmap_lock_trace_acquire_returned(mm, true, true);
547547
}
548548

549-
static inline int mmap_write_lock_killable(struct mm_struct *mm)
549+
static inline int __must_check mmap_write_lock_killable(struct mm_struct *mm)
550550
{
551551
int ret;
552552

@@ -593,7 +593,7 @@ static inline void mmap_read_lock(struct mm_struct *mm)
593593
__mmap_lock_trace_acquire_returned(mm, false, true);
594594
}
595595

596-
static inline int mmap_read_lock_killable(struct mm_struct *mm)
596+
static inline int __must_check mmap_read_lock_killable(struct mm_struct *mm)
597597
{
598598
int ret;
599599

@@ -603,7 +603,7 @@ static inline int mmap_read_lock_killable(struct mm_struct *mm)
603603
return ret;
604604
}
605605

606-
static inline bool mmap_read_trylock(struct mm_struct *mm)
606+
static inline bool __must_check mmap_read_trylock(struct mm_struct *mm)
607607
{
608608
bool ret;
609609

0 commit comments

Comments
 (0)