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-next>] [day] [month] [year] [list]
Message-ID: <20250804114900.GA6656@redhat.com>
Date: Mon, 4 Aug 2025 13:49:01 +0200
From: Oleg Nesterov <oleg@...hat.com>
To: 高翔 <gaoxiang17@...omi.com>
Cc: Al Viro <viro@...iv.linux.org.uk>, Xiang Gao <gxxa03070307@...il.com>,
	"brauner@...nel.org" <brauner@...nel.org>,
	"mjguzik@...il.com" <mjguzik@...il.com>,
	"Liam.Howlett@...cle.com" <Liam.Howlett@...cle.com>,
	"joel.granados@...nel.org" <joel.granados@...nel.org>,
	"lorenzo.stoakes@...cle.com" <lorenzo.stoakes@...cle.com>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] pid: Add a judgment for ns null in pid_nr_ns

On 08/04, 高翔 wrote:
>
>     struct task_struct *tsk = current;
>
>     struct task_struct *parent;
>
>     ...
>
>     info->pid = task_pid_vnr(tsk);
>     rcu_read_lock();
>     parent = rcu_dereference(tsk->real_parent);
>     get_task_struct(parent);
>     rcu_read_unlock();
>     info->ppid = task_tgid_vnr(parent);
>     strncpy(info->ptask_name, parent->comm, TASK_COMM_LEN);
>     put_task_struct(parent);

So I guess the kernel crashes when you try to obtain another process's pid, not
the current process's pid. This is was I suspected.

This code is buggy. tsk->real_parent points to nowhere if tsk = current was reaped.
rcu_read_lock() alone can't help. Even get_task_struct(parent) is not safe. And it
is not needed.

You need something like

	info->pid = info->ppid = 0;

	rcu_read_lock();
	if (pid_alive(tsk)) {
		info->pid = task_pid_vnr(tsk);
		info->ppid = task_tgid_vnr(tsk->real_parent);
	}
	rcu_read_unlock();

Oleg.

> 
> 
> 
> ________________________________
> 发件人: Oleg Nesterov <oleg@...hat.com>
> 发送时间: 2025年8月2日 16:45:26
> 收件人: 高翔
> 抄送: Al Viro; Xiang Gao; brauner@...nel.org; mjguzik@...il.com; Liam.Howlett@...cle.com; joel.granados@...nel.org; lorenzo.stoakes@...cle.com; linux-kernel@...r.kernel.org
> 主题: Re: 答复: [External Mail]Re: [PATCH] pid: Add a judgment for ns null in pid_nr_ns
> 
> [外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给misec@...omi.com进行反馈
> 
> On 08/02, 高翔 wrote:
> >
> > Obtain the current process pid in the ufs compl command. This scene is possible.
> 
> How exactly your module tries to obtain the current process pid?
> 
> task_pid_vnr(current) should work and return 0 if the task was reaped.
> 
> Oleg.
> 


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ