|
| 1 | +From b27303905e208e89b9cb7cc5aab9f57339424a86 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Erik Larsson <erik@tuxera.com> |
| 3 | +Date: Tue, 24 Feb 2026 10:04:31 +0200 |
| 4 | +Subject: [PATCH] acls.c: Fix heap buffer overflow in |
| 5 | + 'ntfs_build_permissions_posix'. |
| 6 | + |
| 7 | +The root cause was that the memory allocated for the ACE entries was |
| 8 | +insufficient for the worst case scenario when group entries were added |
| 9 | +for mask entries that didn't have a corresponding group entry already. |
| 10 | +Fixed by allocating space for the worst case number of ACE entries. |
| 11 | + |
| 12 | +This was reported by Andrea Bocchetti with a thorough report which made |
| 13 | +it very easy to fix. |
| 14 | + |
| 15 | +Signed-off-by: Azure Linux Security Servicing Account <azurelinux-security@microsoft.com> |
| 16 | +Upstream-reference: https://github.com/tuxera/ntfs-3g/commit/e48e1ef2a1fcff13a590c2224ec21c5bd5d3e92e.patch |
| 17 | +--- |
| 18 | + libntfs-3g/acls.c | 25 ++++++++++++++++++++----- |
| 19 | + 1 file changed, 20 insertions(+), 5 deletions(-) |
| 20 | + |
| 21 | +diff --git a/libntfs-3g/acls.c b/libntfs-3g/acls.c |
| 22 | +index 9f16fec..4cf534b 100644 |
| 23 | +--- a/libntfs-3g/acls.c |
| 24 | ++++ b/libntfs-3g/acls.c |
| 25 | +@@ -3716,12 +3716,27 @@ struct POSIX_SECURITY *ntfs_build_permissions_posix( |
| 26 | + /* |
| 27 | + * Build a raw posix security descriptor |
| 28 | + * by just translating permissions and ids |
| 29 | +- * Add 2 to the count of ACE to be able to insert |
| 30 | +- * a group ACE later in access and default ACLs |
| 31 | +- * and add 2 more to be able to insert ACEs for owner |
| 32 | +- * and 2 more for other |
| 33 | ++ * |
| 34 | ++ * The worst case number of ACE entries consists of: |
| 35 | ++ * - 'acecount' ACE entries from the main loop (see below) |
| 36 | ++ * iterating over the 'securattr' array. |
| 37 | ++ * - 1 ACE entry which may be added when creating world |
| 38 | ++ * permissions if none exist. |
| 39 | ++ * - 1 ACE entry which may be added when setting basic owner |
| 40 | ++ * permissions if none exist (both lists). |
| 41 | ++ * - 1 ACE entry which may be added when duplicating world |
| 42 | ++ * permissions as group_obj permissions if none exist. |
| 43 | ++ * - 'acecount + 2' ACE entries which may be added when |
| 44 | ++ * duplicating world permissions as group permissions if they |
| 45 | ++ * were converted to masks and the masks are not followed by a |
| 46 | ++ * group entry. |
| 47 | ++ * - 1 ACE entry which may be added when inserting a default |
| 48 | ++ * mask if none is present and there are designated users or |
| 49 | ++ * groups. |
| 50 | ++ * |
| 51 | ++ * This amounts to 2*acecnt + 6 ACE entries in the worst case. |
| 52 | + */ |
| 53 | +- alloccnt = acecnt + 6; |
| 54 | ++ alloccnt = 2*acecnt + 6; |
| 55 | + pxdesc = (struct POSIX_SECURITY*)malloc( |
| 56 | + sizeof(struct POSIX_SECURITY) |
| 57 | + + alloccnt*sizeof(struct POSIX_ACE)); |
| 58 | +-- |
| 59 | +2.45.4 |
| 60 | + |
0 commit comments