From patchwork Thu Apr 28 06:53:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 12830052 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED7BEC43217 for ; Thu, 28 Apr 2022 06:54:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244597AbiD1G5R (ORCPT ); Thu, 28 Apr 2022 02:57:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244625AbiD1G5R (ORCPT ); Thu, 28 Apr 2022 02:57:17 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0A59C98F5C for ; Wed, 27 Apr 2022 23:54:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651128840; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=zwX4PiGzcipWSNJvCybHe1EDP9yF7u/VOFfGLmOeC8g=; b=WnUEwP6PjpmvyROI73EPlYKleWU1squ/gYPH5/t1Yj/Rl5M9mAU0SJyRkiuoexYo/0XFJ/ 37nOlEPO/zuYGk0+JvYXAzkr1n5wVvcwYRuiAj/At5Sz5RwepN2k7HGE+xMo300ivFFFB5 BC4wZf6UEPSq2VhFR/tJWLyEDz4z7YU= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-3-dQzDunfMOnKVZDBTmt6bew-1; Thu, 28 Apr 2022 02:53:59 -0400 X-MC-Unique: dQzDunfMOnKVZDBTmt6bew-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CC4BD3C0E182 for ; Thu, 28 Apr 2022 06:53:58 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (unknown [10.39.192.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id DFECC416384; Thu, 28 Apr 2022 06:53:57 +0000 (UTC) From: Laszlo Ersek To: SELinux List , Laszlo Ersek Cc: "Richard W.M. Jones" , Petr Lautrbach Subject: [PATCH for-3.5 0/5] selinux_restorecon(3), setfiles(8): skip relabeling errors Date: Thu, 28 Apr 2022 08:53:49 +0200 Message-Id: <20220428065354.27605-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1794518 The first three patches in the series are cleanups. The fourth patch introduces a new feature (and API) to libselinux, and the fifth patch exposes the feature through a new setfiles(8) command line option. In libguestfs, we invoke setfiles(8) on masses of directory trees (in a large amount of virtual machines). We don't care if relabeling fails on a few individual files, but we still want to catch fatal errors. Currently these error conditions are impossible to tell apart, because selinux_restorecon[_parallel()], even though it is capable of continuing through relabeling errors, ultimately reports even the case of *only* relabeling errors, with return value (-1). Setfiles(8) then has no choice but to exit with status 255 in this case as well. The fourth patch introduces a new selinux_restorecon[_parallel()] flag, namely SELINUX_RESTORECON_COUNT_ERRORS, which counts, but otherwise ignores, relabeling errors encountered during the file tree walk. In case the function succeeds, the skipped error count can be fetched with a new API, selinux_restorecon_get_skipped_errors(). This relies on static library data, which is inspired by existent APIs such as selinux_restorecon_set_sehandle(3) and selinux_restorecon_set_exclude_list(3) -- those do the same (albeit before calling selinux_restorecon[_parallel()], not after). The fifth patch wires the new flag to the new setfiles(8) option "-C". Please CC me on all replies to the series; I'm not subscribed to the SELinux mailing list. ("CONTRIBUTING.md" does not say that subscribing is a requirement.) Cc: "Richard W.M. Jones" Cc: Petr Lautrbach Thanks, Laszlo Laszlo Ersek (5): setfiles: fix up inconsistent indentation setfiles: remove useless assignment and comment (after RHBZ#1926386) setfiles: remove useless "iamrestorecon" checks in option parsing selinux_restorecon: introduce SELINUX_RESTORECON_COUNT_ERRORS setfiles: introduce the -C option for distinguishing file tree walk errors libselinux/include/selinux/restorecon.h | 15 ++++++++ libselinux/man/man3/selinux_restorecon.3 | 22 +++++++++++- libselinux/man/man3/selinux_restorecon_get_skipped_errors.3 | 28 +++++++++++++++ libselinux/src/libselinux.map | 5 +++ libselinux/src/selinux_restorecon.c | 34 +++++++++++++++--- policycoreutils/setfiles/restore.c | 8 +++-- policycoreutils/setfiles/restore.h | 4 ++- policycoreutils/setfiles/setfiles.8 | 22 ++++++++++++ policycoreutils/setfiles/setfiles.c | 36 +++++++++----------- 9 files changed, 145 insertions(+), 29 deletions(-) create mode 100644 libselinux/man/man3/selinux_restorecon_get_skipped_errors.3 base-commit: 2a167d1156578fc29541f6fb60af65452f431aae