Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp658316ybb; Wed, 8 Apr 2020 07:31:27 -0700 (PDT) X-Google-Smtp-Source: APiQypJ0pX8OaG4/pByxmY0WJJ60CB+Q1ybllhbl7noe8EUIQ1oh1RDNKUzP6kUIQ4NJvKpg3HWg X-Received: by 2002:aca:f346:: with SMTP id r67mr2702354oih.39.1586356282133; Wed, 08 Apr 2020 07:31:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586356282; cv=none; d=google.com; s=arc-20160816; b=WHhgehDBrxGrVTWp3zeuwk9L5ypknyZAVKvY+wMfaW2NaaC3fVsDqxttAsog0osd0X VoAsMnioH+Hc/jUgFyn1UV08Q33xIhOsovntHQCorR7DOap0ATiN6pvv5hPHY5dAzIXN cu75AGXbupsik47A+PSXDiRQ4qycpSca4ujaBF+hjBOMrrFdxZFeHPuQiTHFsyOzJaJ6 yZ1krIxyV/eoKNKgvygRfHiKx4g2Do7zJ8wNny4iQGUqr9ouia6UeR1nmHh1AJVZUZbe kTteopzuu4PdPPUALG4ArjSpO8pAr/tjK3+CavRBQW/czCnbIZ52M2C1pcpz8jwstVBP Ek+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=eba1VMEprWsSH8m7GqLrxl9KcTqcuyWJHmIjPccMPPs=; b=HCc1WJ6KreFj0n93fhrt7YHbGi9H2YNB6d/X9gNARF8awKie5EIAt300HEvVR8b2b+ CDvZGIjDXsovlpFdMkQLmdRLg+3cKh1Jm7vaXZojPK5cEDsB+jRs7vPX7sLMYQsp3uhN UfAtZu+p+RA/Sa6A9sluqjXrSR+Lx95M/5mDn9PuwB4Dq2pvIBXi32XoNGsmy1PqDQee HaIxTwKzoBWU3jeZxMqIb9thNWRiDuzlGGEMT3EwFyGwANBZszdp72NKi0veZlITFAnT TGG8qAi5tDCHoeSHffaG3x/FQ6wHmQX/79Wp+myyq94IZo800WuF+7fn8CHKCLrKkcFw wjzQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k70si2546339oih.24.2020.04.08.07.31.02; Wed, 08 Apr 2020 07:31:22 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728683AbgDHMVE (ORCPT + 99 others); Wed, 8 Apr 2020 08:21:04 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:49687 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726760AbgDHMVC (ORCPT ); Wed, 8 Apr 2020 08:21:02 -0400 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1jM9hR-0006Be-Ha; Wed, 08 Apr 2020 14:20:57 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 206F71C047B; Wed, 8 Apr 2020 14:20:57 +0200 (CEST) Date: Wed, 08 Apr 2020 12:20:56 -0000 From: "tip-bot2 for Jann Horn" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/urgent] locking/refcount: Document interaction with PID_MAX_LIMIT Cc: Kees Cook , Will Deacon , Jann Horn , "Peter Zijlstra (Intel)" , Ingo Molnar , x86 , LKML In-Reply-To: <20200303105427.260620-1-jannh@google.com> References: <20200303105427.260620-1-jannh@google.com> MIME-Version: 1.0 Message-ID: <158634845677.28353.8519164850978803726.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the locking/urgent branch of tip: Commit-ID: a13f58a0cafa7b0416a2898bc3b0defbb305d108 Gitweb: https://git.kernel.org/tip/a13f58a0cafa7b0416a2898bc3b0defbb305d108 Author: Jann Horn AuthorDate: Tue, 03 Mar 2020 11:54:27 +01:00 Committer: Ingo Molnar CommitterDate: Wed, 08 Apr 2020 12:05:07 +02:00 locking/refcount: Document interaction with PID_MAX_LIMIT Document the circumstances under which refcount_t's saturation mechanism works deterministically. Acked-by: Kees Cook Acked-by: Will Deacon Signed-off-by: Jann Horn Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Link: https://lkml.kernel.org/r/20200303105427.260620-1-jannh@google.com --- include/linux/refcount.h | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/include/linux/refcount.h b/include/linux/refcount.h index 0ac50cf..0e3ee25 100644 --- a/include/linux/refcount.h +++ b/include/linux/refcount.h @@ -38,11 +38,24 @@ * atomic operations, then the count will continue to edge closer to 0. If it * reaches a value of 1 before /any/ of the threads reset it to the saturated * value, then a concurrent refcount_dec_and_test() may erroneously free the - * underlying object. Given the precise timing details involved with the - * round-robin scheduling of each thread manipulating the refcount and the need - * to hit the race multiple times in succession, there doesn't appear to be a - * practical avenue of attack even if using refcount_add() operations with - * larger increments. + * underlying object. + * Linux limits the maximum number of tasks to PID_MAX_LIMIT, which is currently + * 0x400000 (and can't easily be raised in the future beyond FUTEX_TID_MASK). + * With the current PID limit, if no batched refcounting operations are used and + * the attacker can't repeatedly trigger kernel oopses in the middle of refcount + * operations, this makes it impossible for a saturated refcount to leave the + * saturation range, even if it is possible for multiple uses of the same + * refcount to nest in the context of a single task: + * + * (UINT_MAX+1-REFCOUNT_SATURATED) / PID_MAX_LIMIT = + * 0x40000000 / 0x400000 = 0x100 = 256 + * + * If hundreds of references are added/removed with a single refcounting + * operation, it may potentially be possible to leave the saturation range; but + * given the precise timing details involved with the round-robin scheduling of + * each thread manipulating the refcount and the need to hit the race multiple + * times in succession, there doesn't appear to be a practical avenue of attack + * even if using refcount_add() operations with larger increments. * * Memory ordering * ===============