mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	x86/uaccess: Don't leak the AC flag into __put_user() value evaluation
When calling __put_user(foo(), ptr), the __put_user() macro would call
foo() in between __uaccess_begin() and __uaccess_end().  If that code
were buggy, then those bugs would be run without SMAP protection.
Fortunately, there seem to be few instances of the problem in the
kernel. Nevertheless, __put_user() should be fixed to avoid doing this.
Therefore, evaluate __put_user()'s argument before setting AC.
This issue was noticed when an objtool hack by Peter Zijlstra complained
about genregs_get() and I compared the assembly output to the C source.
 [ bp: Massage commit message and fixed up whitespace. ]
Fixes: 11f1a4b975 ("x86: reorganize SMAP handling in user space accesses")
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/20190225125231.845656645@infradead.org
			
			
This commit is contained in:
		
							parent
							
								
									f331e766c4
								
							
						
					
					
						commit
						2a418cf3f5
					
				
					 1 changed files with 4 additions and 2 deletions
				
			
		| 
						 | 
					@ -284,7 +284,7 @@ do {									\
 | 
				
			||||||
		__put_user_goto(x, ptr, "l", "k", "ir", label);		\
 | 
							__put_user_goto(x, ptr, "l", "k", "ir", label);		\
 | 
				
			||||||
		break;							\
 | 
							break;							\
 | 
				
			||||||
	case 8:								\
 | 
						case 8:								\
 | 
				
			||||||
		__put_user_goto_u64((__typeof__(*ptr))(x), ptr, label);	\
 | 
							__put_user_goto_u64(x, ptr, label);			\
 | 
				
			||||||
		break;							\
 | 
							break;							\
 | 
				
			||||||
	default:							\
 | 
						default:							\
 | 
				
			||||||
		__put_user_bad();					\
 | 
							__put_user_bad();					\
 | 
				
			||||||
| 
						 | 
					@ -431,8 +431,10 @@ do {									\
 | 
				
			||||||
({								\
 | 
					({								\
 | 
				
			||||||
	__label__ __pu_label;					\
 | 
						__label__ __pu_label;					\
 | 
				
			||||||
	int __pu_err = -EFAULT;					\
 | 
						int __pu_err = -EFAULT;					\
 | 
				
			||||||
 | 
						__typeof__(*(ptr)) __pu_val;				\
 | 
				
			||||||
 | 
						__pu_val = x;						\
 | 
				
			||||||
	__uaccess_begin();					\
 | 
						__uaccess_begin();					\
 | 
				
			||||||
	__put_user_size((x), (ptr), (size), __pu_label);	\
 | 
						__put_user_size(__pu_val, (ptr), (size), __pu_label);	\
 | 
				
			||||||
	__pu_err = 0;						\
 | 
						__pu_err = 0;						\
 | 
				
			||||||
__pu_label:							\
 | 
					__pu_label:							\
 | 
				
			||||||
	__uaccess_end();					\
 | 
						__uaccess_end();					\
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue