Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp581817img; Fri, 22 Mar 2019 04:30:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqyut6oWo1b6nfrlntpOMBK3cQvN2tenZ83rdXg4tGwgZEDvKXtIp0d2SLgWmW1ensuXysyS X-Received: by 2002:a63:1960:: with SMTP id 32mr8377945pgz.171.1553254227716; Fri, 22 Mar 2019 04:30:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553254227; cv=none; d=google.com; s=arc-20160816; b=d7mVcAwSodyW0ixw2H5pVQ2Afto1YaN3OsCajEVlJjXJEAeQgAs4DRfNPfYv0+SrIT Lw3QREJb/tk7SRUSSmxRUTUWleJts6Qy9Jl/idd8wwvaSVPKy7m8RxR5j+Z1f9CAYwIr Gvss6ItzSNqjlDkn4z9apjUbitAIVassNGmOkUTmYTIB7ql0p+25GSqg7CAntRPo/kiW OO6wQauCEOQm3h3rqQF+xQoAx18s6PgM0a1dEMtNIiuMpSTJlCO3ivFbcv42WE9tk0nK XDf7Dy0F7xRgt1lD+HhoxZRIIEYtanyg9KTSRwluhojA8G1XdELb9wmVLc6ouPgMC80J FiXA== 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=eJp5PvAbDcKvL91A7QWpkwz9TtN/MIuIXfRh4q6iLpU=; b=D3pb5MFwfXr7Wd9wBjnVOPI0AjssMjS1tHbW+jls3OILFOcLRwj9RhH60dl85HBPHv el+Wv9B9Nqlo2AASRQQ6jGFxJkFjcUlFh+7XbEXkoNwK7gnty5lZYMRRqscnHDVt6e7H x7LD63Co60TZj1jzxsSPYj24tNO7bXiTCRIn0PG9Eppf66Zpl6y/Lw/3fyClE4NQ0HlI ZwkrZR4VXO7kEjTTxfuffIu7kowZK4t18dzBp4+tTvJwKyqjM5p+XRbU+kvrPRAzUw2j 8Cx1E5xM/8q+P+cwAgtxJx+fy+rXYZNW05zuWNCpTRGSGT84Ee+t5lLCUOJ1s94LoAeZ RGtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=B3TX7H53; 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 r4si6249525pgp.581.2019.03.22.04.30.09; Fri, 22 Mar 2019 04:30:27 -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=B3TX7H53; 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 S1729518AbfCVL1P (ORCPT + 99 others); Fri, 22 Mar 2019 07:27:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:54926 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728857AbfCVL1L (ORCPT ); Fri, 22 Mar 2019 07:27:11 -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 73DB92183E; Fri, 22 Mar 2019 11:27:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553254031; bh=7dpBOJWmaz15lmyZiwQZoRdFBl6Au5dlebQDO0uCTe4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B3TX7H53LJY8Og3aQnSbvRV61H3pKLxNT8B0cMclqn6SW31aZJCPbAHuYuzKPOoiB SW0TO+TZ9LCWZ3D+VNqMliwnI/insDtXBTrTJ6SuWz33s24Yt4GRDjNcBNx69MjViu Cyc3wtSEDJ6M9pXo5PMP7YryytF14iWf6+sBWB9w= 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 4.4 003/230] KEYS: allow reaching the keys quotas exactly Date: Fri, 22 Mar 2019 12:12:21 +0100 Message-Id: <20190322111237.022206898@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111236.796964179@linuxfoundation.org> References: <20190322111236.796964179@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 4.4-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; }