OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: Vladimir Riabchun <vladimir.riabchun@virtuozzo.com>
To: devel@openvz.org
Subject: Re: [Devel] [PATCH VZ10 v9 7/8] ve/printk: Don't use ve log outside task context
Date: Fri, 18 Sep 2026 16:50:45 +0200	[thread overview]
Message-ID: <7bc6ea19-4425-416c-b62a-568c3176ab45@virtuozzo.com> (raw)
In-Reply-To: <156a2b6228d80112485c33b8384acf55b998a9a2.1789491989.git.vladimir.riabchun@virtuozzo.com>

Sashiko review:

On 9/15/26 19:22, Vladimir Riabchun wrote:
> get_exec_env() in interrupt context will return VE of the process
> that was interrupted.
> We don't want to leak logs to unrelated containers if we use
> ve_printk in a function that may be called in an interrupt.
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-135520
> Signed-off-by: Vladimir Riabchun <vladimir.riabchun@virtuozzo.com>
> ---
>   kernel/printk/printk.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 8940b36e790b..90ecd7960800 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -560,7 +560,8 @@ struct log_state *ve_log_state(void)
>   {
>   	struct log_state *log = &init_log_state;
>   #ifdef CONFIG_VE
> -	if (get_exec_env()->log_state)
> +	/* get_exec_env() is not reliable outside task context */
> +	if (get_exec_env()->log_state && in_task())

Sashiko says:
  This is a pre-existing issue, but can the condition in "ve_log_state()" at
  "if (get_exec_env()->log_state && in_task())" lead to incorrectly accessing
  log state outside of task contexts, if callers aren't properly enforcing
  the in_task() guarantee?

This is exactly what the patch is doing: this updated check ensures
that even if somebody forgot to enforce this check or we somehow reached
this from interrupt, we leak nothing to CT.

>   		log = get_exec_env()->log_state;
>   #endif
>   	return log;
> @@ -2538,7 +2539,7 @@ static asmlinkage int ve_vprintk(int dst, const char *fmt, va_list args)
>   	va_copy(args2, args);
>   	if (ve_is_super(get_exec_env()) || (dst & VE0_LOG))
>   		r = vprintk(fmt, args);
> -	if (!ve_is_super(get_exec_env()) && (dst & VE_LOG))
> +	if (!ve_is_super(get_exec_env()) && (dst & VE_LOG) && in_task())

Sashiko says:
  In "ve_vprintk", is it possible that the "ve_vprintk_emit()" call could cause
  a use-after-free scenario given that it lacks an in_task() check,
  unlike similar calls that were updated in the patch?
  Could accessing "get_exec_env()->log_state" without this check lead to
  accessing unstable memory, causing kernel panics?

ve_vprintk_emit uses ve_log_state helper, so it has in_task() check.

>   		r = ve_vprintk_emit(0, LOGLEVEL_DEFAULT, NULL, fmt, args2);
>   	va_end(args2);
>   
> @@ -2570,7 +2571,7 @@ static asmlinkage int ve_vprintk_deferred(int dst, const char *fmt, va_list args
>   	va_copy(args2, args);
>   	if (ve_is_super(get_exec_env()) || (dst & VE0_LOG))
>   		r = vprintk_emit(0, LOGLEVEL_SCHED, NULL, fmt, args);
> -	if (!ve_is_super(get_exec_env()) && (dst & VE_LOG))
> +	if (!ve_is_super(get_exec_env()) && (dst & VE_LOG) && in_task())
>   		r = ve_vprintk_emit(0, LOGLEVEL_SCHED, NULL, fmt, args2);
>   	va_end(args2);
>   

-- 
Best regards, Riabchun Vladimir
Linux Kernel Developer, Virtuozzo

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  reply	other threads:[~2026-09-18 14:52 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-15 17:22 [Devel] [PATCH VZ10 v9 0/8] Add per-VE failcount support Vladimir Riabchun
2026-09-15 17:22 ` [Devel] [PATCH VZ10 v9 1/8] ve/ve.{h, c}: Farewell to spaces as indents Vladimir Riabchun
2026-09-25 15:55   ` Konstantin Khorenko
2026-09-15 17:22 ` [Devel] [PATCH VZ10 v9 2/8] ve/fs: Rework per-ve mount count Vladimir Riabchun
2026-09-18 13:22   ` Vladimir Riabchun
2026-09-15 17:22 ` [Devel] [PATCH VZ10 v9 3/8] selftests/ve: Update ve_ns_owner_test Vladimir Riabchun
2026-09-18 13:28   ` Vladimir Riabchun
2026-09-15 17:22 ` [Devel] [PATCH VZ10 v9 4/8] ve: Move from global VE mounts limit to per-VE limit Vladimir Riabchun
2026-09-18 14:29   ` Vladimir Riabchun
2026-09-15 17:22 ` [Devel] [PATCH VZ10 v9 5/8] ve/ve.c: Generate VE resource accessors using macros Vladimir Riabchun
2026-09-18 14:36   ` Vladimir Riabchun
2026-09-15 17:22 ` [Devel] [PATCH VZ10 v9 6/8] ve: Introduce per-VE failcount Vladimir Riabchun
2026-09-18 14:42   ` Vladimir Riabchun
2026-09-25 16:02   ` Konstantin Khorenko
2026-09-25 16:08   ` Konstantin Khorenko
2026-09-15 17:22 ` [Devel] [PATCH VZ10 v9 7/8] ve/printk: Don't use ve log outside task context Vladimir Riabchun
2026-09-18 14:50   ` Vladimir Riabchun [this message]
2026-09-22 11:21   ` Vladimir Riabchun
2026-09-25 16:02     ` Konstantin Khorenko
2026-09-15 17:22 ` [Devel] [PATCH VZ10 v9 8/8] selftests/ve: Add mount accounting selftest Vladimir Riabchun
2026-09-18 15:06   ` Vladimir Riabchun
2026-09-25 16:04   ` Konstantin Khorenko
2026-09-16 12:30 ` [Devel] [PATCH VZ10 v9 0/8] Add per-VE failcount support Vasileios Almpanis
2026-09-16 17:30 ` Konstantin Khorenko
2026-09-18 15:07   ` Vladimir Riabchun
2026-09-18 16:02   ` Vladimir Riabchun

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=7bc6ea19-4425-416c-b62a-568c3176ab45@virtuozzo.com \
    --to=vladimir.riabchun@virtuozzo.com \
    --cc=devel@openvz.org \
    /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