Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3012142ybi; Mon, 17 Jun 2019 14:39:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqykQzs+c+ntt3rtxgkTGbGMInaoGpN45y8gitZl3yJpZKLkkayq1XmGHdPNdFMjIQBqWEMs X-Received: by 2002:a62:e910:: with SMTP id j16mr14096741pfh.123.1560807587641; Mon, 17 Jun 2019 14:39:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560807587; cv=none; d=google.com; s=arc-20160816; b=xl8LqiF7Qsxxbq2eJILxdhoaeijjdRYQRzzQcngFTWboyUM8QGXvmWS8b+CTUJ59B+ d4YnH8ZBcgBNUiHJVP8jkGJflYrMUPBIVbR7MHeKoxhray0XWeOhTDerU1q8/OEtoM02 9s/XZJVdX006OoFg8afvDSMMD3QqETzSnGWbeS+lSaDQHBHUrEGab6Gp7Z4on8XCpkyT IeYw+6mWL3BTYVzeVrpZo6QNuuvY3ZuqcRIf2TvF32fjO7XfQLWUnTTYErYQkqK2xcG+ 1hV8oPr1D4ipYRKPYYR6bsSikhiMKg2MEVXGHTYoa/YyTGKKRJlKTrinbrupoNgb/MPi Go3w== 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=d8caTqNKH0TXWVOpbeEXpLwiBnEerIUI+QRxt+m5XRA=; b=TAa3lvlt+pwq4EsS4xsdjXHbt1vddnHoK6vLHOM4s+WJZ1MZAQ2XmfDwfiWXoXKGys 19v9mG0dFqg3s/iLj51kZ1GtjRD2j0/l+cqSmaxavnXL0MWtnISDnF3N4kKo7iCFhIZ0 1ehnUO1BGm9IgnqKEnx9I4QHwa76Mx7n8A/XJTxQqoXmF1n3S6btTi6zK9MXBl4KfKoZ i6JboMTBVCMjTm3o+aUOb65lP4QHuqlr1a2JHGvQY39U2mgVkMG09oZwPqlkmpoOU875 BCIksfNqT6Q8Tmp4ZutZ8WJ5875QtJrZg3H9bVbWFgZ6bhMX8QsNjLr+ryqcCTAcDSE6 E/XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GU6+GZ8O; 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 t13si3872727pgu.142.2019.06.17.14.39.32; Mon, 17 Jun 2019 14:39:47 -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=GU6+GZ8O; 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 S1729189AbfFQViP (ORCPT + 99 others); Mon, 17 Jun 2019 17:38:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:42490 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728287AbfFQVSz (ORCPT ); Mon, 17 Jun 2019 17:18:55 -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 E17842133F; Mon, 17 Jun 2019 21:18:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560806334; bh=M3WtjkHNv4iTtky1f5EnerEPfoZTklWgPAO2tVoeFv4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GU6+GZ8O+L6VKtnBvPuxxEnU/X+RQlqbU2Yj5oVmKWCDhPIEeDBMgll9H17W0Qoae Y8vxoBE7MWeTwaPD/skfegC+2fZplqanz6Ii7Q5pr1XVIYSuiAPAsHFCz+eCpTEDLi mqVFRhyqud1cRS4gFydwB8AzWwq5C17FJZo+Wgrc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ondrej Mosnacek , Richard Guy Briggs , Paul Moore Subject: [PATCH 5.1 017/115] selinux: log raw contexts as untrusted strings Date: Mon, 17 Jun 2019 23:08:37 +0200 Message-Id: <20190617210800.792335370@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190617210759.929316339@linuxfoundation.org> References: <20190617210759.929316339@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 From: Ondrej Mosnacek commit aff7ed4851680d0d28ad9f52cd2f99213e1371b2 upstream. These strings may come from untrusted sources (e.g. file xattrs) so they need to be properly escaped. Reproducer: # setenforce 0 # touch /tmp/test # setfattr -n security.selinux -v 'kuřecí řízek' /tmp/test # runcon system_u:system_r:sshd_t:s0 cat /tmp/test (look at the generated AVCs) Actual result: type=AVC [...] trawcon=kuřecí řízek Expected result: type=AVC [...] trawcon=6B75C5996563C3AD20C599C3AD7A656B Fixes: fede148324c3 ("selinux: log invalid contexts in AVCs") Cc: stable@vger.kernel.org # v5.1+ Signed-off-by: Ondrej Mosnacek Acked-by: Richard Guy Briggs Signed-off-by: Paul Moore Signed-off-by: Greg Kroah-Hartman --- security/selinux/avc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/security/selinux/avc.c +++ b/security/selinux/avc.c @@ -739,14 +739,20 @@ static void avc_audit_post_callback(stru rc = security_sid_to_context_inval(sad->state, sad->ssid, &scontext, &scontext_len); if (!rc && scontext) { - audit_log_format(ab, " srawcon=%s", scontext); + if (scontext_len && scontext[scontext_len - 1] == '\0') + scontext_len--; + audit_log_format(ab, " srawcon="); + audit_log_n_untrustedstring(ab, scontext, scontext_len); kfree(scontext); } rc = security_sid_to_context_inval(sad->state, sad->tsid, &scontext, &scontext_len); if (!rc && scontext) { - audit_log_format(ab, " trawcon=%s", scontext); + if (scontext_len && scontext[scontext_len - 1] == '\0') + scontext_len--; + audit_log_format(ab, " trawcon="); + audit_log_n_untrustedstring(ab, scontext, scontext_len); kfree(scontext); } }