0001-Detect-multiplication-overflow-when-computing-sector.patch 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. From 06de62c022138f63de9bcd04074491945eaa8662 Mon Sep 17 00:00:00 2001
  2. From: Christos Zoulas <christos@zoulas.com>
  3. Date: Fri, 23 Aug 2019 14:29:14 +0000
  4. Subject: [PATCH] Detect multiplication overflow when computing sector position
  5. (found by oss-fuzz)
  6. Fixes CVE-2019-18218
  7. Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
  8. ---
  9. src/cdf.c | 20 +++++++++++++++++---
  10. 1 file changed, 17 insertions(+), 3 deletions(-)
  11. diff --git a/src/cdf.c b/src/cdf.c
  12. index 556a3ff8..9d639674 100644
  13. --- a/src/cdf.c
  14. +++ b/src/cdf.c
  15. @@ -35,7 +35,7 @@
  16. #include "file.h"
  17. #ifndef lint
  18. -FILE_RCSID("@(#)$File: cdf.c,v 1.114 2019/02/20 02:35:27 christos Exp $")
  19. +FILE_RCSID("@(#)$File: cdf.c,v 1.115 2019/08/23 14:29:14 christos Exp $")
  20. #endif
  21. #include <assert.h>
  22. @@ -53,6 +53,10 @@ FILE_RCSID("@(#)$File: cdf.c,v 1.114 2019/02/20 02:35:27 christos Exp $")
  23. #define EFTYPE EINVAL
  24. #endif
  25. +#ifndef SIZE_T_MAX
  26. +#define SIZE_T_MAX CAST(size_t, ~0ULL)
  27. +#endif
  28. +
  29. #include "cdf.h"
  30. #ifdef CDF_DEBUG
  31. @@ -405,7 +409,12 @@ cdf_read_sector(const cdf_info_t *info, void *buf, size_t offs, size_t len,
  32. const cdf_header_t *h, cdf_secid_t id)
  33. {
  34. size_t ss = CDF_SEC_SIZE(h);
  35. - size_t pos = CDF_SEC_POS(h, id);
  36. + size_t pos;
  37. +
  38. + if (SIZE_T_MAX / ss < CAST(size_t, id))
  39. + return -1;
  40. +
  41. + pos = CDF_SEC_POS(h, id);
  42. assert(ss == len);
  43. return cdf_read(info, CAST(off_t, pos), RCAST(char *, buf) + offs, len);
  44. }
  45. @@ -415,7 +424,12 @@ cdf_read_short_sector(const cdf_stream_t *sst, void *buf, size_t offs,
  46. size_t len, const cdf_header_t *h, cdf_secid_t id)
  47. {
  48. size_t ss = CDF_SHORT_SEC_SIZE(h);
  49. - size_t pos = CDF_SHORT_SEC_POS(h, id);
  50. + size_t pos;
  51. +
  52. + if (SIZE_T_MAX / ss < CAST(size_t, id))
  53. + return -1;
  54. +
  55. + pos = CDF_SHORT_SEC_POS(h, id);
  56. assert(ss == len);
  57. if (pos + len > CDF_SEC_SIZE(h) * sst->sst_len) {
  58. DPRINTF(("Out of bounds read %" SIZE_T_FORMAT "u > %"
  59. --
  60. 2.20.1