0048-kernel-fix-keyring-reference-leak-CVE-2016-0728.patch 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Sat, 6 Feb 2016 07:35:33 +0100
  3. Subject: kernel: fix keyring reference leak (CVE-2016-0728)
  4. Signed-off-by: Felix Fietkau <nbd@openwrt.org>
  5. diff --git a/target/linux/generic/patches-3.18/010-KEYS-Fix-keyring-ref-leak-in-join_session_keyring.patch b/target/linux/generic/patches-3.18/010-KEYS-Fix-keyring-ref-leak-in-join_session_keyring.patch
  6. new file mode 100644
  7. index 0000000..9c6a969
  8. --- /dev/null
  9. +++ b/target/linux/generic/patches-3.18/010-KEYS-Fix-keyring-ref-leak-in-join_session_keyring.patch
  10. @@ -0,0 +1,75 @@
  11. +From 7ca88764d45c209791e8813131c1457c2e9e51e7 Mon Sep 17 00:00:00 2001
  12. +From: Yevgeny Pats <yevgeny@perception-point.io>
  13. +Date: Mon, 11 Jan 2016 12:05:28 +0000
  14. +Subject: KEYS: Fix keyring ref leak in join_session_keyring()
  15. +
  16. +If a thread is asked to join as a session keyring the keyring that's already
  17. +set as its session, we leak a keyring reference.
  18. +
  19. +This can be tested with the following program:
  20. +
  21. + #include <stddef.h>
  22. + #include <stdio.h>
  23. + #include <sys/types.h>
  24. + #include <keyutils.h>
  25. +
  26. + int main(int argc, const char *argv[])
  27. + {
  28. + int i = 0;
  29. + key_serial_t serial;
  30. +
  31. + serial = keyctl(KEYCTL_JOIN_SESSION_KEYRING,
  32. + "leaked-keyring");
  33. + if (serial < 0) {
  34. + perror("keyctl");
  35. + return -1;
  36. + }
  37. +
  38. + if (keyctl(KEYCTL_SETPERM, serial,
  39. + KEY_POS_ALL | KEY_USR_ALL) < 0) {
  40. + perror("keyctl");
  41. + return -1;
  42. + }
  43. +
  44. + for (i = 0; i < 100; i++) {
  45. + serial = keyctl(KEYCTL_JOIN_SESSION_KEYRING,
  46. + "leaked-keyring");
  47. + if (serial < 0) {
  48. + perror("keyctl");
  49. + return -1;
  50. + }
  51. + }
  52. +
  53. + return 0;
  54. + }
  55. +
  56. +If, after the program has run, there something like the following line in
  57. +/proc/keys:
  58. +
  59. +3f3d898f I--Q--- 100 perm 3f3f0000 0 0 keyring leaked-keyring: empty
  60. +
  61. +with a usage count of 100 * the number of times the program has been run,
  62. +then the kernel is malfunctioning. If leaked-keyring has zero usages or
  63. +has been garbage collected, then the problem is fixed.
  64. +
  65. +Reported-by: Yevgeny Pats <yevgeny@perception-point.io>
  66. +Signed-off-by: David Howells <dhowells@redhat.com>
  67. +---
  68. + security/keys/process_keys.c | 1 +
  69. + 1 file changed, 1 insertion(+)
  70. +
  71. +diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c
  72. +index a3f85d2..e6d50172 100644
  73. +--- a/security/keys/process_keys.c
  74. ++++ b/security/keys/process_keys.c
  75. +@@ -794,6 +794,7 @@ long join_session_keyring(const char *name)
  76. + ret = PTR_ERR(keyring);
  77. + goto error2;
  78. + } else if (keyring == new->session_keyring) {
  79. ++ key_put(keyring);
  80. + ret = 0;
  81. + goto error2;
  82. + }
  83. +--
  84. +2.7.0.rc3
  85. +