RE: [PATCH] efivarfs: Limit the rate for non-root to read files

From: Luck, Tony
Date: Thu Feb 22 2018 - 00:34:08 EST


> - just make it return -EAGAIN instead of sleeping (which probably
> just works fine and doesn't break anything and is simple)

It is very simple. But it does break things :-(. If I read one of these files
using "dd bs=1", that used to read the whole file (while generating
lots of SMI). With the -EAGAIN it just reads 100 bytes and says:

dd: error reading 'DefSetup-e8a99903-302c-4851-a6be-ab2731873b2f': Resource temporarily unavailable
100+0 records in
100+0 records out
100 bytes copied, 0.153943 s, 0.6 kB/s

> - 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.

I can try that tomorrow (adding the per-user mutex to struct user_struct
right next to the ratelimit I added.

-Tony