0018-Refuse-dbus-message-paths-longer-than-BUS_PATH_SIZE_.patch 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. From febef5e18558c114f4fb7c94f6c8ed3520c50cdf Mon Sep 17 00:00:00 2001
  2. From: Riccardo Schirone <rschiron@redhat.com>
  3. Date: Mon, 4 Feb 2019 14:29:09 +0100
  4. Subject: [PATCH] Refuse dbus message paths longer than BUS_PATH_SIZE_MAX
  5. limit.
  6. Even though the dbus specification does not enforce any length limit on the
  7. path of a dbus message, having to analyze too long strings in PID1 may be
  8. time-consuming and it may have security impacts.
  9. In any case, the limit is set so high that real-life applications should not
  10. have a problem with it.
  11. (cherry picked from commit 61397a60d98e368a5720b37e83f3169e3eb511c4)
  12. Signed-off-by: Baruch Siach <baruch@tkos.co.il>
  13. ---
  14. Upstream status: commit 61397a60d98
  15. src/libsystemd/sd-bus/bus-internal.c | 2 +-
  16. src/libsystemd/sd-bus/bus-internal.h | 4 ++++
  17. 2 files changed, 5 insertions(+), 1 deletion(-)
  18. diff --git a/src/libsystemd/sd-bus/bus-internal.c b/src/libsystemd/sd-bus/bus-internal.c
  19. index 40acae213381..598b7f110c73 100644
  20. --- a/src/libsystemd/sd-bus/bus-internal.c
  21. +++ b/src/libsystemd/sd-bus/bus-internal.c
  22. @@ -43,7 +43,7 @@ bool object_path_is_valid(const char *p) {
  23. if (slash)
  24. return false;
  25. - return true;
  26. + return (q - p) <= BUS_PATH_SIZE_MAX;
  27. }
  28. char* object_path_startswith(const char *a, const char *b) {
  29. diff --git a/src/libsystemd/sd-bus/bus-internal.h b/src/libsystemd/sd-bus/bus-internal.h
  30. index f208b294d8f1..a8d61bf72a4e 100644
  31. --- a/src/libsystemd/sd-bus/bus-internal.h
  32. +++ b/src/libsystemd/sd-bus/bus-internal.h
  33. @@ -332,6 +332,10 @@ struct sd_bus {
  34. #define BUS_MESSAGE_SIZE_MAX (128*1024*1024)
  35. #define BUS_AUTH_SIZE_MAX (64*1024)
  36. +/* Note that the D-Bus specification states that bus paths shall have no size limit. We enforce here one
  37. + * anyway, since truly unbounded strings are a security problem. The limit we pick is relatively large however,
  38. + * to not clash unnecessarily with real-life applications. */
  39. +#define BUS_PATH_SIZE_MAX (64*1024)
  40. #define BUS_CONTAINER_DEPTH 128
  41. --
  42. 2.20.1