Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10527873ybi; Thu, 25 Jul 2019 00:57:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqyOBx0VhM3kkF7CNGaeur3SsEoajpGOTOgbzUlsyCbJlA8B4ZjMwpVLfhKwiX2b8V9bmRGR X-Received: by 2002:aa7:81d9:: with SMTP id c25mr15607403pfn.255.1564041441847; Thu, 25 Jul 2019 00:57:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564041441; cv=none; d=google.com; s=arc-20160816; b=DeJPQSkVZhnot5XuB9xCN32SGRmKqwrdFt68Y00wiXxUMrg5x01LEUc+M8gnDZa8iJ Oy6FYVPwsd/dVT/N+8mNDD9fR7ffXNuq8AYF0PMQji3p4iYpMuulUKjcYrLVLHm+Zh6Z jqNt3SVQo8nsIwCyF1YpjxAh1JzbrpeiiEEyBTvLnm1QTjGfUH9XTymzib2AB6hlBj4b nsWDu0vnIzCNOhZdltYogRYNGqM3dUMlc4KdhsreWRyfNe7D82AofFQkhdE6Yl0qb7eL XdaAwvZbDCPivGXaruAB80optJFQpxLF9x8+njPacF2w2E9zBCgnqpCpAHh1gkncsHWM xVAg== 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=TSIcnIv0G8xDoLGfY/e4cmxo5vFoVlyWcQ5DJKXVeTU=; b=R0nxDRt34CxW75LnVtTS/zGMBUsy8vWixtsTcMT09DNcl1pXrBZzQg9EQz6tvMFJpm jTtOIs70SxA77tn4ZWELa7gR2W0Pf6CnZaV00W47snE5VvsqQh21D9dK/t7h4kfMPi6C I6noz0y7MoCLDte4cH+j6HBTN/bnLX4g5SVS89fUq3YXg0PlU8UGFfPZq5iEBsTmnPyY 8B86QWG21CXQgWN1WGbLh+3f6Q4gJNo1/9Gkvw5IDHOebQ/QPNbrO/YwWDO3Sxty6IZ2 pg93kxwTs7P3+ZUGShdPgPqtm5igZ4ljtGdzM+jh2ibvKFOR4NWwtHiKfXjJz6bh15bj GB/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=I5yq8Uw5; 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 x9si17626112plo.98.2019.07.25.00.57.03; Thu, 25 Jul 2019 00:57:21 -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=I5yq8Uw5; 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 S2392470AbfGXUEN (ORCPT + 99 others); Wed, 24 Jul 2019 16:04:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:55030 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392456AbfGXUEI (ORCPT ); Wed, 24 Jul 2019 16:04:08 -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 496A32147A; Wed, 24 Jul 2019 20:04:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563998647; bh=lgxI0LR00qRyA3YaGTN518XuZEY2K4RnWD2AbaPaGdQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I5yq8Uw50EIAxughepC+xf74JxhFPogfo7Y+9EhQLajk8yk8PQXLPID71rEqUX4G/ NMjMmDRe3Jj0EAJjw4oAuLPzeiaih2lv1DFe6PtxB8H6RclycMugRiSWt4Jj/F81G9 P6ADdWTQqald252A2tT7C4oP/Uc7f/JEFWcZEZlE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kir Kolyshkin , Ondrej Mosnacek , Paul Moore , Sasha Levin Subject: [PATCH 4.19 066/271] selinux: fix empty write to keycreate file Date: Wed, 24 Jul 2019 21:18:55 +0200 Message-Id: <20190724191700.851717639@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191655.268628197@linuxfoundation.org> References: <20190724191655.268628197@linuxfoundation.org> User-Agent: quilt/0.66 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 [ Upstream commit 464c258aa45b09f16aa0f05847ed8895873262d9 ] When sid == 0 (we are resetting keycreate_sid to the default value), we should skip the KEY__CREATE check. Before this patch, doing a zero-sized write to /proc/self/keycreate would check if the current task can create unlabeled keys (which would usually fail with -EACCESS and generate an AVC). Now it skips the check and correctly sets the task's keycreate_sid to 0. Bug report: https://bugzilla.redhat.com/show_bug.cgi?id=1719067 Tested using the reproducer from the report above. Fixes: 4eb582cf1fbd ("[PATCH] keys: add a way to store the appropriate context for newly-created keys") Reported-by: Kir Kolyshkin Signed-off-by: Ondrej Mosnacek Signed-off-by: Paul Moore Signed-off-by: Sasha Levin --- security/selinux/hooks.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 70bad15ed7a0..109ab510bdb1 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6550,11 +6550,12 @@ static int selinux_setprocattr(const char *name, void *value, size_t size) } else if (!strcmp(name, "fscreate")) { tsec->create_sid = sid; } else if (!strcmp(name, "keycreate")) { - error = avc_has_perm(&selinux_state, - mysid, sid, SECCLASS_KEY, KEY__CREATE, - NULL); - if (error) - goto abort_change; + if (sid) { + error = avc_has_perm(&selinux_state, mysid, sid, + SECCLASS_KEY, KEY__CREATE, NULL); + if (error) + goto abort_change; + } tsec->keycreate_sid = sid; } else if (!strcmp(name, "sockcreate")) { tsec->sockcreate_sid = sid; -- 2.20.1