From patchwork Fri Nov 13 14:14:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladis Dronov X-Patchwork-Id: 7612091 X-Patchwork-Delegate: paul@paul-moore.com Return-Path: X-Original-To: patchwork-selinux@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 48A64BF90C for ; Fri, 13 Nov 2015 14:24:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A9144205F5 for ; Fri, 13 Nov 2015 14:24:38 +0000 (UTC) Received: from emvm-gh1-uea08.nsa.gov (emvm-gh1-uea08.nsa.gov [63.239.67.9]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C0E29205F1 for ; Fri, 13 Nov 2015 14:24:37 +0000 (UTC) X-TM-IMSS-Message-ID: <1d1a78c000033aaa@nsa.gov> Received: from tarius.tycho.ncsc.mil ([144.51.242.1]) by nsa.gov ([63.239.67.9]) with ESMTP (TREND IMSS SMTP Service 7.1) id 1d1a78c000033aaa ; Fri, 13 Nov 2015 09:23:09 -0500 Received: from prometheus.infosec.tycho.ncsc.mil (prometheus [192.168.25.40]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id tADELe2x003359; Fri, 13 Nov 2015 09:21:54 -0500 Received: from tarius.tycho.ncsc.mil (tarius.infosec.tycho.ncsc.mil [144.51.242.1]) by prometheus.infosec.tycho.ncsc.mil (8.15.2/8.15.2) with ESMTP id tADEFQ3W251895 for ; Fri, 13 Nov 2015 09:15:26 -0500 Received: from goalie.tycho.ncsc.mil (goalie [144.51.242.250]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id tADEFQqu002745; Fri, 13 Nov 2015 09:15:26 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1BPCAAR70VW/xy3hNFeGQEBAg8BAQEBgwsBgUGvHwFKjEOEDRKFfoE9TAEBAQEBAYVtUoEOMAESiC7BLIZUiTIBhQQFjRuJLY0njyyNGWOBSkcdFoFBcYNzAR+BKgEBAQ X-IPAS-Result: A1BPCAAR70VW/xy3hNFeGQEBAg8BAQEBgwsBgUGvHwFKjEOEDRKFfoE9TAEBAQEBAYVtUoEOMAESiC7BLIZUiTIBhQQFjRuJLY0njyyNGWOBSkcdFoFBcYNzAR+BKgEBAQ X-IronPort-AV: E=Sophos;i="5.20,287,1444708800"; d="scan'208";a="4930384" Received: from emvm-gh1-uea08.nsa.gov ([63.239.67.9]) by goalie.tycho.ncsc.mil with ESMTP; 13 Nov 2015 09:15:07 -0500 X-TM-IMSS-Message-ID: <1d13397f0003384c@nsa.gov> Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by nsa.gov ([63.239.67.9]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 ADH-AES256-SHA (256/256)) id 1d13397f0003384c ; Fri, 13 Nov 2015 09:15:14 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 8F895C0AAB3D; Fri, 13 Nov 2015 14:15:05 +0000 (UTC) Received: from rules.brq.redhat.com (ovpn-204-127.brq.redhat.com [10.40.204.127]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tADEF0VC022140; Fri, 13 Nov 2015 09:15:01 -0500 From: Vladis Dronov To: Paul Moore , Stephen Smalley , Eric Paris , James Morris , "Serge E. Hallyn" , linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov Subject: [PATCH v3] selinux: rate-limit unrecognized netlink message warnings in selinux_nlmsg_perm() Date: Fri, 13 Nov 2015 15:14:19 +0100 Message-Id: <1447424059-11174-1-git-send-email-vdronov@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-TM-AS-MML: disable X-Mailman-Approved-At: Fri, 13 Nov 2015 09:21:40 -0500 X-BeenThere: selinux@tycho.nsa.gov X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: Cc: Vladis Dronov MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Any process is able to send netlink messages with invalid types. Make the warning rate-limited to prevent too much log spam. The warning is supposed to help to find misbehaving programs, so print the triggering command name and pid. Reported-by: Florian Weimer Signed-off-by: Vladis Dronov --- security/selinux/hooks.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index d0cfaa9..791fc46 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -4785,11 +4785,12 @@ static int selinux_nlmsg_perm(struct sock *sk, struct sk_buff *skb) err = selinux_nlmsg_lookup(sksec->sclass, nlh->nlmsg_type, &perm); if (err) { if (err == -EINVAL) { - printk(KERN_WARNING - "SELinux: unrecognized netlink message:" - " protocol=%hu nlmsg_type=%hu sclass=%s\n", + pr_warn_ratelimited("SELinux: unrecognized netlink" + " message: protocol=%hu nlmsg_type=%hu sclass=%s" + " pig=%d comm=%s\n", sk->sk_protocol, nlh->nlmsg_type, - secclass_map[sksec->sclass - 1].name); + secclass_map[sksec->sclass - 1].name, + task_pid_nr(current), current->comm); if (!selinux_enforcing || security_get_allow_unknown()) err = 0; }