From nobody Tue May 14 18:48:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1609784465; cv=none; d=zohomail.com; s=zohoarc; b=IDLMtPZjHrZX4412C30aEBW/J3z3Pvj2PIdxEUhxD8q5Sq2G1cJodMjMHOcwccN7bB/tTU86JQvwFrl/2iUVVkC0dndcTC3cF/NlRe7U0/9Ef0SWTbgAV3F9YQgN/2ei805UKLC9nj6fMbfG2rMJbSmUT+cJGQEm/zQThbR+iGU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609784465; 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=A3iKMAfeHwYOkn0c4RLgR3sCx4WsR4UvOpBvvCvtgTE=; b=PGmAvj/Uv9+XSi4TxHF2qlGGchuxV140QjLC/PprHxKx05OVnge51FgZSJqnDDAf9Os6dxKY6TxMGyptuI/sFer0TmZfBGoKbbFWy1xKJnBGS4K794JxHeVRMZ6lHKcYuI2U22lvDOTjvDutsyCCHlY35CYQudGNu7usuET1Od4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 160978446564532.409130893422; Mon, 4 Jan 2021 10:21:05 -0800 (PST) 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-311-P_I2EPcxOx2NmvEbMMVpfQ-1; Mon, 04 Jan 2021 13:21:02 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 66941180A087; Mon, 4 Jan 2021 18:20:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 30E2F27C20; Mon, 4 Jan 2021 18:20:55 +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 E2A515002C; Mon, 4 Jan 2021 18:20:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104IKrEI018184 for ; Mon, 4 Jan 2021 13:20:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id BA6125D751; Mon, 4 Jan 2021 18:20:53 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3ACA45D756 for ; Mon, 4 Jan 2021 18:20:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609784464; 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=A3iKMAfeHwYOkn0c4RLgR3sCx4WsR4UvOpBvvCvtgTE=; b=duSA5jKteGbw3Em8Ckpjgakqgr0/vEqanI3OE9gcnw/Jb4fA3t1UGu8VrYeaGnYt+9K6h3 YRBq7gWKEbAx3/PS4mErnXgjfeqny/TQZCZxyzz0jciVI1IlcdLtKmQBt7mb5Ux5fxRP9M s7RUXBlt1IJtEnkyEOftqJNDRoZNYcw= X-MC-Unique: P_I2EPcxOx2NmvEbMMVpfQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/5] qemu: Use virStrcpy in qemuNodeGetSecurityModel() Date: Mon, 4 Jan 2021 19:20:41 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.84 on 10.5.11.23 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 code we have there to copy seclabel model or doi can be replaced by virStrcpy() calls which do exactly the same checks. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a376824854..a9e8f660c7 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5930,7 +5930,6 @@ static int qemuNodeGetSecurityModel(virConnectPtr con= n, virSecurityModelPtr secmodel) { virQEMUDriverPtr driver =3D conn->privateData; - char *p; g_autoptr(virCaps) caps =3D NULL; =20 memset(secmodel, 0, sizeof(*secmodel)); @@ -5946,23 +5945,21 @@ static int qemuNodeGetSecurityModel(virConnectPtr c= onn, caps->host.secModels[0].model =3D=3D NULL) return 0; =20 - p =3D caps->host.secModels[0].model; - if (strlen(p) >=3D VIR_SECURITY_MODEL_BUFLEN-1) { + if (virStrcpy(secmodel->model, caps->host.secModels[0].model, + VIR_SECURITY_MODEL_BUFLEN) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("security model string exceeds max %d bytes"), - VIR_SECURITY_MODEL_BUFLEN-1); + VIR_SECURITY_MODEL_BUFLEN - 1); return -1; } - strcpy(secmodel->model, p); =20 - p =3D caps->host.secModels[0].doi; - if (strlen(p) >=3D VIR_SECURITY_DOI_BUFLEN-1) { + if (virStrcpy(secmodel->doi, caps->host.secModels[0].doi, + VIR_SECURITY_DOI_BUFLEN) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("security DOI string exceeds max %d bytes"), - VIR_SECURITY_DOI_BUFLEN-1); + VIR_SECURITY_DOI_BUFLEN - 1); return -1; } - strcpy(secmodel->doi, p); =20 return 0; } --=20 2.26.2 From nobody Tue May 14 18:48:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1609784465; cv=none; d=zohomail.com; s=zohoarc; b=WdesVQWbE7WzqoPksVZ/arfIfUDlzx7Fo7dwUE8mEZ4ILKVmG/d/fewW6jN3WGhvL8hNt8eL1JlBtpH1AGix46dS1gRL3mo9MIry7iXEbGdAJ9YLAotzgCLUULkd2CsMckqXPoqrvq1SOqHS2LDi+LWs0e/JXfWdfJQ+bR+6kik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609784465; 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=kk97hQQCjumQs/GUt0F1VWEtZwdfnBz3HekWuixiOi0=; b=Pa1mcnF2f+445VkRRauzBXwq6/UAObXQ2TsdZYnwj4LRSUHvTiSwfA8CD4iT5Xv13bLg69Y8OY4q1849kZpOZlt5oiCtav2D7f283guRtqIuLr41gl4fAL3BckiLbEZq+yYJU0py/rNh/0b/Rilv0O9rO+y0OUHg6dcEwoEx+vA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1609784465230915.8740403438615; Mon, 4 Jan 2021 10:21:05 -0800 (PST) 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-3-y5UvvHAVPeylMMQ4A2Whkg-1; Mon, 04 Jan 2021 13:21:01 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BBF5210054FF; Mon, 4 Jan 2021 18:20:55 +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 9B59B60BFA; Mon, 4 Jan 2021 18:20:55 +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 64EC4180954D; Mon, 4 Jan 2021 18:20:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104IKsMK018189 for ; Mon, 4 Jan 2021 13:20:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id 97BE05D768; Mon, 4 Jan 2021 18:20:54 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17AB75D764 for ; Mon, 4 Jan 2021 18:20:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609784464; 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=kk97hQQCjumQs/GUt0F1VWEtZwdfnBz3HekWuixiOi0=; b=ZsWAEFDGHaksjJegbUM/wQlWuiwCTMWi/BnpV8lm/rZo0b8JLpOsn2wfCQlw/zi31tYndx v6c4qoW4oSazfWKeOuqwCn18tYfeYaiHfmQzDjy7xRc8UP/FA10ObqaCmxkB+qNGBgfn0W W/aYthRrd0cShUN247oT44TKWqWPBig= X-MC-Unique: y5UvvHAVPeylMMQ4A2Whkg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/5] qemu: Obtain @caps only after ACL check in qemuNodeGetSecurityModel Date: Mon, 4 Jan 2021 19:20:42 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.12 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" Even though we are getting driver capabilities with refresh=3Dfalse (so that it is not expensive), we still should do ACL check first because there is no point in bothering with the capabilities if caller doesn't have permissions to call the API. Also, this way the comment makes more sense. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a9e8f660c7..96ec84bd1c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5934,14 +5934,12 @@ static int qemuNodeGetSecurityModel(virConnectPtr c= onn, =20 memset(secmodel, 0, sizeof(*secmodel)); =20 - if (!(caps =3D virQEMUDriverGetCapabilities(driver, false))) - return 0; - if (virNodeGetSecurityModelEnsureACL(conn) < 0) return 0; =20 /* We treat no driver as success, but simply return no data in *secmod= el */ - if (caps->host.nsecModels =3D=3D 0 || + if (!(caps =3D virQEMUDriverGetCapabilities(driver, false)) || + caps->host.nsecModels =3D=3D 0 || caps->host.secModels[0].model =3D=3D NULL) return 0; =20 --=20 2.26.2 From nobody Tue May 14 18:48:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1609784470; cv=none; d=zohomail.com; s=zohoarc; b=BdCmx3rGAwjwJob0jLJ6hYb+J6YTJ2ImcBQvW2eleiPwPJ1WnoURVAM0e6OOtPjh+Mz2fl7nAZKDP7iswbErkqpE7/bIf7Se+pf8Yuv6Oxk/4BifFe5fguPwPHGIkqEvv2qWBCta8u2rOXVnhuk6v7bw9wDXsbR5tzdCge+5bYU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609784470; 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=ZmTHixoZIs9maHgvMeIOv6fYwxOV20KpeohVFw+EXLQ=; b=XEar2Yfpxxm19CgBip+fiWt+2iPrGWGANssfe0SClCsPA9VlNFFN7o1VM0T8963LQKJnKJ4ViMwMnWnBw5PG7DSKkb5YpHbbeyykCmzRNk0rnPCxT55JDRjHTYf4lHHp6aZrYkeyRPCPKmr4xtDAJhdkenTUnG2u75KpPbp7T5g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1609784470059490.75958957111266; Mon, 4 Jan 2021 10:21:10 -0800 (PST) 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-544-j_kNbEvnNoKxUgUla7E6CQ-1; Mon, 04 Jan 2021 13:21:06 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2A5F815722; Mon, 4 Jan 2021 18:21:01 +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 0685D10016FB; Mon, 4 Jan 2021 18:21:01 +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 C5F921809CA1; Mon, 4 Jan 2021 18:21:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104IKtxc018200 for ; Mon, 4 Jan 2021 13:20:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id 73C6561F49; Mon, 4 Jan 2021 18:20:55 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id E908D61F47 for ; Mon, 4 Jan 2021 18:20:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609784468; 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=ZmTHixoZIs9maHgvMeIOv6fYwxOV20KpeohVFw+EXLQ=; b=VOR+dW7XjBdQV+/l2564zkEYaOp6TDn6uWtmMeXpJyD7FpB32AtfoTo5oRtgoyPcQ/uMgu 3BHmyviRkUK+nAEtYVt9psbDMa3sGQ0V3SjXEMK+SzS3kDsI+jaHfLhWbajc3YD2PPU97F /KIudwqtdSKtY+juo5NurqMam++PWGI= X-MC-Unique: j_kNbEvnNoKxUgUla7E6CQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/5] qemu: Fix retval if ACL check fails in qemuNodeGetSecurityModel Date: Mon, 4 Jan 2021 19:20:43 +0100 Message-Id: <8d98a684f55589784a7cf084a723d767d677f597.1609784319.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.84 on 10.5.11.22 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" While previously we returned 0 this is not correct. We have to return a negative value to indicate error. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 96ec84bd1c..88324945ef 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5935,7 +5935,7 @@ static int qemuNodeGetSecurityModel(virConnectPtr con= n, memset(secmodel, 0, sizeof(*secmodel)); =20 if (virNodeGetSecurityModelEnsureACL(conn) < 0) - return 0; + return -1; =20 /* We treat no driver as success, but simply return no data in *secmod= el */ if (!(caps =3D virQEMUDriverGetCapabilities(driver, false)) || --=20 2.26.2 From nobody Tue May 14 18:48:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1609784473; cv=none; d=zohomail.com; s=zohoarc; b=eEKajiGv9JUThCU/zpfyDCFEnSVNMYVsx9tY4TxNfWEASxv+6fD30D0KGc7ANLG9smaOX4cVL5ddccp/i5mJa8e4rF/mBHSxB/O10P1P/fnw2EyMGg9WPMkjLi5Hxp9dCCKk15uJcVoAb+Y6eqDgS2rgWX3jxvpUACqAyt/mu8Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609784473; 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=DNdWLs8uOZpE2MmNVCtK7zEqjBXeOR6CH3UTZZqRVB4=; b=GY6S9z7AZ3o/hwXKPwwbZbmHsSKcJ8n15GhUwE3IYYfIUuWkoPoLuAErRn3G5YyASXWloBvAGJW+P7HWm3u9mgMaHDvWH3Ze3rdineyO9IL0cnybeCfutMQBDpMd48Q5wDbNrI337h+ZYVOrlZZlCEIpPPa/HHgtTAzujr/oCnQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1609784473085325.42515910492943; Mon, 4 Jan 2021 10:21:13 -0800 (PST) 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-262-QVCvQVkCMa23LABQ94Pf_A-1; Mon, 04 Jan 2021 13:21:09 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DEFF78030A3; Mon, 4 Jan 2021 18:21:03 +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 BB10F5D765; Mon, 4 Jan 2021 18:21:03 +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 8430E1809CA3; Mon, 4 Jan 2021 18:21:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104IKvFq018216 for ; Mon, 4 Jan 2021 13:20:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id B1CE55D756; Mon, 4 Jan 2021 18:20:57 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id 307A862462 for ; Mon, 4 Jan 2021 18:20:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609784472; 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=DNdWLs8uOZpE2MmNVCtK7zEqjBXeOR6CH3UTZZqRVB4=; b=Ut1glA9crUPMhgY6TL0nku7mM/uRfeX4K68dbG+C8IAI6JX3d51pajfjmeSa42D6MbPO03 Eldf5Mo17tDp7OJJiXWpqf8gs9ztgeko0EcwZ7xSrSppq+p/itITmQYJA09He3uqappUKs WHe91ES+50tcmV4XyHGWdhb05fLpB9c= X-MC-Unique: QVCvQVkCMa23LABQ94Pf_A-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/5] domain_conf: Parse full length of some attributes Date: Mon, 4 Jan 2021 19:20:44 +0100 Message-Id: <31962a27d6d63172671f8955db9c808b135933dc.1609784319.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.15 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" In virSecurityLabelDefParseXML() we are parsing the element among with its attributes. Some of the attributes are limited in length (because of virNodeGetSecurityModel()), however some are not. And for the latter ones we don't need to use virXMLPropStringLimit() to parse them. Moreover, using VIR_SECURITY_LABEL_BUFLEN as the limit is wrong - we are not storing the parsed strings into a static buffer of that size rather than checking if the string passes string -> enum conversion. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 384710da40..5a8947eeec 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7713,8 +7713,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, /* set default value */ seclabel->type =3D VIR_DOMAIN_SECLABEL_DYNAMIC; =20 - p =3D virXMLPropStringLimit(ctxt->node, "type", - VIR_SECURITY_LABEL_BUFLEN - 1); + p =3D virXMLPropString(ctxt->node, "type"); if (p) { seclabel->type =3D virDomainSeclabelTypeFromString(p); if (seclabel->type <=3D 0) { @@ -7729,8 +7728,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, seclabel->relabel =3D false; =20 VIR_FREE(p); - p =3D virXMLPropStringLimit(ctxt->node, "relabel", - VIR_SECURITY_LABEL_BUFLEN-1); + p =3D virXMLPropString(ctxt->node, "relabel"); if (p) { if (virStringParseYesNo(p, &seclabel->relabel) < 0) { virReportError(VIR_ERR_XML_ERROR, --=20 2.26.2 From nobody Tue May 14 18:48:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1609784475; cv=none; d=zohomail.com; s=zohoarc; b=E4O5l3eB6WWWWB9zkrZfl3ukTsgqhTrJeXTKpFNLZ92Yjek4CfDPMUrx/gosmu0sbdlINHeJaLF+gFRGqHdkZAYegP15010tsVDTkCJhjkVuURhRm+3N/cO2xWqHdC59a0Zk3ePB88NiGVk8e2GYVybVx1tgn2qtsdDt6l+x/Rk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609784475; 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=xFvuYW/upgoOaKqIBMhqo3znGutsS6bH9zsfkkYjTZE=; b=AakDvDKVLCjYRJ587nx58X22rK0GBJmnvfjoV++wwsywaMuL3KkurhtbfzoS7vq8QZvc+pU+w3GeqDQfwboDoh0Wv6DHq7k3c/f7eU8i8m3ZO+23z9msGXk7UL84HgAVOcl8hxwa6eFuyDxDvBvYoDF4+umBSu7Kn588IsmEQ5k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1609784475891587.8514923071968; Mon, 4 Jan 2021 10:21:15 -0800 (PST) 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-239-AQ_LdD-LMcWbDSjiGEQOOg-1; Mon, 04 Jan 2021 13:21:12 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B2A06180A094; Mon, 4 Jan 2021 18:21:06 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 925F760C5F; Mon, 4 Jan 2021 18:21:06 +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 5D6A25002F; Mon, 4 Jan 2021 18:21:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104IKw9E018224 for ; Mon, 4 Jan 2021 13:20:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8E6C65D751; Mon, 4 Jan 2021 18:20:58 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F3505D756 for ; Mon, 4 Jan 2021 18:20:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609784474; 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=xFvuYW/upgoOaKqIBMhqo3znGutsS6bH9zsfkkYjTZE=; b=W72UHSOXbEQUUkRoRGP1/4WPabPQmX7Xz3EtATSUJkEAEfzztdwkMdDwzX4NzDslG1Cbql TPEJqg289KW98k+2v5bmfZ5Lz+i7GPpgjwDmJYSxg82tZpTqt4Qt8Y5gxDo00O9g2OOpvm urbgGYEH7eEl5qD9rVYnRW7zjhFo2mE= X-MC-Unique: AQ_LdD-LMcWbDSjiGEQOOg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 5/5] use more virStrcpy() and virStrcpyStatic() Date: Mon, 4 Jan 2021 19:20:45 +0100 Message-Id: <04b4cab2d7de6e09c9f4eefaf03b10daff71f96f.1609784319.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.12 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" There are a few places where we open code virStrcpy() or virStrcpyStatic(). Call respective functions instead. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/libvirt-lxc.c | 5 ++--- src/remote/remote_driver.c | 12 ++++-------- src/security/security_selinux.c | 3 +-- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/libvirt-lxc.c b/src/libvirt-lxc.c index f6391214be..2a271b74f0 100644 --- a/src/libvirt-lxc.c +++ b/src/libvirt-lxc.c @@ -35,6 +35,7 @@ # include #endif #include "vircgroup.h" +#include "virstring.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 @@ -213,7 +214,7 @@ virDomainLxcEnterSecurityLabel(virSecurityModelPtr mode= l, goto error; } =20 - if (strlen((char *) ctx) >=3D VIR_SECURITY_LABEL_BUFLEN) { + if (virStrcpy(oldlabel->label, ctx, VIR_SECURITY_LABEL_BUFLEN)= < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("security label exceeds " "maximum length: %d"), @@ -221,8 +222,6 @@ virDomainLxcEnterSecurityLabel(virSecurityModelPtr mode= l, freecon(ctx); goto error; } - - strcpy(oldlabel->label, (char *) ctx); freecon(ctx); =20 if ((oldlabel->enforcing =3D security_getenforce()) < 0) { diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index b0af3ee88e..1b784e61c7 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -2328,12 +2328,11 @@ remoteDomainGetSecurityLabel(virDomainPtr domain, v= irSecurityLabelPtr seclabel) } =20 if (ret.label.label_val !=3D NULL) { - if (strlen(ret.label.label_val) >=3D sizeof(seclabel->label)) { + if (virStrcpyStatic(seclabel->label, ret.label.label_val) < 0) { virReportError(VIR_ERR_RPC, _("security label exceeds maximum:= %zu"), sizeof(seclabel->label) - 1); goto cleanup; } - strcpy(seclabel->label, ret.label.label_val); seclabel->enforcing =3D ret.enforcing; } =20 @@ -2372,13 +2371,12 @@ remoteDomainGetSecurityLabelList(virDomainPtr domai= n, virSecurityLabelPtr* secla for (i =3D 0; i < ret.labels.labels_len; i++) { remote_domain_get_security_label_ret *cur =3D &ret.labels.labels_v= al[i]; if (cur->label.label_val !=3D NULL) { - if (strlen(cur->label.label_val) >=3D sizeof((*seclabels)->lab= el)) { + if (virStrcpyStatic((*seclabels)[i].label, cur->label.label_va= l) < 0) { virReportError(VIR_ERR_RPC, _("security label exceeds maxi= mum: %zd"), sizeof((*seclabels)->label) - 1); VIR_FREE(*seclabels); goto cleanup; } - strcpy((*seclabels)[i].label, cur->label.label_val); (*seclabels)[i].enforcing =3D cur->enforcing; } } @@ -2444,21 +2442,19 @@ remoteNodeGetSecurityModel(virConnectPtr conn, virS= ecurityModelPtr secmodel) } =20 if (ret.model.model_val !=3D NULL) { - if (strlen(ret.model.model_val) >=3D sizeof(secmodel->model)) { + if (virStrcpyStatic(secmodel->model, ret.model.model_val) < 0) { virReportError(VIR_ERR_RPC, _("security model exceeds maximum:= %zu"), sizeof(secmodel->model) - 1); goto cleanup; } - strcpy(secmodel->model, ret.model.model_val); } =20 if (ret.doi.doi_val !=3D NULL) { - if (strlen(ret.doi.doi_val) >=3D sizeof(secmodel->doi)) { + if (virStrcpyStatic(secmodel->doi, ret.doi.doi_val) < 0) { virReportError(VIR_ERR_RPC, _("security doi exceeds maximum: %= zu"), sizeof(secmodel->doi) - 1); goto cleanup; } - strcpy(secmodel->doi, ret.doi.doi_val); } =20 rv =3D 0; diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index e9cd95916e..2fc6ef2616 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1209,7 +1209,7 @@ virSecuritySELinuxGetProcessLabel(virSecurityManagerP= tr mgr G_GNUC_UNUSED, return -1; } =20 - if (strlen((char *)ctx) >=3D VIR_SECURITY_LABEL_BUFLEN) { + if (virStrcpy(sec->label, ctx, VIR_SECURITY_LABEL_BUFLEN) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("security label exceeds " "maximum length: %d"), @@ -1218,7 +1218,6 @@ virSecuritySELinuxGetProcessLabel(virSecurityManagerP= tr mgr G_GNUC_UNUSED, return -1; } =20 - strcpy(sec->label, (char *)ctx); freecon(ctx); =20 VIR_DEBUG("label=3D%s", sec->label); --=20 2.26.2