Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10091863ybi; Wed, 24 Jul 2019 15:50:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqxfWOyOWgGGRVUpy3cCOmG6c9fWIfINkV+SmATMM+qh+qfP1OPX9liRPXvQ4P3NdcSBkHy+ X-Received: by 2002:a17:90a:350c:: with SMTP id q12mr90192233pjb.46.1564008627710; Wed, 24 Jul 2019 15:50:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564008627; cv=none; d=google.com; s=arc-20160816; b=QSWu2nGsDjJyjBzRmMbRNRESs5LEitSZQSA73ZkJVywnG9Ih0z23wmCMsgSCpWQtck 1cyvaZnI4RXnpKTZgY+1yz/QaRbazdP3NACQOMXUa2bc/SeyWOg2TNDTycb+qDEjyvQf 6LIbfkgxgd1fNw72315JjKDCw2fNaD8JVmLZTBHi7VYLc4+lVFiNHsC3U9qjdaVExg6w J6BjhLIz2O/+GbOIfkSwNJKWSfVhnb/ZMX1YQiiXA57rHg7y0sNSDqizi0dLHcA68c4u RBe7e/paU0ssOKkSNR6QfvrG9QCab/kH4Pb0X8H4aU1/h9zXesZEaVgWMhvkYSWkO/X8 LoKw== 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=2oaL0GyNtz3Jz8XSB46qMmkmhuV96Y5YcySB1M/uu3g=; b=t61cJ6c4BKZfwjzCni9TOjm3K1bCahVJGdLGniexylDeVmyoUfC4TxpaCX9mQoJxjW 5340xlGknzkn0Sn10CvNjW79xaP86S+Puvqz8Ik6WOFu4pl5nTwdRxK4lKZM+mMydqMw ATSRAelYJgKqhLzwkPTGbHPR5h9SrL/MxD2mGUpyRxAy4t3X1v1rfuFyly6EOUwmAqJI Ix/XXbvuI2RirZKMltv2AfQnZOef7m2yOWg2RptbjrcOsR9qTL3dSuVLI6/T7RF6tH9D kxnBs+k4Digbc7QywDqidpqdld4IOL5jmIJ5vE5/mGdsu4WtRw9IkgFFIdtvDzOMCwTD 6nyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wvyZI1Sl; 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 f131si14397518pgc.265.2019.07.24.15.50.12; Wed, 24 Jul 2019 15:50: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=wvyZI1Sl; 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 S1727771AbfGXT1N (ORCPT + 99 others); Wed, 24 Jul 2019 15:27:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:44666 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728733AbfGXT1J (ORCPT ); Wed, 24 Jul 2019 15:27:09 -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 5B53422387; Wed, 24 Jul 2019 19:27:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996428; bh=nrWoDL7XEid3OLCQ158UCjFe0QkT4IbeN4Q5Enb0E4I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wvyZI1SloFZcUoYoiiRVP0amhmaEIHNXyt7GgvXxmvRA571Lz446prRGeXfj/UgNd +vNUmsl0FHmzfgf9UY9Eowa9f4AfZRj4tnKoTuowCTk1CaUt7clhlCgOdSeWUVEOKr vXjIzsHWWLE71qZzTDdQia/qwiSG/nOzwqty9blI= 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 5.2 094/413] selinux: fix empty write to keycreate file Date: Wed, 24 Jul 2019 21:16:25 +0200 Message-Id: <20190724191741.738557199@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@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 94de51628fdc..3ec7ac70c313 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6351,11 +6351,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