0001-Fix-security-framework-bypass.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. From e03553605b45c88f0b4b2980adfbbb8f6fca2fd6 Mon Sep 17 00:00:00 2001
  2. From: Nick Wellnhofer <wellnhofer@aevum.de>
  3. Date: Sun, 24 Mar 2019 09:51:39 +0100
  4. Subject: [PATCH] Fix security framework bypass
  5. xsltCheckRead and xsltCheckWrite return -1 in case of error but callers
  6. don't check for this condition and allow access. With a specially
  7. crafted URL, xsltCheckRead could be tricked into returning an error
  8. because of a supposedly invalid URL that would still be loaded
  9. succesfully later on.
  10. Fixes #12.
  11. Thanks to Felix Wilhelm for the report.
  12. Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
  13. ---
  14. libxslt/documents.c | 18 ++++++++++--------
  15. libxslt/imports.c | 9 +++++----
  16. libxslt/transform.c | 9 +++++----
  17. libxslt/xslt.c | 9 +++++----
  18. 4 files changed, 25 insertions(+), 20 deletions(-)
  19. diff --git a/libxslt/documents.c b/libxslt/documents.c
  20. index 3f3a7312..4aad11bb 100644
  21. --- a/libxslt/documents.c
  22. +++ b/libxslt/documents.c
  23. @@ -296,10 +296,11 @@ xsltLoadDocument(xsltTransformContextPtr ctxt, const xmlChar *URI) {
  24. int res;
  25. res = xsltCheckRead(ctxt->sec, ctxt, URI);
  26. - if (res == 0) {
  27. - xsltTransformError(ctxt, NULL, NULL,
  28. - "xsltLoadDocument: read rights for %s denied\n",
  29. - URI);
  30. + if (res <= 0) {
  31. + if (res == 0)
  32. + xsltTransformError(ctxt, NULL, NULL,
  33. + "xsltLoadDocument: read rights for %s denied\n",
  34. + URI);
  35. return(NULL);
  36. }
  37. }
  38. @@ -372,10 +373,11 @@ xsltLoadStyleDocument(xsltStylesheetPtr style, const xmlChar *URI) {
  39. int res;
  40. res = xsltCheckRead(sec, NULL, URI);
  41. - if (res == 0) {
  42. - xsltTransformError(NULL, NULL, NULL,
  43. - "xsltLoadStyleDocument: read rights for %s denied\n",
  44. - URI);
  45. + if (res <= 0) {
  46. + if (res == 0)
  47. + xsltTransformError(NULL, NULL, NULL,
  48. + "xsltLoadStyleDocument: read rights for %s denied\n",
  49. + URI);
  50. return(NULL);
  51. }
  52. }
  53. diff --git a/libxslt/imports.c b/libxslt/imports.c
  54. index 874870cc..3783b247 100644
  55. --- a/libxslt/imports.c
  56. +++ b/libxslt/imports.c
  57. @@ -130,10 +130,11 @@ xsltParseStylesheetImport(xsltStylesheetPtr style, xmlNodePtr cur) {
  58. int secres;
  59. secres = xsltCheckRead(sec, NULL, URI);
  60. - if (secres == 0) {
  61. - xsltTransformError(NULL, NULL, NULL,
  62. - "xsl:import: read rights for %s denied\n",
  63. - URI);
  64. + if (secres <= 0) {
  65. + if (secres == 0)
  66. + xsltTransformError(NULL, NULL, NULL,
  67. + "xsl:import: read rights for %s denied\n",
  68. + URI);
  69. goto error;
  70. }
  71. }
  72. diff --git a/libxslt/transform.c b/libxslt/transform.c
  73. index 13793914..0636dbd0 100644
  74. --- a/libxslt/transform.c
  75. +++ b/libxslt/transform.c
  76. @@ -3493,10 +3493,11 @@ xsltDocumentElem(xsltTransformContextPtr ctxt, xmlNodePtr node,
  77. */
  78. if (ctxt->sec != NULL) {
  79. ret = xsltCheckWrite(ctxt->sec, ctxt, filename);
  80. - if (ret == 0) {
  81. - xsltTransformError(ctxt, NULL, inst,
  82. - "xsltDocumentElem: write rights for %s denied\n",
  83. - filename);
  84. + if (ret <= 0) {
  85. + if (ret == 0)
  86. + xsltTransformError(ctxt, NULL, inst,
  87. + "xsltDocumentElem: write rights for %s denied\n",
  88. + filename);
  89. xmlFree(URL);
  90. xmlFree(filename);
  91. return;
  92. diff --git a/libxslt/xslt.c b/libxslt/xslt.c
  93. index 780a5ad7..a234eb79 100644
  94. --- a/libxslt/xslt.c
  95. +++ b/libxslt/xslt.c
  96. @@ -6763,10 +6763,11 @@ xsltParseStylesheetFile(const xmlChar* filename) {
  97. int res;
  98. res = xsltCheckRead(sec, NULL, filename);
  99. - if (res == 0) {
  100. - xsltTransformError(NULL, NULL, NULL,
  101. - "xsltParseStylesheetFile: read rights for %s denied\n",
  102. - filename);
  103. + if (res <= 0) {
  104. + if (res == 0)
  105. + xsltTransformError(NULL, NULL, NULL,
  106. + "xsltParseStylesheetFile: read rights for %s denied\n",
  107. + filename);
  108. return(NULL);
  109. }
  110. }
  111. --
  112. 2.11.0