linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Marcos Del Sol Vives <marcos@orca.pet>
Cc: kernel test robot <oliver.sang@intel.com>,
	oe-lkp@lists.linux.dev, lkp@intel.com,
	linux-kernel@vger.kernel.org,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Kees Cook <kees@kernel.org>, "Xin Li (Intel)" <xin@zytor.com>,
	Sabyrzhan Tasbolatov <snovitoll@gmail.com>
Subject: Re: [PATCH v2] x86: add hintable NOPs emulation
Date: Sun, 31 Aug 2025 20:48:55 +0100	[thread overview]
Message-ID: <20250831204855.5e41af1d@pumpkin> (raw)
In-Reply-To: <0ffa7c6e-f32f-4966-85df-3ee5f2426e9e@orca.pet>

On Sun, 31 Aug 2025 16:34:05 +0200
Marcos Del Sol Vives <marcos@orca.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

      parent reply	other threads:[~2025-08-31 19:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-20 11:04 [PATCH v2] x86: add hintable NOPs emulation Marcos Del Sol Vives
2025-08-20 15:31 ` H. Peter Anvin
2025-08-30  6:56 ` kernel test robot
2025-08-31 14:34   ` Marcos Del Sol Vives
2025-08-31 19:32     ` H. Peter Anvin
2025-09-01 11:43       ` Marcos Del Sol Vives
2025-09-01 21:28         ` H. Peter Anvin
2025-09-02  8:16           ` Marc Haber
2025-09-02 10:52             ` Marcos Del Sol Vives
2025-08-31 19:48     ` David Laight [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250831204855.5e41af1d@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=marcos@orca.pet \
    --cc=mingo@redhat.com \
    --cc=oe-lkp@lists.linux.dev \
    --cc=oliver.sang@intel.com \
    --cc=peterz@infradead.org \
    --cc=snovitoll@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=xin@zytor.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).