[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CA+55aFzJXsPcsJ5MtsxTp2n+43xC0yGzANLNcDm1mFbZKR75FQ@mail.gmail.com>
Date: Wed, 21 Feb 2018 17:58:37 -0800
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: "Luck, Tony" <tony.luck@...el.com>
Cc: Andi Kleen <ak@...ux.intel.com>,
Ard Biesheuvel <ard.biesheuvel@...aro.org>,
Joe Konno <joe.konno@...ux.intel.com>,
"linux-efi@...r.kernel.org" <linux-efi@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Jeremy Kerr <jk@...abs.org>,
Matthew Garrett <mjg59@...gle.com>,
Peter Jones <pjones@...hat.com>,
Andy Lutomirski <luto@...nel.org>,
James Bottomley <james.bottomley@...senpartnership.com>
Subject: Re: [PATCH] efivarfs: Limit the rate for non-root to read files
On Wed, Feb 21, 2018 at 5:45 PM, Luck, Tony <tony.luck@...el.com> 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
Powered by blists - more mailing lists