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


Groups > linux.kernel > #1589933

Re: [PATCH 0/5] mm subsystem refcounter conversions

From Andrew Morton <akpm@linux-foundation.org>
Newsgroups linux.kernel
Subject Re: [PATCH 0/5] mm subsystem refcounter conversions
Date 2017-03-01 02:40 +0100
Message-ID <tg1pg-3Zx-5@gated-at.bofh.it> (permalink)
References <tdfoJ-NC-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Tue, 21 Feb 2017 11:58:39 +0200 Elena Reshetova <elena.reshetova@intel.com> wrote:

> Now when new refcount_t type and API are finally merged
> (see include/linux/refcount.h), the following
> patches convert various refcounters in the mm susystem from atomic_t
> to refcount_t. By doing this we prevent intentional or accidental
> underflows or overflows that can led to use-after-free vulnerabilities.
> 
> The below patches are fully independent and can be cherry-picked separately.
> Since we convert all kernel subsystems in the same fashion, resulting
> in about 300 patches, we have to group them for sending at least in some
> fashion to be manageable. Please excuse the long cc list.

I don't think so.  Unless I'm missing something rather large...


We're going to convert every

	atomic_inc(&foo);

into an uninlined function which calls an uninlined

bool refcount_inc_not_zero(refcount_t *r)
{
	unsigned int old, new, val = atomic_read(&r->refs);

	for (;;) {
		new = val + 1;

		if (!val)
			return false;

		if (unlikely(!new))
			return true;

		old = atomic_cmpxchg_relaxed(&r->refs, val, new);
		if (old == val)
			break;

		val = old;
	}

	WARN(new == UINT_MAX, "refcount_t: saturated; leaking memory.\n");

	return true;
}

The performance implications of this proposal are terrifying.

I suggest adding a set of non-debug inlined refcount functions which
just fall back to the simple atomic.h operations.

And add a new CONFIG_DEBUG_REFCOUNT.  So the performance (and code
size!) with CONFIG_DEBUG_REFCOUNT=n is unaltered from present code. 
And make CONFIG_DEBUG_REFCOUNT suitably difficult to set.

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


Thread

[PATCH 0/5] mm subsystem refcounter conversions Elena Reshetova <elena.reshetova@intel.com> - 2017-02-21 11:00 +0100
  [PATCH 5/5] mm: convert mm_struct.mm_count from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-02-21 11:00 +0100
  [PATCH 1/5] mm: convert bdi_writeback_congested.refcnt from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-02-21 11:00 +0100
  [PATCH 3/5] mm: convert kmemleak_object.use_count from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-02-21 11:10 +0100
  Re: [PATCH 0/5] mm subsystem refcounter conversions Andrew Morton <akpm@linux-foundation.org> - 2017-03-01 02:40 +0100

csiph-web