From a11cd899d873b3a3e9918e81af41cb026e2f11c3 Mon Sep 17 00:00:00 2001 From: lvyy Date: Wed, 7 May 2025 07:55:07 +0000 Subject: [PATCH] quotaio_xfs: Fix error handling in xfs_read_dquot() (cherry picked from commit 648f3151b5aa6a0b532d1e9ef59c2a7db40d20ed) --- ...Fix-error-handling-in-xfs_read_dquot.patch | 36 +++++++++++++++++++ 0009-quotaio_xfs-Fix-memory-leak.patch | 30 ++++++++++++++++ quota.spec | 7 +++- 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 0008-quotaio_xfs-Fix-error-handling-in-xfs_read_dquot.patch create mode 100644 0009-quotaio_xfs-Fix-memory-leak.patch diff --git a/0008-quotaio_xfs-Fix-error-handling-in-xfs_read_dquot.patch b/0008-quotaio_xfs-Fix-error-handling-in-xfs_read_dquot.patch new file mode 100644 index 0000000..b5c5740 --- /dev/null +++ b/0008-quotaio_xfs-Fix-error-handling-in-xfs_read_dquot.patch @@ -0,0 +1,36 @@ +From dba8c5ca95516b9550fc44b2a476ceca60ee4b38 Mon Sep 17 00:00:00 2001 +From: Jan Kara +Date: Tue, 7 May 2024 12:55:30 +0200 +Subject: [PATCH] quotaio_xfs: Fix error handling in xfs_read_dquot() + +When quotactl(2) fails, xfs_read_dquot() will happily return zero-filled +structure. This is fine when the user structure does not exist but it is +wrong when there's other error (like EACCESS). Fix the error handling. + +Signed-off-by: Jan Kara +--- + quotaio_xfs.c | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/quotaio_xfs.c b/quotaio_xfs.c +index 5abb2c2..a91567d 100644 +--- a/quotaio_xfs.c ++++ b/quotaio_xfs.c +@@ -175,7 +175,13 @@ static struct dquot *xfs_read_dquot(struct quota_handle *h, qid_t id) + + qcmd = QCMD(Q_XFS_GETQUOTA, h->qh_type); + if (quotactl(qcmd, h->qh_quotadev, id, (void *)&xdqblk) < 0) { +- ; ++ /* ++ * ENOENT means the structure just does not exist - return all ++ * zeros. Otherwise return failure. ++ */ ++ if (errno != ENOENT) { ++ return NULL; ++ } + } + else { + xfs_kern2utildqblk(&dquot->dq_dqb, &xdqblk); +-- +2.33.0 + diff --git a/0009-quotaio_xfs-Fix-memory-leak.patch b/0009-quotaio_xfs-Fix-memory-leak.patch new file mode 100644 index 0000000..f3496dc --- /dev/null +++ b/0009-quotaio_xfs-Fix-memory-leak.patch @@ -0,0 +1,30 @@ +From c59b85805ee64c7ee2937b91533eb96f56d87738 Mon Sep 17 00:00:00 2001 +From: Pavel Reichl +Date: Tue, 30 Jul 2024 00:18:13 +0200 +Subject: [PATCH] quotaio_xfs: Fix memory leak + +Error: RESOURCE_LEAK (CWE-772): +quota-4.09/quotaio_xfs.c:162:2: alloc_fn: Storage is returned from allocation function "get_empty_dquot". +quota-4.09/quotaio_xfs.c:162:2: var_assign: Assigning: "dquot" = storage returned from "get_empty_dquot()". +quota-4.09/quotaio_xfs.c:180:4: leaked_storage: Variable "dquot" going out of scope leaks the storage it points to. + +Signed-off-by: Pavel Reichl +--- + quotaio_xfs.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/quotaio_xfs.c b/quotaio_xfs.c +index 2df27b5..5446bc5 100644 +--- a/quotaio_xfs.c ++++ b/quotaio_xfs.c +@@ -174,6 +174,7 @@ static struct dquot *xfs_read_dquot(struct quota_handle *h, qid_t id) + * zeros. Otherwise return failure. + */ + if (errno != ENOENT) { ++ free(dquot); + return NULL; + } + } +-- +2.33.0 + diff --git a/quota.spec b/quota.spec index 90e07d9..824bb58 100644 --- a/quota.spec +++ b/quota.spec @@ -1,7 +1,7 @@ Name: quota Version: 4.06 Epoch: 1 -Release: 9 +Release: 10 Summary: Linux Diskquota system as part of the Linux kernel License: BSD and GPLv2 and GPLv2+ and LGPLv2+ URL: http://sourceforge.net/projects/linuxquota/ @@ -20,6 +20,8 @@ Patch4: 0004-quota_nld-Initialize-sa_mask-when-registering-PID-fi.patch Patch5: 0005-quota-nld-fix-open-PID-file-failed-when-systemd-read.patch Patch6: 0006-common.c-fix-strncat-usage.patch Patch7: 0007-quota-Use-realloc-3-instead-of-reallocarray-3.patch +Patch8: 0008-quotaio_xfs-Fix-error-handling-in-xfs_read_dquot.patch +Patch9: 0009-quotaio_xfs-Fix-memory-leak.patch BuildRequires: autoconf, automake, coreutils, rpcgen, systemd, gcc BuildRequires: e2fsprogs-devel, gettext-devel, openldap-devel @@ -128,6 +130,9 @@ make check %{_mandir}/man*/* %changelog +* Wed May 7 2025 lvyy - 1:4.06-10 +- DESC:Fix error handling in xfs_read_dquot() + * Mon Oct 14 2024 lvyy - 1:4.06-9 - DESC:Use realloc(3) instead of reallocarray(3)