Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6090AC433EF for ; Mon, 9 Sep 2019 09:26:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3F182206CD for ; Mon, 9 Sep 2019 09:26:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728115AbfIIJ0F (ORCPT ); Mon, 9 Sep 2019 05:26:05 -0400 Received: from ithil.bigon.be ([163.172.57.153]:55768 "EHLO ithil.bigon.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727664AbfIIJ0E (ORCPT ); Mon, 9 Sep 2019 05:26:04 -0400 X-Greylist: delayed 430 seconds by postgrey-1.27 at vger.kernel.org; Mon, 09 Sep 2019 05:26:04 EDT Received: from localhost (localhost [IPv6:::1]) by ithil.bigon.be (Postfix) with ESMTP id CAA3D20059; Mon, 9 Sep 2019 11:18:52 +0200 (CEST) Received: from ithil.bigon.be ([IPv6:::1]) by localhost (ithil.bigon.be [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id OsM7qKN10Gut; Mon, 9 Sep 2019 11:18:52 +0200 (CEST) Received: from [10.40.0.155] (unknown [193.53.238.198]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bigon@bigon.be) by ithil.bigon.be (Postfix) with ESMTPSA; Mon, 9 Sep 2019 11:18:52 +0200 (CEST) Subject: Re: Permissions in the udevadm_t domain To: Nicolas Iooss , selinux-refpolicy@vger.kernel.org References: <6d208e36-cf81-7fde-2b57-fddf4a529f52@debian.org> From: Laurent Bigonville Message-ID: <9906138d-4c2e-b300-755f-b65629841836@debian.org> Date: Mon, 9 Sep 2019 11:18:51 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: selinux-refpolicy-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux-refpolicy@vger.kernel.org On 7/09/19 15:14, Nicolas Iooss wrote: > [Adding selinux-refpolicy@vger.kernel.org, which is better suited for > questions related to refpolicy] > > On Sat, Sep 7, 2019 at 12:19 PM Laurent Bigonville wrote: > [...] >> But when >> looking at the current policy code I'm seeing that udevadm is allowed to >> delete files/directory/.. in /var/run and I'm wondering why. I've never >> seen this happening during my (limited) test, an idea? > Which policy? On my test system based on a lightly-patched refpolicy, I have: > > # sesearch -A -s udevadm_t -t var_run_t > allow udevadm_t var_run_t:dir { getattr open search }; > allow udevadm_t var_run_t:lnk_file { getattr read }; It's the refpolicy, but I meant udev_var_run_t (/var/run/udev) rather than var_run_t # sesearch -A -s udevadm_t -t udev_var_run_t allow udevadm_t udev_var_run_t:dir { getattr ioctl lock open read remove_name rmdir search write }; allow udevadm_t udev_var_run_t:file { getattr unlink }; allow udevadm_t udev_var_run_t:lnk_file { getattr unlink }; allow udevadm_t udev_var_run_t:sock_file { append getattr open write }; > >> For the later, it seems that the kernel the mode to 400 on some files in >> /sys (ie. --w------- 1 root root 4096 sep 5 17:06 >> /sys/module/snd_hda_codec_generic/uevent) looking at the code it seems >> that udev is ready to handle EACCES already, so I was wondering, should >> we just allow dac_read_search or don't audit dac_read_search (and >> dac_override as well then)? > For the record, even with dac_read_search, opening this file fails > with EACCES, because the kernel did not implement show() on this sysfs > file (cf. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/module.c?h=v5.2#n1204 > and kernfs_fop_open() in fs/kernfs/file.c). More precisely, openat() > returns EACCES because kernfs_fop_open() returns this error code when > trying to open a write-only file for reading. Unfortunately this check > happens after the capability checks, which is why you got the denials > for dac_override and dac_read_search. > > I do not have an opinion about allowing dac_read_search vs. > dontaudit-ing dac_read_search and dac_override. Grift was saying that "the cap_dac_read_search could maybe be dontaudited, but then cap_dac_override would have to be dontaudited as well. cap_dac_read_search would also be triggered when you run `sudo udevadm ...` where pwd or/and oldpwd is ~" So I guess I will just allow it