On Fri, 24 May 2024 at 00:43, Yafang Shao <laoar.shao@xxxxxxxxx> wrote: > > Actually, there are already helpers for this: get_task_comm() and > __get_task_comm(). We can simply replace the memcpy() with one of > these No. We should get rid of those horrendous helpers. > If the task_lock() in __get_task_comm() is a concern, we could > consider adding a new __get_current_comm(). The task_lock is indeed the problem - it generates locking problems and basically means that most places cannot use them. Certainly not things like tracing etc. The locking is also entirely pointless\, since absolutely nobody cares. If somebody is changing the name at the same time - which doesn't happen in practice - getting some halfway result is fine as long as you get a proper NUL terminated result. Even for non-current, they are largely useless. They were a mistake. So those functions should never be used for any normal thing. Instead of locking, the function should literally just do a "copy a couple of words and make sure the end result still has a NUL at the end". That's literally what selinuxfs.c wants, for example - it copies the thing to a local buffer not because it cares about some locking issue, but because it wants one stable value. But by using 'memcpy()' and that fixed size, it means that we can't sanely extend the source size because now it wouldn't be NUL-terminated. But selinux never wanted a lock, and never wanted any kind of *consistent* result, it just wanted a *stable* result. Since user space can randomly change their names anyway, using locking was always wrong for readers (for writers it probably does make sense to have some lock - although practically speaking nobody cares there either, but at least for a writer some kind of race could have long-term mixed results) Oh well. Linus