lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250831204855.5e41af1d@pumpkin>
Date: Sun, 31 Aug 2025 20:48:55 +0100
From: David Laight <david.laight.linux@...il.com>
To: Marcos Del Sol Vives <marcos@...a.pet>
Cc: kernel test robot <oliver.sang@...el.com>, oe-lkp@...ts.linux.dev,
 lkp@...el.com, linux-kernel@...r.kernel.org, Thomas Gleixner
 <tglx@...utronix.de>, Ingo Molnar <mingo@...hat.com>, Borislav Petkov
 <bp@...en8.de>, Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
 "H. Peter Anvin" <hpa@...or.com>, Peter Zijlstra <peterz@...radead.org>,
 Kees Cook <kees@...nel.org>, "Xin Li (Intel)" <xin@...or.com>, Sabyrzhan
 Tasbolatov <snovitoll@...il.com>
Subject: Re: [PATCH v2] x86: add hintable NOPs emulation

On Sun, 31 Aug 2025 16:34:05 +0200
Marcos Del Sol Vives <marcos@...a.pet> wrote:

> El 30/08/2025 a las 8:56, kernel test robot escribió:
> > [   24.176151][ T2696] BUG: sleeping function called from invalid context at include/linux/uaccess.h:162
> > [   24.176703][ T2696] in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 2696, name: trinity-c4
> > [   24.177213][ T2696] preempt_count: 0, expected: 0
> > [   24.177492][ T2696] no locks held by trinity-c4/2696.
> > [   24.177788][ T2696] irq event stamp: 335112
> > [ 24.178030][ T2696] hardirqs last enabled at (335111): irqentry_exit (kernel/entry/common.c:210) 
> > [ 24.178521][ T2696] hardirqs last disabled at (335112): irqentry_enter (kernel/entry/common.c:?) 
> > [ 24.179004][ T2696] softirqs last enabled at (332212): __do_softirq (kernel/softirq.c:614) 
> > [ 24.179473][ T2696] softirqs last disabled at (332207): __do_softirq (kernel/softirq.c:614) 
> > [   24.179948][ T2696] CPU: 1 UID: 65534 PID: 2696 Comm: trinity-c4 Tainted: G                T   6.17.0-rc2-00017-g09c737e0df5a #1 VOLUNTARY
> > [   24.179952][ T2696] Tainted: [T]=RANDSTRUCT
> > [   24.179954][ T2696] Call Trace:
> > [ 24.179956][ T2696] __dump_stack (lib/dump_stack.c:95) 
> > [ 24.179961][ T2696] dump_stack_lvl (lib/dump_stack.c:123) 
> > [ 24.179963][ T2696] ? nbcon_get_cpu_emergency_nesting (kernel/printk/nbcon.c:1375) 
> > [ 24.179967][ T2696] dump_stack (lib/dump_stack.c:129) 
> > [ 24.179969][ T2696] __might_resched (kernel/sched/core.c:8958) 
> > [ 24.179976][ T2696] __might_sleep (kernel/sched/core.c:8887) 
> > [ 24.179979][ T2696] __might_fault (mm/memory.c:6957) 
> > [ 24.179983][ T2696] _copy_from_user (include/linux/uaccess.h:?) 
> > [ 24.179991][ T2696] insn_fetch_from_user (include/linux/uaccess.h:212 arch/x86/lib/insn-eval.c:1516) 
> > [ 24.179995][ T2696] handle_invalid_op (arch/x86/kernel/traps.c:308) 
> > [ 24.180010][ T2696] ? exc_overflow (arch/x86/kernel/traps.c:417) 
> > [ 24.180012][ T2696] exc_invalid_op (arch/x86/kernel/traps.c:432) 
> > [ 24.180014][ T2696] handle_exception (arch/x86/entry/entry_32.S:1055)  
> 
> I am familiar with interrupts on microcontrollers and embedded systems,
> but not with Linux's, so unsure how to proceed.
> 
> I've seen UMIP and IOPL emulation and they both run with interrupts enabled,
> by means of cond_local_irq_enable, and then fetch from memory using regular
> insn_fetch_from_user/get_user which may sleep.
> 
> VC, on the other hand, uses the insn_fetch_from_user_inatomic.
> 
> Can someone chime in on what should I do for this? Enable IRQs temporarily
> using cond_local_irq_enable or local_irq_enable, or use the inatomic
> version?
> 

My 2c:
Enabling interrupts might have all sorts of side effects.
In this case it should be ok to use the 'inatomic' read of userspace
that will fail in the very unlikely case where the page got unmapped
between userpace executing the instruction and the trap handler
trying to read it.
If that happens just return back to userspace and re-execute the 'bad'
instruction - it will fault again and hopefully you'll manage to
read it the second time (or eventually).

I guess there might be a problem if the cpu is faulting on the first
few bytes of the instruction and a malicious program has put those
bytes right at the end of a page - and not mapped the following page.
You'd need to differentiate those from the valid:
	for (i = 0; i < 256; i++)
		hintable_nop();

	David

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ