From nobody Mon Feb 9 16:17:04 2026 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=1626871620; cv=none; d=zohomail.com; s=zohoarc; b=FAnt1IBppbmeQd8bFwofcw++Tk3zy+gEGPIW4mhEUqIvNmjba2yLiukTkLCLvmhA/ZmpKzqN5gTsFj4PBE7kFMBfBkKmwcTNGE0puKzJvWqg/SI5BqiO/utEj+82hCdDHo4egqux7co7aQpy58/Bu41yhzdXi6682ohwikLnWdc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1626871620; h=Content-Type:Content-Transfer-Encoding:Cc: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=hZ3JYI+XJWl8Xo2U8n/pV/+ThZYG46bSw7hi5C6a1Iw=; b=Z7thQ8XQ56a3pRVJlvDO0ADChmZL+7PTvBgCpuiGREXVzeyyBAHaaRjxiJCzNox9R115I8NqHFNRCSKyunFYbFkntqmq6SmlZizT5tpJxhXiAreGgdprnaH4zoIgIrU45vOFiHt1rSCeq3XHMPRBYD07XeVUHVT9RWsKCGfVZeQ= 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) 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 1626871620406625.9282681150339; Wed, 21 Jul 2021 05:47:00 -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-283-HDaD7m4pNB-bAzXbDLSuhg-1; Wed, 21 Jul 2021 08:46:57 -0400 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 686CF107ACF5; Wed, 21 Jul 2021 12:46:52 +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 3C86E27199; Wed, 21 Jul 2021 12:46:52 +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 030001801028; Wed, 21 Jul 2021 12:46:52 +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 16LCkn7L023536 for ; Wed, 21 Jul 2021 08:46:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id B024B5D741; Wed, 21 Jul 2021 12:46:49 +0000 (UTC) Received: from work.speedport.ip (ovpn-113-159.ams2.redhat.com [10.36.113.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 05AA561F21; Wed, 21 Jul 2021 12:46:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626871619; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=hZ3JYI+XJWl8Xo2U8n/pV/+ThZYG46bSw7hi5C6a1Iw=; b=CQ/fbPwC3lPNSHyT5APauX6BlP+j8kOGuvZvQgE49KagFIif5Z5Z1Cc22Lt4s4Q5P0KH8S fJB1Y+JxIbl0WdwQIWCZBS5iO0cq89d+GXxlhJ3yCqT6HNtTpImbEjruIKgSsmU/5ke9K+ R6x/ACjMIkQsABzgFnRUUE+OGmiVDFE= X-MC-Unique: HDaD7m4pNB-bAzXbDLSuhg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 1/4] virfile: Move max file size macro Date: Wed, 21 Jul 2021 14:46:40 +0200 Message-Id: <20210721124643.36824-2-twiederh@redhat.com> In-Reply-To: <20210721124643.36824-1-twiederh@redhat.com> References: <20210721124643.36824-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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) X-ZM-MESSAGEID: 1626871621962100003 Content-Type: text/plain; charset="utf-8" The next commit will use this macro outside the apparmor context. Signed-off-by: Tim Wiederhake --- src/security/security_apparmor.c | 4 ++-- src/security/security_apparmor.h | 1 - src/security/virt-aa-helper.c | 10 +++++----- src/util/virfile.h | 3 +++ 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/security/security_apparmor.c b/src/security/security_appar= mor.c index 84363015dc..c2cae43137 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -83,7 +83,7 @@ profile_status(const char *str, const int check_enforcing) etmp =3D g_strdup_printf("%s (enforce)", str); } =20 - if (virFileReadAll(APPARMOR_PROFILES_PATH, MAX_FILE_LEN, &content) < 0= ) { + if (virFileReadAll(APPARMOR_PROFILES_PATH, VIR_MAX_FILE_LEN, &content)= < 0) { virReportSystemError(errno, _("Failed to read AppArmor profiles list " "\'%s\'"), APPARMOR_PROFILES_PATH); @@ -131,7 +131,7 @@ profile_status_file(const char *str) if (!virFileExists(profile)) goto failed; =20 - if ((len =3D virFileReadAll(profile, MAX_FILE_LEN, &content)) < 0) { + if ((len =3D virFileReadAll(profile, VIR_MAX_FILE_LEN, &content)) < 0)= { virReportSystemError(errno, _("Failed to read \'%s\'"), profile); goto failed; diff --git a/src/security/security_apparmor.h b/src/security/security_appar= mor.h index 7b54eefd8d..ceffa30f14 100644 --- a/src/security/security_apparmor.h +++ b/src/security/security_apparmor.h @@ -24,4 +24,3 @@ extern virSecurityDriver virAppArmorSecurityDriver; =20 #define AA_PREFIX "libvirt-" #define PROFILE_NAME_SIZE 8 + VIR_UUID_STRING_BUFLEN /* AA_PREFIX + uuid = */ -#define MAX_FILE_LEN (1024*1024*10) /* 10MB limit for sanity check = */ diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index e21557c810..0db2248a59 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -211,7 +211,7 @@ update_include_file(const char *include_file, const cha= r *included_files, "# DO NOT EDIT THIS FILE DIRECTLY. IT IS MANAGED BY LIBVIRT.\n"; =20 if (virFileExists(include_file)) { - flen =3D virFileReadAll(include_file, MAX_FILE_LEN, &existing); + flen =3D virFileReadAll(include_file, VIR_MAX_FILE_LEN, &existing); if (flen < 0) return rc; } @@ -222,7 +222,7 @@ update_include_file(const char *include_file, const cha= r *included_files, pcontent =3D g_strdup_printf("%s%s", warning, included_files); =20 plen =3D strlen(pcontent); - if (plen > MAX_FILE_LEN) { + if (plen > VIR_MAX_FILE_LEN) { vah_error(NULL, 0, _("invalid length for new profile")); goto cleanup; } @@ -299,7 +299,7 @@ create_profile(const char *profile, const char *profile= _name, return -1; } =20 - if ((tlen =3D virFileReadAll(template, MAX_FILE_LEN, &tcontent)) < 0) { + if ((tlen =3D virFileReadAll(template, VIR_MAX_FILE_LEN, &tcontent)) <= 0) { vah_error(NULL, 0, _("failed to read AppArmor template")); return -1; } @@ -326,7 +326,7 @@ create_profile(const char *profile, const char *profile= _name, if (virtType !=3D VIR_DOMAIN_VIRT_LXC) plen +=3D strlen(replace_files) - strlen(template_end); =20 - if (plen > MAX_FILE_LEN || plen < tlen) { + if (plen > VIR_MAX_FILE_LEN || plen < tlen) { vah_error(NULL, 0, _("invalid length for new profile")); return -1; } @@ -1429,7 +1429,7 @@ vahParseArgv(vahControl * ctl, int argc, char **argv) =20 if (ctl->cmd =3D=3D 'c' || ctl->cmd =3D=3D 'r') { char *xmlStr =3D NULL; - if (virFileReadLimFD(STDIN_FILENO, MAX_FILE_LEN, &xmlStr) < 0) + if (virFileReadLimFD(STDIN_FILENO, VIR_MAX_FILE_LEN, &xmlStr) < 0) vah_error(ctl, 1, _("could not read xml file")); =20 if (get_definition(ctl, xmlStr) !=3D 0 || ctl->def =3D=3D NULL) { diff --git a/src/util/virfile.h b/src/util/virfile.h index 72368495bf..b6bcd1257d 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -42,6 +42,9 @@ typedef enum { # define VIR_FILE_MODULE_EXT ".so" #endif =20 +/* 10MB limit for sanity check */ +#define VIR_MAX_FILE_LEN (10 * 1024 * 1024) + ssize_t saferead(int fd, void *buf, size_t count) G_GNUC_WARN_UNUSED_RESUL= T; ssize_t safewrite(int fd, const void *buf, size_t count) G_GNUC_WARN_UNUSED_RESULT; --=20 2.31.1