Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S940991AbcKQOai convert rfc822-to-8bit (ORCPT ); Thu, 17 Nov 2016 09:30:38 -0500 Received: from mga04.intel.com ([192.55.52.120]:3881 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753810AbcKQOae (ORCPT ); Thu, 17 Nov 2016 09:30:34 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,653,1473145200"; d="scan'208";a="32472246" From: "Reshetova, Elena" To: Peter Zijlstra , David Windsor CC: Kees Cook , Greg KH , Will Deacon , Arnd Bergmann , "Thomas Gleixner" , Ingo Molnar , "H. Peter Anvin" , LKML , "Alexei Starovoitov" , Daniel Borkmann Subject: RE: [RFC][PATCH 2/7] kref: Add kref_read() Thread-Topic: [RFC][PATCH 2/7] kref: Add kref_read() Thread-Index: AQHSPp8xNqFGs6lR9EeBqDMncz0eH6DZp9cAgAAIWACAANc8gIAA3lqAgACT3QCAAOQVAIAAQc2AgAADroCAAACTUA== Date: Thu, 17 Nov 2016 13:01:49 +0000 Message-ID: <2236FBA76BA1254E88B949DDB74E612B41C14089@IRSMSX102.ger.corp.intel.com> References: <20161114173946.501528675@infradead.org> <20161114174446.486581399@infradead.org> <20161115073322.GC28248@kroah.com> <20161115080314.GD3142@twins.programming.kicks-ass.net> <20161116100925.GM3142@twins.programming.kicks-ass.net> <20161117083458.GZ3142@twins.programming.kicks-ass.net> <20161117124339.GC3117@twins.programming.kicks-ass.net> In-Reply-To: <20161117124339.GC3117@twins.programming.kicks-ass.net> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2551 Lines: 29 On Thu, Nov 17, 2016 at 07:30:29AM -0500, David Windsor wrote: > On Thu, Nov 17, 2016 at 3:34 AM, Peter Zijlstra wrote: > > No, its not a statistic. Also, I'm far from convinced stats_t is an > > actually useful thing to have. > > > > Regarding this, has there been any thought given as to how stats_t > will meaningfully differ from atomic_t? If refcount_t is semantically > "atomic_t with reference counter overflow protection," what > services/guarantees does stats_t provide? I cannot think of any that > don't require implementing overflow detection of some sort, which > incurs a performance hit. >Afaict the whole point of stats_t was to allow overflow, since its only stats, nobody cares etc.. >I think the sole motivator is a general distaste of atomic_t, which isn't a good reason at all. I don't think anyone has this as motivation. But atomic_t is so powerful and flexible that easily ends up being misused (as past CVEs shown). Even if we now find all occurrences of atomic_t used as refcounter (which we cannot actually guarantee in any case unless someone manually reads every line) and convert it to refcount_t, we still have atomic_t type present and new usage of it as refount will crawl in. It is just a matter of time IMO. So, this approach still doesn't solve the main problem: abuse of atomic_t a refcounter and security vulnerabilities as result. What other mechanisms can we think we can utilize to prevent it? - Checkpatch? Would be hard to write enough rules to find all possible patterns how creative people might use atomic as refcounter. - People reviewing the code? Many kernel vulnerabilities live outside of core kernel, where maintainers are careful about what gets in and what's not. Further you go from core kernel (especially when you reach non-upstream drivers), code review quality is less, possibility of mistake is higher, and on average this code has more vulnerabilities. We can't say "this is not upstream code, who cares", because we want Linux kernel to follow "secure by default" principle: to provide enough mechanisms in kernel itself to minimize risk of mistakes and vulnerabilities. I think atomic is a great example of such case. We need to make it hard for people to make mistakes with overflows when overflows actually matter. This was really a reason for our initial approach that provided "security by default". Certainly it had some issues (we all agree on this), but let's think how else can we provide "secure by default" protection for this.