Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp728656ima; Fri, 1 Feb 2019 10:03:45 -0800 (PST) X-Google-Smtp-Source: AHgI3IbRxgAAxaKc0pXDKyWJY8llVpIMw1nAEoLqKGMBC78bLpDNFCkeLqXqLwiLv4P4Da/3XRvc X-Received: by 2002:a63:e21:: with SMTP id d33mr3178333pgl.272.1549044225779; Fri, 01 Feb 2019 10:03:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549044225; cv=none; d=google.com; s=arc-20160816; b=wlnTn5UoGKIQZ30rJT+k90kyEe0pjpupONIPajWj1nkkpq+XFMNIu5Yc6rGcevsGHd q/vJeMj/9rc3DSHVqpwy+UrMqfAsOcZZsY7o1Sw/E9LSEnpHmW/NlY24QKdztXG7dieY ovN9HZ81MQbbBP/6hAYTfb1CSE99L8uz6S8x23iOnQvt64I7A+tBPk2ZPA8qRyVBenp3 h2rV5AhW06h+KMjcdrvQXDOYMm7szzGoD/HPRtSHVZ7m3xaGDuBpZb/3/ng9m7WvKT7C Tg2fsyWXv/LtTrt/dSqwfXoHbYuLy4NOWgf72R1YEXtDwwBYW8zhRzAA7/S9sXt6ZtoO BLFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:subject:cc:to :from:date; bh=Ch2OSRErkqPw6hI7M7Tr8qHPfGYh6/o0oHlTkeOTr2Y=; b=rPfYOhlJ9fOIlQAM2rV1SV6Ke6paqQz3i7gxtNS3PV0sV1z+YBkwBxcFPvMwT6vimb Kd9U6IlwP+BiFc0kdj4K3RMsSzij4ilhpSONxRFkBV1PxKkYxLOvXW6sldAuT+fmMOPt R6RDRXGZ4kUfSLt1k7GeRrPNoYSiYXyStQNm3U1d52IjsXhXJQgs3NVzi9LgNkoMYG18 h29YQ8xc9S3Z+5CzgYmfLgWW/tjBmJZMbq1DhE+uSJlXHhp1hKiG/JPwtCTFlRbm0VE5 nMhzG3FlRp1yJQNa41eVYtzvd9UO0zAo5c3oAUGkPpR2FYe7jbM2GIpJ8jj+BAc3N4Cb cjXg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v124si1704226pgb.7.2019.02.01.10.03.28; Fri, 01 Feb 2019 10:03:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729778AbfBARWB (ORCPT + 99 others); Fri, 1 Feb 2019 12:22:01 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:47276 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729009AbfBARWA (ORCPT ); Fri, 1 Feb 2019 12:22:00 -0500 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x11HJpqd001743 for ; Fri, 1 Feb 2019 12:21:59 -0500 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2qctbngbrf-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 01 Feb 2019 12:21:59 -0500 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 1 Feb 2019 17:21:56 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 1 Feb 2019 17:21:54 -0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x11HLr1U40960064 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 1 Feb 2019 17:21:53 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3464642047; Fri, 1 Feb 2019 17:21:53 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 64D824203F; Fri, 1 Feb 2019 17:21:51 +0000 (GMT) Received: from linux.vnet.ibm.com (unknown [9.126.150.29]) by d06av24.portsmouth.uk.ibm.com (Postfix) with SMTP; Fri, 1 Feb 2019 17:21:51 +0000 (GMT) Date: Fri, 1 Feb 2019 22:51:50 +0530 From: Srikar Dronamraju To: Elena Reshetova Cc: rostedt@goodmis.org, peterz@infradead.org, mingo@redhat.com, akpm@linux-foundation.org, acme@kernel.org, alexander.shishkin@linux.intel.com, jolsa@redhat.com, linux-kernel@vger.kernel.org, keescook@chromium.org Subject: Re: [PATCH] uprobes: convert uprobe.ref to refcount_t Reply-To: Srikar Dronamraju References: <1547637627-29526-1-git-send-email-elena.reshetova@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1547637627-29526-1-git-send-email-elena.reshetova@intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-TM-AS-GCONF: 00 x-cbid: 19020117-0016-0000-0000-0000024F6448 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19020117-0017-0000-0000-000032A968B1 Message-Id: <20190201172150.GA1853@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-02-01_12:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902010127 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Elena Reshetova [2019-01-16 13:20:27]: > 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 uprobe.ref is used as pure reference counter. > Convert it to refcount_t and fix up the operations. > > **Important note for maintainers: > > Some functions from refcount_t API defined in lib/refcount.c > have different memory ordering guarantees than their atomic > counterparts. > The full comparison can be seen in > https://lkml.org/lkml/2017/11/15/57 and it is hopefully soon > in state to be merged to the documentation tree. > Normally the differences should not matter since refcount_t provides > enough guarantees to satisfy the refcounting use cases, but in > some rare cases it might matter. > Please double check that you don't have some undocumented > memory guarantees for this variable usage. > > For the uprobe.ref it might make a difference > in following places: > - put_uprobe(): decrement in refcount_dec_and_test() only > provides RELEASE ordering and control dependency on success > vs. fully ordered atomic counterpart > > Suggested-by: Kees Cook > Reviewed-by: David Windsor > Reviewed-by: Hans Liljestrand > Signed-off-by: Elena Reshetova > --- > kernel/events/uprobes.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > Looks good to me. Reviewed-by: Srikar Dronamraju -- Thanks and Regards Srikar Dronamraju