Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp126027imj; Thu, 14 Feb 2019 16:52:39 -0800 (PST) X-Google-Smtp-Source: AHgI3IZYhz3mAfozt+J+9HLczcGc2LVke9FZExXqQdkm/81/nfq4rxbZTbhe+bJvP2s53ToN7yuE X-Received: by 2002:a62:7042:: with SMTP id l63mr6936438pfc.1.1550191959781; Thu, 14 Feb 2019 16:52:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550191959; cv=none; d=google.com; s=arc-20160816; b=wAXfLxMprjzUBFaE1B+CY8SDfChMzkBc9QbaDXHBejtD6LxxbX3w8in6olE1ubyASd fLo9vn3LlbVmfmcCtNtgIB8Ti6Q1FknM3zEQLtSMnvzRetF8RF9NjNqzo82jBAxcwczE XTcSh/f6XnJewGicN3uj7w0hTGQwEIO/sigpAKsQ10F4XwoqOiFi/A4Yi1pi8caOC2wh VHMFbsfcv3P8AQJ6tW4Ptu+otEOmrpn7Rbl760BCVWVVMTMsWWC3RD+mRyJa5fdIh6yk 0vAG4LYQg5f2J0mVL3kfD8ZeIXipL8zkkWquvzFlLYDe6lsf95nAZQs2Pf+o14JjHFCF BCTg== 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:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization; bh=97LyucnLWikt3L8Vuj26sL/NylBmgUZjEZ/oZgiJRsQ=; b=JIyLESDKdPC7RUg4wJ2DM8D7frJui99RgUcc7mIXbo2Et6YoKTe5b4NHx9jGt32DVl WgRaN+rEOM2qTyny+kOA/y7zMQ5qoQG9WM3tfMlNdoS/atmN3NwDpZCMioNKWtUYxTaF rc7Eo9nMvnaaO7sAMyLGiMkSfuAqH2GqBS+AUG5Q+QPxABQUHN3gYBQe5w/K1VBpLU0E Ms/V2OWQePnXy0cY4bu1zBMt0qYpmjY2D3ZaqNFvcDUHOmD7oOfciUZbySoLQX6R6YAn Gc+fp64OdHSnjHOgFONP8nAy0jbLC1vPh4PtN6ou1zELLZQ06RokBzwEuxJW1pPnM7eb GP/A== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 66si3920384pfk.209.2019.02.14.16.52.23; Thu, 14 Feb 2019 16:52:39 -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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391105AbfBNQUH (ORCPT + 99 others); Thu, 14 Feb 2019 11:20:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:64722 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731620AbfBNQUG (ORCPT ); Thu, 14 Feb 2019 11:20:06 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EE89F10F8C; Thu, 14 Feb 2019 16:20:05 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-121-129.rdu2.redhat.com [10.10.121.129]) by smtp.corp.redhat.com (Postfix) with ESMTP id A9A9660BE3; Thu, 14 Feb 2019 16:20:02 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 1/4] KEYS: allow reaching the keys quotas exactly From: David Howells To: jmorris@namei.org Cc: linux-security-module@vger.kernel.org, keyrings@vger.kernel.org, dhowells@redhat.com, ebiggers@kernel.org, linux-kernel@vger.kernel.org Date: Thu, 14 Feb 2019 16:20:01 +0000 Message-ID: <155016119453.8115.5525641267104914850.stgit@warthog.procyon.org.uk> In-Reply-To: <155016118572.8115.3243711127043478822.stgit@warthog.procyon.org.uk> References: <155016118572.8115.3243711127043478822.stgit@warthog.procyon.org.uk> User-Agent: StGit/unknown-version MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 14 Feb 2019 16:20:06 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Biggers If the sysctl 'kernel.keys.maxkeys' is set to some number n, then actually users can only add up to 'n - 1' keys. Likewise for 'kernel.keys.maxbytes' and the root_* versions of these sysctls. But these sysctls are apparently supposed to be *maximums*, as per their names and all documentation I could find -- the keyrings(7) man page, Documentation/security/keys/core.rst, and all the mentions of EDQUOT meaning that the key quota was *exceeded* (as opposed to reached). Thus, fix the code to allow reaching the quotas exactly. Fixes: 0b77f5bfb45c ("keys: make the keyring quotas controllable through /proc/sys") Cc: stable@vger.kernel.org Signed-off-by: Eric Biggers Signed-off-by: David Howells --- security/keys/key.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/security/keys/key.c b/security/keys/key.c index 44a80d6741a1..0ec9322af4f9 100644 --- a/security/keys/key.c +++ b/security/keys/key.c @@ -265,8 +265,8 @@ struct key *key_alloc(struct key_type *type, const char *desc, spin_lock(&user->lock); if (!(flags & KEY_ALLOC_QUOTA_OVERRUN)) { - if (user->qnkeys + 1 >= maxkeys || - user->qnbytes + quotalen >= maxbytes || + if (user->qnkeys + 1 > maxkeys || + user->qnbytes + quotalen > maxbytes || user->qnbytes + quotalen < user->qnbytes) goto no_quota; }