From nobody Fri May 10 19:16:33 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=1694427562; cv=none; d=zohomail.com; s=zohoarc; b=ZZUVn6vA8/wyp9lQ7HLIsEJ9AGLfMAg6jeZV2sxupqcpfKioWAyvBDDZ4XdJSthQ6OdeX3VcSQuSh63kZItWxe9/n7ZJsv+2sZ7ih8wDjkyaY0YBZAYs2X2sD6L8U+UgOwMki5HcFHrkp8P4B9wZnk9F1CNPhc+zUeStrVV99Cg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694427562; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1DKWzmbV6opst0O20pIlyogJVfTC0mc4gFeuDD2w9yo=; b=VxI8eZFfwH7Sa7S7G2cORiEnrZZZDWNz1572ylGXK5Ww0FWxnAOpeOMTMHdlKhw1ELKVCpQHFwNmCorfhKeQeLcQQ/Lf/zTFnyL65Wjmi8Qom/vnZAkNpZMRL92jNlU8gURVumdjTyG97rNWkdfAq2gi8PjbLGUI21OmHCNyJJw= 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) 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 1694427562748593.7454899007098; Mon, 11 Sep 2023 03:19:22 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx-ext.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-326-toJsOXh3OHWnvF_knWTt-A-1; Mon, 11 Sep 2023 06:19:12 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AEA4129DD986; Mon, 11 Sep 2023 10:19:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9538A40C2064; Mon, 11 Sep 2023 10:19:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id EC48919465BA; Mon, 11 Sep 2023 10:18:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E56CD1946587 for ; Mon, 11 Sep 2023 10:18:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id CF99110F1BE8; Mon, 11 Sep 2023 10:18:37 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.2.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71EBF10F1BE7 for ; Mon, 11 Sep 2023 10:18:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694427561; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=1DKWzmbV6opst0O20pIlyogJVfTC0mc4gFeuDD2w9yo=; b=B7CceoFq1DMXxyvJYWATxRVbWVgj0yp4HhDO0f5GSbIigLWEazYGq2WfgILSJw5UqUoHUf ZrI+50lw1KJV33XRlLztZihyJQiuHA4bDsAlDnxI2r+UP3r1go60OlGau2k2sECPr0gWK0 B0tVx73bxT5D0AXv/TK9S5AQPi+nhwo= X-MC-Unique: toJsOXh3OHWnvF_knWTt-A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/2] lxc_container: Check retval of capng_get_caps_process() Date: Mon, 11 Sep 2023 12:18:29 +0200 Message-ID: <660227b3ccbabffee07b1625bfa553a7c8cd2ea8.1694427342.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1694427564151100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Added in v0.6.5~14 the call to capng_get_caps_process() inside of lxcContainerDropCapabilities() is not really explained in the commit message. But looking into the libcap-ng sources it's to initialize the internal state of the library. But with recent libcap-ng commit [1] (which some bleeding edge distros - like Fedora rawhide - already picked up) the function has been marked as 'warn unused result'. Well, check for its retval then. 1: https://github.com/stevegrubb/libcap-ng/commit/a0743c335c9a16a2fda9b2512= 0a5523742119e47 Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko Reviewed-by: Martin Kletzander --- src/lxc/lxc_container.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 21220661f7..4c37fcd012 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -1725,7 +1725,13 @@ static int lxcContainerDropCapabilities(virDomainDef= *def, CAP_SYSLOG, CAP_WAKE_ALARM}; =20 - capng_get_caps_process(); + /* Init the internal state of capng */ + if ((ret =3D capng_get_caps_process()) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to get current process capabilities %1$d"= ), + ret); + return -1; + } =20 /* Make sure we drop everything if required by the user */ if (policy =3D=3D VIR_DOMAIN_CAPABILITIES_POLICY_DENY) --=20 2.41.0 From nobody Fri May 10 19:16:33 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=1694427551; cv=none; d=zohomail.com; s=zohoarc; b=XJcklgQUeS0ueuR/CWXC8awhLCAUKlN4GOtDEdur+ev55r47IMI/Dan1+se+CsKFB9oRoFmYypUjmfjEdrxu9di1QSzcrXwsAV1gKTK1ONbDGABCIXzW33Iryq85gTSIyEd1CqFyRuvrpIDxxQBV1RfYXOb2xXrvCS6HTit76Co= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694427551; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2IQrKiq1KMQI8IO8pdnRcr0dNGATqXZZ6RL2lb30D4A=; b=VWMZRE5OoeCWeuNi/rh1V7m69QDGc8hb4wQ3UFCc/OQwPfgX0/oPoujNZgIOgQLsvnanaPdImPBEccZ+ewaT2+yk8YLd9AH22UUqAg40gBHp1+eMtaI/KXkSXDq8WePhxL05avjLhQA7Ws/sHzbTvjFguQzjb085/73gVoWa62w= 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) 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 1694427551172432.70571202681197; Mon, 11 Sep 2023 03:19:11 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-422-jp6PkoJOMaWz2j2-0Olt8w-1; Mon, 11 Sep 2023 06:19:07 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 34AC3816546; Mon, 11 Sep 2023 10:19:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C3322156701; Mon, 11 Sep 2023 10:19:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 095B019465A0; Mon, 11 Sep 2023 10:18:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7D0CC1946587 for ; Mon, 11 Sep 2023 10:18:38 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 6C4F510005D2; Mon, 11 Sep 2023 10:18:38 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.2.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 120191006B5C for ; Mon, 11 Sep 2023 10:18:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694427550; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=2IQrKiq1KMQI8IO8pdnRcr0dNGATqXZZ6RL2lb30D4A=; b=JwEYKL9/d8c7Ln/TF6clyvMKK6LQPJqCL7Td9lKmYxCGvylS8C6a6IuUdPs7VEu//Nbu0P O+97f7i8Z1R311h99EEYQPBOKFhhZy2W8T9onGVzgKIPr7xp/gqyTv589SYkb5HCsyyLz9 c1cxpf7rYX+gVVUG0TaH1NWsrG9s4ys= X-MC-Unique: jp6PkoJOMaWz2j2-0Olt8w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/2] virutil: Check retval of capng_apply() Date: Mon, 11 Sep 2023 12:18:30 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1694427552702100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Inside of virSetUIDGIDWithCaps() there's a naked call to capng_apply(), i.e. without any retval check. This is potentially dangerous as capng_apply() may fail. Do the check and report an error. This also fixes the build on bleeding edge distros - like Fedora rawhide - where the function is declared with 'warn unused result' [1]. 1: https://github.com/stevegrubb/libcap-ng/commit/a0743c335c9a16a2fda9b2512= 0a5523742119e47 Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko Reviewed-by: Martin Kletzander --- src/util/virutil.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/util/virutil.c b/src/util/virutil.c index b5b65fb415..edc39b981f 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1200,8 +1200,12 @@ virSetUIDGIDWithCaps(uid_t uid, gid_t gid, gid_t *gr= oups, int ngroups, * do this if we failed to get the capability above, so ignore the * return value. */ - if (!need_setpcap) - capng_apply(CAPNG_SELECT_BOUNDS); + if (!need_setpcap && + (capng_ret =3D capng_apply(CAPNG_SELECT_BOUNDS)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot apply process capabilities %1$d"), capng_= ret); + return -1; + } =20 /* Drop the caps that allow setuid/gid (unless they were requested) */ if (need_setgid) --=20 2.41.0