Live data from Hacker News

size_t-to-int vulnerability in Linux’s filesystem layer

openwall.com

211–220 of 280 posts

Re: size_t-to-int vulnerability in Linux’s filesystem layer

#211

Why does the compiler not warn if you use a 64 bit unsigned integer when a 32 bit signed integer is required?

You actually can pass -Wconversion to a compiler, but it's one of those things that's going to generate a lot of noise and not be a vulnerability 99% of the time. It's not an easy solved problem, because if you annoy developers with noise they stop caring.

Re: size_t-to-int vulnerability in Linux’s filesystem layer

#212

Earlier quoted context omitted.

GCC's -Wconversion has some issues. For example, good luck getting gcc to /not/ emit a warning for this code, in C or C++. I have yet to find the appropriate cast to avoid a warning. Clang does not warn for this. typedef struct { unsigned value : 4; } S; void foo(S* s, unsigned value) { // error: conversion from 'unsigned int' to 'unsigned char:4' may change value s->value = value; } I mean, I guess I can see the rat…

Does it still warn if you do `s->value = value & 0x0F`? That seems like a reasonable alternative to pragmas if it works.

It doesn't.

Re: size_t-to-int vulnerability in Linux’s filesystem layer

#213

Earlier quoted context omitted.

Perhaps a distinction here can be made between running as a server OS and a desktop OS. In a server I generally want a crash immediately. But on a desktop I'd rather it limp along and give me a chance to finish writing my Hackernews post.

I'd rather push the other way on that. We should treat desktops with as much security paranoia at servers. I'd much rather _not_ have my desktop "limp along" in a poorly understood and probably exploitable fashion while the malware gets a chance to finish encrypting all my files... If that costs the world the "benefit" of my shared wisdom in a half written Hackernews post, I'm good with that.

I run a a lot more untrusted code on my laptop than on my cloud servers. Likewise for work, even more so as I don’t myself trust the spyware/malware they jam on the laptops.

Re: size_t-to-int vulnerability in Linux’s filesystem layer

#214
post #148

Earlier quoted context omitted.

Yes, arbitrary precision integers could theoretically become a C language/library feature. But let's say that it gets proposed and accepted and it's integrated into popular compiler toolchains. The kernel wouldn't leverage it here or likely anywhere else because of its cost. A newly designed OS kernel could perhaps take on this kind of feature. This would be the kind of OS that could be formally verified and would be…

C doesn’t have the abstraction power to make anything with such a datatype.

I left myself a lot of latitude when I referred to this as a potential "language/library feature".

    typedef struct { /* TODO */ } arb_int;
    arb_int *new_arb_int(void);
    void delete_arb_int(arb_int *);
    arb_int *arb_int_add(arb_int *, arb_int *);
    arb_int *arb_int_sub(arb_int *, arb_int *);
    arb_int *arb_int_mul(arb_int *, arb_int *);
    arb_int *arb_int_div(arb_int *, arb_int *);
    bool arb_int_gt(arb_int *, arb_int *);
    bool arb_int_lt(arb_int *, arb_int *);
    bool arb_int_gte(arb_int *, arb_int *);
    bool arb_int_lte(arb_int *, arb_int *);
    bool arb_int_eq(arb_int *, arb_int *);

Re: size_t-to-int vulnerability in Linux’s filesystem layer

#215

Earlier quoted context omitted.

On a server I'd usually want it to limp along too... Better fire an alert but keep happy customers than cause a massive outage just because of someone's overly strict checkfail... It depends really what your server does, and what the consequences of it doing the wrong thing are.

Or just don't put stuff that crashes in pid1

seriously, if you're doing allocations in pid1 you fucked up.

Re: size_t-to-int vulnerability in Linux’s filesystem layer

#216

Earlier quoted context omitted.

Poorly designed security architecture and division of labor. A more idealized init / systemd would have all of the execution flow of PID 1 mathematically provably correct, and correspondingly have as small a footprint as possible there. All additional functions would run under one or more child processes (where the bulk of systemd would execute).

"Lets put the graphics drivers in ring 0, for better performance!" -- Windows NT architects, 1996 "Ummm, lets not do that, it's not such a great idea..." -- Windows Vista team, 2006

Different trade offs for different eras and different constraints.

Re: size_t-to-int vulnerability in Linux’s filesystem layer

#217
post #161

Earlier quoted context omitted.

Yep: https://github.com/systemd/systemd/commit/b34a4f0e6729de292c... strdupa(input) without any length check Fix is to replace it with unbounded malloc() instead of checking for sane length first.

Good find thanks for sharing. And everyone at work gripes about me carrying the size around with a lot of my variables in the form of a struct. It's strictly a reminder to always be checking the size since I'm juggling with shotguns.

The fact that c doesn't have a native concept of an array with length and strings usually use a null byte to determine the end is, IMO c's biggest failing, and it's worst legacy on the wider software world.

Re: size_t-to-int vulnerability in Linux’s filesystem layer

#218
post #173
post #159

Earlier quoted context omitted.

Probably unbounded alloca() as always.

was that a guess? wtf... btw. it would probably be hard to make the same mistake in rust. unless you write your own code for strings or use strdupa, too via libc. I also do never understand why some libraries use "faster" methods everywhere, unless safer ones. it's not like all interfaces to systemd would need to be fast. but they should be secure.

In rust you can't currently dynamically allocate on the stack, although that's probably something that will be added in the future. And as others have pointed out, allocating on the stack is a fairly reasonable optimization here.

I don't think you could even call strdupa through libc in rust. I would guess that strdupa is either a macro that uses the alloca compiler intrinsic or is itself a compiler intrinsic. Even if it isn't, it will break assumptions the rust compiler makes about the size of the stack frame.

Re: size_t-to-int vulnerability in Linux’s filesystem layer

#219
post #60

Earlier quoted context omitted.

Wait how does a user space daemon exhausting its stack lead to a kernel panic?

Poorly designed security architecture and division of labor. A more idealized init / systemd would have all of the execution flow of PID 1 mathematically provably correct, and correspondingly have as small a footprint as possible there. All additional functions would run under one or more child processes (where the bulk of systemd would execute).

Systemd is a swiss-army-kitchen-sink-knife monolith of brittle complexity.

A proper init system similar to runit or s6 would be written in something safer (minimum unsafe) like Rust, be modular, simpler, follow UNIX philosophy, and not try to do everything in one process. Microkernel-style.

Re: size_t-to-int vulnerability in Linux’s filesystem layer

#220

Earlier quoted context omitted.

Poorly designed security architecture and division of labor. A more idealized init / systemd would have all of the execution flow of PID 1 mathematically provably correct, and correspondingly have as small a footprint as possible there. All additional functions would run under one or more child processes (where the bulk of systemd would execute).

"Lets put the graphics drivers in ring 0, for better performance!" -- Windows NT architects, 1996 "Ummm, lets not do that, it's not such a great idea..." -- Windows Vista team, 2006

Initial Windows NT uses user mode graphic driver, then NT 4.0 move it kernel mode.

https://docs.microsoft.com/en-us/previous-versions//cc750820...

Post reply on HN