From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932205AbdJ3PDH convert rfc822-to-8bit (ORCPT ); Mon, 30 Oct 2017 11:03:07 -0400 Received: from smtp.nue.novell.com ([195.135.221.5]:48380 "EHLO smtp.nue.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751582AbdJ3PDF (ORCPT ); Mon, 30 Oct 2017 11:03:05 -0400 From: =?utf-8?Q?Aur=C3=A9lien?= Aptel To: Elena Reshetova , linux-cifs@vger.kernel.org Cc: linux-kernel@vger.kernel.org, sfrench@samba.org, samba-technical@lists.samba.org, peterz@infradead.org, keescook@chromium.org, Elena Reshetova Subject: Re: [PATCH] fs, cifs: convert tcon_link.tl_count from atomic_t to refcount_t In-Reply-To: <1508496110-2292-1-git-send-email-elena.reshetova@intel.com> References: <1508496110-2292-1-git-send-email-elena.reshetova@intel.com> User-Agent: Notmuch/0.22.1 (http://notmuchmail.org) Emacs/25.1.1 (x86_64-unknown-linux-gnu) Date: Mon, 30 Oct 2017 16:03:02 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Elena Reshetova writes: > 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 tcon_link.tl_count is used as pure reference counter. > Convert it to refcount_t and fix up the operations. > - cifs_get_tlink(tlink); > + refcount_set(&tlink->tl_count, 1); Since cifs_get_tlink() basically only increments the reference count and given that this is a new tlink I also think this replacement is ok. Looks good to me and passes 'make C=1'. Reviewed-by: Aurelien Aptel -- Aurélien Aptel / SUSE Labs Samba Team GPG: 1839 CB5F 9F5B FB9B AA97 8C99 03C8 A49B 521B D5D3 SUSE Linux GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)