0001-unistr.c-Fix-use-after-free-in-ntfs_uppercase_mbs.patch 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. From 7b6210c5be46e5120b42c09f910e8f104bf3edf1 Mon Sep 17 00:00:00 2001
  2. From: Erik Larsson <erik@tuxera.com>
  3. Date: Tue, 13 Jun 2023 17:47:15 +0300
  4. Subject: [PATCH] unistr.c: Fix use-after-free in 'ntfs_uppercase_mbs'.
  5. If 'utf8_to_unicode' throws an error due to an invalid UTF-8 sequence,
  6. then 'n' will be less than 0 and the loop will terminate without storing
  7. anything in '*t'. After the loop the uppercase string's allocation is
  8. freed, however after it is freed it is unconditionally accessed through
  9. '*t', which points into the freed allocation, for the purpose of NULL-
  10. terminating the string. This leads to a use-after-free.
  11. Fixed by only NULL-terminating the string when no error has been thrown.
  12. Thanks for Jeffrey Bencteux for reporting this issue:
  13. https://github.com/tuxera/ntfs-3g/issues/84
  14. Upstream-Status: Backport [https://github.com/tuxera/ntfs-3g/commit/75dcdc2cf37478fad6c0e3427403d198b554951d]
  15. CVE: CVE-2023-52890
  16. Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
  17. ---
  18. libntfs-3g/unistr.c | 3 ++-
  19. 1 file changed, 2 insertions(+), 1 deletion(-)
  20. diff --git a/libntfs-3g/unistr.c b/libntfs-3g/unistr.c
  21. index 5854b3b..db8ddf4 100644
  22. --- a/libntfs-3g/unistr.c
  23. +++ b/libntfs-3g/unistr.c
  24. @@ -1189,8 +1189,9 @@ char *ntfs_uppercase_mbs(const char *low,
  25. free(upp);
  26. upp = (char*)NULL;
  27. errno = EILSEQ;
  28. + } else {
  29. + *t = 0;
  30. }
  31. - *t = 0;
  32. }
  33. return (upp);
  34. }
  35. --
  36. 2.34.1