From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752727AbdJTSjt (ORCPT ); Fri, 20 Oct 2017 14:39:49 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:54947 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752581AbdJTSjr (ORCPT ); Fri, 20 Oct 2017 14:39:47 -0400 X-Google-Smtp-Source: ABhQp+Sm6SgqiRyVg4R4qBLd7jWcBH5I+tp8mYqH0e1cXFUZAPj4vgNJi3YWaNtN4WmAXlAwpxbCsw== Subject: Re: [PATCH 1/4] bcache: convert cached_dev.count from atomic_t to refcount_t To: Elena Reshetova , dm-devel@redhat.com Cc: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, kent.overstreet@gmail.com, koverstreet@google.com, ejt@redhat.comg, snitzer@redhat.com, shli@kernel.org, agk@redhat.com, peterz@infradead.org, keescook@chromium.org References: <1508485059-21881-1-git-send-email-elena.reshetova@intel.com> <1508485059-21881-2-git-send-email-elena.reshetova@intel.com> From: Michael Lyle Message-ID: <8bd05fae-d41f-24e7-4e58-bf07d9a09a99@lyle.org> Date: Fri, 20 Oct 2017 11:39:42 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <1508485059-21881-2-git-send-email-elena.reshetova@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/20/2017 12:37 AM, Elena Reshetova wrote: > atomic_t variables are currently used to implement reference > counters with the following properties: > - counter is initialized to 1 using atomic_set() > - a resource is freed upon counter reaching zero > - once counter reaches zero, its further > increments aren't allowed > - counter schema uses basic atomic operations > (set, inc, inc_not_zero, dec_and_test, etc.) > > Such atomic variables should be converted to a newly provided > refcount_t type and API that prevents accidental counter overflows > and underflows. This is important since overflows and underflows > can lead to use-after-free situation and be exploitable. > > The variable cached_dev.count is used as pure reference counter. > Convert it to refcount_t and fix up the operations. > > Suggested-by: Kees Cook > Reviewed-by: David Windsor > Reviewed-by: Hans Liljestrand > Signed-off-by: Elena Reshetova Reviewed-by: Michael Lyle Thanks for this-- I'm including it in my tree for possible inclusion in 4.15 (I've already sent my main chunk of changes upwards). Mike