From nobody Tue May 14 12:53:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620636766; cv=none; d=zohomail.com; s=zohoarc; b=cBx9lmXwFiXeB6T3JckkOSa9mr8HqRTQY7CUk50ppo/txOuhNEv0FukzxBXEeDux5Hcj1n+iU0vhxx5NWxK1m4I5ZYLn/fTHWCfC9RxbE9fi28hGQ5q0v+Gaunu8b8RMy0JjW8TRRn6b7fR/OY7URHMfKdH6p5vGPTpRYMoEmOs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620636766; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=sigLR+NSgxUA7P9HXwitX0wXUaonxdCkMNheqPNfbY4=; b=UhQdE5AkpR8b7QX6LzDXEk9jilA8bRZk2Rbjmdiztt2pHVmSFRs41QqUGn3QWWL3OY7dnsnpEGSRVQ4GgIR5JkAVL4UFxoUzFUsKvEu182h9FiOil6B8QWOa9BaO+/DI9vvrIj1Xmo3uviKMl88NPdeC79jhUBkXdY+jXW6Vp6Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1620636766286806.5725981301458; Mon, 10 May 2021 01:52:46 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-102-bH-wInCoNNue-xc3EE_9YA-1; Mon, 10 May 2021 04:52:38 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CCFEF18D6A29; Mon, 10 May 2021 08:52:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B84905D9CA; Mon, 10 May 2021 08:52:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 50DF0180B463; Mon, 10 May 2021 08:52:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14A8qRGd018189 for ; Mon, 10 May 2021 04:52:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2C9BE1F5; Mon, 10 May 2021 08:52:27 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.214]) by smtp.corp.redhat.com (Postfix) with ESMTP id A400319C44 for ; Mon, 10 May 2021 08:52:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620636765; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=sigLR+NSgxUA7P9HXwitX0wXUaonxdCkMNheqPNfbY4=; b=KR3kj+K42dmB+UJdH0C0YkLJWfmODKe0fl5BTR37wGB6LFcMpI5rcC0FJbmX336Subh2a7 bvaRyDqiajuJSsluNYkd7t51wiyKuqnJ1NZKcNwgm/wooHb6fEitbnURfvoADZURx++e1h +YcMeIUw9TCOfLG+AE05YANYSpFWygI= X-MC-Unique: bH-wInCoNNue-xc3EE_9YA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] securityselinuxhelper: Fix retval of setcon_raw() and security_disable() Date: Mon, 10 May 2021 10:52:16 +0200 Message-Id: <19d023e8eb3b15f26d1125a21bcc1eee56be031d.1620636736.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The securityselinuxhelper is a mock that's replacing libselinux APIs with our own implementation to achieve deterministic results. Our implementation uses env vars (among other things) to hold internal state. For instance, "FAKE_SELINUX_CONTEXT" and "FAKE_SELINUX_DISABLED" variables are used. However, as we were switching from setenv() to g_setenv() we also changed the set of possible retvals from setcon_raw() and security_disable(). Previously, the retval of setenv() was used directly which returns 0 on success and -1 on error. But g_setenv() has different retval semantics: it returns 1 on success and 0 on error. This discrepancy can be observed by running viridentitytest where case #2 reports an error ("!") - because setcon_raw() returns 1. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tests/securityselinuxhelper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/securityselinuxhelper.c b/tests/securityselinuxhelper.c index b308ef5095..c3d6505ef2 100644 --- a/tests/securityselinuxhelper.c +++ b/tests/securityselinuxhelper.c @@ -140,7 +140,7 @@ int setcon_raw(const char *context) errno =3D EINVAL; return -1; } - return g_setenv("FAKE_SELINUX_CONTEXT", context, TRUE); + return g_setenv("FAKE_SELINUX_CONTEXT", context, TRUE) =3D=3D TRUE ? 0= : -1; } =20 int setcon(const char *context) @@ -219,7 +219,7 @@ int security_disable(void) return -1; } =20 - return g_setenv("FAKE_SELINUX_DISABLED", "1", TRUE); + return g_setenv("FAKE_SELINUX_DISABLED", "1", TRUE) =3D=3D TRUE ? 0 : = -1; } =20 int security_getenforce(void) --=20 2.26.3