Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1696054

Re: [kernel-hardening] [PATCH v8 3/3] x86/refcount: Implement fast refcount overflow protection

From Kees Cook <keescook@chromium.org>
Newsgroups linux.kernel
Subject Re: [kernel-hardening] [PATCH v8 3/3] x86/refcount: Implement fast refcount overflow protection
Date 2017-07-25 21:20 +0200
Message-ID <u7dx9-6OD-33@gated-at.bofh.it> (permalink)
References <u6QqR-dR-3@gated-at.bofh.it> <u6QqR-dR-11@gated-at.bofh.it> <u76P0-2BR-15@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Tue, Jul 25, 2017 at 5:03 AM, Li Kun <hw.likun@huawei.com> wrote:
> Hi Kees,
>
>
> on 2017/7/25 2:35, Kees Cook wrote:
>>
>> +static __always_inline __must_check
>> +int __refcount_add_unless(refcount_t *r, int a, int u)
>> +{
>> +       int c, new;
>> +
>> +       c = atomic_read(&(r->refs));
>> +       do {
>> +               if (unlikely(c == u))
>> +                       break;
>> +
>> +               asm volatile("addl %2,%0\n\t"
>> +                       REFCOUNT_CHECK_LT_ZERO
>> +                       : "=r" (new)
>> +                       : "0" (c), "ir" (a),
>> +                         [counter] "m" (r->refs.counter)
>> +                       : "cc", "cx");
>> +
>> +       } while (!atomic_try_cmpxchg(&(r->refs), &c, new));
>> +
>> +       return c;
>> +}
>
> here when the result LT_ZERO, you will saturate the r->refs.counter and make
> the
>
> atomic_try_cmpxchg(&(r->refs), &c, new) bound to fail first time.
>
> maybe we can just saturate the value of variable "new" ?

Oh, good catch! Thanks. Actually, it's even worse than that: we'll
exit this function without the refcount being correctly saturated. The
final result will be INT_MIN / 2 + a. It's not terrible, but I should
have noticed this in testing. (There was a gap in my testing for the
_not_zero() overflows, which I've fixed now...)

I'll figure this out or revert to the logic I was using in v6...

-Kees

-- 
Kees Cook
Pixel Security

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH v8 0/3] x86: Implement fast refcount overflow protection Kees Cook <keescook@chromium.org> - 2017-07-24 20:40 +0200
  [PATCH v8 3/3] x86/refcount: Implement fast refcount overflow protection Kees Cook <keescook@chromium.org> - 2017-07-24 20:40 +0200
    Re: [kernel-hardening] [PATCH v8 3/3] x86/refcount: Implement fast  refcount overflow protection Li Kun <hw.likun@huawei.com> - 2017-07-25 14:10 +0200
      Re: [kernel-hardening] [PATCH v8 3/3] x86/refcount: Implement fast  refcount overflow protection Kees Cook <keescook@chromium.org> - 2017-07-25 21:20 +0200

csiph-web