From nobody Sat May 4 03:41:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1680014637; cv=none; d=zohomail.com; s=zohoarc; b=oKkvSmbncgp9OOj/yV8BSr0fc96Vj4Hn4okm/PcQwZLZ4lgut5wcuEf8XGUIgC/4wcchpTMaor1746BqD4eXZt/66fi/2NlIG/AqPWm//vr0V7QvD2Yq3+nWfP+vrKEFnxOeqtsivrUW1Mu9qijm2L7r8DRHhkqc7swTKMgkZ5c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680014637; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=WJKej2F2T0liQUy5RrirY2PhZ84TxQV/5YAjMJ02gg0=; b=VVTSyXin3dKNUHGgVeBQK2aNH/FasGVmt/ymU9VQbQX+2j2w744vH/lPK44uKGqWacqxgCX+x6J0ODpGQok7pB3evd5tL31IU5+jJSC7PQvz1cnVuaqNYdve9q9zr+WUw9lv9Ucgrovh1hAXdHyNxeVDegppjSDAX1JLNK35++E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1680014637803137.23745556063216; Tue, 28 Mar 2023 07:43:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.515910.799260 (Exim 4.92) (envelope-from ) id 1phAXt-00051o-4E; Tue, 28 Mar 2023 14:43:33 +0000 Received: by outflank-mailman (output) from mailman id 515910.799260; Tue, 28 Mar 2023 14:43:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1phAXt-00051h-0k; Tue, 28 Mar 2023 14:43:33 +0000 Received: by outflank-mailman (input) for mailman id 515910; Tue, 28 Mar 2023 14:43:32 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1phAXr-00051b-VO for xen-devel@lists.xenproject.org; Tue, 28 Mar 2023 14:43:31 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e78ee3cf-cd76-11ed-b464-930f4c7d94ae; Tue, 28 Mar 2023 16:43:29 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 063D221A2E; Tue, 28 Mar 2023 14:43:29 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id CF4BB1390D; Tue, 28 Mar 2023 14:43:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id fj9iMRD9ImRvfwAAMHmgww (envelope-from ); Tue, 28 Mar 2023 14:43:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e78ee3cf-cd76-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680014609; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=WJKej2F2T0liQUy5RrirY2PhZ84TxQV/5YAjMJ02gg0=; b=bYA1m47rG+RYuvY1drnbx/Kj+vPAIp4ooiUX1AQfFpvXTPYiTFGxGfPW0t0CNR2LbaFh/P Ga20qDsIxxvv12HeVBQ/H1Xd6Sbx9/a3otrdFnbsDJTP+Z0kevu2JR5WLUylg5v0qaSAi6 09FA3bVJrb5gGennYS75PqghfzfzORo= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v2] tools/xenstore: fix quota check in acc_fix_domains() Date: Tue, 28 Mar 2023 16:43:27 +0200 Message-Id: <20230328144327.6562-1-jgross@suse.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680014638367100001 Content-Type: text/plain; charset="utf-8" Today when finalizing a transaction the number of node quota is checked to not being exceeded after the transaction. This check is always done, even if the transaction is being performed by a privileged connection, or if there were no nodes created in the transaction. Correct that by checking quota only if: - the transaction is being performed by an unprivileged guest, and - at least one node was created in the transaction Reported-by: Julien Grall Fixes: f2bebf72c4d5 ("xenstore: rework of transaction handling") Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V2: - add comment (Julien Grall) --- tools/xenstore/xenstored_core.c | 3 +++ tools/xenstore/xenstored_domain.c | 4 ++-- tools/xenstore/xenstored_domain.h | 7 ++++++- tools/xenstore/xenstored_transaction.c | 16 ++++++++++++++-- tools/xenstore/xenstored_transaction.h | 3 +++ 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index a61db2db2d..3ca68681e3 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -1472,6 +1472,9 @@ static struct node *create_node(struct connection *co= nn, const void *ctx, if (!node) return NULL; =20 + if (conn && conn->transaction) + ta_node_created(conn->transaction); + node->data =3D data; node->datalen =3D datalen; =20 diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index d7fc2fafc7..f62be2245c 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -544,7 +544,7 @@ static struct domain *find_domain_by_domid(unsigned int= domid) return (d && d->introduced) ? d : NULL; } =20 -int acc_fix_domains(struct list_head *head, bool update) +int acc_fix_domains(struct list_head *head, bool chk_quota, bool update) { struct changed_domain *cd; int cnt; @@ -552,7 +552,7 @@ int acc_fix_domains(struct list_head *head, bool update) list_for_each_entry(cd, head, list) { cnt =3D domain_nbentry_fix(cd->domid, cd->nbentry, update); if (!update) { - if (cnt >=3D quota_nb_entry_per_domain) + if (chk_quota && cnt >=3D quota_nb_entry_per_domain) return ENOSPC; if (cnt < 0) return ENOMEM; diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index dc4660861e..279cccb3ad 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -96,7 +96,12 @@ void domain_outstanding_dec(struct connection *conn); void domain_outstanding_domid_dec(unsigned int domid); int domain_get_quota(const void *ctx, struct connection *conn, unsigned int domid); -int acc_fix_domains(struct list_head *head, bool update); + +/* + * Update or check number of nodes per domain at the end of a transaction. + * If "update" is true, "chk_quota" is ignored. + */ +int acc_fix_domains(struct list_head *head, bool chk_quota, bool update); =20 /* Write rate limiting */ =20 diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xensto= red_transaction.c index 1aa9d3cb3d..2b15506953 100644 --- a/tools/xenstore/xenstored_transaction.c +++ b/tools/xenstore/xenstored_transaction.c @@ -160,12 +160,20 @@ struct transaction /* List of changed domains - to record the changed domain entry number */ struct list_head changed_domains; =20 + /* There was at least one node created in the transaction. */ + bool node_created; + /* Flag for letting transaction fail. */ bool fail; }; =20 uint64_t generation; =20 +void ta_node_created(struct transaction *trans) +{ + trans->node_created =3D true; +} + static struct accessed_node *find_accessed_node(struct transaction *trans, const char *name) { @@ -509,6 +517,7 @@ int do_transaction_end(const void *ctx, struct connecti= on *conn, const char *arg =3D onearg(in); struct transaction *trans; bool is_corrupt =3D false; + bool chk_quota; int ret; =20 if (!arg || (!streq(arg, "T") && !streq(arg, "F"))) @@ -523,13 +532,16 @@ int do_transaction_end(const void *ctx, struct connec= tion *conn, if (!conn->transaction_started) conn->ta_start_time =3D 0; =20 + chk_quota =3D trans->node_created && domain_is_unprivileged(conn); + /* Attach transaction to ctx for auto-cleanup */ talloc_steal(ctx, trans); =20 if (streq(arg, "T")) { if (trans->fail) return ENOMEM; - ret =3D acc_fix_domains(&trans->changed_domains, false); + ret =3D acc_fix_domains(&trans->changed_domains, chk_quota, + false); if (ret) return ret; ret =3D finalize_transaction(conn, trans, &is_corrupt); @@ -539,7 +551,7 @@ int do_transaction_end(const void *ctx, struct connecti= on *conn, wrl_apply_debit_trans_commit(conn); =20 /* fix domain entry for each changed domain */ - acc_fix_domains(&trans->changed_domains, true); + acc_fix_domains(&trans->changed_domains, false, true); =20 if (is_corrupt) corrupt(conn, "transaction inconsistency"); diff --git a/tools/xenstore/xenstored_transaction.h b/tools/xenstore/xensto= red_transaction.h index b6f8cb7d0a..883145163f 100644 --- a/tools/xenstore/xenstored_transaction.h +++ b/tools/xenstore/xenstored_transaction.h @@ -36,6 +36,9 @@ int do_transaction_end(const void *ctx, struct connection= *conn, =20 struct transaction *transaction_lookup(struct connection *conn, uint32_t i= d); =20 +/* Set flag for created node. */ +void ta_node_created(struct transaction *trans); + /* This node was accessed. */ int __must_check access_node(struct connection *conn, struct node *node, enum node_access_type type, TDB_DATA *key); --=20 2.35.3