Re: [GIT PULL] sysctl constification changes for v6.14-rc1

2025-01-29 Thread Linus Torvalds
On Wed, 29 Jan 2025 at 00:14, Joel Granados wrote: > > All ctl_table declared outside of functions and that remain unmodified after > initialization are const qualified. Hmm. A quick grep shows static struct ctl_table alignment_tbl[5] = { in arch/csky/abiv1/alignment.c that didn't get c

Re: [PATCH] exec: Make sure task->comm is always NUL-terminated

2024-12-01 Thread Linus Torvalds
On Fri, 29 Nov 2024 at 23:15, Linus Torvalds wrote: > > And yes, we could make the word-at-a-time case also know about masking > the last word, but it's kind of annoying and depends on byte ordering. Actually, it turned out to be really trivial to do. It does depend on byte order

Re: [PATCH] exec: fix up /proc/pid/comm in the execveat(AT_EMPTY_PATH) case

2024-12-01 Thread Linus Torvalds
On Sun, 1 Dec 2024 at 06:17, Christian Brauner wrote: > > /* > * Hold rcu lock to keep the name from being freed behind our back. > * Use cquire semantics to make sure the terminating NUL from > * __d_alloc() is seen. > * > * Note, we're deliberately sloppy here. We don't need to care about >

Re: [PATCH] exec: Make sure task->comm is always NUL-terminated

2024-11-30 Thread Linus Torvalds
On Sat, 30 Nov 2024 at 13:05, Kees Cook wrote: > > Yeah, this just means it has greater potential to be garbled. Garbled is fine. Id' just rather it be "consistently padded". > This is fine, but it doesn't solve either an unstable source nor > concurrent writers to dest. Yeah, I guess concurren

Re: [PATCH] exec: fix up /proc/pid/comm in the execveat(AT_EMPTY_PATH) case

2024-11-30 Thread Linus Torvalds
On Sat, 30 Nov 2024 at 12:28, Mateusz Guzik wrote: > > > + /* The dentry name won't change while we hold the rcu read > > lock. */ > > + __set_task_comm(me, > > smp_load_acquire(&bprm->file->f_path.dentry->d_name.name), > > + true); > > This do

Re: [PATCH] exec: fix up /proc/pid/comm in the execveat(AT_EMPTY_PATH) case

2024-11-30 Thread Linus Torvalds
On Sat, 30 Nov 2024 at 04:30, Christian Brauner wrote: > > What does the smp_load_acquire() pair with? I'm not sure we have them everywhere, but at least this one at dentry creation time. __d_alloc(): /* Make sure we always see the terminating NUL character */ smp_store_release(&

Re: [PATCH] exec: Make sure task->comm is always NUL-terminated

2024-11-29 Thread Linus Torvalds
Edited down to just the end result: On Fri, 29 Nov 2024 at 20:49, Kees Cook wrote: > > void __set_task_comm(struct task_struct *tsk, const char *buf, bool exec) > { > size_t len = min(strlen(buf), sizeof(tsk->comm) - 1); > > trace_task_rename(tsk, buf); > memcpy(tsk->com

Re: [PATCH] hardening: Adjust dependencies in selection of MODVERSIONS

2024-09-29 Thread Linus Torvalds
On Sat, 28 Sept 2024 at 11:13, Nathan Chancellor wrote: > > MODVERSIONS recently grew a dependency on !COMPILE_TEST so that Rust > could be more easily tested. However, this introduces a Kconfig warning > when building allmodconfig with a clang version that supports RANDSTRUCT > natively because R

Re: [PATCH v4] proc: add config & param to block forcing mem writes

2024-07-30 Thread Linus Torvalds
On Tue, 30 Jul 2024 at 16:09, Jeff Xu wrote: > > > + task = get_proc_task(file_inode(file)); > > + if (task) { > > + ptrace_active = task->ptrace && task->mm == mm && > > task->parent == current; > > Do we need to call "read_lock(&tasklist_lock);"

Re: [PATCH] proc: add config & param to block forcing mem writes

2024-07-23 Thread Linus Torvalds
On Tue, 23 Jul 2024 at 11:30, Linus Torvalds wrote: > > but while that looks a bit prettier, the whole "fs_parser.h" thing is > admittedly odd. .. don't get me wrong - /proc obviously *is* a filesystem, but in this context it's a boot command line parame

Re: [PATCH] proc: add config & param to block forcing mem writes

2024-07-23 Thread Linus Torvalds
On Tue, 23 Jul 2024 at 10:18, Adrian Ratiu wrote: > > This adds a Kconfig option and boot param to allow removing > the FOLL_FORCE flag from /proc/pid/mem write calls because > it can be abused. Ack, this looks much simpler. That said, I think this can be prettied up some more: > +enum proc_mem

Re: [PATCH] proc: add config to block FOLL_FORCE in mem writes

2024-07-17 Thread Linus Torvalds
On Wed, 17 Jul 2024 at 15:24, Kees Cook wrote: > > > In particular, this patch would make it easy to make that > > SECURITY_PROC_MEM_RESTRICT_FOLL_FORCE config option be a "choice" > > where you pick "never, ptrace, always" by just changing the rules in > > proc_is_ptracing(). > > So the original

Re: [PATCH] proc: add config to block FOLL_FORCE in mem writes

2024-07-17 Thread Linus Torvalds
On Wed, 17 Jul 2024 at 10:23, Kees Cook wrote: > > For this to be available for general distros, I still want to have a > bootparam to control this, otherwise this mitigation will never see much > testing as most kernel deployments don't build their own kernels. A > simple __ro_after_init variable

Re: [GIT PULL] pstore updates for v6.11-rc1

2024-07-16 Thread Linus Torvalds
On Mon, 15 Jul 2024 at 09:29, Kees Cook wrote: > > Please pull these small pstore updates for v6.11-rc1. (Note that since there > were no pstore updates for v6.10, this is based on v6.9-rc2. I forgot > to do my traditional merge-on-rc2 for this tree when v6.10-rc2 happened.) Note that this is exa

Re: [PATCH] x86/hpet: Read HPET directly if panic in progress

2024-05-28 Thread Linus Torvalds
On Tue, 28 May 2024 at 15:12, Thomas Gleixner wrote: > > I principle it applies to any clocksource which needs a spinlock to > serialize access. HPET is not the only insanity here. HPET may be the main / only one we care about. Because: > Think about i8253 :) I see the smiley, but yeah, I don'

Re: [RFC] Mitigating unexpected arithmetic overflow

2024-05-12 Thread Linus Torvalds
On Sun, 12 May 2024 at 01:03, Martin Uecker wrote: > > But I guess it still could be smarter. Or does it have to be a > sanitizer because compile-time will always have too many false > positives? Yes, there will be way too many false positives. I'm pretty sure there will be a ton of "intentional

Re: [RFC] Mitigating unexpected arithmetic overflow

2024-05-09 Thread Linus Torvalds
On Thu, 9 May 2024 at 11:48, Al Viro wrote: > > FWIW, the thing that somewhat worries me about having a helper along > the lines of combine_to_u64(low, high) is that > foo->splat = combine_to_u64(something, something_else); > would be inviting hard-to-catch brainos - > foo->splat =

Re: [RFC] Mitigating unexpected arithmetic overflow

2024-05-09 Thread Linus Torvalds
On Thu, 9 May 2024 at 11:08, Linus Torvalds wrote: > > Any half-way decent compiler will end up optimizing away the shifts > and adds for the high bits because they see the assignment to > 'all_bits'. There's no point in generating high bits that just get >

Re: [RFC] Mitigating unexpected arithmetic overflow

2024-05-09 Thread Linus Torvalds
On Thu, 9 May 2024 at 10:54, Al Viro wrote: > > On Thu, May 09, 2024 at 08:38:28AM -0700, Linus Torvalds wrote: > > > Going the other way is similar: > > > > all_bits = low_bits + ((u64) high_bits << 16) << 16); > > > > and again, the

Re: [RFC] Mitigating unexpected arithmetic overflow

2024-05-09 Thread Linus Torvalds
On Thu, 9 May 2024 at 07:09, Theodore Ts'o wrote: > > struct ext2_super { >... >__u32time_lo; >__u32time_high; >... > } > > time_t now; > > sb->time_low = now; > sb->time_high = now >> 32; > > This is obviously (to a human) correct,

Re: [RFC] Mitigating unexpected arithmetic overflow

2024-05-08 Thread Linus Torvalds
On Wed, 8 May 2024 at 16:47, Linus Torvalds wrote: > > So *that* I feel could be something where you can warn without a ton > of compiler smarts at all. If you see an *implicit* cast to unsigned > and then the subsequent operations wraps around, it's probably worth > bein

Re: [RFC] Mitigating unexpected arithmetic overflow

2024-05-08 Thread Linus Torvalds
On Wed, 8 May 2024 at 16:47, Linus Torvalds wrote: > > But again, maybe it would be worth looking into, at least for some > limited cases. To go back to your particular example, it might be > worth trying to limit it for unusual type sizes like implicit casts to > 'u16'

Re: [RFC] Mitigating unexpected arithmetic overflow

2024-05-08 Thread Linus Torvalds
On Wed, 8 May 2024 at 15:54, Kees Cook wrote: > > Sure, but if the bar is omniscience, that's not a path forward. I really don't think there's a lot of omniscience involved at all. > I haven't really heard a viable counterproposal here. So let me make the counter-proposal that you actually conc

Re: [RFC] Mitigating unexpected arithmetic overflow

2024-05-08 Thread Linus Torvalds
On Wed, 8 May 2024 at 12:45, Kees Cook wrote: > > On Wed, May 08, 2024 at 10:52:44AM -0700, Linus Torvalds wrote: > > Example: > > > >static inline u32 __hash_32_generic(u32 val) > >{ > > return val * GOLDEN_RATIO_32; > >}

Re: [RFC] Mitigating unexpected arithmetic overflow

2024-05-08 Thread Linus Torvalds
On Tue, 7 May 2024 at 16:27, Kees Cook wrote: > > When I say "overflow", I mean "overflow and underflow", but more > specifically I mean "wrap-around". This is not about "undefined > behavior". We already demand from our compilers that all our arithmetic > uses a well-defined overflow resolution s

Re: KFENCE: included in x86 defconfig?

2024-02-08 Thread Linus Torvalds
On Thu, 8 Feb 2024 at 10:55, Borislav Petkov wrote: > > What about its benefit? > > I haven't seen a bug fix saying "found by KFENCE" or so but that doesn't > mean a whole lot. It does find some things. You can search for "BUG: KFENCE" on lore, and there are real bug reports. That said, there ar

Re: [GIT PULL] Enable -Wstringop-overflow globally

2024-02-02 Thread Linus Torvalds
On Thu, 1 Feb 2024 at 23:53, Arnd Bergmann wrote: > > I did a creduce pass on this warning when it first showed up > and opened a gcc bug report as well as a driver workaround: > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113214 > https://lore.kernel.org/lkml/20240103114819.2913937-1-a...@kern

Re: [GIT PULL] Enable -Wstringop-overflow globally

2024-01-26 Thread Linus Torvalds
On Fri, 26 Jan 2024 at 14:24, Kees Cook wrote: > > I think xe has some other weird problems too. This may be related (under > allocating): > > ../drivers/gpu/drm/xe/xe_vm.c: In function 'xe_vma_create': > ../drivers/gpu/drm/xe/xe_vm.c:806:21: warning: allocation of insufficient > size '224' for t

Re: [GIT PULL] Enable -Wstringop-overflow globally

2024-01-26 Thread Linus Torvalds
On Mon, 22 Jan 2024 at 07:29, Gustavo A. R. Silva wrote: > > Enable -Wstringop-overflow globally I suspect I'll have to revert this. On arm64, I get a "writing 16 bytes into a region of size 0" in the Xe driver drivers/gpu/drm/xe/xe_gt_pagefault.c:340 but I haven't looked into it much yet.

Re: [PATCH 34/82] ipc: Refactor intentional wrap-around calculation

2024-01-23 Thread Linus Torvalds
On Mon, 22 Jan 2024 at 17:38, Kees Cook wrote: > > I've tried to find the right balance between not enough details and too > much. I guess I got it wrong. My complaint isn't about the level of detail. My complaint is about how the commit log IS ACTIVELY MISLEADING GARBAGE and does not match the

Re: [PATCH 34/82] ipc: Refactor intentional wrap-around calculation

2024-01-22 Thread Linus Torvalds
On Mon, 22 Jan 2024 at 16:46, Kees Cook wrote: > > Refactor open-coded unsigned wrap-around addition test to use > check_add_overflow(), NAK. First off, none of this has anything to do with -fno-strict-overflow. We do that, because without it gcc ends up doing various odd and surprising things,

Re: the nul-terminated string helper desk chair rearrangement

2023-10-20 Thread Linus Torvalds
On Fri, 20 Oct 2023 at 10:40, Justin Stitt wrote: > > There's some docs at [1]. Perhaps there could be more? > > [1]: > https://elixir.bootlin.com/linux/v6.6-rc6/source/include/linux/fortify-string.h#L292 Note that we have so few 'strlcpy()' calls that we really should remove that horrid horrid

Re: [GIT PULL] hardening fixes for v6.6-rc3

2023-09-24 Thread Linus Torvalds
On Sun, 24 Sept 2023 at 09:58, Alexey Dobriyan wrote: > > Most of those in uapi/ are likely unnecessary: extern "C" means > "don't mangle", but kernel doesn't export functions to userspace > except vDSO so there is nothing to mangle in the first place. I suspect a lot of it is "this got copied-an

Re: [GIT PULL] hardening fixes for v6.6-rc3

2023-09-23 Thread Linus Torvalds
On Fri, 22 Sept 2023 at 20:49, Kees Cook wrote: > > 2) __cplusplus is relatively common in UAPI headers already: >$ git grep __cplusplus -- include/uapi | wc -l >58 Look a bit closer. Most of those - by far - is for the usual #if defined(__cplusplus) extern "C" { #endif pattern.