Re: [PATCH] audit: use mmget() instead of get_task_exe_file() when auditing @current

2023-10-18 Thread Mateusz Guzik
mm = current->mm; >> + } else { >> + /* this can deadlock outside the fork/clone usage (see >> above) */ >> + mm = get_task_mm(tsk); >> + if (!mm) >> + return 0; >> + } >> + exe_file = get_mm_exe_file(mm); >> + mmput(mm); >> if (!exe_file) >> return 0; >> ino = file_inode(exe_file)->i_ino; Assuming concerns expressed above are moot, I would hide the logic in audit_get_task_exe_file or similar. -- Mateusz Guzik

Re: [PATCH] audit: use mmget() instead of get_task_exe_file() when auditing @current

2023-10-18 Thread Mateusz Guzik
On 10/19/23, Paul Moore wrote: > On Wed, Oct 18, 2023 at 8:22 PM Mateusz Guzik wrote: >> On 10/19/23, Paul Moore wrote: >> >> The get_task_exe_file() function locks the given task with task_lock() >> >> which when used inside audit_exe_compare() can caus

Re: [PATCH] audit: use mmget() instead of get_task_exe_file() when auditing @current

2023-10-18 Thread Mateusz Guzik
On 10/19/23, Mateusz Guzik wrote: > On 10/19/23, Paul Moore wrote: >> On Wed, Oct 18, 2023 at 8:22 PM Mateusz Guzik wrote: >>> On 10/19/23, Paul Moore wrote: >>> >> The get_task_exe_file() function locks the given task with >>> >> task_lock()

Re: [PATCH] audit: use mmget() instead of get_task_exe_file() when auditing @current

2023-10-19 Thread Mateusz Guzik
ing rlimits is cheaper. I'm going to create a new thread about it later. -- Mateusz Guzik

Re: [PATCH] audit: use mmget() instead of get_task_exe_file() when auditing @current

2023-10-19 Thread Mateusz Guzik
On 10/19/23, Paul Moore wrote: > On Thu, Oct 19, 2023 at 10:52 AM Mateusz Guzik wrote: >> On 10/19/23, Paul Moore wrote: >> > Thinking about it a bit more this morning, I think we can safely >> > ignore the non-@current case in audit_exe_compare() as the whole point &

Re: [PATCH] audit: use mmget() instead of get_task_exe_file() when auditing @current

2023-10-21 Thread Mateusz Guzik
On 10/19/23, Paul Moore wrote: > On Thu, Oct 19, 2023 at 12:56 PM Mateusz Guzik wrote: >> On 10/19/23, Paul Moore wrote: >> > On Thu, Oct 19, 2023 at 10:52 AM Mateusz Guzik >> > wrote: >> >> On 10/19/23, Paul Moore wrote: >> >> > Thi

Re: [PATCH v2] audit: don't take task_lock() in audit_exe_compare() code path

2023-10-24 Thread Mateusz Guzik
->mm has to be set. Although I do find it plausible there maybe a corner case during kernel bootstrap and it may be that code can land here with that state, but I can't be arsed to check. Given that stock code has an unintentional property of handling empty mm and this is a bugfix, I am definitely not going to protest adding a check. But I would WARN_ONCE it though. >> > if (!exe_file) >> > return 0; >> > ino = file_inode(exe_file)->i_ino; >> > dev = file_inode(exe_file)->i_sb->s_dev; >> > fput(exe_file); >> > + >> > return audit_mark_compare(mark, ino, dev); >> > } > > -- > paul-moore.com > -- Mateusz Guzik

Re: [PATCH v3] audit: don't take task_lock() in audit_exe_compare() code path

2023-10-24 Thread Mateusz Guzik
This does fix the bug, and with the caveat I can't vouch for ignoring non-current in the routine: Reviewed-by: Mateusz Guzik Thanks for fixing the bug. Pretty weird it took this long for it to surface. On 10/24/23, Paul Moore wrote: > On Tue, Oct 24, 2023 at 2:39 PM Paul Moor

Re: [PATCH v2] audit: don't take task_lock() in audit_exe_compare() code path

2023-11-14 Thread Mateusz Guzik
On 11/14/23, Artem Savkov wrote: > On Tue, Oct 24, 2023 at 07:59:18PM +0200, Mateusz Guzik wrote: >> For the thread to start executing ->mm has to be set. >> >> Although I do find it plausible there maybe a corner case during >> kernel bootstrap and it may be tha

Re: [PATCH v2] audit: don't take task_lock() in audit_exe_compare() code path

2023-11-14 Thread Mateusz Guzik
On 11/14/23, Paul Moore wrote: > On Tue, Nov 14, 2023 at 5:33 AM Mateusz Guzik wrote: >> On 11/14/23, Artem Savkov wrote: >> > On Tue, Oct 24, 2023 at 07:59:18PM +0200, Mateusz Guzik wrote: >> >> For the thread to start executing ->mm has to be set. >> &

Re: audit_reusename in getname_flags

2025-02-06 Thread Mateusz Guzik
On Thu, Feb 6, 2025 at 9:24 PM Jeff Layton wrote: > > On Thu, 2025-02-06 at 20:07 +0100, Mateusz Guzik wrote: > > You added it in: > > commit 7ac86265dc8f665cc49d6e60a125e608cd2fca14 > > Author: Jeff Layton > > Date: Wed Oct 10 15:25:28 2012 -0400 > > > &

Re: audit_reusename in getname_flags

2025-02-06 Thread Mateusz Guzik
On Thu, Feb 6, 2025 at 9:34 PM Mateusz Guzik wrote: > > On Thu, Feb 6, 2025 at 9:24 PM Jeff Layton wrote: > > > > On Thu, 2025-02-06 at 20:07 +0100, Mateusz Guzik wrote: > > > You added it in: > > > commit 7ac86265dc8f665cc49d6e60a125e608cd2fca14 > > &g

Re: [PATCH] fs: support filename refcount without atomics

2025-03-07 Thread Mateusz Guzik
tions from disabled to enabled -- will they suddenly start looking here? Should this test for audit_enabled, audit_dummy_context() or something else? I did not want to bother analyzing this. I'll note though this would be an optimization on top of the current code, so I don't think it *blocks* the patch. -- Mateusz Guzik

[PATCH] fs: support filename refcount without atomics

2025-03-07 Thread Mateusz Guzik
ame object and having refname() and putname() detect if another thread is trying to modify them. Benchmarked on Sapphire Rapids issuing access() (ops/s): before: 5106246 after: 5269678 (+3%) Signed-off-by: Mateusz Guzik --- this can be split into 2 patches (refname, initname vs the atomic chang

Re: [PATCH] fs: support filename refcount without atomics

2025-03-07 Thread Mateusz Guzik
On Fri, Mar 7, 2025 at 5:32 PM Jens Axboe wrote: > > On 3/7/25 9:25 AM, Mateusz Guzik wrote: > > On Fri, Mar 7, 2025 at 5:18?PM Jens Axboe wrote: > >> > >>> +static inline void makeatomicname(struct filename *name) > >>>

Re: [PATCH] fs: support filename refcount without atomics

2025-03-07 Thread Mateusz Guzik
On Fri, Mar 7, 2025 at 5:38 PM Jens Axboe wrote: > > On 3/7/25 9:35 AM, Mateusz Guzik wrote: > > Since you volunteered to sort this out, I'll be happy to wait. > > I'll take a look start next week, don't think it should be too bad. You > already did 90% of t

Re: [PATCH] fs: support filename refcount without atomics

2025-03-07 Thread Mateusz Guzik
On Fri, Mar 7, 2025 at 5:42 PM Al Viro wrote: > > On Fri, Mar 07, 2025 at 05:11:55PM +0100, Mateusz Guzik wrote: > > Atomics are only needed for a combination of io_uring and audit. > > > > Regular file access (even with audit) gets around fine without them. > &g

Re: [PATCH] fs: support filename refcount without atomics

2025-03-07 Thread Mateusz Guzik
On Fri, Mar 7, 2025 at 5:26 PM Matthew Wilcox wrote: > > On Fri, Mar 07, 2025 at 05:11:55PM +0100, Mateusz Guzik wrote: > > +++ b/include/linux/fs.h > > @@ -2765,11 +2765,19 @@ struct audit_names; > > struct filename { > > const char *name

Re: [PATCH] fs: support filename refcount without atomics

2025-03-07 Thread Mateusz Guzik
On Fri, Mar 7, 2025 at 5:44 PM Mateusz Guzik wrote: > > On Fri, Mar 7, 2025 at 5:42 PM Al Viro wrote: > > Not a good way to handle that, IMO. > > > > Atomics do hurt there, but they are only plastering over the real > > problem - names formed in one thread, inserte

[PATCH] fs: dodge an atomic in putname if ref == 1

2025-03-11 Thread Mateusz Guzik
/s): before: 5106246 after: 5269678 (+3%) Link 1: https://lore.kernel.org/linux-fsdevel/20250307161155.760949-1-mjgu...@gmail.com/ Link 2: https://lore.kernel.org/linux-fsdevel/20250307164216.GI2023217@ZenIV/ Signed-off-by: Mateusz Guzik --- This is an alternative to the patch I linked above