Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp575414img; Fri, 22 Mar 2019 04:21:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqzEtUe4qKdMII58vnZrlOxlhszf3Rnxq+kyZkl0DaSepTz0YmmJCtX/JzRMTa1sj6WjMOHg X-Received: by 2002:a62:19c3:: with SMTP id 186mr6818152pfz.172.1553253706221; Fri, 22 Mar 2019 04:21:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553253706; cv=none; d=google.com; s=arc-20160816; b=ID8mmRrqFXzF044NvTQGEapyeSKHiFSnAn9sd5C+k1vCBqAzWFevzThTIhr9ZTex+M Jyid1KILaMHjNZiHYJw6VzvOYcxjPpvPG37i5GwXpe9Bxu9uLalbf3O9UPwfQJG4yuFZ 3fSGCAxtDchw2UcD0FjIoFNrqg7oKhcWGTGxX4ZaaxTaMPp7+763iu+Q5TmCb0CGncem GFBJSWU9IWinS6r+9WoX27ebo2r81WKv/VQwdrxHQoBzHwnjDOOigZ5nYx4i0eQWlYCT YYi/xeeLiU1y/iNLFSPIHPzJoLHWrNYL17jsGuzKPQ1HpTo6BnBMX69l15iOwXqa64gs r4uA== 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:subject:cc:to :from:dkim-signature; bh=IWc7mMqRMIKqlEovqJGvkBT3r8qBTTBJHiimp5nDkic=; b=vtseZPtP4kFqQ4GpBR0L/VqkeXgudl4rssGYkI/MTDxUJzcjduqjbzjNDVs7C87n9g VY5TEmxlswJjLdyQnzQBsVWrorAjqntNkq3w9JR6ME8tS9tLG6cLomOVUXMQZE1Cplwd W5SELujpnYLiMJQoJUR8nAm8hJkNHrisBAsn8RyS+Xyzk8r9rhYERiRnn6yKA7lelXQD +hSKeuNtHK9pIgsHH3TFnvIx4mG7XmepXcEaH49oq3waUZzrzuIzyEYDeWH2wLXiC4Pc ADVG4vplw0y3+1NdOEhCDsdZGPuIJKze/F4LiaVCV9xKFz7eh4gb9RheCnxDSRYGNAVR Ou2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="XVC/o1LX"; 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 h127si6709102pfb.213.2019.03.22.04.21.31; Fri, 22 Mar 2019 04:21:46 -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; dkim=pass header.i=@kernel.org header.s=default header.b="XVC/o1LX"; 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 S1728321AbfCVLUS (ORCPT + 99 others); Fri, 22 Mar 2019 07:20:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:46614 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728236AbfCVLUR (ORCPT ); Fri, 22 Mar 2019 07:20:17 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2D6B7218A2; Fri, 22 Mar 2019 11:20:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553253612; bh=sl5IdIWGBKzjaOa8Ict0Oud52xFDNgFIueteDvK69Fk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XVC/o1LXXHNbG2pS88/16SJpJRAT0fsbdCXOyYoxEE9OFywmkAj/JednGP/+PEbU3 Mscua+uZ6mm3q4DB8JlvPxtpdJZqkoGG+Szge6mJU5/Fa08Wagt/Nx6T90/xIDAW7S BImOoY+W90pW9Qb3NFjRLKjJPZRNqjKRV4DenIpk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Biggers , David Howells , James Morris Subject: [PATCH 3.18 003/134] KEYS: allow reaching the keys quotas exactly Date: Fri, 22 Mar 2019 12:13:36 +0100 Message-Id: <20190322111210.595149426@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111210.465931067@linuxfoundation.org> References: <20190322111210.465931067@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Biggers commit a08bf91ce28ed3ae7b6fef35d843fef8dc8c2cd9 upstream. 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 Signed-off-by: James Morris Signed-off-by: Greg Kroah-Hartman --- security/keys/key.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/security/keys/key.c +++ b/security/keys/key.c @@ -260,8 +260,8 @@ struct key *key_alloc(struct key_type *t 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; }