Re: [PATCH] efivarfs: Limit the rate for non-root to read files
From: Linus Torvalds
Date: Wed Feb 21 2018 - 20:58:54 EST
On Wed, Feb 21, 2018 at 5:45 PM, Luck, Tony <tony.luck@xxxxxxxxx> wrote:
>
> Linus suggested per-user rate limit to solve this.
Note that you also need to serialize per user, because otherwise..
> + if (!__ratelimit(&file->f_cred->user->ratelimit))
> + usleep_range(10000, 10000);
..this doesn't really ratelimit anything, because you can just start a
thousand threads, and they all end up being rate-limited, but they all
just sleep for 10ms each, so you can get a hundred thousand accesses
per second anyway.
To fix that, you can either:
- just make it return -EAGAIN instead of sleeping (which probably
just works fine and doesn't break anything and is simple)
- add a per-user mutex, and do the usleep inside of it, so that
anybody who tries to do a thousand threads will just be serialized by
the mutex.
Note that the mutex needs to be per-user, because otherwise it will be
a DoS for the other users.
Of course, to avoid *another* DoS, the mutex should probably be
interruptible, and return -EAGAIN, so that you don't have a thousand
thread waiting for the mutex and have something that is effectively
unkillable for ten seconds.
Can it be hard and annoying to avoid DoS by rate limiting? Why, yes.
Yes it can.
Linus