messages
listlengths
3
3
metadata
dict
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2013-1418\n\nThe setup_server_realm function in main.c in the Key Distribution Center (KDC) in MIT Kerberos 5 (aka krb5) before 1.10.7, when multiple realms are configured, allows remote attackers to cause a denial of service (NULL pointer dereference and daemon crash) via a crafted request.\n\n## Package\nkrb5-mini\n\n## Files to modify\n- src/lib/krb5/os/changepw.c\n- krb5-1.10.2.orig/src/lib/krb5/os/changepw.c\n\n## Target Source Code\n\n### src/lib/krb5/os/changepw.c\n\n#### change_set_password() [lines 362-427]\n```c\n krb5_data *result_code_string,\n krb5_data *result_string)\n{\n return change_set_password(context, creds, newpw, NULL,\n result_code, result_code_string, result_string );\n}\n\n/*\n * krb5_set_password - Implements set password per RFC 3244\n *\n */\n\nkrb5_error_code KRB5_CALLCONV\nkrb5_set_password(krb5_context context,\n krb5_creds *creds,\n char *newpw,\n krb5_principal change_password_for,\n int *result_code,\n krb5_data *result_code_string,\n krb5_data *result_string\n)\n{\n return change_set_password(context, creds, newpw, change_password_for,\n result_code, result_code_string, result_string );\n}\n\nkrb5_error_code KRB5_CALLCONV\nkrb5_set_password_using_ccache(krb5_context context,\n krb5_ccache ccache,\n char *newpw,\n krb5_principal change_password_for,\n int *result_code,\n krb5_data *result_code_string,\n krb5_data *result_string\n)\n{\n krb5_creds creds;\n krb5_creds *credsp;\n krb5_error_code code;\n\n /*\n ** get the proper creds for use with krb5_set_password -\n */\n memset (&creds, 0, sizeof(creds));\n /*\n ** first get the principal for the password service -\n */\n code = krb5_cc_get_principal (context, ccache, &creds.client);\n if (!code) {\n code = krb5_build_principal(context, &creds.server,\n krb5_princ_realm(context, change_password_for)->length,\n krb5_princ_realm(context, change_password_for)->data,\n \"kadmin\", \"changepw\", NULL);\n if (!code) {\n code = krb5_get_credentials(context, 0, ccache, &creds, &credsp);\n if (!code) {\n code = krb5_set_password(context, credsp, newpw, change_password_for,\n result_code, result_code_string,\n result_string);\n krb5_free_creds(context, credsp);\n }\n }\n krb5_free_cred_contents(context, &creds);\n }\n return code;\n}\n```\n\n\n## Upstream Fix\n```diff\nFall back to TCP on kdc-unresolvable/unreachable errors. We still have\nto wait for UDP to fail, so this might not be ideal. RT #5868.\n\nIndex: krb5-1.10.2/src/lib/krb5/os/changepw.c\n===================================================================\n--- krb5-1.10.2.orig/src/lib/krb5/os/changepw.c\n+++ krb5-1.10.2/src/lib/krb5/os/changepw.c\n@@ -274,10 +274,22 @@ change_set_password(krb5_context context\n &callback_info, &chpw_rep, ss2sa(&remote_addr),\n &addrlen, NULL, NULL, NULL);\n if (code) {\n- /*\n- * Here we may want to switch to TCP on some errors.\n- * right?\n- */\n+ /* if we're not using a stream socket, and it's an error which\n+ * might reasonably be specific to a datagram \"connection\", try\n+ * again with a stream socket */\n+ if (!use_tcp) {\n+ switch (code) {\n+ case KRB5_KDC_UNREACH:\n+ case KRB5_REALM_CANT_RESOLVE:\n+ case KRB5KRB_ERR_RESPONSE_TOO_BIG:\n+ /* should we do this for more result codes than these? */\n+ k5_free_serverlist (&sl);\n+ use_tcp = 1;\n+ continue;\n+ default:\n+ break;\n+ }\n+ }\n break;\n }\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "Fall back to TCP on kdc-unresolvable/unreachable errors. We still have\nto wait for UDP to fail, so this might not be ideal. RT #5868.\n\nIndex: krb5-1.10.2/src/lib/krb5/os/changepw.c\n===================================================================\n--- krb5-1.10.2.orig/src/lib/krb5/os/changepw.c\n+++ krb5-1.10.2/src/lib/krb5/os/changepw.c\n@@ -274,10 +274,22 @@ change_set_password(krb5_context context\n &callback_info, &chpw_rep, ss2sa(&remote_addr),\n &addrlen, NULL, NULL, NULL);\n if (code) {\n- /*\n- * Here we may want to switch to TCP on some errors.\n- * right?\n- */\n+ /* if we're not using a stream socket, and it's an error which\n+ * might reasonably be specific to a datagram \"connection\", try\n+ * again with a stream socket */\n+ if (!use_tcp) {\n+ switch (code) {\n+ case KRB5_KDC_UNREACH:\n+ case KRB5_REALM_CANT_RESOLVE:\n+ case KRB5KRB_ERR_RESPONSE_TOO_BIG:\n+ /* should we do this for more result codes than these? */\n+ k5_free_serverlist (&sl);\n+ use_tcp = 1;\n+ continue;\n+ default:\n+ break;\n+ }\n+ }\n break;\n }" } ]
{ "id": "krb5-mini-2233-krb5-1.10-kpasswd_tcp.patch", "cve_id": "CVE-2013-1418", "package": "krb5-mini", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": true, "license": "MIT", "context_tokens_est": 615, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-2698\n\nThe iakerb_gss_export_sec_context function in lib/gssapi/krb5/iakerb.c in MIT Kerberos 5 (aka krb5) 1.14 pre-release 2015-09-14 improperly accesses a certain pointer, which allows remote authenticated users to cause a denial of service (memory corruption) or possibly have unspecified other impact by interacting with an application that calls the gss_export_sec_context function. NOTE: this vulnerability exists because of an incorrect fix for CVE-2015-2696.\n\n## Package\nkrb5\n\n## Files to modify\n- src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c\n\n## Upstream Fix\n```diff\nFrom d1f707024f1d0af6e54a18885322d70fa15ec4d3 Mon Sep 17 00:00:00 2001\nFrom: Greg Hudson <ghudson@mit.edu>\nDate: Fri, 5 Dec 2014 14:01:39 -0500\nSubject: [PATCH] Fix LDAP misused policy name crash [CVE-2014-5353]\n\nIn krb5_ldap_get_password_policy_from_dn, if LDAP_SEARCH returns\nsuccessfully with no results, return KRB5_KDB_NOENTRY instead of\nreturning success with a zeroed-out policy object. This fixes a null\ndereference when an admin attempts to use an LDAP ticket policy name\nas a password policy name.\n\nCVE-2014-5353:\n\nIn MIT krb5, when kadmind is configured to use LDAP for the KDC\ndatabase, an authenticated remote attacker can cause a NULL dereference\nby attempting to use a named ticket policy object as a password policy\nfor a principal. The attacker needs to be authenticated as a user who\nhas the elevated privilege for setting password policy by adding or\nmodifying principals.\n\nQueries to LDAP scoped to the krbPwdPolicy object class will correctly\nnot return entries of other classes, such as ticket policy objects, but\nmay return success with no returned elements if an object with the\nrequested DN exists in a different object class. In this case, the\nroutine to retrieve a password policy returned success with a password\npolicy object that consisted entirely of zeroed memory. In particular,\naccesses to the policy name will dereference a NULL pointer. KDC\noperation does not access the policy name field, but most kadmin\noperations involving the principal with incorrect password policy\nwill trigger the crash.\n\nThanks to Patrik Kis for reporting this problem.\n\nCVSSv2 Vector: AV:N/AC:M/Au:S/C:N/I:N/A:C/E:H/RL:OF/RC:C\n\n[kaduk@mit.edu: CVE description and CVSS score]\n\nticket: 8051 (new)\ntarget_version: 1.13.1\ntags: pullup\n---\n src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c b/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c\nindex 522773e95b9..6779f51c7bf 100644\n--- a/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c\n+++ b/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c\n@@ -314,10 +314,11 @@ krb5_ldap_get_password_policy_from_dn(krb5_context context, char *pol_name,\n LDAP_SEARCH(pol_dn, LDAP_SCOPE_BASE, \"(objectclass=krbPwdPolicy)\", password_policy_attributes);\n \n ent=ldap_first_entry(ld, result);\n- if (ent != NULL) {\n- if ((st = populate_policy(context, ld, ent, pol_name, *policy)) != 0)\n- goto cleanup;\n+ if (ent == NULL) {\n+ st = KRB5_KDB_NOENTRY;\n+ goto cleanup;\n }\n+ st = populate_policy(context, ld, ent, pol_name, *policy);\n \n cleanup:\n ldap_msgfree(result);\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From d1f707024f1d0af6e54a18885322d70fa15ec4d3 Mon Sep 17 00:00:00 2001\nFrom: Greg Hudson <ghudson@mit.edu>\nDate: Fri, 5 Dec 2014 14:01:39 -0500\nSubject: [PATCH] Fix LDAP misused policy name crash [CVE-2014-5353]\n\nIn krb5_ldap_get_password_policy_from_dn, if LDAP_SEARCH returns\nsuccessfully with no results, return KRB5_KDB_NOENTRY instead of\nreturning success with a zeroed-out policy object. This fixes a null\ndereference when an admin attempts to use an LDAP ticket policy name\nas a password policy name.\n\nCVE-2014-5353:\n\nIn MIT krb5, when kadmind is configured to use LDAP for the KDC\ndatabase, an authenticated remote attacker can cause a NULL dereference\nby attempting to use a named ticket policy object as a password policy\nfor a principal. The attacker needs to be authenticated as a user who\nhas the elevated privilege for setting password policy by adding or\nmodifying principals.\n\nQueries to LDAP scoped to the krbPwdPolicy object class will correctly\nnot return entries of other classes, such as ticket policy objects, but\nmay return success with no returned elements if an object with the\nrequested DN exists in a different object class. In this case, the\nroutine to retrieve a password policy returned success with a password\npolicy object that consisted entirely of zeroed memory. In particular,\naccesses to the policy name will dereference a NULL pointer. KDC\noperation does not access the policy name field, but most kadmin\noperations involving the principal with incorrect password policy\nwill trigger the crash.\n\nThanks to Patrik Kis for reporting this problem.\n\nCVSSv2 Vector: AV:N/AC:M/Au:S/C:N/I:N/A:C/E:H/RL:OF/RC:C\n\n[kaduk@mit.edu: CVE description and CVSS score]\n\nticket: 8051 (new)\ntarget_version: 1.13.1\ntags: pullup\n---\n src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c b/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c\nindex 522773e..6779f51 100644\n--- a/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c\n+++ b/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c\n@@ -314,10 +314,11 @@ krb5_ldap_get_password_policy_from_dn(krb5_context context, char *pol_name,\n LDAP_SEARCH(pol_dn, LDAP_SCOPE_BASE, \"(objectclass=krbPwdPolicy)\", password_policy_attributes);\n \n ent=ldap_first_entry(ld, result);\n- if (ent != NULL) {\n- if ((st = populate_policy(context, ld, ent, pol_name, *policy)) != 0)\n- goto cleanup;\n+ if (ent == NULL) {\n+ st = KRB5_KDB_NOENTRY;\n+ goto cleanup;\n }\n+ st = populate_policy(context, ld, ent, pol_name, *policy);\n \n cleanup:\n ldap_msgfree(result);" } ]
{ "id": "krb5-4431-krb5-1.12.2-CVE-2014-5353.patc", "cve_id": "CVE-2015-2698", "package": "krb5", "upstream_enriched": true, "upstream_commit": "d1f707024f1d0af6e54a18885322d70fa15ec4d3", "upstream_repo": "krb5/krb5", "tier": "adapted", "has_source_context": false, "license": "MIT", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-5276\n\nThe std::random_device class in libstdc++ in the GNU Compiler Collection (aka GCC) before 4.9.4 does not properly handle short reads from blocking sources, which makes it easier for context-dependent attackers to predict the random values via unspecified vectors.\n\n## Package\ngcc5\n\n## Files to modify\n- gcc/fortran/simplify.c\n- gcc/ubsan.c\n\n## Upstream Fix\n```diff\nIndex: configure.ac\n===================================================================\n--- configure.ac\t(revision 216911)\n+++ configure.ac\t(working copy)\n@@ -1454,7 +1454,7 @@ if test -d ${srcdir}/gcc && test \"x$have\n AC_MSG_CHECKING([for the correct version of mpfr.h])\n AC_TRY_COMPILE([#include <gmp.h>\n #include <mpfr.h>],[\n- #if MPFR_VERSION < MPFR_VERSION_NUM(2,4,0)\n+ #if MPFR_VERSION < MPFR_VERSION_NUM(2,3,1)\n choke me\n #endif\n ], [AC_TRY_COMPILE([#include <gmp.h>\nIndex: configure\n===================================================================\n--- configure\t(revision 216911)\n+++ configure\t(working copy)\n@@ -5524,7 +5524,7 @@ int\n main ()\n {\n \n- #if MPFR_VERSION < MPFR_VERSION_NUM(2,4,0)\n+ #if MPFR_VERSION < MPFR_VERSION_NUM(2,3,1)\n choke me\n #endif\n \nIndex: gcc/fortran/simplify.c\n===================================================================\n--- gcc/fortran/simplify.c\t(revision 216911)\n+++ gcc/fortran/simplify.c\t(working copy)\n@@ -4278,10 +4278,7 @@ gfc_simplify_mod (gfc_expr *a, gfc_expr\n \t return &gfc_bad_expr;\n \t }\n \n-\tgfc_set_model_kind (kind);\n-\tmpfr_fmod (result->value.real, a->value.real, p->value.real,\n-\t\t GFC_RND_MODE);\n-\tbreak;\n+\treturn NULL;\n \n default:\n \tgfc_internal_error (\"gfc_simplify_mod(): Bad arguments\");\n@@ -4327,19 +4324,7 @@ gfc_simplify_modulo (gfc_expr *a, gfc_ex\n \t return &gfc_bad_expr;\n \t }\n \n-\tgfc_set_model_kind (kind);\n-\tmpfr_fmod (result->value.real, a->value.real, p->value.real,\n-\t\t GFC_RND_MODE);\n-\tif (mpfr_cmp_ui (result->value.real, 0) != 0)\n-\t {\n-\t if (mpfr_signbit (a->value.real) != mpfr_signbit (p->value.real))\n-\t mpfr_add (result->value.real, result->value.real, p->value.real,\n-\t\t\tGFC_RND_MODE);\n-\t }\n-\telse\n-\t mpfr_copysign (result->value.real, result->value.real,\n-\t\t\t p->value.real, GFC_RND_MODE);\n-\tbreak;\n+\treturn NULL;\n \n default:\n \tgfc_internal_error (\"gfc_simplify_modulo(): Bad arguments\");\nIndex: gcc/ubsan.c\n===================================================================\n--- gcc/ubsan.c.orig\t2015-06-01 14:52:11.717105684 +0200\n+++ gcc/ubsan.c\t2015-06-01 14:52:26.945253071 +0200\n@@ -1564,40 +1564,6 @@\n \t min = build_real (expr_type, minval2);\n \t}\n }\n- else if (REAL_MODE_FORMAT (mode)->b == 10)\n- {\n- /* For _Decimal128 up to 34 decimal digits, - sign,\n-\t dot, e, exponent. */\n- char buf[64];\n- mpfr_t m;\n- int p = REAL_MODE_FORMAT (mode)->p;\n- REAL_VALUE_TYPE maxval, minval;\n-\n- /* Use mpfr_snprintf rounding to compute the smallest\n-\t representable decimal number greater or equal than\n-\t 1 << (prec - !uns_p). */\n- mpfr_init2 (m, prec + 2);\n- mpfr_set_ui_2exp (m, 1, prec - !uns_p, GMP_RNDN);\n- mpfr_snprintf (buf, sizeof buf, \"%.*RUe\", p - 1, m);\n- decimal_real_from_string (&maxval, buf);\n- max = build_real (expr_type, maxval);\n-\n- /* For unsigned, assume -1.0 is always representable. */\n- if (uns_p)\n-\tmin = build_minus_one_cst (expr_type);\n- else\n-\t{\n-\t /* Use mpfr_snprintf rounding to compute the largest\n-\t representable decimal number less or equal than\n-\t (-1 << (prec - 1)) - 1. */\n-\t mpfr_set_si_2exp (m, -1, prec - 1, GMP_RNDN);\n-\t mpfr_sub_ui (m, m, 1, GMP_RNDN);\n-\t mpfr_snprintf (buf, sizeof buf, \"%.*RDe\", p - 1, m);\n-\t decimal_real_from_string (&minval, buf);\n-\t min = build_real (expr_type, minval);\n-\t}\n- mpfr_clear (m);\n- }\n else\n return NULL_TREE;\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "Index: configure.ac\n===================================================================\n--- configure.ac\t(revision 216911)\n+++ configure.ac\t(working copy)\n@@ -1454,7 +1454,7 @@ if test -d ${srcdir}/gcc && test \"x$have\n AC_MSG_CHECKING([for the correct version of mpfr.h])\n AC_TRY_COMPILE([#include <gmp.h>\n #include <mpfr.h>],[\n- #if MPFR_VERSION < MPFR_VERSION_NUM(2,4,0)\n+ #if MPFR_VERSION < MPFR_VERSION_NUM(2,3,1)\n choke me\n #endif\n ], [AC_TRY_COMPILE([#include <gmp.h>\nIndex: configure\n===================================================================\n--- configure\t(revision 216911)\n+++ configure\t(working copy)\n@@ -5524,7 +5524,7 @@ int\n main ()\n {\n \n- #if MPFR_VERSION < MPFR_VERSION_NUM(2,4,0)\n+ #if MPFR_VERSION < MPFR_VERSION_NUM(2,3,1)\n choke me\n #endif\n \nIndex: gcc/fortran/simplify.c\n===================================================================\n--- gcc/fortran/simplify.c\t(revision 216911)\n+++ gcc/fortran/simplify.c\t(working copy)\n@@ -4278,10 +4278,7 @@ gfc_simplify_mod (gfc_expr *a, gfc_expr\n \t return &gfc_bad_expr;\n \t }\n \n-\tgfc_set_model_kind (kind);\n-\tmpfr_fmod (result->value.real, a->value.real, p->value.real,\n-\t\t GFC_RND_MODE);\n-\tbreak;\n+\treturn NULL;\n \n default:\n \tgfc_internal_error (\"gfc_simplify_mod(): Bad arguments\");\n@@ -4327,19 +4324,7 @@ gfc_simplify_modulo (gfc_expr *a, gfc_ex\n \t return &gfc_bad_expr;\n \t }\n \n-\tgfc_set_model_kind (kind);\n-\tmpfr_fmod (result->value.real, a->value.real, p->value.real,\n-\t\t GFC_RND_MODE);\n-\tif (mpfr_cmp_ui (result->value.real, 0) != 0)\n-\t {\n-\t if (mpfr_signbit (a->value.real) != mpfr_signbit (p->value.real))\n-\t mpfr_add (result->value.real, result->value.real, p->value.real,\n-\t\t\tGFC_RND_MODE);\n-\t }\n-\telse\n-\t mpfr_copysign (result->value.real, result->value.real,\n-\t\t\t p->value.real, GFC_RND_MODE);\n-\tbreak;\n+\treturn NULL;\n \n default:\n \tgfc_internal_error (\"gfc_simplify_modulo(): Bad arguments\");\nIndex: gcc/ubsan.c\n===================================================================\n--- gcc/ubsan.c.orig\t2015-06-01 14:52:11.717105684 +0200\n+++ gcc/ubsan.c\t2015-06-01 14:52:26.945253071 +0200\n@@ -1564,40 +1564,6 @@\n \t min = build_real (expr_type, minval2);\n \t}\n }\n- else if (REAL_MODE_FORMAT (mode)->b == 10)\n- {\n- /* For _Decimal128 up to 34 decimal digits, - sign,\n-\t dot, e, exponent. */\n- char buf[64];\n- mpfr_t m;\n- int p = REAL_MODE_FORMAT (mode)->p;\n- REAL_VALUE_TYPE maxval, minval;\n-\n- /* Use mpfr_snprintf rounding to compute the smallest\n-\t representable decimal number greater or equal than\n-\t 1 << (prec - !uns_p). */\n- mpfr_init2 (m, prec + 2);\n- mpfr_set_ui_2exp (m, 1, prec - !uns_p, GMP_RNDN);\n- mpfr_snprintf (buf, sizeof buf, \"%.*RUe\", p - 1, m);\n- decimal_real_from_string (&maxval, buf);\n- max = build_real (expr_type, maxval);\n-\n- /* For unsigned, assume -1.0 is always representable. */\n- if (uns_p)\n-\tmin = build_minus_one_cst (expr_type);\n- else\n-\t{\n-\t /* Use mpfr_snprintf rounding to compute the largest\n-\t representable decimal number less or equal than\n-\t (-1 << (prec - 1)) - 1. */\n-\t mpfr_set_si_2exp (m, -1, prec - 1, GMP_RNDN);\n-\t mpfr_sub_ui (m, m, 1, GMP_RNDN);\n-\t mpfr_snprintf (buf, sizeof buf, \"%.*RDe\", p - 1, m);\n-\t decimal_real_from_string (&minval, buf);\n-\t min = build_real (expr_type, minval);\n-\t}\n- mpfr_clear (m);\n- }\n else\n return NULL_TREE;" } ]
{ "id": "gcc5-4931-gcc48-remove-mpfr-2.4.0-requir", "cve_id": "CVE-2015-5276", "package": "gcc5", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": false, "license": "GPL-3.0-or-later", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2014-9819\n\nHeap-based buffer overflow in ImageMagick allows remote attackers to have unspecified impact via a crafted palm file, a different vulnerability than CVE-2014-9823.\n\n## Package\nGraphicsMagick\n\n## Files to modify\n- coders/svg.c\n- GraphicsMagick-1.3.20.orig/coders/svg.c\n- magick/render.c\n- GraphicsMagick-1.3.20.orig/magick/render.c\n\n## Upstream Fix\n```diff\nIndex: GraphicsMagick-1.3.20/coders/svg.c\n===================================================================\n--- GraphicsMagick-1.3.20.orig/coders/svg.c\t2013-03-10 00:19:31.000000000 +0100\n+++ GraphicsMagick-1.3.20/coders/svg.c\t2016-06-23 10:05:21.805840780 +0200\n@@ -316,25 +316,22 @@ static char **GetTransformTokens(void *c\n *p,\n *q;\n \n- register long\n+ register size_t\n i;\n \n SVGInfo\n *svg_info;\n \n+ size_t\n+ alloc_tokens;\n+\n svg_info=(SVGInfo *) context;\n *number_tokens=0;\n if (text == (const char *) NULL)\n return((char **) NULL);\n- /*\n- Determine the number of arguments.\n- */\n- for (p=text; *p != '\\0'; p++)\n- {\n- if (*p == '(')\n- (*number_tokens)+=2;\n- }\n- tokens=MagickAllocateMemory(char **,(*number_tokens+2)*sizeof(*tokens));\n+\n+ alloc_tokens=8;\n+ tokens=MagickAllocateMemory(char **,(alloc_tokens+2)*sizeof(*tokens));\n if (tokens == (char **) NULL)\n {\n ThrowException3(svg_info->exception,ResourceLimitError,\n@@ -350,15 +347,28 @@ static char **GetTransformTokens(void *c\n {\n if ((*q != '(') && (*q != ')') && (*q != '\\0'))\n continue;\n+ if (i == alloc_tokens)\n+ {\n+ alloc_tokens <<= 1;\n+ MagickReallocMemory(char **,tokens,(alloc_tokens+2)*sizeof(*tokens));\n+ if (tokens == (char **) NULL)\n+ {\n+ ThrowException3(svg_info->exception,ResourceLimitError,\n+ MemoryAllocationFailed,UnableToConvertStringToTokens);\n+ return((char **) NULL);\n+ }\n+ }\n tokens[i]=AllocateString(p);\n (void) strlcpy(tokens[i],p,q-p+1);\n- Strip(tokens[i++]);\n+ Strip(tokens[i]);\n+ i++;\n p=q+1;\n }\n tokens[i]=AllocateString(p);\n (void) strlcpy(tokens[i],p,q-p+1);\n Strip(tokens[i++]);\n tokens[i]=(char *) NULL;\n+ *number_tokens=i;\n return(tokens);\n }\n \n@@ -1177,18 +1187,20 @@ static void SVGStartElement(void *contex\n IdentityAffine(&transform);\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\" \");\n tokens=GetTransformTokens(context,value,&number_tokens);\n- for (j=0; j < (number_tokens-1); j+=2)\n+ if ((tokens != (char **) NULL) && (number_tokens > 0))\n {\n- keyword=(char *) tokens[j];\n- if (keyword == (char *) NULL)\n- continue;\n- value=(char *) tokens[j+1];\n- (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n- \" %.1024s: %.1024s\",keyword,value);\n- current=transform;\n- IdentityAffine(&affine);\n- switch (*keyword)\n+ for (j=0; j < (number_tokens-1); j+=2)\n {\n+ keyword=(char *) tokens[j];\n+ if (keyword == (char *) NULL)\n+ continue;\n+ value=(char *) tokens[j+1];\n+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n+ \" %.1024s: %.1024s\",keyword,value);\n+ current=transform;\n+ IdentityAffine(&affine);\n+ switch (*keyword)\n+ {\n case 'M':\n case 'm':\n {\n@@ -1293,22 +1305,23 @@ static void SVGStartElement(void *contex\n }\n default:\n break;\n- }\n- transform.sx=current.sx*affine.sx+current.ry*affine.rx;\n- transform.rx=current.rx*affine.sx+current.sy*affine.rx;\n- transform.ry=current.sx*affine.ry+current.ry*affine.sy;\n- transform.sy=current.rx*affine.ry+current.sy*affine.sy;\n- transform.tx=current.sx*affine.tx+current.ry*affine.ty+\n- current.tx;\n- transform.ty=current.rx*affine.tx+current.sy*affine.ty+\n- current.ty;\n- }\n- MVGPrintf(svg_info->file,\"affine %g %g %g %g %g %g\\n\",\n- transform.sx,transform.rx,transform.ry,transform.sy,\n- transform.tx,transform.ty);\n- for (j=0; tokens[j] != (char *) NULL; j++)\n- MagickFreeMemory(tokens[j]);\n- MagickFreeMemory(tokens);\n+ } /* end switch */\n+ transform.sx=current.sx*affine.sx+current.ry*affine.rx;\n+ transform.rx=current.rx*affine.sx+current.sy*affine.rx;\n+ transform.ry=current.sx*affine.ry+current.ry*affine.sy;\n+ transform.sy=current.rx*affine.ry+current.sy*affine.sy;\n+ transform.tx=current.sx*affine.tx+current.ry*affine.ty+\n+ current.tx;\n+ transform.ty=current.rx*affine.tx+current.sy*affine.ty+\n+ current.ty;\n+ } /* end for */\n+ MVGPrintf(svg_info->file,\"affine %g %g %g %g %g %g\\n\",\n+ transform.sx,transform.rx,transform.ry,transform.sy,\n+ transform.tx,transform.ty);\n+ for (j=0; tokens[j] != (char *) NULL; j++)\n+ MagickFreeMemory(tokens[j]);\n+ MagickFreeMemory(tokens);\n+ } /* end if */\n break;\n }\n if (LocaleCompare(keyword,\"gradientUnits\") == 0)\n@@ -1746,6 +1759,8 @@ static void SVGStartElement(void *contex\n IdentityAffine(&transform);\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\" \");\n tokens=GetTransformTokens(context,value,&number_tokens);\n+ if ((tokens != (char **) NULL) && (number_tokens > 0))\n+ {\n for (j=0; j < (number_tokens-1); j+=2)\n {\n keyword=(char *) tokens[j];\n@@ -1873,8 +1888,10 @@ static void SVGStartElement(void *contex\n MVGPrintf(svg_info->file,\"affine %g %g %g %g %g %g\\n\",\n transform.sx,transform.rx,transform.ry,transform.sy,\n transform.tx,transform.ty);\n- for (j=0; tokens[j] != (char *) NULL; j++)\n- MagickFreeMemory(tokens[j]);\n+ }\n+ if (number_tokens > 0)\n+ for (j=0; tokens[j] != (char *) NULL; j++)\n+ MagickFreeMemory(tokens[j]);\n MagickFreeMemory(tokens);\n break;\n }\nIndex: GraphicsMagick-1.3.20/magick/render.c\n===================================================================\n--- GraphicsMagick-1.3.20.orig/magick/render.c\t2016-06-23 10:05:21.649838266 +0200\n+++ GraphicsMagick-1.3.20/magick/render.c\t2016-06-23 10:05:21.805840780 +0200\n@@ -432,7 +432,7 @@ ConvertPathToPolygon(const PathInfo *pat\n {\n number_edges<<=1;\n MagickReallocMemory(EdgeInfo *,polygon_info->edges,\n- number_edges*sizeof(EdgeInfo));\n+ MagickArraySize(number_edges,sizeof(EdgeInfo)));\n if (polygon_info->edges == (EdgeInfo *) NULL)\n return((PolygonInfo *) NULL);\n }\n@@ -484,7 +484,7 @@ ConvertPathToPolygon(const PathInfo *pat\n {\n number_edges<<=1;\n MagickReallocMemory(EdgeInfo *,polygon_info->edges,\n- number_edges*sizeof(EdgeInfo));\n+ MagickArraySize(number_edges,sizeof(EdgeInfo)));\n if (polygon_info->edges == (EdgeInfo *) NULL)\n return((PolygonInfo *) NULL);\n }\n@@ -517,7 +517,7 @@ ConvertPathToPolygon(const PathInfo *pat\n if (n == number_points)\n {\n number_points<<=1;\n- MagickReallocMemory(PointInfo *,points,number_points*sizeof(PointInfo));\n+ MagickReallocMemory(PointInfo *,points,MagickArraySize(number_points,sizeof(PointInfo)));\n if (points == (PointInfo *) NULL)\n return((PolygonInfo *) NULL);\n }\n@@ -541,7 +541,7 @@ ConvertPathToPolygon(const PathInfo *p\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "Index: GraphicsMagick-1.3.20/coders/svg.c\n===================================================================\n--- GraphicsMagick-1.3.20.orig/coders/svg.c\t2013-03-10 00:19:31.000000000 +0100\n+++ GraphicsMagick-1.3.20/coders/svg.c\t2016-06-23 10:05:21.805840780 +0200\n@@ -316,25 +316,22 @@ static char **GetTransformTokens(void *c\n *p,\n *q;\n \n- register long\n+ register size_t\n i;\n \n SVGInfo\n *svg_info;\n \n+ size_t\n+ alloc_tokens;\n+\n svg_info=(SVGInfo *) context;\n *number_tokens=0;\n if (text == (const char *) NULL)\n return((char **) NULL);\n- /*\n- Determine the number of arguments.\n- */\n- for (p=text; *p != '\\0'; p++)\n- {\n- if (*p == '(')\n- (*number_tokens)+=2;\n- }\n- tokens=MagickAllocateMemory(char **,(*number_tokens+2)*sizeof(*tokens));\n+\n+ alloc_tokens=8;\n+ tokens=MagickAllocateMemory(char **,(alloc_tokens+2)*sizeof(*tokens));\n if (tokens == (char **) NULL)\n {\n ThrowException3(svg_info->exception,ResourceLimitError,\n@@ -350,15 +347,28 @@ static char **GetTransformTokens(void *c\n {\n if ((*q != '(') && (*q != ')') && (*q != '\\0'))\n continue;\n+ if (i == alloc_tokens)\n+ {\n+ alloc_tokens <<= 1;\n+ MagickReallocMemory(char **,tokens,(alloc_tokens+2)*sizeof(*tokens));\n+ if (tokens == (char **) NULL)\n+ {\n+ ThrowException3(svg_info->exception,ResourceLimitError,\n+ MemoryAllocationFailed,UnableToConvertStringToTokens);\n+ return((char **) NULL);\n+ }\n+ }\n tokens[i]=AllocateString(p);\n (void) strlcpy(tokens[i],p,q-p+1);\n- Strip(tokens[i++]);\n+ Strip(tokens[i]);\n+ i++;\n p=q+1;\n }\n tokens[i]=AllocateString(p);\n (void) strlcpy(tokens[i],p,q-p+1);\n Strip(tokens[i++]);\n tokens[i]=(char *) NULL;\n+ *number_tokens=i;\n return(tokens);\n }\n \n@@ -1177,18 +1187,20 @@ static void SVGStartElement(void *contex\n IdentityAffine(&transform);\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\" \");\n tokens=GetTransformTokens(context,value,&number_tokens);\n- for (j=0; j < (number_tokens-1); j+=2)\n+ if ((tokens != (char **) NULL) && (number_tokens > 0))\n {\n- keyword=(char *) tokens[j];\n- if (keyword == (char *) NULL)\n- continue;\n- value=(char *) tokens[j+1];\n- (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n- \" %.1024s: %.1024s\",keyword,value);\n- current=transform;\n- IdentityAffine(&affine);\n- switch (*keyword)\n+ for (j=0; j < (number_tokens-1); j+=2)\n {\n+ keyword=(char *) tokens[j];\n+ if (keyword == (char *) NULL)\n+ continue;\n+ value=(char *) tokens[j+1];\n+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n+ \" %.1024s: %.1024s\",keyword,value);\n+ current=transform;\n+ IdentityAffine(&affine);\n+ switch (*keyword)\n+ {\n case 'M':\n case 'm':\n {\n@@ -1293,22 +1305,23 @@ static void SVGStartElement(void *contex\n }\n default:\n break;\n- }\n- transform.sx=current.sx*affine.sx+current.ry*affine.rx;\n- transform.rx=current.rx*affine.sx+current.sy*affine.rx;\n- transform.ry=current.sx*affine.ry+current.ry*affine.sy;\n- transform.sy=current.rx*affine.ry+current.sy*affine.sy;\n- transform.tx=current.sx*affine.tx+current.ry*affine.ty+\n- current.tx;\n- transform.ty=current.rx*affine.tx+current.sy*affine.ty+\n- current.ty;\n- }\n- MVGPrintf(svg_info->file,\"affine %g %g %g %g %g %g\\n\",\n- transform.sx,transform.rx,transform.ry,transform.sy,\n- transform.tx,transform.ty);\n- for (j=0; tokens[j] != (char *) NULL; j++)\n- MagickFreeMemory(tokens[j]);\n- MagickFreeMemory(tokens);\n+ } /* end switch */\n+ transform.sx=current.sx*affine.sx+current.ry*affine.rx;\n+ transform.rx=current.rx*affine.sx+current.sy*affine.rx;\n+ transform.ry=current.sx*affine.ry+current.ry*affine.sy;\n+ transform.sy=current.rx*affine.ry+current.sy*affine.sy;\n+ transform.tx=current.sx*affine.tx+current.ry*affine.ty+\n+ current.tx;\n+ transform.ty=current.rx*affine.tx+current.sy*affine.ty+\n+ current.ty;\n+ } /* end for */\n+ MVGPrintf(svg_info->file,\"affine %g %g %g %g %g %g\\n\",\n+ transform.sx,transform.rx,transform.ry,transform.sy,\n+ transform.tx,transform.ty);\n+ for (j=0; tokens[j] != (char *) NULL; j++)\n+ MagickFreeMemory(tokens[j]);\n+ MagickFreeMemory(tokens);\n+ } /* end if */\n break;\n }\n if (LocaleCompare(keyword,\"gradientUnits\") == 0)\n@@ -1746,6 +1759,8 @@ static void SVGStartElement(void *contex\n IdentityAffine(&transform);\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\" \");\n tokens=GetTransformTokens(context,value,&number_tokens);\n+ if ((tokens != (char **) NULL) && (number_tokens > 0))\n+ {\n for (j=0; j < (number_tokens-1); j+=2)\n {\n keyword=(char *) tokens[j];\n@@ -1873,8 +1888,10 @@ static void SVGStartElement(void *contex\n MVGPrintf(svg_info->file,\"affine %g %g %g %g %g %g\\n\",\n transform.sx,transform.rx,transform.ry,transform.sy,\n transform.tx,transform.ty);\n- for (j=0; tokens[j] != (char *) NULL; j++)\n- MagickFreeMemory(tokens[j]);\n+ }\n+ if (number_tokens > 0)\n+ for (j=0; tokens[j] != (char *) NULL; j++)\n+ MagickFreeMemory(tokens[j]);\n MagickFreeMemory(tokens);\n break;\n }\nIndex: GraphicsMagick-1.3.20/magick/render.c\n===================================================================\n--- GraphicsMagick-1.3.20.orig/magick/render.c\t2016-06-23 10:05:21.649838266 +0200\n+++ GraphicsMagick-1.3.20/magick/render.c\t2016-06-23 10:05:21.805840780 +0200\n@@ -432,7 +432,7 @@ ConvertPathToPolygon(const PathInfo *pat\n {\n number_edges<<=1;\n MagickReallocMemory(EdgeInfo *,polygon_info->edges,\n- number_edges*sizeof(EdgeInfo));\n+ MagickArraySize(number_edges,sizeof(EdgeInfo)));\n if (polygon_info->edges == (EdgeInfo *) NULL)\n return((PolygonInfo *) NULL);\n }\n@@ -484,7 +484,7 @@ ConvertPathToPolygon(const PathInfo *pat\n {\n number_edges<<=1;\n MagickReallocMemory(EdgeInfo *,polygon_info->edges,\n- number_edges*sizeof(EdgeInfo));\n+ MagickArraySize(number_edges,sizeof(EdgeInfo)));\n if (polygon_info->edges == (EdgeInfo *) NULL)\n return((PolygonInfo *) NULL);\n }\n@@ -517,7 +517,7 @@ ConvertPathToPolygon(const PathInfo *pat\n if (n == number_points)\n {\n number_points<<=1;\n- MagickReallocMemory(PointInfo *,points,number_points*sizeof(PointInfo));\n+ MagickReallocMemory(PointInfo *,points,MagickArraySize(number_points,sizeof(PointInfo)));\n if (points == (PointInfo *) NULL)\n return((PolygonInfo *) NULL);\n }\n@@ -541,7 +541,7 @@ ConvertPathToPolygon(const PathInfo *pat\n {\n number_edges<<=1;\n MagickReallocMemory(EdgeInfo *,polygon_info->edges,\n- number_edges*sizeof(EdgeInfo));\n+ MagickArraySize(number_edges,sizeof(EdgeInfo)));\n if (polygon_info->edges == (EdgeInfo *) NULL)\n return((PolygonInfo *) NULL);\n }\n@@ -2309,7 +2309,7 @@ DrawImage(Image *image,const DrawInfo *d\n {\n n++;\n MagickReallocMemory(DrawInfo **,graphic_context,\n- (n+1)*sizeof(DrawInfo *));\n+ MagickArraySize((n+1),sizeof(DrawInfo *)));\n if (graphic_context == (DrawInfo **) NULL)\n {\n ThrowException3(&image->exception,ResourceLimitError,\n@@ -2671,7 +2671,7 @@ DrawImage(Image *image,const DrawInfo *d\n continue;\n number_points<<=1;\n MagickReallocMemory(PrimitiveInfo *,primitive_info,\n- number_points*sizeof(PrimitiveInfo));\n+ MagickArraySize(number_points,sizeof(PrimitiveInfo)));\n if (primitive_info == (PrimitiveInfo *) NULL)\n {\n ThrowException3(&image->exception,ResourceLimitError,\n@@ -2777,7 +2777,7 @@ DrawImage(Image *image,const DrawInfo *d\n {\n number_points+=length+1;\n MagickReallocMemory(PrimitiveInfo *,primitive_info,\n- number_points*sizeof(PrimitiveInfo));\n+ MagickArraySize(number_points,sizeof(PrimitiveInfo)));\n if (primitive_info == (PrimitiveInfo *) NULL)\n {\n ThrowException3(&image->exception,ResourceLimitError,\n@@ -5468,8 +5468,8 @@ TraceStrokePolygon(const DrawInfo *draw_\n if (q >= (max_strokes-6*BezierQuantum-360))\n {\n max_strokes+=6*BezierQuantum+360;\n- MagickReallocMemory(PointInfo *,path_p,max_strokes*sizeof(PointInfo));\n- MagickReallocMemory(PointInfo *,path_q,max_strokes*sizeof(PointInfo));\n+ MagickReallocMemory(PointInfo *,path_p,MagickArraySize(max_strokes,sizeof(PointInfo)));\n+ MagickReallocMemory(PointInfo *,path_q,MagickArraySize(max_strokes,sizeof(PointInfo)));\n if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL))\n {\n MagickFreeMemory(polygon_primitive);" } ]
{ "id": "GraphicsMagick-5467-GraphicsMagick-CVE-2016-2317.p", "cve_id": "CVE-2014-9819", "package": "GraphicsMagick", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": false, "license": "MIT", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2014-9761\n\nMultiple stack-based buffer overflows in the GNU C Library (aka glibc or libc6) before 2.23 allow context-dependent attackers to cause a denial of service (application crash) or possibly execute arbitrary code via a long argument to the (1) nan, (2) nanf, or (3) nanl function.\n\n## Package\nglibc-utils\n\n## Files to modify\n- glibc-2.19.orig/nss/nss_files/files-alias.c\n- glibc-2.19.orig/nis/nss_compat/compat-grp.c\n- glibc-2.19.orig/nis/nss_compat/compat-pwd.c\n- glibc-2.19.orig/nis/nss_compat/compat-spwd.c\n- nss/nss_files/files-XXX.c\n\n## Target Source Code\n\n### nis/nss_compat/compat-grp.c\n\n#### _nss_compat_setgrent() [lines 174-193]\n```c\n\n\nenum nss_status\n_nss_compat_setgrent (int stayopen)\n{\n enum nss_status result;\n\n __libc_lock_lock (lock);\n\n if (ni == NULL)\n init_nss_interface ();\n\n result = internal_setgrent (&ext_ent, stayopen, 1);\n\n __libc_lock_unlock (lock);\n\n return result;\n}\n\n\n```\n\n#### _nss_compat_endgrent() [lines 216-232]\n```c\n}\n\nenum nss_status\n_nss_compat_endgrent (void)\n{\n enum nss_status result;\n\n __libc_lock_lock (lock);\n\n result = internal_endgrent (&ext_ent);\n\n __libc_lock_unlock (lock);\n\n return result;\n}\n\n/* get the next group from NSS (+ entry) */\n```\n\n### nis/nss_compat/compat-pwd.c\n\n#### _nss_compat_setpwent() [lines 291-310]\n```c\n\n\nenum nss_status\n_nss_compat_setpwent (int stayopen)\n{\n enum nss_status result;\n\n __libc_lock_lock (lock);\n\n if (ni == NULL)\n init_nss_interface ();\n\n result = internal_setpwent (&ext_ent, stayopen, 1);\n\n __libc_lock_unlock (lock);\n\n return result;\n}\n\n\n```\n\n#### _nss_compat_endpwent() [lines 340-356]\n```c\n}\n\nenum nss_status\n_nss_compat_endpwent (void)\n{\n enum nss_status result;\n\n __libc_lock_lock (lock);\n\n result = internal_endpwent (&ext_ent);\n\n __libc_lock_unlock (lock);\n\n return result;\n}\n\n\n```\n\n### nis/nss_compat/compat-spwd.c\n\n#### copy_spwd_changes() [lines 134-171]\n```c\n}\n\nstatic void\ncopy_spwd_changes (struct spwd *dest, struct spwd *src,\n\t\t char *buffer, size_t buflen)\n{\n if (src->sp_pwdp != NULL && strlen (src->sp_pwdp))\n {\n if (buffer == NULL)\n\tdest->sp_pwdp = strdup (src->sp_pwdp);\n else if (dest->sp_pwdp &&\n\t strlen (dest->sp_pwdp) >= strlen (src->sp_pwdp))\n\tstrcpy (dest->sp_pwdp, src->sp_pwdp);\n else\n\t{\n\t dest->sp_pwdp = buffer;\n\t strcpy (dest->sp_pwdp, src->sp_pwdp);\n\t buffer += strlen (dest->sp_pwdp) + 1;\n\t buflen = buflen - (strlen (dest->sp_pwdp) + 1);\n\t}\n }\n if (src->sp_lstchg != 0)\n dest->sp_lstchg = src->sp_lstchg;\n if (src->sp_min != 0)\n dest->sp_min = src->sp_min;\n if (src->sp_max != 0)\n dest->sp_max = src->sp_max;\n if (src->sp_warn != -1)\n dest->sp_warn = src->sp_warn;\n if (src->sp_inact != -1)\n dest->sp_inact = src->sp_inact;\n if (src->sp_expire != -1)\n dest->sp_expire = src->sp_expire;\n if (src->sp_flag != ~0ul)\n dest->sp_flag = src->sp_flag;\n}\n\nstatic enum nss_status\n```\n\n#### internal_setspent() [lines 169-248]\n```c\n}\n\nstatic enum nss_status\ninternal_setspent (ent_t *ent, int stayopen)\n{\n enum nss_status status = NSS_STATUS_SUCCESS;\n\n ent->first = ent->netgroup = 0;\n ent->files = true;\n\n /* If something was left over free it. */\n if (ent->netgroup)\n __internal_endnetgrent (&ent->netgrdata);\n\n if (ent->blacklist.data != NULL)\n {\n ent->blacklist.current = 1;\n ent->blacklist.data[0] = '|';\n ent->blacklist.data[1] = '\\0';\n }\n else\n ent->blacklist.current = 0;\n\n if (ent->stream == NULL)\n {\n ent->stream = fopen (\"/etc/shadow\", \"rme\");\n\n if (ent->stream == NULL)\n\tstatus = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;\n else\n\t{\n\t /* We have to make sure the file is `closed on exec'. */\n\t int result = 0;\n\n\t if (__compat_have_cloexec <= 0)\n\t {\n\t int flags;\n\t result = flags = fcntl (fileno_unlocked (ent->stream), F_GETFD,\n\t\t\t\t 0);\n\t if (result >= 0)\n\t\t{\n#if defined O_CLOEXEC && !defined __ASSUME_O_CLOEXEC\n\t\t if (__compat_have_cloexec == 0)\n/* ... truncated ... */\n```\n\n### nss/nss_files/files-XXX.c\n\n#### region() [lines 21-125]\n```c\n#include <errno.h>\n#include <fcntl.h>\n#include <bits/libc-lock.h>\n#include \"nsswitch.h\"\n\n#include <kernel-features.h>\n\n/* These symbols are defined by the including source file:\n\n ENTNAME -- database name of the structure and functions (hostent, pwent).\n STRUCTURE -- struct name, define only if not ENTNAME (passwd, group).\n DATABASE -- string of the database file's name (\"hosts\", \"passwd\").\n\n NEED_H_ERRNO - defined iff an arg `int *herrnop' is used.\n\n Also see files-parse.c.\n*/\n\n#define ENTNAME_r\tCONCAT(ENTNAME,_r)\n\n#define DATAFILE\t\"/etc/\" DATABASE\n\n#ifdef NEED_H_ERRNO\n# include <netdb.h>\n# define H_ERRNO_PROTO\t, int *herrnop\n# define H_ERRNO_ARG\t, herrnop\n# define H_ERRNO_SET(val) (*herrnop = (val))\n#else\n# define H_ERRNO_PROTO\n# define H_ERRNO_ARG\n# define H_ERRNO_SET(val) ((void) 0)\n#endif\n\n#ifndef EXTRA_ARGS\n# define EXTRA_ARGS\n# define EXTRA_ARGS_DECL\n# define EXTRA_ARGS_VALUE\n#endif\n\n/* Locks the static variables in this file. */\n__libc_lock_define_initialized (static, lock)\n\f\n/* Maintenance of the shared stream open on the database file. */\n\nstatic FILE *stream;\nstatic fpos_t position;\nstatic enum { nouse, getent, getby } last_use;\nstatic int keep_stream;\n\n/* Open database file if not already opened. */\nstatic enum nss_status\ninternal_setent (int stayopen)\n{\n enum nss_status status = NSS_STATUS_SUCCESS;\n\n if (stream == NULL)\n {\n stream = fopen (DATAFILE, \"rce\");\n\n if (stream == NULL)\n\tstatus = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;\n else\n\t{\n#if !defined O_CLOEXEC || !defined __ASSUME_O_CLOEXEC\n# ifdef O_CLOEXEC\n\t if (__have_o_cloexec <= 0)\n# endif\n\t {\n\t /* We have to make sure the file is `closed on exec'. */\n\t int result;\n\t int flags;\n\n\t result = flags = fcntl (fileno (stream), F_GETFD, 0);\n\t if (result >= 0)\n\t\t{\n# ifdef O_CLOEXEC\n\t\t if (__have_o_cloexec == 0)\n\t\t __have_o_cloexec = (flags & FD_CLOEXEC) == 0 ? -1 : 1;\n\t\t if (__have_o_cloexec < 0)\n# endif\n\t\t {\n\t\t flags |= FD_CLOEXEC;\n\t\t result = fcntl (fileno (stream), F_SETFD, flags);\n\t\t \n/* ... truncated ... */\n```\n\n### nss/nss_files/files-alias.c\n\n#### region() [lines 1-97]\n```c\n/* Mail alias file parser in nss_files module.\n Copyright (C) 1996-2014 Free Software Foundation, Inc.\n This file is part of the GNU C Library.\n Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.\n\n The GNU C Library is free software; you can redistribute it and/or\n modify it under the terms of the GNU Lesser General Public\n License as published by the Free Software Foundation; either\n version 2.1 of the License, or (at your option) any later version.\n\n The GNU C Library is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public\n License along with the GNU C Library; if not, see\n <http://www.gnu.org/licenses/>. */\n\n#include <aliases.h>\n#include <ctype.h>\n#include <errno.h>\n#include <fcntl.h>\n#include <bits/libc-lock.h>\n#include <stdlib.h>\n#include <stdio.h>\n#include <string.h>\n\n#include <kernel-features.h>\n\n#include \"nsswitch.h\"\n\n/* Locks the static variables in this file. */\n__libc_lock_define_initialized (static, lock)\n\f\n/* Maintenance of the shared stream open on the database file. */\n\nstatic FILE *stream;\nstatic fpos_t position;\nstatic enum { nouse, getent, getby } last_use;\n\n\nstatic enum nss_status\ninternal_setent (void)\n{\n enum nss_status status = NSS_STATUS_SUCCESS;\n\n if (stream == NULL)\n {\n stream = fopen (\"/etc/aliases\", \"rce\");\n\n if (stream == NULL)\n\tstatus = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;\n else\n\t{\n#if !defined O_CLOEXEC || !defined __ASSUME_O_CLOEXEC\n# ifdef O_CLOEXEC\n\t if (__have_o_cloexec <= 0)\n# endif\n\t {\n\t /* We have to make sure the file is `closed on exec'. */\n\t int result;\n\t int flags;\n\n\t result = flags = fcntl (fileno (stream), F_GETFD, 0);\n\t if (result >= 0)\n\t\t{\n# ifdef O_CLOEXEC\n\t\t if (__have_o_cloexec == 0)\n\t\t __have_o_cloexec = (flags & FD_CLOEXEC) == 0 ? -1 : 1;\n\t\t if (__ha\n/* ... truncated ... */\n```\n\n### nss/nss_files/files-hosts.c\n\n#### _nss_files_gethostbyname3_r() [lines 116-356]\n```c\n#undef EXTRA_ARGS_VALUE\n\nenum nss_status\n_nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result,\n\t\t\t char *buffer, size_t buflen, int *errnop,\n\t\t\t int *herrnop, int32_t *ttlp, char **canonp)\n{\n uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct hostent_data);\n buffer += pad;\n buflen = buflen > pad ? buflen - pad : 0;\n\n __libc_lock_lock (lock);\n\n /* Reset file pointer to beginning or open file. */\n enum nss_status status = internal_setent (keep_stream);\n\n if (status == NSS_STATUS_SUCCESS)\n {\n /* XXX Is using _res to determine whether we want to convert IPv4\n addresses to IPv6 addresses really the right thing to do? */\n int flags = ((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0);\n\n /* Tell getent function that we have repositioned the file pointer. */\n last_use = getby;\n\n while ((status = internal_getent (result, buffer, buflen, errnop,\n\t\t\t\t\therrnop, af, flags))\n\t == NSS_STATUS_SUCCESS)\n\t{\n\t LOOKUP_NAME_CASE (h_name, h_aliases)\n\t}\n\n if (status == NSS_STATUS_SUCCESS\n\t && _res_hconf.flags & HCONF_FLAG_MULTI)\n\t{\n\t /* We have to get all host entries from the file. */\n\t size_t tmp_buflen = MIN (buflen, 4096);\n\t char tmp_buffer_stack[tmp_buflen]\n\t __attribute__ ((__aligned__ (__alignof__ (struct hostent_data))));\n\t char *tmp_buffer = tmp_buffer_stack;\n/* ... 187 lines omitted ... */\n\t else\n\t status = NSS_STATUS_SUCCESS;\n\tout:\n\t if (tmp_buffer_malloced)\n\t free (tmp_buffer);\n\t}\n\n if (! keep_stream)\n\tinternal_endent ();\n }\n\n if (canonp && status == NSS_STATUS_SUCCESS)\n *canonp = result->h_name;\n\n __libc_lock_unlock (lock);\n\n return status;\n}\n\nenum nss_status\n```\n\n#### _nss_files_gethostbyname4_r() [lines 374-496]\n```c\n}\n\nenum nss_status\n_nss_files_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,\n\t\t\t char *buffer, size_t buflen, int *errnop,\n\t\t\t int *herrnop, int32_t *ttlp)\n{\n __libc_lock_lock (lock);\n\n /* Reset file pointer to beginning or open file. */\n enum nss_status status = interna\n/* ... truncated ... */\n```\n\n\n## Upstream Fix\n```diff\n2015-05-11 Andreas Schwab <schwab@suse.de>\n\n\t[BZ #18007]\n\t* nis/nss_compat/compat-grp.c (internal_endgrent): Don't call\n\tnss_endgrent.\n\t(_nss_compat_endgrent): Call nss_endgrent.\n\t* nis/nss_compat/compat-pwd.c (internal_endpwent): Don't call\n\tnss_endpwent.\n\t(_nss_compat_endpwent): Call nss_endpwent.\n\t* nis/nss_compat/compat-spwd.c (internal_setspent): Add parameter\n\tneedent, call nss_setspent only if non-zero.\n\t(_nss_compat_setspent, _nss_compat_getspent_r): Pass non-zero.\n\t(internal_endspent): Don't call nss_endspent.\n\t(_nss_compat_endspent): Call nss_endspent.\n\t* nss/nss_files/files-XXX.c (position, last_use, keep_stream):\n\tRemove. All uses removed.\n\t(internal_setent): Remove parameter stayopen, add parameter\n\tstream. Use it instead of global variable.\n\t(CONCAT(_nss_files_set,ENTNAME)): Pass global stream.\n\t(internal_endent, internal_getent): Add parameter stream. Use it\n\tinstead of global variable.\n\t(CONCAT(_nss_files_end,ENTNAME))\n\t(CONCAT(_nss_files_get,ENTNAME_r)): Pass global stream.\n\t(_nss_files_get##name##_r): Pass local stream. Remove locking.\n\t* nss/nss_files/files-alias.c (position, last_use): Remove. All\n\tuses removed.\n\t(internal_setent, internal_endent): Add parameter stream. Use it\n\tinstead of global variable.\n\t(_nss_files_setaliasent, _nss_files_endaliasent): Pass global\n\tstream.\n\t(get_next_alias): Add parameter stream.\n\t(_nss_files_getaliasent_r): Pass global stream.\n\t(_nss_files_getaliasbyname_r): Pass local stream. Remove locking.\n\t* nss/nss_files/files-hosts.c (_nss_files_gethostbyname3_r)\n\t(_nss_files_gethostbyname4_r): Pass local stream to\n\tinternal_setent, internal_getent and internal_endent. Remove\n\tlocking.\n\nIndex: glibc-2.19/nis/nss_compat/compat-grp.c\n===================================================================\n--- glibc-2.19.orig/nis/nss_compat/compat-grp.c\n+++ glibc-2.19/nis/nss_compat/compat-grp.c\n@@ -194,9 +194,6 @@ _nss_compat_setgrent (int stayopen)\n static enum nss_status\n internal_endgrent (ent_t *ent)\n {\n- if (nss_endgrent)\n- nss_endgrent ();\n-\n if (ent->stream != NULL)\n {\n fclose (ent->stream);\n@@ -222,6 +219,9 @@ _nss_compat_endgrent (void)\n \n __libc_lock_lock (lock);\n \n+ if (nss_endgrent)\n+ nss_endgrent ();\n+\n result = internal_endgrent (&ext_ent);\n \n __libc_lock_unlock (lock);\nIndex: glibc-2.19/nis/nss_compat/compat-pwd.c\n===================================================================\n--- glibc-2.19.orig/nis/nss_compat/compat-pwd.c\n+++ glibc-2.19/nis/nss_compat/compat-pwd.c\n@@ -311,9 +311,6 @@ _nss_compat_setpwent (int stayopen)\n static enum nss_status\n internal_endpwent (ent_t *ent)\n {\n- if (nss_endpwent)\n- nss_endpwent ();\n-\n if (ent->stream != NULL)\n {\n fclose (ent->stream);\n@@ -346,6 +343,9 @@ _nss_compat_endpwent (void)\n \n __libc_lock_lock (lock);\n \n+ if (nss_endpwent)\n+ nss_endpwent ();\n+\n result = internal_endpwent (&ext_ent);\n \n __libc_lock_unlock (lock);\nIndex: glibc-2.19/nis/nss_compat/compat-spwd.c\n===================================================================\n--- glibc-2.19.orig/nis/nss_compat/compat-spwd.c\n+++ glibc-2.19/nis/nss_compat/compat-spwd.c\n@@ -169,7 +169,7 @@ copy_spwd_changes (struct spwd *dest, st\n }\n \n static enum nss_status\n-internal_setspent (ent_t *ent, int stayopen)\n+internal_setspent (ent_t *ent, int stayopen, int needent)\n {\n enum nss_status status = NSS_STATUS_SUCCESS;\n \n@@ -239,7 +239,7 @@ internal_setspent (ent_t *ent, int stayo\n \n give_spwd_free (&ent->pwd);\n \n- if (status == NSS_STATUS_SUCCESS && nss_setspent)\n+ if (needent && status == NSS_STATUS_SUCCESS && nss_setspent)\n ent->setent_status = nss_setspent (stayopen);\n \n return status;\n@@ -256,7 +256,7 @@ _nss_compat_setspent (int stayopen)\n if (ni == NULL)\n init_nss_interface ();\n \n- result = internal_setspent (&ext_ent, stayopen);\n+ result = internal_setspent (&ext_ent, stayopen, 1);\n \n __libc_lock_unlock (lock);\n \n@@ -267,9 +267,6 @@ _nss_compat_setspent (int stayopen)\n static enum nss_status\n internal_endspent (ent_t *ent)\n {\n- if (nss_endspent)\n- nss_endspent ();\n-\n if (ent->stream != NULL)\n {\n fclose (ent->stream);\n@@ -303,6 +300,9 @@ _nss_compat_endspent (void)\n \n __libc_lock_lock (lock);\n \n+ if (nss_endspent)\n+ nss_endspent ();\n+\n result = internal_endspent (&ext_ent);\n \n __libc_lock_unlock (lock);\n@@ -658,7 +658,7 @@ _nss_compat_getspent_r (struct spwd *pwd\n init_nss_interface ();\n \n if (ext_ent.stream == NULL)\n- result = internal_setspent (&ext_ent, 1);\n+ result = internal_setspent (&ext_ent, 1, 1);\n \n if (result == NSS_STATUS_SUCCESS)\n result = internal_getspent_r (pwd, &ext_ent, buffer, buflen, errnop);\n@@ -830,7 +830,7 @@ _nss_compat_getspnam_r (const char *name\n \n __libc_lock_unlock (lock);\n \n- result = internal_setspent (&ent, 0);\n+ result = internal_setspent (&ent, 0, 0);\n \n if (result == NSS_STATUS_SUCCESS)\n result = internal_getspnam_r (name, pwd, &ent, buffer, buflen, errnop);\nIndex: glibc-2.19/nss/nss_files/files-XXX.c\n===================================================================\n--- glibc-2.19.orig/nss/nss_files/files-XXX.c\n+++ glibc-2.19/nss/nss_files/files-XXX.c\n@@ -60,24 +60,23 @@\n /* Locks the static variables in this file. */\n __libc_lock_define_initialized (static, lock)\n \f\n-/* Maintenance of the shared stream open on the database file. */\n+/* Maintenance of the stream open on the database file. For getXXent\n+ operations the stream needs to be held open across calls, the other\n+ getXXbyYY operations all use their own stream. */\n \n static FILE *stream;\n-static fpos_t position;\n-static enum { nouse, getent, getby } last_use;\n-static int keep_stream;\n \n /* Open database file if not already opened. */\n static enum nss_status\n-internal_setent (int stayopen)\n+internal_setent (FILE **stream)\n {\n enum nss_status status = NSS_STATUS_SUCCESS;\n \n- if (stream == NULL)\n+ if (*stream == NULL)\n {\n- stream = fopen (DATAFILE, \"rce\");\n+ *stream = fopen (DATAFILE, \"rce\");\n \n- if (stream == NULL)\n+ if (*stream == NULL)\n \tstatus = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;\n else\n \t{\n@@ -90,7 +89,7 @@ internal_setent (int stayopen)\n \t int result;\n \t int flags;\n \n-\t result = flags = fcntl (fileno (stream), F_GETFD, 0);\n+\t result = flags = fcntl (fileno (*stream), F_GETFD, 0);\n \t if (result >= 0)\n \t\t{\n # ifdef O_CLOEXEC\n@@ -100,15 +99,15 @@ internal_setent (int stayopen)\n # endif\n \t\t {\n \t\t flags |= FD_CLOEXEC;\n-\t\t result = fcntl (fileno (stream), F_SETFD, flags);\n+\t\t result = fcntl (fileno (*stream), F_SETFD, flags);\n \t\t }\n \t\t}\n \t if (result < 0)\n \t\t{\n \t\t /* Something went wrong. Close the stream and return a\n \t\t failure. */\n-\t\t fclose (stream);\n-\t\t stream = NULL;\n+\t\t fclose (*stream);\n+\t\t *stream = NULL;\n \t\t status = NSS_STATUS_UNAVAIL;\n \t\t}\n \t }\n@@ -116,11 +115,7 @@ internal_setent (int stayopen)\n \t}\n }\n else\n- rewind (stream);\n-\n- /* Remember STAYOPEN flag. */\n- if (stream != NULL)\n- keep_stream |= stayopen;\n+ rewind (*stream);\n \n return status;\n }\n@@ -134,16 +129,7 @@ CONCAT(_nss_files_set,ENTNAME) (int stay\n \n __libc_lock_lock (lock);\n \n- status = internal_setent (stayopen);\n-\n- if (status == NSS_STATUS_SUCCESS && fgetpos (stream, &position) < 0)\n- {\n- fclose (stream);\n- stream = NULL;\n- status = NSS_STATUS_UNAVAIL;\n- }\n-\n- last_use = getent;\n+ status = internal_setent (&stream);\n \n __libc_lock_unlock (lock);\n \n@@ -153,12 +139,12 @@ CONCAT(_nss_files_set,ENTNAME) (int stay\n \n /* Close the database file. */\n static void\n-internal_endent (void)\n+internal_endent (FILE **stream)\n {\n- if (stream != NULL)\n+ if (*stream != NULL)\n {\n- fclose (stream);\n- stream = NULL;\n+ fclose (*stream);\n+ *stream = NULL;\n }\n }\n \n@@ -169,10 +155,7 @@ CONCAT(_nss_files_end,ENTNAME) (void)\n {\n __libc_lock_lock (lock);\n \n- internal_endent ();\n-\n- /* Reset STAYOPEN flag. */\n- ke\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "2015-05-11 Andreas Schwab <schwab@suse.de>\n\n\t[BZ #18007]\n\t* nis/nss_compat/compat-grp.c (internal_endgrent): Don't call\n\tnss_endgrent.\n\t(_nss_compat_endgrent): Call nss_endgrent.\n\t* nis/nss_compat/compat-pwd.c (internal_endpwent): Don't call\n\tnss_endpwent.\n\t(_nss_compat_endpwent): Call nss_endpwent.\n\t* nis/nss_compat/compat-spwd.c (internal_setspent): Add parameter\n\tneedent, call nss_setspent only if non-zero.\n\t(_nss_compat_setspent, _nss_compat_getspent_r): Pass non-zero.\n\t(internal_endspent): Don't call nss_endspent.\n\t(_nss_compat_endspent): Call nss_endspent.\n\t* nss/nss_files/files-XXX.c (position, last_use, keep_stream):\n\tRemove. All uses removed.\n\t(internal_setent): Remove parameter stayopen, add parameter\n\tstream. Use it instead of global variable.\n\t(CONCAT(_nss_files_set,ENTNAME)): Pass global stream.\n\t(internal_endent, internal_getent): Add parameter stream. Use it\n\tinstead of global variable.\n\t(CONCAT(_nss_files_end,ENTNAME))\n\t(CONCAT(_nss_files_get,ENTNAME_r)): Pass global stream.\n\t(_nss_files_get##name##_r): Pass local stream. Remove locking.\n\t* nss/nss_files/files-alias.c (position, last_use): Remove. All\n\tuses removed.\n\t(internal_setent, internal_endent): Add parameter stream. Use it\n\tinstead of global variable.\n\t(_nss_files_setaliasent, _nss_files_endaliasent): Pass global\n\tstream.\n\t(get_next_alias): Add parameter stream.\n\t(_nss_files_getaliasent_r): Pass global stream.\n\t(_nss_files_getaliasbyname_r): Pass local stream. Remove locking.\n\t* nss/nss_files/files-hosts.c (_nss_files_gethostbyname3_r)\n\t(_nss_files_gethostbyname4_r): Pass local stream to\n\tinternal_setent, internal_getent and internal_endent. Remove\n\tlocking.\n\nIndex: glibc-2.19/nis/nss_compat/compat-grp.c\n===================================================================\n--- glibc-2.19.orig/nis/nss_compat/compat-grp.c\n+++ glibc-2.19/nis/nss_compat/compat-grp.c\n@@ -194,9 +194,6 @@ _nss_compat_setgrent (int stayopen)\n static enum nss_status\n internal_endgrent (ent_t *ent)\n {\n- if (nss_endgrent)\n- nss_endgrent ();\n-\n if (ent->stream != NULL)\n {\n fclose (ent->stream);\n@@ -222,6 +219,9 @@ _nss_compat_endgrent (void)\n \n __libc_lock_lock (lock);\n \n+ if (nss_endgrent)\n+ nss_endgrent ();\n+\n result = internal_endgrent (&ext_ent);\n \n __libc_lock_unlock (lock);\nIndex: glibc-2.19/nis/nss_compat/compat-pwd.c\n===================================================================\n--- glibc-2.19.orig/nis/nss_compat/compat-pwd.c\n+++ glibc-2.19/nis/nss_compat/compat-pwd.c\n@@ -311,9 +311,6 @@ _nss_compat_setpwent (int stayopen)\n static enum nss_status\n internal_endpwent (ent_t *ent)\n {\n- if (nss_endpwent)\n- nss_endpwent ();\n-\n if (ent->stream != NULL)\n {\n fclose (ent->stream);\n@@ -346,6 +343,9 @@ _nss_compat_endpwent (void)\n \n __libc_lock_lock (lock);\n \n+ if (nss_endpwent)\n+ nss_endpwent ();\n+\n result = internal_endpwent (&ext_ent);\n \n __libc_lock_unlock (lock);\nIndex: glibc-2.19/nis/nss_compat/compat-spwd.c\n===================================================================\n--- glibc-2.19.orig/nis/nss_compat/compat-spwd.c\n+++ glibc-2.19/nis/nss_compat/compat-spwd.c\n@@ -169,7 +169,7 @@ copy_spwd_changes (struct spwd *dest, st\n }\n \n static enum nss_status\n-internal_setspent (ent_t *ent, int stayopen)\n+internal_setspent (ent_t *ent, int stayopen, int needent)\n {\n enum nss_status status = NSS_STATUS_SUCCESS;\n \n@@ -239,7 +239,7 @@ internal_setspent (ent_t *ent, int stayo\n \n give_spwd_free (&ent->pwd);\n \n- if (status == NSS_STATUS_SUCCESS && nss_setspent)\n+ if (needent && status == NSS_STATUS_SUCCESS && nss_setspent)\n ent->setent_status = nss_setspent (stayopen);\n \n return status;\n@@ -256,7 +256,7 @@ _nss_compat_setspent (int stayopen)\n if (ni == NULL)\n init_nss_interface ();\n \n- result = internal_setspent (&ext_ent, stayopen);\n+ result = internal_setspent (&ext_ent, stayopen, 1);\n \n __libc_lock_unlock (lock);\n \n@@ -267,9 +267,6 @@ _nss_compat_setspent (int stayopen)\n static enum nss_status\n internal_endspent (ent_t *ent)\n {\n- if (nss_endspent)\n- nss_endspent ();\n-\n if (ent->stream != NULL)\n {\n fclose (ent->stream);\n@@ -303,6 +300,9 @@ _nss_compat_endspent (void)\n \n __libc_lock_lock (lock);\n \n+ if (nss_endspent)\n+ nss_endspent ();\n+\n result = internal_endspent (&ext_ent);\n \n __libc_lock_unlock (lock);\n@@ -658,7 +658,7 @@ _nss_compat_getspent_r (struct spwd *pwd\n init_nss_interface ();\n \n if (ext_ent.stream == NULL)\n- result = internal_setspent (&ext_ent, 1);\n+ result = internal_setspent (&ext_ent, 1, 1);\n \n if (result == NSS_STATUS_SUCCESS)\n result = internal_getspent_r (pwd, &ext_ent, buffer, buflen, errnop);\n@@ -830,7 +830,7 @@ _nss_compat_getspnam_r (const char *name\n \n __libc_lock_unlock (lock);\n \n- result = internal_setspent (&ent, 0);\n+ result = internal_setspent (&ent, 0, 0);\n \n if (result == NSS_STATUS_SUCCESS)\n result = internal_getspnam_r (name, pwd, &ent, buffer, buflen, errnop);\nIndex: glibc-2.19/nss/nss_files/files-XXX.c\n===================================================================\n--- glibc-2.19.orig/nss/nss_files/files-XXX.c\n+++ glibc-2.19/nss/nss_files/files-XXX.c\n@@ -60,24 +60,23 @@\n /* Locks the static variables in this file. */\n __libc_lock_define_initialized (static, lock)\n \f\n-/* Maintenance of the shared stream open on the database file. */\n+/* Maintenance of the stream open on the database file. For getXXent\n+ operations the stream needs to be held open across calls, the other\n+ getXXbyYY operations all use their own stream. */\n \n static FILE *stream;\n-static fpos_t position;\n-static enum { nouse, getent, getby } last_use;\n-static int keep_stream;\n \n /* Open database file if not already opened. */\n static enum nss_status\n-internal_setent (int stayopen)\n+internal_setent (FILE **stream)\n {\n enum nss_status status = NSS_STATUS_SUCCESS;\n \n- if (stream == NULL)\n+ if (*stream == NULL)\n {\n- stream = fopen (DATAFILE, \"rce\");\n+ *stream = fopen (DATAFILE, \"rce\");\n \n- if (stream == NULL)\n+ if (*stream == NULL)\n \tstatus = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;\n else\n \t{\n@@ -90,7 +89,7 @@ internal_setent (int stayopen)\n \t int result;\n \t int flags;\n \n-\t result = flags = fcntl (fileno (stream), F_GETFD, 0);\n+\t result = flags = fcntl (fileno (*stream), F_GETFD, 0);\n \t if (result >= 0)\n \t\t{\n # ifdef O_CLOEXEC\n@@ -100,15 +99,15 @@ internal_setent (int stayopen)\n # endif\n \t\t {\n \t\t flags |= FD_CLOEXEC;\n-\t\t result = fcntl (fileno (stream), F_SETFD, flags);\n+\t\t result = fcntl (fileno (*stream), F_SETFD, flags);\n \t\t }\n \t\t}\n \t if (result < 0)\n \t\t{\n \t\t /* Something went wrong. Close the stream and return a\n \t\t failure. */\n-\t\t fclose (stream);\n-\t\t stream = NULL;\n+\t\t fclose (*stream);\n+\t\t *stream = NULL;\n \t\t status = NSS_STATUS_UNAVAIL;\n \t\t}\n \t }\n@@ -116,11 +115,7 @@ internal_setent (int stayopen)\n \t}\n }\n else\n- rewind (stream);\n-\n- /* Remember STAYOPEN flag. */\n- if (stream != NULL)\n- keep_stream |= stayopen;\n+ rewind (*stream);\n \n return status;\n }\n@@ -134,16 +129,7 @@ CONCAT(_nss_files_set,ENTNAME) (int stay\n \n __libc_lock_lock (lock);\n \n- status = internal_setent (stayopen);\n-\n- if (status == NSS_STATUS_SUCCESS && fgetpos (stream, &position) < 0)\n- {\n- fclose (stream);\n- stream = NULL;\n- status = NSS_STATUS_UNAVAIL;\n- }\n-\n- last_use = getent;\n+ status = internal_setent (&stream);\n \n __libc_lock_unlock (lock);\n \n@@ -153,12 +139,12 @@ CONCAT(_nss_files_set,ENTNAME) (int stay\n \n /* Close the database file. */\n static void\n-internal_endent (void)\n+internal_endent (FILE **stream)\n {\n- if (stream != NULL)\n+ if (*stream != NULL)\n {\n- fclose (stream);\n- stream = NULL;\n+ fclose (*stream);\n+ *stream = NULL;\n }\n }\n \n@@ -169,10 +155,7 @@ CONCAT(_nss_files_end,ENTNAME) (void)\n {\n __libc_lock_lock (lock);\n \n- internal_endent ();\n-\n- /* Reset STAYOPEN flag. */\n- keep_stream = 0;\n+ internal_endent (&stream);\n \n __libc_lock_unlock (lock);\n \n@@ -227,7 +210,7 @@ get_contents (char *linebuf, size_t len,\n \n /* Parsing the database file into `struct STRUCTURE' data structures. */\n static enum nss_status\n-internal_getent (struct STRUCTURE *result,\n+internal_getent (FILE *stream, struct STRUCTURE *result,\n \t\t char *buffer, size_t buflen, int *errnop H_ERRNO_PROTO\n \t\t EXTRA_ARGS_DECL)\n {\n@@ -300,45 +283,14 @@ CONCAT(_nss_files_get,ENTNAME_r) (struct\n {\n int save_errno = errno;\n \n- status = internal_setent (0);\n+ status = internal_setent (&stream);\n \n __set_errno (save_errno);\n-\n- if (status == NSS_STATUS_SUCCESS && fgetpos (stream, &position) < 0)\n-\t{\n-\t fclose (stream);\n-\t stream = NULL;\n-\t status = NSS_STATUS_UNAVAIL;\n-\t}\n }\n \n if (status == NSS_STATUS_SUCCESS)\n- {\n- /* If the last use was not by the getent function we need the\n-\t position the stream. */\n- if (last_use != getent)\n-\t{\n-\t if (fsetpos (stream, &position) < 0)\n-\t status = NSS_STATUS_UNAVAIL;\n-\t else\n-\t last_use = getent;\n-\t}\n-\n- if (status == NSS_STATUS_SUCCESS)\n-\t{\n-\t status = internal_getent (result, buffer, buflen, errnop\n-\t\t\t\t H_ERRNO_ARG EXTRA_ARGS_VALUE);\n-\n-\t /* Remember this position if we were successful. If the\n-\t operation failed we give the user a chance to repeat the\n-\t operation (perhaps the buffer was too small). */\n-\t if (status == NSS_STATUS_SUCCESS)\n-\t fgetpos (stream, &position);\n-\t else\n-\t /* We must make sure we reposition the stream the next call. */\n-\t last_use = nouse;\n-\t}\n- }\n+ status = internal_getent (stream, result, buffer, buflen, errnop\n+\t\t\t H_ERRNO_ARG EXTRA_ARGS_VALUE);\n \n __libc_lock_unlock (lock);\n \n@@ -364,27 +316,20 @@ _nss_files_get##name##_r (proto,\n \t\t\t size_t buflen, int *errnop H_ERRNO_PROTO)\t \\\n {\t\t\t\t\t\t\t\t\t \\\n enum nss_status status;\t\t\t\t\t\t \\\n+ FILE *stream = NULL;\t\t\t\t\t\t\t \\\n \t\t\t\t\t\t\t\t\t \\\n- __libc_lock_lock (lock);\t\t\t\t\t\t \\\n-\t\t\t\t\t\t\t\t\t \\\n- /* Reset file pointer to beginning or open file. */\t\t\t \\\n- status = internal_setent (keep_stream);\t\t\t\t \\\n+ /* Open file. */\t\t\t\t\t\t\t \\\n+ status = internal_setent (&stream);\t\t\t\t\t \\\n \t\t\t\t\t\t\t\t\t \\\n if (status == NSS_STATUS_SUCCESS)\t\t\t\t\t \\\n {\t\t\t\t\t\t\t\t\t \\\n- /* Tell getent function that we have repositioned the file pointer. */ \\\n- last_use = getby;\t\t\t\t\t\t\t \\\n-\t\t\t\t\t\t\t\t\t \\\n- while ((status = internal_getent (result, buffer, buflen, errnop\t \\\n+ while ((status = internal_getent (stream, result, buffer, buflen, errnop \\\n \t\t\t\t\tH_ERRNO_ARG EXTRA_ARGS_VALUE))\t \\\n \t == NSS_STATUS_SUCCESS)\t\t\t\t\t \\\n \t{ break_if_match }\t\t\t\t\t\t \\\n \t\t\t\t\t\t\t\t\t \\\n- if (! keep_stream)\t\t\t\t\t\t \\\n-\tinternal_endent ();\t\t\t\t\t\t \\\n+ internal_endent (&stream);\t\t\t\t\t \\\n }\t\t\t\t\t\t\t\t\t \\\n \t\t\t\t\t\t\t\t\t \\\n- __libc_lock_unlock (lock);\t\t\t\t\t\t \\\n-\t\t\t\t\t\t\t\t\t \\\n return status;\t\t\t\t\t\t\t \\\n }\nIndex: glibc-2.19/nss/nss_files/files-alias.c\n===================================================================\n--- glibc-2.19.orig/nss/nss_files/files-alias.c\n+++ glibc-2.19/nss/nss_files/files-alias.c\n@@ -33,23 +33,23 @@\n /* Locks the static variables in this file. */\n __libc_lock_define_initialized (static, lock)\n \f\n-/* Maintenance of the shared stream open on the database file. */\n+/* Maintenance of the stream open on the database file. For getXXent\n+ operations the stream needs to be held open across calls, the other\n+ getXXbyYY operations all use their own stream. */\n \n static FILE *stream;\n-static fpos_t position;\n-static enum { nouse, getent, getby } last_use;\n \n \n static enum nss_status\n-internal_setent (void)\n+internal_setent (FILE **stream)\n {\n enum nss_status status = NSS_STATUS_SUCCESS;\n \n- if (stream == NULL)\n+ if (*stream == NULL)\n {\n- stream = fopen (\"/etc/aliases\", \"rce\");\n+ *stream = fopen (\"/etc/aliases\", \"rce\");\n \n- if (stream == NULL)\n+ if (*stream == NULL)\n \tstatus = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;\n else\n \t{\n@@ -62,7 +62,7 @@ internal_setent (void)\n \t int result;\n \t int flags;\n \n-\t result = flags = fcntl (fileno (stream), F_GETFD, 0);\n+\t result = flags = fcntl (fileno (*stream), F_GETFD, 0);\n \t if (result >= 0)\n \t\t{\n # ifdef O_CLOEXEC\n@@ -72,14 +72,14 @@ internal_setent (void)\n # endif\n \t\t {\n \t\t flags |= FD_CLOEXEC;\n-\t\t result = fcntl (fileno (stream), F_SETFD, flags);\n+\t\t result = fcntl (fileno (*stream), F_SETFD, flags);\n \t\t }\n \t\t}\n \t if (result < 0)\n \t\t{\n \t\t /* Something went wrong. Close the stream and return a\n \t\t failure. */\n-\t\t fclose (stream);\n+\t\t fclose (*stream);\n \t\t stream = NULL;\n \t\t status = NSS_STATUS_UNAVAIL;\n \t\t}\n@@ -88,7 +88,7 @@ internal_setent (void)\n \t}\n }\n else\n- rewind (stream);\n+ rewind (*stream);\n \n return status;\n }\n@@ -102,16 +102,7 @@ _nss_files_setaliasent (void)\n \n __libc_lock_lock (lock);\n \n- status = internal_setent ();\n-\n- if (status == NSS_STATUS_SUCCESS && fgetpos (stream, &position) < 0)\n- {\n- fclose (stream);\n- stream = NULL;\n- status = NSS_STATUS_UNAVAIL;\n- }\n-\n- last_use = getent;\n+ status = internal_setent (&stream);\n \n __libc_lock_unlock (lock);\n \n@@ -121,12 +112,12 @@ _nss_files_setaliasent (void)\n \n /* Close the database file. */\n static void\n-internal_endent (void)\n+internal_endent (FILE **stream)\n {\n- if (stream != NULL)\n+ if (*stream != NULL)\n {\n- fclose (stream);\n- stream = NULL;\n+ fclose (*stream);\n+ *stream = NULL;\n }\n }\n \n@@ -137,7 +128,7 @@ _nss_files_endaliasent (void)\n {\n __libc_lock_lock (lock);\n \n- internal_endent ();\n+ internal_endent (&stream);\n \n __libc_lock_unlock (lock);\n \n@@ -146,7 +137,7 @@ _nss_files_endaliasent (void)\n \f\n /* Parsing the database file into `struct aliasent' data structures. */\n static enum nss_status\n-get_next_alias (const char *match, struct aliasent *result,\n+get_next_alias (FILE *stream, const char *match, struct aliasent *result,\n \t\tchar *buffer, size_t buflen, int *errnop)\n {\n enum nss_status status = NSS_STATUS_NOTFOUND;\n@@ -397,35 +388,16 @@ _nss_files_getaliasent_r (struct aliasen\n \n /* Be prepared that the set*ent function was not called before. */\n if (stream == NULL)\n- status = internal_setent ();\n+ status = internal_setent (&stream);\n \n if (status == NSS_STATUS_SUCCESS)\n {\n- /* If the last use was not by the getent function we need the\n-\t position the stream. */\n- if (last_use != getent)\n-\t{\n-\t if (fsetpos (stream, &position) < 0)\n-\t status = NSS_STATUS_UNAVAIL;\n-\t else\n-\t last_use = getent;\n-\t}\n-\n- if (status == NSS_STATUS_SUCCESS)\n-\t{\n-\t result->alias_local = 1;\n+ result->alias_local = 1;\n \n-\t /* Read lines until we get a definite result. */\n-\t do\n-\t status = get_next_alias (NULL, result, buffer, buflen, errnop);\n-\t while (status == NSS_STATUS_RETURN);\n-\n-\t /* If we successfully read an entry remember this position. */\n-\t if (status == NSS_STATUS_SUCCESS)\n-\t fgetpos (stream, &position);\n-\t else\n-\t last_use = nouse;\n-\t}\n+ /* Read lines until we get a definite result. */\n+ do\n+\tstatus = get_next_alias (stream, NULL, result, buffer, buflen, errnop);\n+ while (status == NSS_STATUS_RETURN);\n }\n \n __libc_lock_unlock (lock);\n@@ -440,6 +412,7 @@ _nss_files_getaliasbyname_r (const char\n {\n /* Return next entry in host file. */\n enum nss_status status = NSS_STATUS_SUCCESS;\n+ FILE *stream = NULL;\n \n if (name == NULL)\n {\n@@ -447,11 +420,8 @@ _nss_files_getaliasbyname_r (const char\n return NSS_STATUS_UNAVAIL;\n }\n \n- __libc_lock_lock (lock);\n-\n- /* Open the stream or rest it. */\n- status = internal_setent ();\n- last_use = getby;\n+ /* Open the stream. */\n+ status = internal_setent (&stream);\n \n if (status == NSS_STATUS_SUCCESS)\n {\n@@ -459,13 +429,11 @@ _nss_files_getaliasbyname_r (const char\n \n /* Read lines until we get a definite result. */\n do\n-\tstatus = get_next_alias (name, result, buffer, buflen, errnop);\n+\tstatus = get_next_alias (stream, name, result, buffer, buflen, errnop);\n while (status == NSS_STATUS_RETURN);\n }\n \n- internal_endent ();\n-\n- __libc_lock_unlock (lock);\n+ internal_endent (&stream);\n \n return status;\n }\nIndex: glibc-2.19/nss/nss_files/files-hosts.c\n===================================================================\n--- glibc-2.19.orig/nss/nss_files/files-hosts.c\n+++ glibc-2.19/nss/nss_files/files-hosts.c\n@@ -115,14 +115,13 @@ _nss_files_gethostbyname3_r (const char\n \t\t\t char *buffer, size_t buflen, int *errnop,\n \t\t\t int *herrnop, int32_t *ttlp, char **canonp)\n {\n+ FILE *stream = NULL;\n uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct hostent_data);\n buffer += pad;\n buflen = buflen > pad ? buflen - pad : 0;\n \n- __libc_lock_lock (lock);\n-\n- /* Reset file pointer to beginning or open file. */\n- enum nss_status status = internal_setent (keep_stream);\n+ /* Open file. */\n+ enum nss_status status = internal_setent (&stream);\n \n if (status == NSS_STATUS_SUCCESS)\n {\n@@ -130,10 +129,7 @@ _nss_files_gethostbyname3_r (const char\n addresses to IPv6 addresses really the right thing to do? */\n int flags = ((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0);\n \n- /* Tell getent function that we have repositioned the file pointer. */\n- last_use = getby;\n-\n- while ((status = internal_getent (result, buffer, buflen, errnop,\n+ while ((status = internal_getent (stream, result, buffer, buflen, errnop,\n \t\t\t\t\therrnop, af, flags))\n \t == NSS_STATUS_SUCCESS)\n \t{\n@@ -160,7 +156,7 @@ _nss_files_gethostbyname3_r (const char\n \t bufferend = (char *) &result->h_aliases[naliases + 1];\n \n \tagain:\n-\t while ((status = internal_getent (&tmp_result_buf, tmp_buffer,\n+\t while ((status = internal_getent (stream, &tmp_result_buf, tmp_buffer,\n \t\t\t\t\t tmp_buflen, errnop, herrnop, af,\n \t\t\t\t\t flags))\n \t\t == NSS_STATUS_SUCCESS)\n@@ -336,15 +332,12 @@ _nss_files_gethostbyname3_r (const char\n \t free (tmp_buffer);\n \t}\n \n- if (! keep_stream)\n-\tinternal_endent ();\n+ internal_endent (&stream);\n }\n \n if (canonp && status == NSS_STATUS_SUCCESS)\n *canonp = result->h_name;\n \n- __libc_lock_unlock (lock);\n-\n return status;\n }\n \n@@ -373,16 +366,13 @@ _nss_files_gethostbyname4_r (const char\n \t\t\t char *buffer, size_t buflen, int *errnop,\n \t\t\t int *herrnop, int32_t *ttlp)\n {\n- __libc_lock_lock (lock);\n+ FILE *stream = NULL;\n \n- /* Reset file pointer to beginning or open file. */\n- enum nss_status status = internal_setent (keep_stream);\n+ /* Open file. */\n+ enum nss_status status = internal_setent (&stream);\n \n if (status == NSS_STATUS_SUCCESS)\n {\n- /* Tell getent function that we have repositioned the file pointer. */\n- last_use = getby;\n-\n bool any = false;\n bool got_canon = false;\n while (1)\n@@ -394,7 +384,7 @@ _nss_files_gethostbyname4_r (const char\n \t buflen = buflen > pad ? buflen - pad : 0;\n \n \t struct hostent result;\n-\t status = internal_getent (&result, buffer, buflen, errnop,\n+\t status = internal_getent (stream, &result, buffer, buflen, errnop,\n \t\t\t\t herrnop, AF_UNSPEC, 0);\n \t if (status != NSS_STATUS_SUCCESS)\n \t break;\n@@ -470,8 +460,7 @@ _nss_files_gethostbyname4_r (const char\n \t status = NSS_STATUS_SUCCESS;\n \t}\n \n- if (! keep_stream)\n-\tinternal_endent ();\n+ internal_endent (&stream);\n }\n else if (status == NSS_STATUS_TRYAGAIN)\n {\n@@ -484,7 +473,5 @@ _nss_files_gethostbyname4_r (const char\n *herrnop = NO_DATA;\n }\n \n- __libc_lock_unlock (lock);\n-\n return status;\n }" } ]
{ "id": "glibc-utils-4690-nss-separate-state-getXXent.pa", "cve_id": "CVE-2014-9761", "package": "glibc-utils", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 2493, "context_files": 6 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2024-34459\n\nAn issue was discovered in xmllint (from libxml2) before 2.11.8 and 2.12.x before 2.12.7. Formatting error messages with xmllint --htmlout can result in a buffer over-read in xmlHTMLPrintFileContext in xmllint.c.\n\nSeverity: HIGH\nCVSS Score: 7.5\n\n## Package\nlibxml2\n\n## Files to modify\n- xmllint.c\n\n## Target Source Code\n\n### xmllint.c\n\n#### xmlHTMLPrintFileContext() [lines 584-628]\n```c\n */\n\nstatic void\nxmlHTMLPrintFileContext(xmlParserInputPtr input) {\n const xmlChar *cur, *base;\n int len;\n int n;\n\n if (input == NULL) return;\n xmlGenericError(xmlGenericErrorContext, \"<pre>\\n\");\n cur = input->cur;\n base = input->base;\n while ((cur > base) && ((*cur == '\\n') || (*cur == '\\r'))) {\n\tcur--;\n }\n n = 0;\n while ((n++ < 80) && (cur > base) && (*cur != '\\n') && (*cur != '\\r'))\n cur--;\n if ((*cur == '\\n') || (*cur == '\\r')) cur++;\n base = cur;\n n = 0;\n while ((*cur != 0) && (*cur != '\\n') && (*cur != '\\r') && (n < 79)) {\n\tlen = strlen(buffer);\n snprintf(&buffer[len], sizeof(buffer) - len, \"%c\",\n\t\t (unsigned char) *cur++);\n\tn++;\n }\n len = strlen(buffer);\n snprintf(&buffer[len], sizeof(buffer) - len, \"\\n\");\n cur = input->cur;\n while ((*cur == '\\n') || (*cur == '\\r'))\n\tcur--;\n n = 0;\n while ((cur != base) && (n++ < 80)) {\n\tlen = strlen(buffer);\n snprintf(&buffer[len], sizeof(buffer) - len, \" \");\n base++;\n }\n len = strlen(buffer);\n snprintf(&buffer[len], sizeof(buffer) - len, \"^\\n\");\n xmlHTMLEncodeSend();\n xmlGenericError(xmlGenericErrorContext, \"</pre>\");\n}\n\n/**\n```\n\n\n## Upstream Fix\n```diff\nFrom 3ad7f81624572ebd5b9e6058c9f67d38207c10e2 Mon Sep 17 00:00:00 2001\nFrom: Nick Wellnhofer <wellnhofer@aevum.de>\nDate: Wed, 8 May 2024 11:49:31 +0200\nSubject: [PATCH] [CVE-2024-34459] Fix buffer overread with `xmllint --htmlout`\n\nAdd a missing bounds check.\n\nFixes #720.\n---\n xmllint.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/xmllint.c b/xmllint.c\nindex b2afbe9697..35c328578d 100644\n--- a/xmllint.c\n+++ b/xmllint.c\n@@ -543,7 +543,7 @@ xmlHTMLPrintFileContext(xmlParserInputPtr input) {\n len = strlen(buffer);\n snprintf(&buffer[len], sizeof(buffer) - len, \"\\n\");\n cur = input->cur;\n- while ((*cur == '\\n') || (*cur == '\\r'))\n+ while ((cur > base) && ((*cur == '\\n') || (*cur == '\\r')))\n \tcur--;\n n = 0;\n while ((cur != base) && (n++ < 80)) {\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 3ad7f81624572ebd5b9e6058c9f67d38207c10e2 Mon Sep 17 00:00:00 2001\nFrom: Nick Wellnhofer <wellnhofer@aevum.de>\nDate: Wed, 8 May 2024 11:49:31 +0200\nSubject: [PATCH] [CVE-2024-34459] Fix buffer overread with `xmllint --htmlout`\n\nAdd a missing bounds check.\n\nFixes #720.\n---\n xmllint.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/xmllint.c b/xmllint.c\nindex b2afbe969..35c328578 100644\n--- a/xmllint.c\n+++ b/xmllint.c\n@@ -543,7 +543,7 @@ xmlHTMLPrintFileContext(xmlParserInputPtr input) {\n len = strlen(buffer);\n snprintf(&buffer[len], sizeof(buffer) - len, \"\\n\");\n cur = input->cur;\n- while ((*cur == '\\n') || (*cur == '\\r'))\n+ while ((cur > base) && ((*cur == '\\n') || (*cur == '\\r')))\n \tcur--;\n n = 0;\n while ((cur != base) && (n++ < 80)) {\n-- \nGitLab" } ]
{ "id": "libxml2-CVE-2024-34459-libxml2-CVE-2024-344", "cve_id": "CVE-2024-34459", "package": "libxml2", "upstream_enriched": true, "upstream_commit": "3ad7f81624572ebd5b9e6058c9f67d38207c10e2", "upstream_repo": "GNOME/libxml2", "tier": "adapted", "has_source_context": true, "license": "MIT", "context_tokens_est": 316, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-3706\n\nStack-based buffer overflow in the getaddrinfo function in sysdeps/posix/getaddrinfo.c in the GNU C Library (aka glibc or libc6) allows remote attackers to cause a denial of service (crash) via vectors involving hostent conversion. NOTE: this vulnerability exists because of an incomplete fix for CVE-2013-4458.\n\n## Package\nglibc-testsuite\n\n## Files to modify\n- glibc-2.19.orig/nss/nss_files/files-alias.c\n- glibc-2.19.orig/nis/nss_compat/compat-grp.c\n- glibc-2.19.orig/nis/nss_compat/compat-pwd.c\n- glibc-2.19.orig/nis/nss_compat/compat-spwd.c\n- nss/nss_files/files-XXX.c\n\n## Target Source Code\n\n### nis/nss_compat/compat-grp.c\n\n#### _nss_compat_setgrent() [lines 174-193]\n```c\n\n\nenum nss_status\n_nss_compat_setgrent (int stayopen)\n{\n enum nss_status result;\n\n __libc_lock_lock (lock);\n\n if (ni == NULL)\n init_nss_interface ();\n\n result = internal_setgrent (&ext_ent, stayopen, 1);\n\n __libc_lock_unlock (lock);\n\n return result;\n}\n\n\n```\n\n#### _nss_compat_endgrent() [lines 216-232]\n```c\n}\n\nenum nss_status\n_nss_compat_endgrent (void)\n{\n enum nss_status result;\n\n __libc_lock_lock (lock);\n\n result = internal_endgrent (&ext_ent);\n\n __libc_lock_unlock (lock);\n\n return result;\n}\n\n/* get the next group from NSS (+ entry) */\n```\n\n#### _nss_compat_getgrnam_r() [lines 511-540]\n```c\n}\n\nenum nss_status\n_nss_compat_getgrnam_r (const char *name, struct group *grp,\n\t\t\tchar *buffer, size_t buflen, int *errnop)\n{\n ent_t ent = { TRUE, NSS_STATUS_SUCCESS, NULL, { NULL, 0, 0 }};\n enum nss_status result;\n\n if (name[0] == '-' || name[0] == '+')\n return NSS_STATUS_NOTFOUND;\n\n __libc_lock_lock (lock);\n\n if (ni == NULL)\n init_nss_interface ();\n\n __libc_lock_unlock (lock);\n\n result = internal_setgrent (&ent, 0, 0);\n\n if (result == NSS_STATUS_SUCCESS)\n result = internal_getgrnam_r (name, grp, &ent, buffer, buflen, errnop);\n\n internal_endgrent (&ent);\n\n return result;\n}\n\n/* Searches in /etc/group and the NIS/NIS+ map for a special group id */\n```\n\n#### _nss_compat_getgrgid_r() [lines 643-669]\n```c\n}\n\nenum nss_status\n_nss_compat_getgrgid_r (gid_t gid, struct group *grp,\n\t\t\tchar *buffer, size_t buflen, int *errnop)\n{\n ent_t ent = { TRUE, NSS_STATUS_SUCCESS, NULL, { NULL, 0, 0 }};\n enum nss_status result;\n\n __libc_lock_lock (lock);\n\n if (ni == NULL)\n init_nss_interface ();\n\n __libc_lock_unlock (lock);\n\n result = internal_setgrent (&ent, 0, 0);\n\n if (result == NSS_STATUS_SUCCESS)\n result = internal_getgrgid_r (gid, grp, &ent, buffer, buflen, errnop);\n\n internal_endgrent (&ent);\n\n return result;\n}\n\n\n```\n\n### nis/nss_compat/compat-pwd.c\n\n#### _nss_compat_setpwent() [lines 291-310]\n```c\n\n\nenum nss_status\n_nss_compat_setpwent (int stayopen)\n{\n enum nss_status result;\n\n __libc_lock_lock (lock);\n\n if (ni == NULL)\n init_nss_interface ();\n\n result = internal_setpwent (&ext_ent, stayopen, 1);\n\n __libc_lock_unlock (lock);\n\n return result;\n}\n\n\n```\n\n#### _nss_compat_endpwent() [lines 340-356]\n```c\n}\n\nenum nss_status\n_nss_compat_endpwent (void)\n{\n enum nss_status result;\n\n __libc_lock_lock (lock);\n\n result = internal_endpwent (&ext_ent);\n\n __libc_lock_unlock (lock);\n\n return result;\n}\n\n\n```\n\n#### _nss_compat_getpwnam_r() [lines 849-879]\n```c\n}\n\nenum nss_status\n_nss_compat_getpwnam_r (const char *name, struct passwd *pwd,\n\t\t\tchar *buffer, size_t buflen, int *errnop)\n{\n enum nss_status result;\n ent_t ent = { false, false, true, NSS_STATUS_SUCCESS, NULL, { NULL, 0, 0 },\n\t\t{ NULL, NULL, 0, 0, NULL, NULL, NULL }};\n\n if (name[0] == '-' || name[0] == '+')\n return NSS_STATUS_NOTFOUND;\n\n __libc_lock_lock (lock);\n\n if (ni == NULL)\n init_nss_interface ();\n\n __libc_lock_unlock (lock);\n\n result = internal_setpwent (&ent, 0, 0);\n\n if (result == NSS_STATUS_SUCCESS)\n result = internal_getpwnam_r (name, pwd, &ent, buffer, buflen, errnop);\n\n internal_endpwent (&ent);\n\n return result;\n}\n\n/* This function handle the + entry in /etc/passwd for getpwuid */\n```\n\n#### _nss_compat_getpwuid_r() [lines 1091-1118]\n```c\n}\n\nenum nss_status\n_nss_compat_getpwuid_r (uid_t uid, struct passwd *pwd,\n\t\t\tchar *buffer, size_t buflen, int *errnop)\n{\n enum nss_status result;\n ent_t ent = { false, false, true, NSS_STATUS_SUCCESS, NULL, { NULL, 0, 0 },\n\t\t{ NULL, NULL, 0, 0, NULL, NULL, NULL }};\n\n __libc_lock_lock (lock);\n\n if (ni == NULL)\n init_nss_interface ();\n\n __libc_lock_unlock (lock);\n\n result = internal_setpwent (&ent, 0, 0);\n\n if (result == NSS_STATUS_SUCCESS)\n result = internal_getpwuid_r (uid, pwd, &ent, buffer, buflen, errnop);\n\n internal_endpwent (&ent);\n\n return result;\n}\n\n\n```\n\n### nis/nss_compat/compat-spwd.c\n\n#### copy_spwd_changes() [lines 134-171]\n```c\n}\n\nstatic void\ncopy_spwd_changes (struct spwd *dest, struct spwd *src,\n\t\t char *buffer, size_t buflen)\n{\n if (src->sp_pwdp != NULL && strlen (src->sp_pwdp))\n {\n if (buffer == NULL)\n\tdest->sp_pwdp = strdup (src->sp_pwdp);\n else if (dest->sp_pwdp &&\n\t strlen (dest->sp_pwdp) >= strlen (src->sp_pwdp))\n\tstrcpy (dest->sp_pwdp, src->sp_pwdp);\n else\n\t{\n\t dest->sp_pwdp = buffer;\n\t strcpy (dest->sp_pwdp, src->sp_pwdp);\n\t buffer += strlen (dest->sp_pwdp) + 1;\n\t buflen = buflen - (strlen (dest->sp_pwdp) + 1);\n\t}\n }\n if (src->sp_lstchg != 0)\n dest->sp_lstchg = src->sp_lstchg;\n if (src->sp_min != 0)\n dest->sp_min = src->sp_min;\n if (src->sp_max != 0)\n dest->sp_max = src->sp_max;\n if (src->sp_warn != -1)\n dest->sp_warn = src->sp_warn;\n if (src->sp_inact != -1)\n dest->sp_inact = src->sp_inact;\n if (src->sp_expire != -1)\n dest->sp_expire = src->sp_expire;\n if (src->sp_flag != ~0ul)\n dest->sp_flag = src->sp_flag;\n}\n\nstatic enum nss_status\n```\n\n#### internal_setspent() [lines 169-248]\n```c\n}\n\nstatic enum nss_status\ninternal_setspent (ent_t *ent, int stayopen)\n{\n enum nss_status status = NSS_STATUS_SUCCESS;\n\n ent->first = ent->netgroup = 0;\n ent->files = true;\n\n /* If something was left over free it. */\n if (ent->netgroup)\n __internal_endnetgrent (&ent->netgrdata);\n\n if (ent->blacklist.data != NULL)\n {\n ent->blacklist.current = 1;\n ent->blacklist.data[0] = '|';\n ent->blacklist.data[1] = '\\0';\n }\n else\n ent->blacklist.current = 0;\n\n if (ent->stream == NULL)\n {\n ent->stream = fopen (\"/etc/shadow\", \"rme\");\n\n if (ent->stream == NULL)\n\tstatus = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;\n else\n\t{\n\t /* We have to make sure the file is `closed on exec'. */\n\t int result = 0;\n\n\t if (__compat_have_cloexec <= 0)\n\t {\n\t int flags;\n\t result = flags = fcntl (fileno_unlocked (ent->stream), F_GETFD,\n\t\t\t\t 0);\n\t if (result >= 0)\n\t\t{\n#if defined O_CLOEXEC && !defined __ASSUME_O_CLOEXEC\n\t\t if (__compat_have_cloexec == 0)\n/* ... truncated ... */\n```\n\n### nss/nss_files/files-XXX.c\n\n#### __libc_lock_define_initialized() [lines 24-125]\n```c\n#include \"nsswitch.h\"\n\n#include <kernel-features.h>\n\n/* These symbols are defined by the including source file:\n\n ENTNAME -- database name of the structure and functions (hostent, pwent).\n STRUCTURE -- struct name, define only if not ENTNAME (passwd, group).\n DATABASE -- string of the database file's name (\"hosts\", \"passwd\").\n\n NEED_H_ERRNO - defined iff an arg `int *herrnop' is used.\n\n Also see files-parse.c.\n*/\n\n#define ENTNAME_r\tCONCAT(ENTNAME,_r)\n\n#define DATAFILE\t\"/etc/\" DATABASE\n\n#ifdef NEED_H_ERRNO\n# include <netdb.h>\n# define H_ERRNO_PROTO\t, int *herrnop\n# define H_ERRNO_ARG\t, herrnop\n# define H_ERRNO_SET(val) (*herrnop = (val))\n#else\n# define H_ERRNO_PROTO\n# define H_ERRNO_ARG\n# define H_ERRNO_SET(val) ((void) 0)\n#endif\n\n#ifndef EXTRA_ARGS\n# define EXTRA_ARGS\n# define EXTRA_ARGS_DECL\n# define EXTRA_ARGS_VALUE\n#endif\n\n/* Locks the static variables in this file. */\n__libc_lock_define_initialized (static, lock)\n\f\n/* Maintenance of the shared stream open on the database file. */\n\nstatic FILE *stream;\nstatic fpos_t position;\nstatic enum { nouse, getent, getby } last_use;\nstatic int keep_stream;\n\n/* Open database file if not already opened. */\nstatic enum nss_status\ninternal_setent (int stayopen)\n{\n enum nss_status status = NSS_STATUS_SUCCESS;\n\n if (stream == NULL)\n {\n stream = fopen (DATAFILE, \"rce\");\n\n if (stream == NULL)\n\tstatus = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;\n else\n\t{\n#if !defined O_CLOEXEC || !defined __ASSUME_O_CLOEXEC\n# ifdef O_CLOEXEC\n\t if (__have_o_cloexec <= 0)\n# endif\n\t {\n\t /* We have to make sure the file is `closed on exec'. */\n\t int result;\n\t int flags;\n\n\t result = flags = fcntl (fileno (stream), F_GETFD, 0);\n\t if (result >= 0)\n\t\t{\n# ifdef O_CLOEXEC\n\t\t if (__have_o_cloexec == 0)\n\t\t __have_o_cloexec = (flags & FD_CLOEXEC) == 0 ? -1 : 1;\n\t\t if (__have_o_cloexec < 0)\n# endif\n\t\t {\n\t\t flags |= FD_CLOEXEC;\n\t\t result = fcntl (fileno (stream), F_SETFD, flags);\n\t\t }\n\t\t}\n\t if (result < 0)\n\t\t{\n\t\t /* S\n/* ... truncated ... */\n```\n\n### nss/nss_files/files-alias.c\n\n#### __libc_lock_define_initialized() [lines 1-97]\n```c\n/* Mail alias file parser in nss_files module.\n Copyright (C) 1996-2014 Free Software Foundation, Inc.\n This file is part of the GNU C Library.\n Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.\n\n The GNU C Library is free software; you can redistribute it and/or\n modify it under the terms of the GNU Lesser General Public\n License as published by the Free Software Foundation; either\n version 2.1 of the License, or (at your option) any later version.\n\n The GNU C Library is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public\n License along with the GNU C Library; if not, see\n <http://www.gnu.org/licenses/>. */\n\n#include <aliases.h>\n#include <ctype.h>\n#include <errno.h>\n#include <fcntl.h>\n#include <bits/libc-lock.h>\n#include <stdlib.h>\n#include <stdio.h>\n#include <string.h>\n\n#include <kernel-features.h>\n\n#include \"nsswitch.h\"\n\n/* Locks the static variables in this file. */\n__libc_lock_define_initialized (static, lock)\n\f\n/* Maintenance of the shared stream open on the database file. */\n\nstatic FILE *stream;\nstatic fpos_t position;\nstatic enum { nouse, getent, getby } last_use;\n\n\nstatic enum nss_status\ninternal_setent (void)\n{\n enum nss_status status = NSS_STATUS_SUCCESS;\n\n if (stream == NULL)\n {\n stream = fopen (\"/etc/aliases\", \"rce\");\n\n if (stream == NULL)\n\tstatus = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;\n else\n\t{\n#if !defined O_CLOEXEC || !defined __ASSUME_O_CLOEXEC\n# ifdef O_CLOEXEC\n\t if (__have_o_cloexec <= 0)\n# endif\n\t {\n\t /* We have to make sure the file is `closed on exec'. */\n\t int result;\n\t int flags;\n\n\t result = flags = fcntl (fileno (stream), F_GETFD, 0);\n\t if (result >= 0)\n\t\t{\n# ifdef O_CLOEXEC\n\t\t if (__have_o_cloexec == 0)\n\t\t __have_o_cloexec = (flags & FD_CLOEXEC) == \n/* ... truncated ... */\n```\n\n### nss/nss_files/files-hosts.c\n\n#### _nss_files_gethostbyname3_r() [lines 116-356]\n```c\n#undef EXTRA_ARGS_VALUE\n\nenum nss_status\n_nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result,\n\t\t\t char *buffer, size_t buflen, int *errnop,\n\t\t\t int *herrnop, int32_t *ttlp, char **canonp)\n{\n uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct hostent_data);\n buffer += pad;\n buflen = buflen > pad ? buflen - pad : 0;\n\n __libc_lock_lock (lock);\n\n /* Reset file pointer to beginning or open file. */\n enum nss_status status = internal_setent (keep_stream);\n\n if (status == NSS_STATUS_SUCCESS)\n {\n /* XXX Is using _res to determine whether we want to convert IPv4\n addresses to IPv6 addresses really the right thing to do? */\n int flags = ((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0);\n\n /* Tell getent function that we have repositioned the file pointer. */\n last_use = getby;\n\n while ((status = internal_getent (result, buffer, buflen, errnop,\n\t\t\t\t\therrnop, af, flags))\n\t == NSS_STATUS_SUCCESS)\n\t{\n\t LOOKUP_NAME_CASE (h_name, h_aliases)\n\t}\n\n if (status == NSS_STATUS_SUCCESS\n\t && _res_hconf.flags & HCONF_FLAG_MULTI)\n\t{\n\t /* We have to get all host entries from the file. */\n\t size_t tmp_buflen = MIN (buflen, 4096);\n\t char tmp_buffer_stack[tmp_buflen]\n\t __attribute__ ((__aligned__ (__alignof__ (struct hostent_data))));\n\t char *tmp_buffer = tmp_buffer_stack;\n/* ... 187 lines omitted ... */\n\t else\n\t status = NSS_STATUS_SUCCESS;\n\tout:\n\t if (tmp_buffer_malloced)\n\t free (tmp_buffer);\n\t}\n\n if (! keep_stream)\n\tinternal_endent ();\n }\n\n if (canonp && status == NSS_STATUS_SUCCESS)\n *canonp = result->h_name;\n\n __libc_lock_unlock (lock);\n\n return status;\n}\n\nenum nss_status\n```\n\n#### _nss_files_gethostbyname4_r() [lines 374-496]\n```c\n}\n\nenum nss_status\n_nss_files_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,\n\t\t\t char *buffer, size_t buflen, int *errnop,\n\t\t\t int *herrnop, int32_t *ttlp)\n{\n __libc_lock_lock (lock);\n\n /* Reset file pointer to beginning or open file. */\n enum nss_status status = interna\n/* ... truncated ... */\n```\n\n\n## Upstream Fix\n```diff\n[BZ #18007]\n\t* nis/nss_compat/compat-grp.c (internal_endgrent): Add parameter\n\tneedent, call nss_endgrent only if non-zero.\n\t(_nss_compat_endgrent): Pass non-zero.\n\t(_nss_compat_getgrnam_r, _nss_compat_getgrgid_r): Pass zero.\n\t* nis/nss_compat/compat-pwd.c (internal_endpwent): Add parameter\n\tneedent, call nss_endpwent only if non-zero.\n\t(_nss_compat_endpwent): Pass non-zero.\n\t(_nss_compat_getpwnam_r, _nss_compat_getpwuid_r): Pass zero.\n\t* nis/nss_compat/compat-spwd.c (internal_setspent): Add parameter\n\tneedent, call nss_setspent only if non-zero.\n\t(_nss_compat_setspent): Pass non-zero.\n\t(internal_endspent): Add parameter needent, call nss_endspent only\n\tif non-zero.\n\t(_nss_compat_endspent, _nss_compat_getspent_r): Pass non-zero.\n\t(_nss_compat_getspnam_r): Pass zero.\n\t* nss/nss_files/files-XXX.c (position, last_use, keep_stream):\n\tRemove. All uses removed.\n\t(internal_setent): Remove parameter stayopen, add parameter\n\tstream. Use it instead of global variable.\n\t(CONCAT(_nss_files_set,ENTNAME)): Pass global stream.\n\t(internal_endent, internal_getent): Add parameter stream. Use it\n\tinstead of global variable.\n\t(CONCAT(_nss_files_end,ENTNAME))\n\t(CONCAT(_nss_files_get,ENTNAME_r)): Pass global stream.\n\t(_nss_files_get##name##_r): Pass local stream. Remove locking.\n\t* nss/nss_files/files-alias.c (position, last_use): Remove. All\n\tuses removed.\n\t(internal_setent, internal_endent): Add parameter stream. Use it\n\tinstead of global variable.\n\t(_nss_files_setaliasent, _nss_files_endaliasent): Pass global\n\tstream.\n\t(get_next_alias): Add parameter stream.\n\t(_nss_files_getaliasent_r): Pass global stream.\n\t(_nss_files_getaliasbyname_r): Pass local stream. Remove locking.\n\t* nss/nss_files/files-hosts.c (_nss_files_gethostbyname3_r)\n\t(_nss_files_gethostbyname4_r): Pass local stream to\n\tinternal_setent, internal_getent and internal_endent. Remove\n\tlocking.\n\nIndex: glibc-2.19/nis/nss_compat/compat-grp.c\n===================================================================\n--- glibc-2.19.orig/nis/nss_compat/compat-grp.c\n+++ glibc-2.19/nis/nss_compat/compat-grp.c\n@@ -192,9 +192,9 @@ _nss_compat_setgrent (int stayopen)\n \n \n static enum nss_status\n-internal_endgrent (ent_t *ent)\n+internal_endgrent (ent_t *ent, int needent)\n {\n- if (nss_endgrent)\n+ if (needent && nss_endgrent)\n nss_endgrent ();\n \n if (ent->stream != NULL)\n@@ -222,7 +222,7 @@ _nss_compat_endgrent (void)\n \n __libc_lock_lock (lock);\n \n- result = internal_endgrent (&ext_ent);\n+ result = internal_endgrent (&ext_ent, 1);\n \n __libc_lock_unlock (lock);\n \n@@ -532,7 +532,7 @@ _nss_compat_getgrnam_r (const char *name\n if (result == NSS_STATUS_SUCCESS)\n result = internal_getgrnam_r (name, grp, &ent, buffer, buflen, errnop);\n \n- internal_endgrent (&ent);\n+ internal_endgrent (&ent, 0);\n \n return result;\n }\n@@ -661,7 +661,7 @@ _nss_compat_getgrgid_r (gid_t gid, struc\n if (result == NSS_STATUS_SUCCESS)\n result = internal_getgrgid_r (gid, grp, &ent, buffer, buflen, errnop);\n \n- internal_endgrent (&ent);\n+ internal_endgrent (&ent, 0);\n \n return result;\n }\nIndex: glibc-2.19/nis/nss_compat/compat-pwd.c\n===================================================================\n--- glibc-2.19.orig/nis/nss_compat/compat-pwd.c\n+++ glibc-2.19/nis/nss_compat/compat-pwd.c\n@@ -309,9 +309,9 @@ _nss_compat_setpwent (int stayopen)\n \n \n static enum nss_status\n-internal_endpwent (ent_t *ent)\n+internal_endpwent (ent_t *ent, int needent)\n {\n- if (nss_endpwent)\n+ if (needent && nss_endpwent)\n nss_endpwent ();\n \n if (ent->stream != NULL)\n@@ -346,7 +346,7 @@ _nss_compat_endpwent (void)\n \n __libc_lock_lock (lock);\n \n- result = internal_endpwent (&ext_ent);\n+ result = internal_endpwent (&ext_ent, 1);\n \n __libc_lock_unlock (lock);\n \n@@ -871,7 +871,7 @@ _nss_compat_getpwnam_r (const char *name\n if (result == NSS_STATUS_SUCCESS)\n result = internal_getpwnam_r (name, pwd, &ent, buffer, buflen, errnop);\n \n- internal_endpwent (&ent);\n+ internal_endpwent (&ent, 0);\n \n return result;\n }\n@@ -1110,7 +1110,7 @@ _nss_compat_getpwuid_r (uid_t uid, struc\n if (result == NSS_STATUS_SUCCESS)\n result = internal_getpwuid_r (uid, pwd, &ent, buffer, buflen, errnop);\n \n- internal_endpwent (&ent);\n+ internal_endpwent (&ent, 0);\n \n return result;\n }\nIndex: glibc-2.19/nis/nss_compat/compat-spwd.c\n===================================================================\n--- glibc-2.19.orig/nis/nss_compat/compat-spwd.c\n+++ glibc-2.19/nis/nss_compat/compat-spwd.c\n@@ -169,7 +169,7 @@ copy_spwd_changes (struct spwd *dest, st\n }\n \n static enum nss_status\n-internal_setspent (ent_t *ent, int stayopen)\n+internal_setspent (ent_t *ent, int stayopen, int needent)\n {\n enum nss_status status = NSS_STATUS_SUCCESS;\n \n@@ -239,7 +239,7 @@ internal_setspent (ent_t *ent, int stayo\n \n give_spwd_free (&ent->pwd);\n \n- if (status == NSS_STATUS_SUCCESS && nss_setspent)\n+ if (needent && status == NSS_STATUS_SUCCESS && nss_setspent)\n ent->setent_status = nss_setspent (stayopen);\n \n return status;\n@@ -256,7 +256,7 @@ _nss_compat_setspent (int stayopen)\n if (ni == NULL)\n init_nss_interface ();\n \n- result = internal_setspent (&ext_ent, stayopen);\n+ result = internal_setspent (&ext_ent, stayopen, 1);\n \n __libc_lock_unlock (lock);\n \n@@ -265,9 +265,9 @@ _nss_compat_setspent (int stayopen)\n \n \n static enum nss_status\n-internal_endspent (ent_t *ent)\n+internal_endspent (ent_t *ent, int needent)\n {\n- if (nss_endspent)\n+ if (needent && nss_endspent)\n nss_endspent ();\n \n if (ent->stream != NULL)\n@@ -303,7 +303,7 @@ _nss_compat_endspent (void)\n \n __libc_lock_lock (lock);\n \n- result = internal_endspent (&ext_ent);\n+ result = internal_endspent (&ext_ent, 1);\n \n __libc_lock_unlock (lock);\n \n@@ -658,7 +658,7 @@ _nss_compat_getspent_r (struct spwd *pwd\n init_nss_interface ();\n \n if (ext_ent.stream == NULL)\n- result = internal_setspent (&ext_ent, 1);\n+ result = internal_setspent (&ext_ent, 1, 1);\n \n if (result == NSS_STATUS_SUCCESS)\n result = internal_getspent_r (pwd, &ext_ent, buffer, buflen, errnop);\n@@ -830,12 +830,12 @@ _nss_compat_getspnam_r (const char *name\n \n __libc_lock_unlock (lock);\n \n- result = internal_setspent (&ent, 0);\n+ result = internal_setspent (&ent, 0, 0);\n \n if (result == NSS_STATUS_SUCCESS)\n result = internal_getspnam_r (name, pwd, &ent, buffer, buflen, errnop);\n \n- internal_endspent (&ent);\n+ internal_endspent (&ent, 0);\n \n return result;\n }\nIndex: glibc-2.19/nss/nss_files/files-XXX.c\n===================================================================\n--- glibc-2.19.orig/nss/nss_files/files-XXX.c\n+++ glibc-2.19/nss/nss_files/files-XXX.c\n@@ -63,21 +63,18 @@ __libc_lock_define_initialized (static,\n /* Maintenance of the shared stream open on the database file. */\n \n static FILE *stream;\n-static fpos_t position;\n-static enum { nouse, getent, getby } last_use;\n-static int keep_stream;\n \n /* Open database file if not already opened. */\n static enum nss_status\n-internal_setent (int stayopen)\n+internal_setent (FILE **stream)\n {\n enum nss_status status = NSS_STATUS_SUCCESS;\n \n- if (stream == NULL)\n+ if (*stream == NULL)\n {\n- stream = fopen (DATAFILE, \"rce\");\n+ *stream = fopen (DATAFILE, \"rce\");\n \n- if (stream == NULL)\n+ if (*stream == NULL)\n \tstatus = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;\n else\n \t{\n@@ -90,7 +87,7 @@ internal_setent (int stayopen)\n \t int result;\n \t int flags;\n \n-\t result = flags = fcntl (fileno (stream), F_GETFD, 0);\n+\t result = flags = fcntl (fileno (*stream), F_GETFD, 0);\n \t if (result >= 0)\n \t\t{\n # ifdef O_CLOEXEC\n@@ -100,15 +97,15 @@ internal_setent (int stayopen)\n # endif\n \t\t {\n \t\t flags |= FD_CLOEXEC;\n-\t\t result = fcntl (fileno (stream), F_SETFD, flags);\n+\t\t result = fcntl (fileno (*stream), F_SETFD, flags);\n \t\t }\n \t\t}\n \t if (result < 0)\n \t\t{\n \t\t /* Something went wrong. Close the stream and return a\n \t\t failure. */\n-\t\t fclose (stream);\n-\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "[BZ #18007]\n\t* nis/nss_compat/compat-grp.c (internal_endgrent): Add parameter\n\tneedent, call nss_endgrent only if non-zero.\n\t(_nss_compat_endgrent): Pass non-zero.\n\t(_nss_compat_getgrnam_r, _nss_compat_getgrgid_r): Pass zero.\n\t* nis/nss_compat/compat-pwd.c (internal_endpwent): Add parameter\n\tneedent, call nss_endpwent only if non-zero.\n\t(_nss_compat_endpwent): Pass non-zero.\n\t(_nss_compat_getpwnam_r, _nss_compat_getpwuid_r): Pass zero.\n\t* nis/nss_compat/compat-spwd.c (internal_setspent): Add parameter\n\tneedent, call nss_setspent only if non-zero.\n\t(_nss_compat_setspent): Pass non-zero.\n\t(internal_endspent): Add parameter needent, call nss_endspent only\n\tif non-zero.\n\t(_nss_compat_endspent, _nss_compat_getspent_r): Pass non-zero.\n\t(_nss_compat_getspnam_r): Pass zero.\n\t* nss/nss_files/files-XXX.c (position, last_use, keep_stream):\n\tRemove. All uses removed.\n\t(internal_setent): Remove parameter stayopen, add parameter\n\tstream. Use it instead of global variable.\n\t(CONCAT(_nss_files_set,ENTNAME)): Pass global stream.\n\t(internal_endent, internal_getent): Add parameter stream. Use it\n\tinstead of global variable.\n\t(CONCAT(_nss_files_end,ENTNAME))\n\t(CONCAT(_nss_files_get,ENTNAME_r)): Pass global stream.\n\t(_nss_files_get##name##_r): Pass local stream. Remove locking.\n\t* nss/nss_files/files-alias.c (position, last_use): Remove. All\n\tuses removed.\n\t(internal_setent, internal_endent): Add parameter stream. Use it\n\tinstead of global variable.\n\t(_nss_files_setaliasent, _nss_files_endaliasent): Pass global\n\tstream.\n\t(get_next_alias): Add parameter stream.\n\t(_nss_files_getaliasent_r): Pass global stream.\n\t(_nss_files_getaliasbyname_r): Pass local stream. Remove locking.\n\t* nss/nss_files/files-hosts.c (_nss_files_gethostbyname3_r)\n\t(_nss_files_gethostbyname4_r): Pass local stream to\n\tinternal_setent, internal_getent and internal_endent. Remove\n\tlocking.\n\nIndex: glibc-2.19/nis/nss_compat/compat-grp.c\n===================================================================\n--- glibc-2.19.orig/nis/nss_compat/compat-grp.c\n+++ glibc-2.19/nis/nss_compat/compat-grp.c\n@@ -192,9 +192,9 @@ _nss_compat_setgrent (int stayopen)\n \n \n static enum nss_status\n-internal_endgrent (ent_t *ent)\n+internal_endgrent (ent_t *ent, int needent)\n {\n- if (nss_endgrent)\n+ if (needent && nss_endgrent)\n nss_endgrent ();\n \n if (ent->stream != NULL)\n@@ -222,7 +222,7 @@ _nss_compat_endgrent (void)\n \n __libc_lock_lock (lock);\n \n- result = internal_endgrent (&ext_ent);\n+ result = internal_endgrent (&ext_ent, 1);\n \n __libc_lock_unlock (lock);\n \n@@ -532,7 +532,7 @@ _nss_compat_getgrnam_r (const char *name\n if (result == NSS_STATUS_SUCCESS)\n result = internal_getgrnam_r (name, grp, &ent, buffer, buflen, errnop);\n \n- internal_endgrent (&ent);\n+ internal_endgrent (&ent, 0);\n \n return result;\n }\n@@ -661,7 +661,7 @@ _nss_compat_getgrgid_r (gid_t gid, struc\n if (result == NSS_STATUS_SUCCESS)\n result = internal_getgrgid_r (gid, grp, &ent, buffer, buflen, errnop);\n \n- internal_endgrent (&ent);\n+ internal_endgrent (&ent, 0);\n \n return result;\n }\nIndex: glibc-2.19/nis/nss_compat/compat-pwd.c\n===================================================================\n--- glibc-2.19.orig/nis/nss_compat/compat-pwd.c\n+++ glibc-2.19/nis/nss_compat/compat-pwd.c\n@@ -309,9 +309,9 @@ _nss_compat_setpwent (int stayopen)\n \n \n static enum nss_status\n-internal_endpwent (ent_t *ent)\n+internal_endpwent (ent_t *ent, int needent)\n {\n- if (nss_endpwent)\n+ if (needent && nss_endpwent)\n nss_endpwent ();\n \n if (ent->stream != NULL)\n@@ -346,7 +346,7 @@ _nss_compat_endpwent (void)\n \n __libc_lock_lock (lock);\n \n- result = internal_endpwent (&ext_ent);\n+ result = internal_endpwent (&ext_ent, 1);\n \n __libc_lock_unlock (lock);\n \n@@ -871,7 +871,7 @@ _nss_compat_getpwnam_r (const char *name\n if (result == NSS_STATUS_SUCCESS)\n result = internal_getpwnam_r (name, pwd, &ent, buffer, buflen, errnop);\n \n- internal_endpwent (&ent);\n+ internal_endpwent (&ent, 0);\n \n return result;\n }\n@@ -1110,7 +1110,7 @@ _nss_compat_getpwuid_r (uid_t uid, struc\n if (result == NSS_STATUS_SUCCESS)\n result = internal_getpwuid_r (uid, pwd, &ent, buffer, buflen, errnop);\n \n- internal_endpwent (&ent);\n+ internal_endpwent (&ent, 0);\n \n return result;\n }\nIndex: glibc-2.19/nis/nss_compat/compat-spwd.c\n===================================================================\n--- glibc-2.19.orig/nis/nss_compat/compat-spwd.c\n+++ glibc-2.19/nis/nss_compat/compat-spwd.c\n@@ -169,7 +169,7 @@ copy_spwd_changes (struct spwd *dest, st\n }\n \n static enum nss_status\n-internal_setspent (ent_t *ent, int stayopen)\n+internal_setspent (ent_t *ent, int stayopen, int needent)\n {\n enum nss_status status = NSS_STATUS_SUCCESS;\n \n@@ -239,7 +239,7 @@ internal_setspent (ent_t *ent, int stayo\n \n give_spwd_free (&ent->pwd);\n \n- if (status == NSS_STATUS_SUCCESS && nss_setspent)\n+ if (needent && status == NSS_STATUS_SUCCESS && nss_setspent)\n ent->setent_status = nss_setspent (stayopen);\n \n return status;\n@@ -256,7 +256,7 @@ _nss_compat_setspent (int stayopen)\n if (ni == NULL)\n init_nss_interface ();\n \n- result = internal_setspent (&ext_ent, stayopen);\n+ result = internal_setspent (&ext_ent, stayopen, 1);\n \n __libc_lock_unlock (lock);\n \n@@ -265,9 +265,9 @@ _nss_compat_setspent (int stayopen)\n \n \n static enum nss_status\n-internal_endspent (ent_t *ent)\n+internal_endspent (ent_t *ent, int needent)\n {\n- if (nss_endspent)\n+ if (needent && nss_endspent)\n nss_endspent ();\n \n if (ent->stream != NULL)\n@@ -303,7 +303,7 @@ _nss_compat_endspent (void)\n \n __libc_lock_lock (lock);\n \n- result = internal_endspent (&ext_ent);\n+ result = internal_endspent (&ext_ent, 1);\n \n __libc_lock_unlock (lock);\n \n@@ -658,7 +658,7 @@ _nss_compat_getspent_r (struct spwd *pwd\n init_nss_interface ();\n \n if (ext_ent.stream == NULL)\n- result = internal_setspent (&ext_ent, 1);\n+ result = internal_setspent (&ext_ent, 1, 1);\n \n if (result == NSS_STATUS_SUCCESS)\n result = internal_getspent_r (pwd, &ext_ent, buffer, buflen, errnop);\n@@ -830,12 +830,12 @@ _nss_compat_getspnam_r (const char *name\n \n __libc_lock_unlock (lock);\n \n- result = internal_setspent (&ent, 0);\n+ result = internal_setspent (&ent, 0, 0);\n \n if (result == NSS_STATUS_SUCCESS)\n result = internal_getspnam_r (name, pwd, &ent, buffer, buflen, errnop);\n \n- internal_endspent (&ent);\n+ internal_endspent (&ent, 0);\n \n return result;\n }\nIndex: glibc-2.19/nss/nss_files/files-XXX.c\n===================================================================\n--- glibc-2.19.orig/nss/nss_files/files-XXX.c\n+++ glibc-2.19/nss/nss_files/files-XXX.c\n@@ -63,21 +63,18 @@ __libc_lock_define_initialized (static,\n /* Maintenance of the shared stream open on the database file. */\n \n static FILE *stream;\n-static fpos_t position;\n-static enum { nouse, getent, getby } last_use;\n-static int keep_stream;\n \n /* Open database file if not already opened. */\n static enum nss_status\n-internal_setent (int stayopen)\n+internal_setent (FILE **stream)\n {\n enum nss_status status = NSS_STATUS_SUCCESS;\n \n- if (stream == NULL)\n+ if (*stream == NULL)\n {\n- stream = fopen (DATAFILE, \"rce\");\n+ *stream = fopen (DATAFILE, \"rce\");\n \n- if (stream == NULL)\n+ if (*stream == NULL)\n \tstatus = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;\n else\n \t{\n@@ -90,7 +87,7 @@ internal_setent (int stayopen)\n \t int result;\n \t int flags;\n \n-\t result = flags = fcntl (fileno (stream), F_GETFD, 0);\n+\t result = flags = fcntl (fileno (*stream), F_GETFD, 0);\n \t if (result >= 0)\n \t\t{\n # ifdef O_CLOEXEC\n@@ -100,15 +97,15 @@ internal_setent (int stayopen)\n # endif\n \t\t {\n \t\t flags |= FD_CLOEXEC;\n-\t\t result = fcntl (fileno (stream), F_SETFD, flags);\n+\t\t result = fcntl (fileno (*stream), F_SETFD, flags);\n \t\t }\n \t\t}\n \t if (result < 0)\n \t\t{\n \t\t /* Something went wrong. Close the stream and return a\n \t\t failure. */\n-\t\t fclose (stream);\n-\t\t stream = NULL;\n+\t\t fclose (*stream);\n+\t\t *stream = NULL;\n \t\t status = NSS_STATUS_UNAVAIL;\n \t\t}\n \t }\n@@ -116,11 +113,7 @@ internal_setent (int stayopen)\n \t}\n }\n else\n- rewind (stream);\n-\n- /* Remember STAYOPEN flag. */\n- if (stream != NULL)\n- keep_stream |= stayopen;\n+ rewind (*stream);\n \n return status;\n }\n@@ -134,16 +127,7 @@ CONCAT(_nss_files_set,ENTNAME) (int stay\n \n __libc_lock_lock (lock);\n \n- status = internal_setent (stayopen);\n-\n- if (status == NSS_STATUS_SUCCESS && fgetpos (stream, &position) < 0)\n- {\n- fclose (stream);\n- stream = NULL;\n- status = NSS_STATUS_UNAVAIL;\n- }\n-\n- last_use = getent;\n+ status = internal_setent (&stream);\n \n __libc_lock_unlock (lock);\n \n@@ -153,12 +137,12 @@ CONCAT(_nss_files_set,ENTNAME) (int stay\n \n /* Close the database file. */\n static void\n-internal_endent (void)\n+internal_endent (FILE **stream)\n {\n- if (stream != NULL)\n+ if (*stream != NULL)\n {\n- fclose (stream);\n- stream = NULL;\n+ fclose (*stream);\n+ *stream = NULL;\n }\n }\n \n@@ -169,10 +153,7 @@ CONCAT(_nss_files_end,ENTNAME) (void)\n {\n __libc_lock_lock (lock);\n \n- internal_endent ();\n-\n- /* Reset STAYOPEN flag. */\n- keep_stream = 0;\n+ internal_endent (&stream);\n \n __libc_lock_unlock (lock);\n \n@@ -227,7 +208,7 @@ get_contents (char *linebuf, size_t len,\n \n /* Parsing the database file into `struct STRUCTURE' data structures. */\n static enum nss_status\n-internal_getent (struct STRUCTURE *result,\n+internal_getent (FILE *stream, struct STRUCTURE *result,\n \t\t char *buffer, size_t buflen, int *errnop H_ERRNO_PROTO\n \t\t EXTRA_ARGS_DECL)\n {\n@@ -300,45 +281,14 @@ CONCAT(_nss_files_get,ENTNAME_r) (struct\n {\n int save_errno = errno;\n \n- status = internal_setent (0);\n+ status = internal_setent (&stream);\n \n __set_errno (save_errno);\n-\n- if (status == NSS_STATUS_SUCCESS && fgetpos (stream, &position) < 0)\n-\t{\n-\t fclose (stream);\n-\t stream = NULL;\n-\t status = NSS_STATUS_UNAVAIL;\n-\t}\n }\n \n if (status == NSS_STATUS_SUCCESS)\n- {\n- /* If the last use was not by the getent function we need the\n-\t position the stream. */\n- if (last_use != getent)\n-\t{\n-\t if (fsetpos (stream, &position) < 0)\n-\t status = NSS_STATUS_UNAVAIL;\n-\t else\n-\t last_use = getent;\n-\t}\n-\n- if (status == NSS_STATUS_SUCCESS)\n-\t{\n-\t status = internal_getent (result, buffer, buflen, errnop\n-\t\t\t\t H_ERRNO_ARG EXTRA_ARGS_VALUE);\n-\n-\t /* Remember this position if we were successful. If the\n-\t operation failed we give the user a chance to repeat the\n-\t operation (perhaps the buffer was too small). */\n-\t if (status == NSS_STATUS_SUCCESS)\n-\t fgetpos (stream, &position);\n-\t else\n-\t /* We must make sure we reposition the stream the next call. */\n-\t last_use = nouse;\n-\t}\n- }\n+ status = internal_getent (stream, result, buffer, buflen, errnop\n+\t\t\t H_ERRNO_ARG EXTRA_ARGS_VALUE);\n \n __libc_lock_unlock (lock);\n \n@@ -364,27 +314,20 @@ _nss_files_get##name##_r (proto,\n \t\t\t size_t buflen, int *errnop H_ERRNO_PROTO)\t \\\n {\t\t\t\t\t\t\t\t\t \\\n enum nss_status status;\t\t\t\t\t\t \\\n+ FILE *stream = NULL;\t\t\t\t\t\t\t \\\n \t\t\t\t\t\t\t\t\t \\\n- __libc_lock_lock (lock);\t\t\t\t\t\t \\\n-\t\t\t\t\t\t\t\t\t \\\n- /* Reset file pointer to beginning or open file. */\t\t\t \\\n- status = internal_setent (keep_stream);\t\t\t\t \\\n+ /* Open file. */\t\t\t\t\t\t\t \\\n+ status = internal_setent (&stream);\t\t\t\t\t \\\n \t\t\t\t\t\t\t\t\t \\\n if (status == NSS_STATUS_SUCCESS)\t\t\t\t\t \\\n {\t\t\t\t\t\t\t\t\t \\\n- /* Tell getent function that we have repositioned the file pointer. */ \\\n- last_use = getby;\t\t\t\t\t\t\t \\\n-\t\t\t\t\t\t\t\t\t \\\n- while ((status = internal_getent (result, buffer, buflen, errnop\t \\\n+ while ((status = internal_getent (stream, result, buffer, buflen, errnop \\\n \t\t\t\t\tH_ERRNO_ARG EXTRA_ARGS_VALUE))\t \\\n \t == NSS_STATUS_SUCCESS)\t\t\t\t\t \\\n \t{ break_if_match }\t\t\t\t\t\t \\\n \t\t\t\t\t\t\t\t\t \\\n- if (! keep_stream)\t\t\t\t\t\t \\\n-\tinternal_endent ();\t\t\t\t\t\t \\\n+ internal_endent (&stream);\t\t\t\t\t \\\n }\t\t\t\t\t\t\t\t\t \\\n \t\t\t\t\t\t\t\t\t \\\n- __libc_lock_unlock (lock);\t\t\t\t\t\t \\\n-\t\t\t\t\t\t\t\t\t \\\n return status;\t\t\t\t\t\t\t \\\n }\nIndex: glibc-2.19/nss/nss_files/files-alias.c\n===================================================================\n--- glibc-2.19.orig/nss/nss_files/files-alias.c\n+++ glibc-2.19/nss/nss_files/files-alias.c\n@@ -36,20 +36,18 @@ __libc_lock_define_initialized (static,\n /* Maintenance of the shared stream open on the database file. */\n \n static FILE *stream;\n-static fpos_t position;\n-static enum { nouse, getent, getby } last_use;\n \n \n static enum nss_status\n-internal_setent (void)\n+internal_setent (FILE **stream)\n {\n enum nss_status status = NSS_STATUS_SUCCESS;\n \n- if (stream == NULL)\n+ if (*stream == NULL)\n {\n- stream = fopen (\"/etc/aliases\", \"rce\");\n+ *stream = fopen (\"/etc/aliases\", \"rce\");\n \n- if (stream == NULL)\n+ if (*stream == NULL)\n \tstatus = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;\n else\n \t{\n@@ -62,7 +60,7 @@ internal_setent (void)\n \t int result;\n \t int flags;\n \n-\t result = flags = fcntl (fileno (stream), F_GETFD, 0);\n+\t result = flags = fcntl (fileno (*stream), F_GETFD, 0);\n \t if (result >= 0)\n \t\t{\n # ifdef O_CLOEXEC\n@@ -72,14 +70,14 @@ internal_setent (void)\n # endif\n \t\t {\n \t\t flags |= FD_CLOEXEC;\n-\t\t result = fcntl (fileno (stream), F_SETFD, flags);\n+\t\t result = fcntl (fileno (*stream), F_SETFD, flags);\n \t\t }\n \t\t}\n \t if (result < 0)\n \t\t{\n \t\t /* Something went wrong. Close the stream and return a\n \t\t failure. */\n-\t\t fclose (stream);\n+\t\t fclose (*stream);\n \t\t stream = NULL;\n \t\t status = NSS_STATUS_UNAVAIL;\n \t\t}\n@@ -88,7 +86,7 @@ internal_setent (void)\n \t}\n }\n else\n- rewind (stream);\n+ rewind (*stream);\n \n return status;\n }\n@@ -102,16 +100,7 @@ _nss_files_setaliasent (void)\n \n __libc_lock_lock (lock);\n \n- status = internal_setent ();\n-\n- if (status == NSS_STATUS_SUCCESS && fgetpos (stream, &position) < 0)\n- {\n- fclose (stream);\n- stream = NULL;\n- status = NSS_STATUS_UNAVAIL;\n- }\n-\n- last_use = getent;\n+ status = internal_setent (&stream);\n \n __libc_lock_unlock (lock);\n \n@@ -121,12 +110,12 @@ _nss_files_setaliasent (void)\n \n /* Close the database file. */\n static void\n-internal_endent (void)\n+internal_endent (FILE **stream)\n {\n- if (stream != NULL)\n+ if (*stream != NULL)\n {\n- fclose (stream);\n- stream = NULL;\n+ fclose (*stream);\n+ *stream = NULL;\n }\n }\n \n@@ -137,7 +126,7 @@ _nss_files_endaliasent (void)\n {\n __libc_lock_lock (lock);\n \n- internal_endent ();\n+ internal_endent (&stream);\n \n __libc_lock_unlock (lock);\n \n@@ -146,7 +135,7 @@ _nss_files_endaliasent (void)\n \f\n /* Parsing the database file into `struct aliasent' data structures. */\n static enum nss_status\n-get_next_alias (const char *match, struct aliasent *result,\n+get_next_alias (FILE *stream, const char *match, struct aliasent *result,\n \t\tchar *buffer, size_t buflen, int *errnop)\n {\n enum nss_status status = NSS_STATUS_NOTFOUND;\n@@ -397,35 +386,16 @@ _nss_files_getaliasent_r (struct aliasen\n \n /* Be prepared that the set*ent function was not called before. */\n if (stream == NULL)\n- status = internal_setent ();\n+ status = internal_setent (&stream);\n \n if (status == NSS_STATUS_SUCCESS)\n {\n- /* If the last use was not by the getent function we need the\n-\t position the stream. */\n- if (last_use != getent)\n-\t{\n-\t if (fsetpos (stream, &position) < 0)\n-\t status = NSS_STATUS_UNAVAIL;\n-\t else\n-\t last_use = getent;\n-\t}\n-\n- if (status == NSS_STATUS_SUCCESS)\n-\t{\n-\t result->alias_local = 1;\n+ result->alias_local = 1;\n \n-\t /* Read lines until we get a definite result. */\n-\t do\n-\t status = get_next_alias (NULL, result, buffer, buflen, errnop);\n-\t while (status == NSS_STATUS_RETURN);\n-\n-\t /* If we successfully read an entry remember this position. */\n-\t if (status == NSS_STATUS_SUCCESS)\n-\t fgetpos (stream, &position);\n-\t else\n-\t last_use = nouse;\n-\t}\n+ /* Read lines until we get a definite result. */\n+ do\n+\tstatus = get_next_alias (stream, NULL, result, buffer, buflen, errnop);\n+ while (status == NSS_STATUS_RETURN);\n }\n \n __libc_lock_unlock (lock);\n@@ -440,6 +410,7 @@ _nss_files_getaliasbyname_r (const char\n {\n /* Return next entry in host file. */\n enum nss_status status = NSS_STATUS_SUCCESS;\n+ FILE *stream = NULL;\n \n if (name == NULL)\n {\n@@ -447,11 +418,8 @@ _nss_files_getaliasbyname_r (const char\n return NSS_STATUS_UNAVAIL;\n }\n \n- __libc_lock_lock (lock);\n-\n- /* Open the stream or rest it. */\n- status = internal_setent ();\n- last_use = getby;\n+ /* Open the stream. */\n+ status = internal_setent (&stream);\n \n if (status == NSS_STATUS_SUCCESS)\n {\n@@ -459,13 +427,11 @@ _nss_files_getaliasbyname_r (const char\n \n /* Read lines until we get a definite result. */\n do\n-\tstatus = get_next_alias (name, result, buffer, buflen, errnop);\n+\tstatus = get_next_alias (stream, name, result, buffer, buflen, errnop);\n while (status == NSS_STATUS_RETURN);\n }\n \n- internal_endent ();\n-\n- __libc_lock_unlock (lock);\n+ internal_endent (&stream);\n \n return status;\n }\nIndex: glibc-2.19/nss/nss_files/files-hosts.c\n===================================================================\n--- glibc-2.19.orig/nss/nss_files/files-hosts.c\n+++ glibc-2.19/nss/nss_files/files-hosts.c\n@@ -115,14 +115,13 @@ _nss_files_gethostbyname3_r (const char\n \t\t\t char *buffer, size_t buflen, int *errnop,\n \t\t\t int *herrnop, int32_t *ttlp, char **canonp)\n {\n+ FILE *stream = NULL;\n uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct hostent_data);\n buffer += pad;\n buflen = buflen > pad ? buflen - pad : 0;\n \n- __libc_lock_lock (lock);\n-\n- /* Reset file pointer to beginning or open file. */\n- enum nss_status status = internal_setent (keep_stream);\n+ /* Open file. */\n+ enum nss_status status = internal_setent (&stream);\n \n if (status == NSS_STATUS_SUCCESS)\n {\n@@ -130,10 +129,7 @@ _nss_files_gethostbyname3_r (const char\n addresses to IPv6 addresses really the right thing to do? */\n int flags = ((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0);\n \n- /* Tell getent function that we have repositioned the file pointer. */\n- last_use = getby;\n-\n- while ((status = internal_getent (result, buffer, buflen, errnop,\n+ while ((status = internal_getent (stream, result, buffer, buflen, errnop,\n \t\t\t\t\therrnop, af, flags))\n \t == NSS_STATUS_SUCCESS)\n \t{\n@@ -160,7 +156,7 @@ _nss_files_gethostbyname3_r (const char\n \t bufferend = (char *) &result->h_aliases[naliases + 1];\n \n \tagain:\n-\t while ((status = internal_getent (&tmp_result_buf, tmp_buffer,\n+\t while ((status = internal_getent (stream, &tmp_result_buf, tmp_buffer,\n \t\t\t\t\t tmp_buflen, errnop, herrnop, af,\n \t\t\t\t\t flags))\n \t\t == NSS_STATUS_SUCCESS)\n@@ -336,15 +332,12 @@ _nss_files_gethostbyname3_r (const char\n \t free (tmp_buffer);\n \t}\n \n- if (! keep_stream)\n-\tinternal_endent ();\n+ internal_endent (&stream);\n }\n \n if (canonp && status == NSS_STATUS_SUCCESS)\n *canonp = result->h_name;\n \n- __libc_lock_unlock (lock);\n-\n return status;\n }\n \n@@ -373,16 +366,13 @@ _nss_files_gethostbyname4_r (const char\n \t\t\t char *buffer, size_t buflen, int *errnop,\n \t\t\t int *herrnop, int32_t *ttlp)\n {\n- __libc_lock_lock (lock);\n+ FILE *stream = NULL;\n \n- /* Reset file pointer to beginning or open file. */\n- enum nss_status status = internal_setent (keep_stream);\n+ /* Open file. */\n+ enum nss_status status = internal_setent (&stream);\n \n if (status == NSS_STATUS_SUCCESS)\n {\n- /* Tell getent function that we have repositioned the file pointer. */\n- last_use = getby;\n-\n bool any = false;\n bool got_canon = false;\n while (1)\n@@ -394,7 +384,7 @@ _nss_files_gethostbyname4_r (const char\n \t buflen = buflen > pad ? buflen - pad : 0;\n \n \t struct hostent result;\n-\t status = internal_getent (&result, buffer, buflen, errnop,\n+\t status = internal_getent (stream, &result, buffer, buflen, errnop,\n \t\t\t\t herrnop, AF_UNSPEC, 0);\n \t if (status != NSS_STATUS_SUCCESS)\n \t break;\n@@ -470,8 +460,7 @@ _nss_files_gethostbyname4_r (const char\n \t status = NSS_STATUS_SUCCESS;\n \t}\n \n- if (! keep_stream)\n-\tinternal_endent ();\n+ internal_endent (&stream);\n }\n else if (status == NSS_STATUS_TRYAGAIN)\n {\n@@ -484,7 +473,5 @@ _nss_files_gethostbyname4_r (const char\n *herrnop = NO_DATA;\n }\n \n- __libc_lock_unlock (lock);\n-\n return status;\n }" } ]
{ "id": "glibc-testsuite-5158-nss-separate-state-getXXent.pa", "cve_id": "CVE-2016-3706", "package": "glibc-testsuite", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 3175, "context_files": 6 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-0747\n\nThe resolver in nginx before 1.8.1 and 1.9.x before 1.9.10 does not properly limit CNAME resolution, which allows remote attackers to cause a denial of service (worker process resource consumption) via vectors related to arbitrary name resolution.\n\n## Package\nnginx\n\n## Files to modify\n- passenger/ext/nginx/Configuration.c\n- passenger.orig/ext/nginx/Configuration.c\n\n## Upstream Fix\n```diff\nIndex: passenger/ext/nginx/Configuration.c\n===================================================================\n--- passenger.orig/ext/nginx/Configuration.c\t2015-06-24 23:29:12.725985654 +0800\n+++ passenger/ext/nginx/Configuration.c\t2015-06-24 23:02:39.654901783 +0800\n@@ -261,7 +261,11 @@\n conf->upstream_config.pass_request_body = NGX_CONF_UNSET;\n \n #if (NGX_HTTP_CACHE)\n- conf->upstream_config.cache = NGX_CONF_UNSET_PTR;\n+ #if NGINX_VERSION_NUM >= 1007009\n+ \tconf->upstream_config.cache = NGX_CONF_UNSET_PTR;\n+ #else\n+ \tconf->upstream_config.cache = NGX_CONF_UNSET;\n+ #endif\n conf->upstream_config.cache_min_uses = NGX_CONF_UNSET_UINT;\n conf->upstream_config.cache_bypass = NGX_CONF_UNSET_PTR;\n conf->upstream_config.no_cache = NGX_CONF_UNSET_PTR;\n@@ -270,6 +274,9 @@\n conf->upstream_config.cache_lock = NGX_CONF_UNSET;\n conf->upstream_config.cache_lock_timeout = NGX_CONF_UNSET_MSEC;\n #endif\n+ #if NGINX_VERSION_NUM >= 1007008\n+ \tconf->upstream_config.cache_lock_age = NGX_CONF_UNSET_MSEC;\n+ #endif\n #endif\n \n conf->upstream_config.intercept_errors = NGX_CONF_UNSET;\n@@ -374,15 +381,34 @@\n /******************************/\n /******************************/\n \n- if (conf->upstream_config.store != 0) {\n- ngx_conf_merge_value(conf->upstream_config.store,\n- prev->upstream_config.store, 0);\n+ #if (NGX_HTTP_CACHE) && NGINX_VERSION_NUM >= 1007009\n+ if (conf->upstream_config.store > 0) {\n+ conf->upstream_config.cache = 0;\n+ }\n+ if (conf->upstream_config.cache > 0) {\n+ conf->upstream_config.store = 0;\n+ }\n+ #endif\n+\n+ #if NGINX_VERSION_NUM >= 1007009\n+ if (conf->upstream_config.store == NGX_CONF_UNSET) {\n+ ngx_conf_merge_value(conf->upstream_config.store,\n+ prev->upstream_config.store, 0);\n \n- if (conf->upstream_config.store_lengths == NULL) {\n conf->upstream_config.store_lengths = prev->upstream_config.store_lengths;\n conf->upstream_config.store_values = prev->upstream_config.store_values;\n }\n- }\n+ #else\n+ if (conf->upstream_config.store != 0) {\n+ ngx_conf_merge_value(conf->upstream_config.store,\n+ prev->upstream_config.store, 0);\n+\n+ if (conf->upstream_config.store_lengths == NULL) {\n+ conf->upstream_config.store_lengths = prev->upstream_config.store_lengths;\n+ conf->upstream_config.store_values = prev->upstream_config.store_values;\n+ }\n+ }\n+ #endif\n \n ngx_conf_merge_uint_value(conf->upstream_config.store_access,\n prev->upstream_config.store_access, 0600);\n@@ -526,20 +552,42 @@\n \n #if (NGX_HTTP_CACHE)\n \n- ngx_conf_merge_ptr_value(conf->upstream_config.cache,\n- prev->upstream_config.cache, NULL);\n+ #if NGINX_VERSION_NUM >= 1007009\n+ if (conf->upstream_config.cache == NGX_CONF_UNSET) {\n+ ngx_conf_merge_value(conf->upstream_config.cache,\n+ prev->upstream_config.cache, 0);\n+\n+ conf->upstream_config.cache_zone = prev->upstream_config.cache_zone;\n+ conf->upstream_config.cache_value = prev->upstream_config.cache_value;\n+ }\n \n- if (conf->upstream_config.cache && conf->upstream_config.cache->data == NULL) {\n- ngx_shm_zone_t *shm_zone;\n+\tif (conf->upstream_config.cache_zone && conf->upstream_config.cache_zone->data == NULL) {\n+ ngx_shm_zone_t *shm_zone;\n \n- shm_zone = conf->upstream_config.cache;\n+ shm_zone = conf->upstream_config.cache_zone;\n \n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n- \"\\\"scgi_cache\\\" zone \\\"%V\\\" is unknown\",\n- &shm_zone->shm.name);\n+ \"\\\"scgi_cache\\\" zone \\\"%V\\\" is unknown\",\n+ &shm_zone->shm.name);\n \n- return NGX_CONF_ERROR;\n- }\n+ return NGX_CONF_ERROR;\n+ }\n+ #else\n+ ngx_conf_merge_ptr_value(conf->upstream_config.cache,\n+ prev->upstream_config.cache, NULL);\n+\n+ if (conf->upstream_config.cache && conf->upstream_config.cache->data == NULL) {\n+ ngx_shm_zone_t *shm_zone;\n+\n+ shm_zone = conf->upstream_config.cache;\n+\n+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n+ \"\\\"scgi_cache\\\" zone \\\"%V\\\" is unknown\",\n+ &shm_zone->shm.name);\n+\n+ return NGX_CONF_ERROR;\n+ }\n+ #endif\n \n ngx_conf_merge_uint_value(conf->upstream_config.cache_min_uses,\n prev->upstream_config.cache_min_uses, 1);\n@@ -585,6 +633,11 @@\n prev->upstream_config.cache_lock_timeout, 5000);\n #endif\n \n+ #if NGINX_VERSION_NUM >= 1007008\n+ ngx_conf_merge_msec_value(conf->upstream_config.cache_lock_age,\n+ prev->upstream_config.cache_lock_age, 5000);\n+ #endif\n+\n #endif\n \n ngx_conf_merge_value(conf->upstream_config.pass_request_headers,\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "Index: passenger/ext/nginx/Configuration.c\n===================================================================\n--- passenger.orig/ext/nginx/Configuration.c\t2015-06-24 23:29:12.725985654 +0800\n+++ passenger/ext/nginx/Configuration.c\t2015-06-24 23:02:39.654901783 +0800\n@@ -261,7 +261,11 @@\n conf->upstream_config.pass_request_body = NGX_CONF_UNSET;\n \n #if (NGX_HTTP_CACHE)\n- conf->upstream_config.cache = NGX_CONF_UNSET_PTR;\n+ #if NGINX_VERSION_NUM >= 1007009\n+ \tconf->upstream_config.cache = NGX_CONF_UNSET_PTR;\n+ #else\n+ \tconf->upstream_config.cache = NGX_CONF_UNSET;\n+ #endif\n conf->upstream_config.cache_min_uses = NGX_CONF_UNSET_UINT;\n conf->upstream_config.cache_bypass = NGX_CONF_UNSET_PTR;\n conf->upstream_config.no_cache = NGX_CONF_UNSET_PTR;\n@@ -270,6 +274,9 @@\n conf->upstream_config.cache_lock = NGX_CONF_UNSET;\n conf->upstream_config.cache_lock_timeout = NGX_CONF_UNSET_MSEC;\n #endif\n+ #if NGINX_VERSION_NUM >= 1007008\n+ \tconf->upstream_config.cache_lock_age = NGX_CONF_UNSET_MSEC;\n+ #endif\n #endif\n \n conf->upstream_config.intercept_errors = NGX_CONF_UNSET;\n@@ -374,15 +381,34 @@\n /******************************/\n /******************************/\n \n- if (conf->upstream_config.store != 0) {\n- ngx_conf_merge_value(conf->upstream_config.store,\n- prev->upstream_config.store, 0);\n+ #if (NGX_HTTP_CACHE) && NGINX_VERSION_NUM >= 1007009\n+ if (conf->upstream_config.store > 0) {\n+ conf->upstream_config.cache = 0;\n+ }\n+ if (conf->upstream_config.cache > 0) {\n+ conf->upstream_config.store = 0;\n+ }\n+ #endif\n+\n+ #if NGINX_VERSION_NUM >= 1007009\n+ if (conf->upstream_config.store == NGX_CONF_UNSET) {\n+ ngx_conf_merge_value(conf->upstream_config.store,\n+ prev->upstream_config.store, 0);\n \n- if (conf->upstream_config.store_lengths == NULL) {\n conf->upstream_config.store_lengths = prev->upstream_config.store_lengths;\n conf->upstream_config.store_values = prev->upstream_config.store_values;\n }\n- }\n+ #else\n+ if (conf->upstream_config.store != 0) {\n+ ngx_conf_merge_value(conf->upstream_config.store,\n+ prev->upstream_config.store, 0);\n+\n+ if (conf->upstream_config.store_lengths == NULL) {\n+ conf->upstream_config.store_lengths = prev->upstream_config.store_lengths;\n+ conf->upstream_config.store_values = prev->upstream_config.store_values;\n+ }\n+ }\n+ #endif\n \n ngx_conf_merge_uint_value(conf->upstream_config.store_access,\n prev->upstream_config.store_access, 0600);\n@@ -526,20 +552,42 @@\n \n #if (NGX_HTTP_CACHE)\n \n- ngx_conf_merge_ptr_value(conf->upstream_config.cache,\n- prev->upstream_config.cache, NULL);\n+ #if NGINX_VERSION_NUM >= 1007009\n+ if (conf->upstream_config.cache == NGX_CONF_UNSET) {\n+ ngx_conf_merge_value(conf->upstream_config.cache,\n+ prev->upstream_config.cache, 0);\n+\n+ conf->upstream_config.cache_zone = prev->upstream_config.cache_zone;\n+ conf->upstream_config.cache_value = prev->upstream_config.cache_value;\n+ }\n \n- if (conf->upstream_config.cache && conf->upstream_config.cache->data == NULL) {\n- ngx_shm_zone_t *shm_zone;\n+\tif (conf->upstream_config.cache_zone && conf->upstream_config.cache_zone->data == NULL) {\n+ ngx_shm_zone_t *shm_zone;\n \n- shm_zone = conf->upstream_config.cache;\n+ shm_zone = conf->upstream_config.cache_zone;\n \n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n- \"\\\"scgi_cache\\\" zone \\\"%V\\\" is unknown\",\n- &shm_zone->shm.name);\n+ \"\\\"scgi_cache\\\" zone \\\"%V\\\" is unknown\",\n+ &shm_zone->shm.name);\n \n- return NGX_CONF_ERROR;\n- }\n+ return NGX_CONF_ERROR;\n+ }\n+ #else\n+ ngx_conf_merge_ptr_value(conf->upstream_config.cache,\n+ prev->upstream_config.cache, NULL);\n+\n+ if (conf->upstream_config.cache && conf->upstream_config.cache->data == NULL) {\n+ ngx_shm_zone_t *shm_zone;\n+\n+ shm_zone = conf->upstream_config.cache;\n+\n+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n+ \"\\\"scgi_cache\\\" zone \\\"%V\\\" is unknown\",\n+ &shm_zone->shm.name);\n+\n+ return NGX_CONF_ERROR;\n+ }\n+ #endif\n \n ngx_conf_merge_uint_value(conf->upstream_config.cache_min_uses,\n prev->upstream_config.cache_min_uses, 1);\n@@ -585,6 +633,11 @@\n prev->upstream_config.cache_lock_timeout, 5000);\n #endif\n \n+ #if NGINX_VERSION_NUM >= 1007008\n+ ngx_conf_merge_msec_value(conf->upstream_config.cache_lock_age,\n+ prev->upstream_config.cache_lock_age, 5000);\n+ #endif\n+\n #endif\n \n ngx_conf_merge_value(conf->upstream_config.pass_request_headers," } ]
{ "id": "nginx-4606-nginx-1.8.0-passenger-4.0.18.p", "cve_id": "CVE-2016-0747", "package": "nginx", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": false, "license": "BSD-2-Clause", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-5384\n\nfontconfig before 2.12.1 does not validate offsets, which allows local users to trigger arbitrary free calls and consequently conduct double free attacks and execute arbitrary code via a crafted cache file.\n\n## Package\nfontconfig\n\n## Upstream Fix\n```diff\nFrom 74b9be6b4030ac1bfd4c20b52bbcdeb66373eaba Mon Sep 17 00:00:00 2001\nFrom: Frederic Crozat <fcrozat@suse.com>\nDate: Fri, 6 Dec 2013 14:23:52 +0100\nSubject: [PATCH 2/2] Add metric aliases for additional Google ChromeOS fonts\n\nMS fonts Cambria, Symbol and Calibri have compat metrics fonts\nfrom ChromeOS.\n---\n conf.d/30-metric-aliases.conf | 43 +++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 43 insertions(+)\n\ndiff --git a/conf.d/30-metric-aliases.conf b/conf.d/30-metric-aliases.conf\nindex c9ee79f..49a9602 100644\n--- a/conf.d/30-metric-aliases.conf\n+++ b/conf.d/30-metric-aliases.conf\n@@ -24,6 +24,9 @@ Arial Liberation Sans Arimo Albany\n Arial Narrow Liberation Sans Narrow\n Times New Roman Liberation Serif Tinos Thorndale Thorndale AMT\n Courier New Liberation Mono Cousine Cumberland Cumberland AMT\n+Cambria Caladea\n+Calibri Carlito\n+Symbol SymbolNeu\n \n Microsoft fonts: Other fonts:\n ================ ============\n@@ -307,7 +310,26 @@ but in an order preferring similar designs first. We do this in three steps:\n \t </default>\n \t</alias>\n \n+\t<alias binding=\"same\">\n+\t <family>Caladea</family>\n+\t <default>\n+\t <family>Cambria</family>\n+\t </default>\n+\t</alias>\n \n+\t<alias binding=\"same\">\n+\t <family>Carlito</family>\n+\t <default>\n+\t <family>Calibri</family>\n+\t </default>\n+\t</alias>\n+\n+\t<alias binding=\"same\">\n+\t <family>SymbolNeu</family>\n+\t <default>\n+\t <family>Symbol</family>\n+\t </default>\n+ </alias>\n \n <!-- Accept the other group as fallback -->\n \n@@ -494,4 +516,25 @@ but in an order preferring similar designs first. We do this in three steps:\n \t </accept>\n \t</alias>\n \n+\t<alias binding=\"same\">\n+\t <family>Cambria</family>\n+\t <accept>\n+\t <family>Caladea</family>\n+\t </accept>\n+\t</alias>\n+\n+\t<alias binding=\"same\">\n+\t <family>Calibri</family>\n+\t <accept>\n+\t <family>Carlito</family>\n+\t </accept>\n+ </alias>\n+\n+\t<alias binding=\"same\">\n+\t <family>Symbol</family>\n+\t <accept>\n+\t <family>SymbolNeu</family>\n+\t </accept>\n+ </alias>\n+\n </fontconfig>\n-- \n1.8.4\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 74b9be6b4030ac1bfd4c20b52bbcdeb66373eaba Mon Sep 17 00:00:00 2001\nFrom: Frederic Crozat <fcrozat@suse.com>\nDate: Fri, 6 Dec 2013 14:23:52 +0100\nSubject: [PATCH 2/2] Add metric aliases for additional Google ChromeOS fonts\n\nMS fonts Cambria, Symbol and Calibri have compat metrics fonts\nfrom ChromeOS.\n---\n conf.d/30-metric-aliases.conf | 43 +++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 43 insertions(+)\n\ndiff --git a/conf.d/30-metric-aliases.conf b/conf.d/30-metric-aliases.conf\nindex c9ee79f..49a9602 100644\n--- a/conf.d/30-metric-aliases.conf\n+++ b/conf.d/30-metric-aliases.conf\n@@ -24,6 +24,9 @@ Arial Liberation Sans Arimo Albany\n Arial Narrow Liberation Sans Narrow\n Times New Roman Liberation Serif Tinos Thorndale Thorndale AMT\n Courier New Liberation Mono Cousine Cumberland Cumberland AMT\n+Cambria Caladea\n+Calibri Carlito\n+Symbol SymbolNeu\n \n Microsoft fonts: Other fonts:\n ================ ============\n@@ -307,7 +310,26 @@ but in an order preferring similar designs first. We do this in three steps:\n \t </default>\n \t</alias>\n \n+\t<alias binding=\"same\">\n+\t <family>Caladea</family>\n+\t <default>\n+\t <family>Cambria</family>\n+\t </default>\n+\t</alias>\n \n+\t<alias binding=\"same\">\n+\t <family>Carlito</family>\n+\t <default>\n+\t <family>Calibri</family>\n+\t </default>\n+\t</alias>\n+\n+\t<alias binding=\"same\">\n+\t <family>SymbolNeu</family>\n+\t <default>\n+\t <family>Symbol</family>\n+\t </default>\n+ </alias>\n \n <!-- Accept the other group as fallback -->\n \n@@ -494,4 +516,25 @@ but in an order preferring similar designs first. We do this in three steps:\n \t </accept>\n \t</alias>\n \n+\t<alias binding=\"same\">\n+\t <family>Cambria</family>\n+\t <accept>\n+\t <family>Caladea</family>\n+\t </accept>\n+\t</alias>\n+\n+\t<alias binding=\"same\">\n+\t <family>Calibri</family>\n+\t <accept>\n+\t <family>Carlito</family>\n+\t </accept>\n+ </alias>\n+\n+\t<alias binding=\"same\">\n+\t <family>Symbol</family>\n+\t <accept>\n+\t <family>SymbolNeu</family>\n+\t </accept>\n+ </alias>\n+\n </fontconfig>\n-- \n1.8.4" } ]
{ "id": "fontconfig-5559-0002-Add-metric-aliases-for-ad", "cve_id": "CVE-2016-5384", "package": "fontconfig", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": false, "license": "MIT", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-8325\n\nThe do_setup_env function in session.c in sshd in OpenSSH through 7.2p2, when the UseLogin feature is enabled and PAM is configured to read .pam_environment files in user home directories, allows local users to gain privileges by triggering a crafted environment for the /bin/login program, as demonstrated by an LD_PRELOAD environment variable.\n\n## Package\nopenssh-askpass-gnome\n\n## Files to modify\n- openssh-6.6p1/readconf.h\n- openssh-6.6p1/readconf.c\n- openssh-6.6p1/servconf.c\n- openssh-6.6p1/auth2.c\n- openssh-6.6p1/servconf.h\n\n## Upstream Fix\n```diff\n# HG changeset patch\n# Parent 3aa40f8165fb2e63e4842e9b7643e4ca48b7bb51\n# The patch below adds support for the deprecated 'gssapi' authentication\n# mechanism to OpenSSH 3.8p1. The newer 'gssapi-with-mic' mechanism is included\n# in this release. The use of 'gssapi' is deprecated due to the presence of\n# potential man-in-the-middle attacks, which 'gssapi-with-mic' is not\n# susceptible to.\n#\n# To use the patch apply it to a OpenSSH 3.8p1 source tree. After compiling,\n# backwards compatibility may be obtained by supplying the\n# 'GssapiEnableMitmAttack yes' option to either the client or server.\n#\n# It should be noted that this patch is being made available purely as a means\n# of easing the process of moving to OpenSSH 3.8p1. Any new installations are\n# recommended to use the 'gssapi-with-mic' mechanism. Existing installations\n# are encouraged to upgrade as soon as possible.\n\ndiff --git a/openssh-6.6p1/auth2-gss.c b/openssh-6.6p1/auth2-gss.c\n--- a/openssh-6.6p1/auth2-gss.c\n+++ b/openssh-6.6p1/auth2-gss.c\n@@ -168,16 +168,25 @@ input_gssapi_token(int type, u_int32_t p\n \t\t\tdispatch_set(SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL);\n \t\t\tif (flags & GSS_C_INTEG_FLAG)\n \t\t\t\tdispatch_set(SSH2_MSG_USERAUTH_GSSAPI_MIC,\n \t\t\t\t &input_gssapi_mic);\n \t\t\telse\n \t\t\t\tdispatch_set(\n \t\t\t\t SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE,\n \t\t\t\t &input_gssapi_exchange_complete);\n+\n+\t\t\t/* \n+\t\t\t * Old style 'gssapi' didn't have the GSSAPI_MIC \n+\t\t\t * and went straight to sending exchange_complete \n+\t\t\t */\n+\t\t\tif (options.gss_enable_mitm)\n+\t\t\t\tdispatch_set(\n+\t\t\t\t SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE,\n+\t\t\t\t &input_gssapi_exchange_complete);\n \t\t}\n \t}\n \n \tgss_release_buffer(&min_status, &send_tok);\n }\n \n static void\n input_gssapi_errtok(int type, u_int32_t plen, void *ctxt)\n@@ -286,9 +295,15 @@ input_gssapi_mic(int type, u_int32_t ple\n }\n \n Authmethod method_gssapi = {\n \t\"gssapi-with-mic\",\n \tuserauth_gssapi,\n \t&options.gss_authentication\n };\n \n+Authmethod method_gssapi_old = {\n+\t\"gssapi\",\n+\tuserauth_gssapi,\n+\t&options.gss_enable_mitm\n+};\n+\n #endif /* GSSAPI */\ndiff --git a/openssh-6.6p1/auth2.c b/openssh-6.6p1/auth2.c\n--- a/openssh-6.6p1/auth2.c\n+++ b/openssh-6.6p1/auth2.c\n@@ -65,23 +65,25 @@ extern Buffer loginmsg;\n \n extern Authmethod method_none;\n extern Authmethod method_pubkey;\n extern Authmethod method_passwd;\n extern Authmethod method_kbdint;\n extern Authmethod method_hostbased;\n #ifdef GSSAPI\n extern Authmethod method_gssapi;\n+extern Authmethod method_gssapi_old;\n #endif\n \n Authmethod *authmethods[] = {\n \t&method_none,\n \t&method_pubkey,\n #ifdef GSSAPI\n \t&method_gssapi,\n+\t&method_gssapi_old,\n #endif\n \t&method_passwd,\n \t&method_kbdint,\n \t&method_hostbased,\n \tNULL\n };\n \n /* protocol */\ndiff --git a/openssh-6.6p1/readconf.c b/openssh-6.6p1/readconf.c\n--- a/openssh-6.6p1/readconf.c\n+++ b/openssh-6.6p1/readconf.c\n@@ -135,17 +135,17 @@ typedef enum {\n \toCompressionLevel, oTCPKeepAlive, oNumberOfPasswordPrompts,\n \toUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,\n \toGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,\n \toKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,\n \toDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,\n \toHostKeyAlgorithms, oBindAddress, oPKCS11Provider,\n \toClearAllForwardings, oNoHostAuthenticationForLocalhost,\n \toEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,\n-\toAddressFamily, oGssAuthentication, oGssDelegateCreds,\n+\toAddressFamily, oGssAuthentication, oGssDelegateCreds, oGssEnableMITM,\n \toServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,\n \toSendEnv, oControlPath, oControlMaster, oControlPersist,\n \toHashKnownHosts,\n \toTunnel, oTunnelDevice, oLocalCommand, oPermitLocalCommand,\n \toVisualHostKey, oUseRoaming,\n \toKexAlgorithms, oIPQoS, oRequestTTY, oIgnoreUnknown, oProxyUseFdpass,\n \toCanonicalDomains, oCanonicalizeHostname, oCanonicalizeMaxDots,\n \toCanonicalizeFallbackLocal, oCanonicalizePermittedCNAMEs,\n@@ -179,19 +179,21 @@ static struct {\n \t{ \"skeyauthentication\", oChallengeResponseAuthentication }, /* alias */\n \t{ \"tisauthentication\", oChallengeResponseAuthentication }, /* alias */\n \t{ \"kerberosauthentication\", oUnsupported },\n \t{ \"kerberostgtpassing\", oUnsupported },\n \t{ \"afstokenpassing\", oUnsupported },\n #if defined(GSSAPI)\n \t{ \"gssapiauthentication\", oGssAuthentication },\n \t{ \"gssapidelegatecredentials\", oGssDelegateCreds },\n+\t{ \"gssapienablemitmattack\", oGssEnableMITM },\n #else\n \t{ \"gssapiauthentication\", oUnsupported },\n \t{ \"gssapidelegatecredentials\", oUnsupported },\n+\t{ \"gssapienablemitmattack\", oUnsupported },\n #endif\n \t{ \"fallbacktorsh\", oDeprecated },\n \t{ \"usersh\", oDeprecated },\n \t{ \"identityfile\", oIdentityFile },\n \t{ \"identityfile2\", oIdentityFile },\t\t\t/* obsolete */\n \t{ \"identitiesonly\", oIdentitiesOnly },\n \t{ \"hostname\", oHostName },\n \t{ \"hostkeyalias\", oHostKeyAlias },\n@@ -839,16 +841,20 @@ parse_time:\n \n \tcase oGssAuthentication:\n \t\tintptr = &options->gss_authentication;\n \t\tgoto parse_flag;\n \n \tcase oGssDelegateCreds:\n \t\tintptr = &options->gss_deleg_creds;\n \t\tgoto parse_flag;\n+\t\t\n+\tcase oGssEnableMITM:\n+\t\tintptr = &options->gss_enable_mitm;\n+\t\tgoto parse_flag;\n \n \tcase oBatchMode:\n \t\tintptr = &options->batch_mode;\n \t\tgoto parse_flag;\n \n \tcase oCheckHostIP:\n \t\tintptr = &options->check_host_ip;\n \t\tgoto parse_flag;\n@@ -1493,16 +1499,17 @@ initialize_options(Options * options)\n \toptions->xauth_location = NULL;\n \toptions->gateway_ports = -1;\n \toptions->use_privileged_port = -1;\n \toptions->rsa_authentication = -1;\n \toptions->pubkey_authentication = -1;\n \toptions->challenge_response_authentication = -1;\n \toptions->gss_authentication = -1;\n \toptions->gss_deleg_creds = -1;\n+\toptions->gss_enable_mitm = -1;\n \toptions->password_authentication = -1;\n \toptions->kbd_interactive_authentication = -1;\n \toptions->kbd_interactive_devices = NULL;\n \toptions->rhosts_rsa_authentication = -1;\n \toptions->hostbased_authentication = -1;\n \toptions->batch_mode = -1;\n \toptions->check_host_ip = -1;\n \toptions->strict_host_key_checking = -1;\n@@ -1613,16 +1620,18 @@ fill_default_options(Options * options)\n \tif (options->pubkey_authentication == -1)\n \t\toptions->pubkey_authentication = 1;\n \tif (options->challenge_response_authentication == -1)\n \t\toptions->challenge_response_authentication = 1;\n \tif (options->gss_authentication == -1)\n \t\toptions->gss_authentication = 0;\n \tif (options->gss_deleg_creds == -1)\n \t\toptions->gss_deleg_creds = 0;\n+\tif (options->gss_enable_mitm == -1)\n+\t\toptions->gss_enable_mitm = 0;\n \tif (options->password_authentication == -1)\n \t\toptions->password_authentication = 1;\n \tif (options->kbd_interactive_authentication == -1)\n \t\toptions->kbd_interactive_authentication = 1;\n \tif (options->rhosts_rsa_authentication == -1)\n \t\toptions->rhosts_rsa_authentication = 0;\n \tif (options->hostbased_authentication == -1)\n \t\toptions->hostbased_authentication = 0;\ndiff --git a/openssh-6.6p1/readconf.h b/openssh-6.6p1/readconf.h\n--- a/openssh-6.6p1/readconf.h\n+++ b/openssh-6.6p1/readconf.h\n@@ -50,16 +50,17 @@ typedef struct {\n \t\t\t\t\t\t * authentication. */\n \tint rsa_authentication;\t/* Try RSA authentication. */\n \tint pubkey_authentication;\t/* Try ssh2 pubkey authentication. */\n \tint hostbased_authentication;\t/* ssh2's rhosts_rsa */\n \tint challenge_response_authentication;\n \t\t\t\t\t/* Try S/Key or TIS, authentication. */\n \tint gss_authentication;\t/* Try GSS authentication */\n \tint gss_deleg_creds;\t/* Delegate GSS credentials */\n+\tint \tgss_enable_mitm;\t/* Enable old style gssapi auth */\n \tint password_authentication;\t/* Try password\n \t\t\t\t\t\t * authentication. */\n \tint kbd_interactive_authentication; /* Try keyboard-interactive auth. */\n \tchar\t*kbd_interactive_devices; /* Keyboard-interactive auth devices. */\n \tint batch_mode;\t/* Batch mode: do not ask for passwords. */\n \tint check_host_ip;\t/* Also keep track of keys for IP address */\n \tint strict_host_key_checking;\t/* Strict host key checking. */\n \tint compression;\t/* Compress packets in\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "# HG changeset patch\n# Parent 3aa40f8165fb2e63e4842e9b7643e4ca48b7bb51\n# The patch below adds support for the deprecated 'gssapi' authentication\n# mechanism to OpenSSH 3.8p1. The newer 'gssapi-with-mic' mechanism is included\n# in this release. The use of 'gssapi' is deprecated due to the presence of\n# potential man-in-the-middle attacks, which 'gssapi-with-mic' is not\n# susceptible to.\n#\n# To use the patch apply it to a OpenSSH 3.8p1 source tree. After compiling,\n# backwards compatibility may be obtained by supplying the\n# 'GssapiEnableMitmAttack yes' option to either the client or server.\n#\n# It should be noted that this patch is being made available purely as a means\n# of easing the process of moving to OpenSSH 3.8p1. Any new installations are\n# recommended to use the 'gssapi-with-mic' mechanism. Existing installations\n# are encouraged to upgrade as soon as possible.\n\ndiff --git a/openssh-6.6p1/auth2-gss.c b/openssh-6.6p1/auth2-gss.c\n--- a/openssh-6.6p1/auth2-gss.c\n+++ b/openssh-6.6p1/auth2-gss.c\n@@ -168,16 +168,25 @@ input_gssapi_token(int type, u_int32_t p\n \t\t\tdispatch_set(SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL);\n \t\t\tif (flags & GSS_C_INTEG_FLAG)\n \t\t\t\tdispatch_set(SSH2_MSG_USERAUTH_GSSAPI_MIC,\n \t\t\t\t &input_gssapi_mic);\n \t\t\telse\n \t\t\t\tdispatch_set(\n \t\t\t\t SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE,\n \t\t\t\t &input_gssapi_exchange_complete);\n+\n+\t\t\t/* \n+\t\t\t * Old style 'gssapi' didn't have the GSSAPI_MIC \n+\t\t\t * and went straight to sending exchange_complete \n+\t\t\t */\n+\t\t\tif (options.gss_enable_mitm)\n+\t\t\t\tdispatch_set(\n+\t\t\t\t SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE,\n+\t\t\t\t &input_gssapi_exchange_complete);\n \t\t}\n \t}\n \n \tgss_release_buffer(&min_status, &send_tok);\n }\n \n static void\n input_gssapi_errtok(int type, u_int32_t plen, void *ctxt)\n@@ -286,9 +295,15 @@ input_gssapi_mic(int type, u_int32_t ple\n }\n \n Authmethod method_gssapi = {\n \t\"gssapi-with-mic\",\n \tuserauth_gssapi,\n \t&options.gss_authentication\n };\n \n+Authmethod method_gssapi_old = {\n+\t\"gssapi\",\n+\tuserauth_gssapi,\n+\t&options.gss_enable_mitm\n+};\n+\n #endif /* GSSAPI */\ndiff --git a/openssh-6.6p1/auth2.c b/openssh-6.6p1/auth2.c\n--- a/openssh-6.6p1/auth2.c\n+++ b/openssh-6.6p1/auth2.c\n@@ -65,23 +65,25 @@ extern Buffer loginmsg;\n \n extern Authmethod method_none;\n extern Authmethod method_pubkey;\n extern Authmethod method_passwd;\n extern Authmethod method_kbdint;\n extern Authmethod method_hostbased;\n #ifdef GSSAPI\n extern Authmethod method_gssapi;\n+extern Authmethod method_gssapi_old;\n #endif\n \n Authmethod *authmethods[] = {\n \t&method_none,\n \t&method_pubkey,\n #ifdef GSSAPI\n \t&method_gssapi,\n+\t&method_gssapi_old,\n #endif\n \t&method_passwd,\n \t&method_kbdint,\n \t&method_hostbased,\n \tNULL\n };\n \n /* protocol */\ndiff --git a/openssh-6.6p1/readconf.c b/openssh-6.6p1/readconf.c\n--- a/openssh-6.6p1/readconf.c\n+++ b/openssh-6.6p1/readconf.c\n@@ -135,17 +135,17 @@ typedef enum {\n \toCompressionLevel, oTCPKeepAlive, oNumberOfPasswordPrompts,\n \toUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,\n \toGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,\n \toKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,\n \toDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,\n \toHostKeyAlgorithms, oBindAddress, oPKCS11Provider,\n \toClearAllForwardings, oNoHostAuthenticationForLocalhost,\n \toEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,\n-\toAddressFamily, oGssAuthentication, oGssDelegateCreds,\n+\toAddressFamily, oGssAuthentication, oGssDelegateCreds, oGssEnableMITM,\n \toServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,\n \toSendEnv, oControlPath, oControlMaster, oControlPersist,\n \toHashKnownHosts,\n \toTunnel, oTunnelDevice, oLocalCommand, oPermitLocalCommand,\n \toVisualHostKey, oUseRoaming,\n \toKexAlgorithms, oIPQoS, oRequestTTY, oIgnoreUnknown, oProxyUseFdpass,\n \toCanonicalDomains, oCanonicalizeHostname, oCanonicalizeMaxDots,\n \toCanonicalizeFallbackLocal, oCanonicalizePermittedCNAMEs,\n@@ -179,19 +179,21 @@ static struct {\n \t{ \"skeyauthentication\", oChallengeResponseAuthentication }, /* alias */\n \t{ \"tisauthentication\", oChallengeResponseAuthentication }, /* alias */\n \t{ \"kerberosauthentication\", oUnsupported },\n \t{ \"kerberostgtpassing\", oUnsupported },\n \t{ \"afstokenpassing\", oUnsupported },\n #if defined(GSSAPI)\n \t{ \"gssapiauthentication\", oGssAuthentication },\n \t{ \"gssapidelegatecredentials\", oGssDelegateCreds },\n+\t{ \"gssapienablemitmattack\", oGssEnableMITM },\n #else\n \t{ \"gssapiauthentication\", oUnsupported },\n \t{ \"gssapidelegatecredentials\", oUnsupported },\n+\t{ \"gssapienablemitmattack\", oUnsupported },\n #endif\n \t{ \"fallbacktorsh\", oDeprecated },\n \t{ \"usersh\", oDeprecated },\n \t{ \"identityfile\", oIdentityFile },\n \t{ \"identityfile2\", oIdentityFile },\t\t\t/* obsolete */\n \t{ \"identitiesonly\", oIdentitiesOnly },\n \t{ \"hostname\", oHostName },\n \t{ \"hostkeyalias\", oHostKeyAlias },\n@@ -839,16 +841,20 @@ parse_time:\n \n \tcase oGssAuthentication:\n \t\tintptr = &options->gss_authentication;\n \t\tgoto parse_flag;\n \n \tcase oGssDelegateCreds:\n \t\tintptr = &options->gss_deleg_creds;\n \t\tgoto parse_flag;\n+\t\t\n+\tcase oGssEnableMITM:\n+\t\tintptr = &options->gss_enable_mitm;\n+\t\tgoto parse_flag;\n \n \tcase oBatchMode:\n \t\tintptr = &options->batch_mode;\n \t\tgoto parse_flag;\n \n \tcase oCheckHostIP:\n \t\tintptr = &options->check_host_ip;\n \t\tgoto parse_flag;\n@@ -1493,16 +1499,17 @@ initialize_options(Options * options)\n \toptions->xauth_location = NULL;\n \toptions->gateway_ports = -1;\n \toptions->use_privileged_port = -1;\n \toptions->rsa_authentication = -1;\n \toptions->pubkey_authentication = -1;\n \toptions->challenge_response_authentication = -1;\n \toptions->gss_authentication = -1;\n \toptions->gss_deleg_creds = -1;\n+\toptions->gss_enable_mitm = -1;\n \toptions->password_authentication = -1;\n \toptions->kbd_interactive_authentication = -1;\n \toptions->kbd_interactive_devices = NULL;\n \toptions->rhosts_rsa_authentication = -1;\n \toptions->hostbased_authentication = -1;\n \toptions->batch_mode = -1;\n \toptions->check_host_ip = -1;\n \toptions->strict_host_key_checking = -1;\n@@ -1613,16 +1620,18 @@ fill_default_options(Options * options)\n \tif (options->pubkey_authentication == -1)\n \t\toptions->pubkey_authentication = 1;\n \tif (options->challenge_response_authentication == -1)\n \t\toptions->challenge_response_authentication = 1;\n \tif (options->gss_authentication == -1)\n \t\toptions->gss_authentication = 0;\n \tif (options->gss_deleg_creds == -1)\n \t\toptions->gss_deleg_creds = 0;\n+\tif (options->gss_enable_mitm == -1)\n+\t\toptions->gss_enable_mitm = 0;\n \tif (options->password_authentication == -1)\n \t\toptions->password_authentication = 1;\n \tif (options->kbd_interactive_authentication == -1)\n \t\toptions->kbd_interactive_authentication = 1;\n \tif (options->rhosts_rsa_authentication == -1)\n \t\toptions->rhosts_rsa_authentication = 0;\n \tif (options->hostbased_authentication == -1)\n \t\toptions->hostbased_authentication = 0;\ndiff --git a/openssh-6.6p1/readconf.h b/openssh-6.6p1/readconf.h\n--- a/openssh-6.6p1/readconf.h\n+++ b/openssh-6.6p1/readconf.h\n@@ -50,16 +50,17 @@ typedef struct {\n \t\t\t\t\t\t * authentication. */\n \tint rsa_authentication;\t/* Try RSA authentication. */\n \tint pubkey_authentication;\t/* Try ssh2 pubkey authentication. */\n \tint hostbased_authentication;\t/* ssh2's rhosts_rsa */\n \tint challenge_response_authentication;\n \t\t\t\t\t/* Try S/Key or TIS, authentication. */\n \tint gss_authentication;\t/* Try GSS authentication */\n \tint gss_deleg_creds;\t/* Delegate GSS credentials */\n+\tint \tgss_enable_mitm;\t/* Enable old style gssapi auth */\n \tint password_authentication;\t/* Try password\n \t\t\t\t\t\t * authentication. */\n \tint kbd_interactive_authentication; /* Try keyboard-interactive auth. */\n \tchar\t*kbd_interactive_devices; /* Keyboard-interactive auth devices. */\n \tint batch_mode;\t/* Batch mode: do not ask for passwords. */\n \tint check_host_ip;\t/* Also keep track of keys for IP address */\n \tint strict_host_key_checking;\t/* Strict host key checking. */\n \tint compression;\t/* Compress packets in both directions. */\ndiff --git a/openssh-6.6p1/servconf.c b/openssh-6.6p1/servconf.c\n--- a/openssh-6.6p1/servconf.c\n+++ b/openssh-6.6p1/servconf.c\n@@ -104,16 +104,17 @@ initialize_server_options(ServerOptions \n \toptions->rsa_authentication = -1;\n \toptions->pubkey_authentication = -1;\n \toptions->kerberos_authentication = -1;\n \toptions->kerberos_or_local_passwd = -1;\n \toptions->kerberos_ticket_cleanup = -1;\n \toptions->kerberos_get_afs_token = -1;\n \toptions->gss_authentication=-1;\n \toptions->gss_cleanup_creds = -1;\n+\toptions->gss_enable_mitm = -1;\n \toptions->password_authentication = -1;\n \toptions->kbd_interactive_authentication = -1;\n \toptions->challenge_response_authentication = -1;\n \toptions->permit_empty_passwd = -1;\n \toptions->permit_user_env = -1;\n \toptions->use_login = -1;\n \toptions->compression = -1;\n \toptions->rekey_limit = -1;\n@@ -241,16 +242,18 @@ fill_default_server_options(ServerOption\n \tif (options->kerberos_ticket_cleanup == -1)\n \t\toptions->kerberos_ticket_cleanup = 1;\n \tif (options->kerberos_get_afs_token == -1)\n \t\toptions->kerberos_get_afs_token = 0;\n \tif (options->gss_authentication == -1)\n \t\toptions->gss_authentication = 0;\n \tif (options->gss_cleanup_creds == -1)\n \t\toptions->gss_cleanup_creds = 1;\n+\tif (options->gss_enable_mitm == -1)\n+\t\toptions->gss_enable_mitm = 0;\n \tif (options->password_authentication == -1)\n \t\toptions->password_authentication = 1;\n \tif (options->kbd_interactive_authentication == -1)\n \t\toptions->kbd_interactive_authentication = 0;\n \tif (options->challenge_response_authentication == -1)\n \t\toptions->challenge_response_authentication = 1;\n \tif (options->permit_empty_passwd == -1)\n \t\toptions->permit_empty_passwd = 0;\n@@ -335,17 +338,17 @@ typedef enum {\n \tsPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,\n \tsRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,\n \tsIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,\n \tsGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,\n \tsMaxStartups, sMaxAuthTries, sMaxSessions,\n \tsBanner, sUseDNS, sHostbasedAuthentication,\n \tsHostbasedUsesNameFromPacketOnly, sClientAliveInterval,\n \tsClientAliveCountMax, sAuthorizedKeysFile,\n-\tsGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,\n+\tsGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel, sGssEnableMITM,\n \tsMatch, sPermitOpen, sForceCommand, sChrootDirectory,\n \tsUsePrivilegeSeparation, sAllowAgentForwarding,\n \tsHostCertificate,\n \tsRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,\n \tsKexAlgorithms, sIPQoS, sVersionAddendum,\n \tsAuthorizedKeysCommand, sAuthorizedKeysCommandUser,\n \tsAuthenticationMethods, sHostKeyAgent,\n \tsDeprecated, sUnsupported\n@@ -402,19 +405,21 @@ static struct {\n \t{ \"kerberosticketcleanup\", sUnsupported, SSHCFG_GLOBAL },\n \t{ \"kerberosgetafstoken\", sUnsupported, SSHCFG_GLOBAL },\n #endif\n \t{ \"kerberostgtpassing\", sUnsupported, SSHCFG_GLOBAL },\n \t{ \"afstokenpassing\", sUnsupported, SSHCFG_GLOBAL },\n #ifdef GSSAPI\n \t{ \"gssapiauthentication\", sGssAuthentication, SSHCFG_ALL },\n \t{ \"gssapicleanupcredentials\", sGssCleanupCreds, SSHCFG_GLOBAL },\n+\t{ \"gssapienablemitmattack\", sGssEnableMITM },\n #else\n \t{ \"gssapiauthentication\", sUnsupported, SSHCFG_ALL },\n \t{ \"gssapicleanupcredentials\", sUnsupported, SSHCFG_GLOBAL },\n+\t{ \"gssapienablemitmattack\", sUnsupported },\n #endif\n \t{ \"passwordauthentication\", sPasswordAuthentication, SSHCFG_ALL },\n \t{ \"kbdinteractiveauthentication\", sKbdInteractiveAuthentication, SSHCFG_ALL },\n \t{ \"challengeresponseauthentication\", sChallengeResponseAuthentication, SSHCFG_GLOBAL },\n \t{ \"skeyauthentication\", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */\n \t{ \"checkmail\", sDeprecated, SSHCFG_GLOBAL },\n \t{ \"listenaddress\", sListenAddress, SSHCFG_GLOBAL },\n \t{ \"addressfamily\", sAddressFamily, SSHCFG_GLOBAL },\n@@ -1085,16 +1090,20 @@ process_server_config_line(ServerOptions\n \tcase sGssAuthentication:\n \t\tintptr = &options->gss_authentication;\n \t\tgoto parse_flag;\n \n \tcase sGssCleanupCreds:\n \t\tintptr = &options->gss_cleanup_creds;\n \t\tgoto parse_flag;\n \n+\tcase sGssEnableMITM:\n+\t\tintptr = &options->gss_enable_mitm;\n+\t\tgoto parse_flag;\n+\n \tcase sPasswordAuthentication:\n \t\tintptr = &options->password_authentication;\n \t\tgoto parse_flag;\n \n \tcase sKbdInteractiveAuthentication:\n \t\tintptr = &options->kbd_interactive_authentication;\n \t\tgoto parse_flag;\n \ndiff --git a/openssh-6.6p1/servconf.h b/openssh-6.6p1/servconf.h\n--- a/openssh-6.6p1/servconf.h\n+++ b/openssh-6.6p1/servconf.h\n@@ -108,16 +108,17 @@ typedef struct {\n \t\t\t\t\t\t * such as SecurID or\n \t\t\t\t\t\t * /etc/passwd */\n \tint kerberos_ticket_cleanup;\t/* If true, destroy ticket\n \t\t\t\t\t\t * file on logout. */\n \tint kerberos_get_afs_token;\t\t/* If true, try to get AFS token if\n \t\t\t\t\t\t * authenticated with Kerberos. */\n \tint gss_authentication;\t/* If true, permit GSSAPI authentication */\n \tint gss_cleanup_creds;\t/* If true, destroy cred cache on logout */\n+\tint\t gss_enable_mitm;\t/* If true, enable old style GSSAPI */\n \tint password_authentication;\t/* If true, permit password\n \t\t\t\t\t\t * authentication. */\n \tint kbd_interactive_authentication;\t/* If true, permit */\n \tint challenge_response_authentication;\n \tint permit_empty_passwd;\t/* If false, do not permit empty\n \t\t\t\t\t * passwords. */\n \tint permit_user_env;\t/* If true, read ~/.ssh/environment */\n \tint use_login;\t/* If true, login(1) is used */\ndiff --git a/openssh-6.6p1/ssh_config b/openssh-6.6p1/ssh_config\n--- a/openssh-6.6p1/ssh_config\n+++ b/openssh-6.6p1/ssh_config\n@@ -51,9 +51,16 @@ ForwardX11Trusted yes\n # Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc\n # MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160\n # EscapeChar ~\n # Tunnel no\n # TunnelDevice any:any\n # PermitLocalCommand no\n # VisualHostKey no\n # ProxyCommand ssh -q -W %h:%p gateway.example.com\n+\n+# Set this to 'yes' to enable support for the deprecated 'gssapi' authentication\n+# mechanism to OpenSSH 3.8p1. The newer 'gssapi-with-mic' mechanism is included\n+# in this release. The use of 'gssapi' is deprecated due to the presence of \n+# potential man-in-the-middle attacks, which 'gssapi-with-mic' is not susceptible to.\n+# GSSAPIEnableMITMAttack no\n+\n # RekeyLimit 1G 1h\ndiff --git a/openssh-6.6p1/sshconnect2.c b/openssh-6.6p1/sshconnect2.c\n--- a/openssh-6.6p1/sshconnect2.c\n+++ b/openssh-6.6p1/sshconnect2.c\n@@ -318,16 +318,21 @@ static char *authmethods_get(void);\n \n Authmethod authmethods[] = {\n #ifdef GSSAPI\n \t{\"gssapi-with-mic\",\n \t\tuserauth_gssapi,\n \t\tNULL,\n \t\t&options.gss_authentication,\n \t\tNULL},\n+\t{\"gssapi\",\n+\t\tuserauth_gssapi,\n+\t\tNULL,\n+\t\t&options.gss_enable_mitm,\n+\t\tNULL},\n #endif\n \t{\"hostbased\",\n \t\tuserauth_hostbased,\n \t\tNULL,\n \t\t&options.hostbased_authentication,\n \t\tNULL},\n \t{\"publickey\",\n \t\tuserauth_pubkey,\n@@ -685,17 +690,19 @@ process_gssapi_token(void *ctxt, gss_buf\n \n \t\tpacket_put_string(send_tok.value, send_tok.length);\n \t\tpacket_send();\n \t\tgss_release_buffer(&ms, &send_tok);\n \t}\n \n \tif (status == GSS_S_COMPLETE) {\n \t\t/* send either complete or MIC, depending on mechanism */\n-\t\tif (!(flags & GSS_C_INTEG_FLAG)) {\n+\t\t\n+\t\tif (strcmp(authctxt->method->name,\"gssapi\") == 0 ||\n+\t\t (!(flags & GSS_C_INTEG_FLAG))) {\n \t\t\tpacket_start(SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE);\n \t\t\tpacket_send();\n \t\t} else {\n \t\t\tssh_gssapi_buildmic(&b, authctxt->server_user,\n \t\t\t authctxt->service, \"gssapi-with-mic\");\n \n \t\t\tgssbuf.value = buffer_ptr(&b);\n \t\t\tgssbuf.length = buffer_len(&b);\ndiff --git a/openssh-6.6p1/sshd_config b/openssh-6.6p1/sshd_config\n--- a/openssh-6.6p1/sshd_config\n+++ b/openssh-6.6p1/sshd_config\n@@ -80,16 +80,23 @@ PasswordAuthentication no\n #KerberosOrLocalPasswd yes\n #KerberosTicketCleanup yes\n #KerberosGetAFSToken no\n \n # GSSAPI options\n #GSSAPIAuthentication no\n #GSSAPICleanupCredentials yes\n \n+# Set this to 'yes' to enable support for the deprecated 'gssapi' authentication\n+# mechanism to OpenSSH 3.8p1. The newer 'gssapi-with-mic' mechanism is included\n+# in this release. The use of 'gssapi' is deprecated due to the presence of \n+# potential man-in-the-middle attacks, which 'gssapi-with-mic' is not susceptible to.\n+#GSSAPIEnableMITMAttack no\n+ \n+\n # Set this to 'yes' to enable PAM authentication, account processing,\n # and session processing. If this is enabled, PAM authentication will\n # be allowed through the ChallengeResponseAuthentication and\n # PasswordAuthentication. Depending on your PAM configuration,\n # PAM authentication via ChallengeResponseAuthentication may bypass\n # the setting of \"PermitRootLogin without-password\".\n # If you just want the PAM account and session checks to run without\n # PAM authentication, then enable this but set PasswordAuthentication" } ]
{ "id": "openssh-askpass-gnome-5136-openssh-6.6p1-gssapimitm.patch", "cve_id": "CVE-2015-8325", "package": "openssh-askpass-gnome", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": false, "license": "BSD-2-Clause", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-2105\n\nInteger overflow in the EVP_EncodeUpdate function in crypto/evp/encode.c in OpenSSL before 1.0.1t and 1.0.2 before 1.0.2h allows remote attackers to cause a denial of service (heap memory corruption) via a large amount of binary data.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1k.orig/crypto/srp/srp.h\n- openssl-1.0.1k.orig/crypto/srp/srp_vfy.c\n- openssl-1.0.1k/crypto/srp/srp_vfy.c\n- openssl-1.0.1k/crypto/srp/srp.h\n- openssl-1.0.1k.orig/apps/s_server.c\n\n## Target Source Code\n\n### apps/s_server.c\n\n#### region() [lines 392-423]\n```c\n (which would normally occur after a worker has finished) and we\n set the user parameters. \n*/\nstatic int MS_CALLBACK ssl_srp_server_param_cb(SSL *s, int *ad, void *arg)\n\t{\n\tsrpsrvparm *p = (srpsrvparm *)arg;\n\tif (p->login == NULL && p->user == NULL )\n\t\t{\n\t\tp->login = SSL_get_srp_username(s);\n\t\tBIO_printf(bio_err, \"SRP username = \\\"%s\\\"\\n\", p->login);\n\t\treturn (-1) ;\n\t\t}\n\n\tif (p->user == NULL)\n\t\t{\n\t\tBIO_printf(bio_err, \"User %s doesn't exist\\n\", p->login);\n\t\treturn SSL3_AL_FATAL;\n\t\t}\n\tif (SSL_set_srp_server_param(s, p->user->N, p->user->g, p->user->s, p->user->v,\n\t\t\t\t p->user->info) < 0)\n\t\t{\n\t\t*ad = SSL_AD_INTERNAL_ERROR;\n\t\treturn SSL3_AL_FATAL;\n\t\t}\n\tBIO_printf(bio_err, \"SRP parameters set: username = \\\"%s\\\" info=\\\"%s\\\" \\n\", p->login,p->user->info);\n\t/* need to check whether there are memory leaks */\n\tp->user = NULL;\n\tp->login = NULL;\n\treturn SSL_ERROR_NONE;\n\t}\n\n#endif\n```\n\n#### region() [lines 384-483]\n```c\n\tSRP_VBASE *vb;\n\tSRP_user_pwd *user;\n\t} srpsrvparm;\n\n/* This callback pretends to require some asynchronous logic in order to obtain\n a verifier. When the callback is called for a new connection we return\n with a negative value. This will provoke the accept etc to return with\n an LOOKUP_X509. The main logic of the reinvokes the suspended call \n (which would normally occur after a worker has finished) and we\n set the user parameters. \n*/\nstatic int MS_CALLBACK ssl_srp_server_param_cb(SSL *s, int *ad, void *arg)\n\t{\n\tsrpsrvparm *p = (srpsrvparm *)arg;\n\tif (p->login == NULL && p->user == NULL )\n\t\t{\n\t\tp->login = SSL_get_srp_username(s);\n\t\tBIO_printf(bio_err, \"SRP username = \\\"%s\\\"\\n\", p->login);\n\t\treturn (-1) ;\n\t\t}\n\n\tif (p->user == NULL)\n\t\t{\n\t\tBIO_printf(bio_err, \"User %s doesn't exist\\n\", p->login);\n\t\treturn SSL3_AL_FATAL;\n\t\t}\n\tif (SSL_set_srp_server_param(s, p->user->N, p->user->g, p->user->s, p->user->v,\n\t\t\t\t p->user->info) < 0)\n\t\t{\n\t\t*ad = SSL_AD_INTERNAL_ERROR;\n\t\treturn SSL3_AL_FATAL;\n\t\t}\n\tBIO_printf(bio_err, \"SRP parameters set: username = \\\"%s\\\" info=\\\"%s\\\" \\n\", p->login,p->user->info);\n\t/* need to check whether there are memory leaks */\n\tp->user = NULL;\n\tp->login = NULL;\n\treturn SSL_ERROR_NONE;\n\t}\n\n#endif\n\n#ifdef MONOLITH\nstatic void s_server_init(void)\n\t{\n\taccept_socket=-1;\n\tcipher=NULL;\n\ts_server_verify=SSL_VERIFY_NONE;\n\ts_dcert_file=NULL;\n\ts_dkey_file=NULL;\n\ts_cert_file=TEST_CERT;\n\ts_key_file=NULL;\n#ifndef OPENSSL_NO_TLSEXT\n\ts_cert_file2=TEST_CERT2;\n\ts_key_file2=NULL;\n\tctx2=NULL;\n#endif\n#ifdef FIONBIO\n\ts_nbio=0;\n#endif\n\ts_nbio_test=0;\n\tctx=NULL;\n\twww=0;\n\n\tbio_s_out=NULL;\n\ts_debug=0;\n\ts_msg=0;\n\ts_quiet=0;\n\thack=0;\n#ifndef OPENSSL_NO_ENGINE\n\tengine_id=NULL;\n#endif\n\t}\n#endif\n\nstatic void sv_usage(void)\n\t{\n\tBIO_printf(bio_err,\"usage: s_server [args ...]\\n\");\n\tBIO_printf(bio_err,\"\\n\");\n\tBIO_printf(bio_err,\" -accept arg - port to accept on (default is %d)\\n\",PORT);\n\tBIO_printf(bio_err,\" -context arg - set session ID context\\n\");\n\tBIO_printf(bio_err,\" -verify arg - turn on peer certificate verification\\n\");\n\tBIO_printf(bio_err,\" -Verify arg - turn on peer certificate verification, must have a cert.\\n\");\n\tBIO_printf(bio_err,\" -verify_return_error - return verificat\n/* ... truncated ... */\n```\n\n### crypto/srp/srp.h\n\n#### DECLARE_STACK_OF() [lines 79-94]\n```c\n\t} SRP_gN_cache;\n\n\nDECLARE_STACK_OF(SRP_gN_cache)\n\ntypedef struct SRP_user_pwd_st\n\t{\n\tchar *id;\n\tBIGNUM *s;\n\tBIGNUM *v;\n\tconst BIGNUM *g;\n\tconst BIGNUM *N;\n\tchar *info;\n\t} SRP_user_pwd;\n\nDECLARE_STACK_OF(SRP_user_pwd)\n```\n\n### crypto/srp/srp_vfy.c\n\n#### region() [lines 143-230]\n```c\n\t\tbreak;\n\t\t}\n\n\twhile(1)\n\t\t{\n\t\tc = (b0 & 0xfc) >> 2;\n\t\tif(notleading || c != 0)\n\t\t\t{\n\t\t\t*dst++ = b64table[c];\n\t\t\tnotleading = 1;\n\t\t\t}\n\t\tc = ((b0 & 3) << 4) | ((b1 & 0xf0) >> 4);\n\t\tif(notleading || c != 0)\n\t\t\t{\n\t\t\t*dst++ = b64table[c];\n\t\t\tnotleading = 1;\n\t\t\t}\n\t\tc = ((b1 & 0xf) << 2) | ((b2 & 0xc0) >> 6);\n\t\tif(notleading || c != 0)\n\t\t\t{\n\t\t\t*dst++ = b64table[c];\n\t\t\tnotleading = 1;\n\t\t\t}\n\t\tc = b2 & 0x3f;\n\t\tif(notleading || c != 0)\n\t\t\t{\n\t\t\t*dst++ = b64table[c];\n\t\t\tnotleading = 1;\n\t\t\t}\n\t\tif(pos >= size) break;\n\t\telse\n\t\t\t{\n\t\t\tb0 = src[pos++];\n\t\t\tb1 = src[pos++];\n\t\t\tb2 = src[pos++];\n\t\t\t}\n\t\t}\n\n\t*dst++ = '\\0';\n\treturn olddst;\n\t}\n\nstatic void SRP_user_pwd_free(SRP_user_pwd *user_pwd)\n\t{\n\tif (user_pwd == NULL) \n\t\treturn;\n\tBN_free(user_pwd->s);\n\tBN_clear_free(user_pwd->v);\n\tOPENSSL_free(user_pwd->id);\n\tOPENSSL_free(user_pwd->info);\n\tOPENSSL_free(user_pwd);\n\t}\n\nstatic SRP_user_pwd *SRP_user_pwd_new()\n\t{\n\tSRP_user_pwd *ret = OPENSSL_malloc(sizeof(SRP_user_pwd));\n\tif (ret == NULL)\n\t\treturn NULL;\t\t\t\t\t\t\t\t\n\tret->N = NULL;\n\tret->g = NULL;\t\n\tret->s = NULL;\n\tret->v = NULL;\n\tret->id = NULL ;\n\tret->info = NULL;\n\treturn ret;\n\t}\n\nstatic void SRP_user_pwd_set_gN(SRP_user_pwd *vinfo, const BIGNUM *g,\n\t\t\t\tconst BIGNUM *N)\n\t{\n\tvinfo->N = N;\n\tvinfo->g = g;\t\n\t}\n\nstatic int SRP_user_pwd_set_ids(SRP_user_pwd *vinfo, const char *id,\n\t\t\t\tconst char *info)\n\t{\n\tif (id != NULL && NULL == (vinfo->id = BUF_strdup(id)))\n\t\treturn 0;\n\treturn (info == NULL || NULL != (vinfo->info = BUF_strdup(info))) ;\n\t}\n\nstatic int SRP_user_pwd_set_sv(SRP_user_pwd *vinfo, const char *s,\n\t\t\t const char *v)\n\t{\n\tunsigned char tmp[MAX_LEN];\n\tint len;\n\n```\n\n#### SRP_user_pwd_set_sv_BN() [lines 237-247]\n```c\n\treturn ((vinfo->s = BN_bin2bn(tmp, len, NULL)) != NULL) ;\n\t}\n\nstatic int SRP_user_pwd_set_sv_BN(SRP_user_pwd *vinfo, BIGNUM *s, BIGNUM *v)\n\t{\n\tvinfo->v = v;\n\tvinfo->s = s;\n\treturn (vinfo->s != NULL && vinfo->v != NULL) ;\n\t}\n\nSRP_VBASE *SRP_VBASE_new(char *seed_key)\n```\n\n#### SRP_VBASE_init() [lines 360-477]\n```c\n */\n\n\nint SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file)\n\t{\n\tint error_code ;\n\tSTACK_OF(SRP_gN) *SRP_gN_tab = sk_SRP_gN_new_null();\n\tchar *last_index = NULL;\n\tint i;\n\tchar **pp;\n\n\tSRP_gN *gN = NULL;\n\tSRP_user_pwd *user_pwd = NULL ;\n\n\tTXT_DB *tmpdb = NULL;\n\tBIO *in = BIO_new(BIO_s_file());\n\n\terror_code = SRP_ERR_OPEN_FILE;\n\n\tif (in == NULL || BIO_read_filename(in,verifier_file) <= 0)\n\t\tgoto err;\n\n\terror_code = SRP_ERR_VBASE_INCOMPLETE_FILE;\n\n\tif ((tmpdb =TXT_DB_read(in,DB_NUMBER)) == NULL)\n\t\tgoto err;\n\n\terror_code = SRP_ERR_MEMORY;\n\n\n\tif (vb->seed_key)\n\t\t{\n\t\tlast_index = SRP_get_default_gN(NULL)->id;\n\t\t}\n\tfor (i = 0; i < sk_OPENSSL_PSTRING_num(tmpdb->data); i++)\n\t\t{\n\t\tpp = sk_OPENSSL_PSTRING_value(tmpdb->data,i);\n\t\tif (pp[DB_srptype][0] == DB_SRP_INDEX)\n\t\t\t{\n\t\t\t/*we add this couple in the internal Stack */\n\n\t\t\tif ((gN = (SRP_gN *)OPENSSL_malloc(sizeof(SRP_gN))) == NULL) \n \t\t\t\tgoto err;\n\n\t\t\tif (!(gN->id = BUF_strdup(pp[DB_srpid]))\n\t || !(gN->N = SRP_gN_place_bn(vb->gN_cache,pp[DB_srpverifier]))\n\t\t\t|| !(gN->g = SRP_gN_place_bn(vb->gN_cache,pp[DB_srpsalt]))\n\t\t\t|| sk_SRP_gN_insert(SRP_gN_tab,gN,0) == 0)\n\t\t\t\tgoto err;\n\n\t\t\tgN = \n/* ... truncated ... */\n```\n\n### util/libeay.num\n\n#### region() [lines 1767-1853]\n```c\nDSO_new_method 2260\tEXIST::FUNCTION:\nDSO_free 2261\tEXIST::FUNCTION:\nDSO_flags 2262\tEXIST::FUNCTION:\nDSO_up 2263\tNOEXIST::FUNCTION:\nDSO_set_default_method 2264\tEXIST::FUNCTION:\nDSO_get_default_method 2265\tEXIST::FUNCTION:\nDSO_get_method 2266\tEXIST::FUNCTION:\nDSO_set_method 2267\tEXIST::FUNCTION:\nDSO_load 2268\tEXIST::FUNCTION:\nDSO_bind_var 2269\tEXIST::FUNCTION:\nDSO_METHOD_null 2270\tEXIST::FUNCTION:\nDSO_METHOD_openssl 2271\tEXIST::FUNCTION:\nDSO_METHOD_dlfcn 2272\tEXIST::FUNCTION:\nDSO_METHOD_win32 2273\tEXIST::FUNCTION:\nERR_load_DSO_strings 2274\tEXIST::FUNCTION:\nDSO_METHOD_dl 2275\tEXIST::FUNCTION:\nNCONF_load 2276\tEXIST::FUNCTION:\nNCONF_load_fp 2278\tEXIST::FUNCTION:FP_API\nNCONF_new 2279\tEXIST::FUNCTION:\nNCONF_get_string 2280\tEXIST::FUNCTION:\nNCONF_free 2281\tEXIST::FUNCTION:\nNCONF_get_number 2282\tNOEXIST::FUNCTION:\nCONF_dump_fp 2283\tEXIST::FUNCTION:\nNCONF_load_bio 2284\tEXIST::FUNCTION:\nNCONF_dump_fp 2285\tEXIST::FUNCTION:\nNCONF_get_section 2286\tEXIST::FUNCTION:\nNCONF_dump_bio 2287\tEXIST::FUNCTION:\nCONF_dump_bio 2288\tEXIST::FUNCTION:\nNCONF_free_data 2289\tEXIST::FUNCTION:\nCONF_set_default_method 2290\tEXIST::FUNCTION:\nERR_error_string_n 2291\tEXIST::FUNCTION:\nBIO_snprintf 2292\tEXIST::FUNCTION:\nDSO_ctrl 2293\tEXIST::FUNCTION:\ni2d_ASN1_SET_OF_ASN1_INTEGER 2317\tNOEXIST::FUNCTION:\ni2d_ASN1_SET_OF_PKCS12_SAFEBAG 2320\tNOEXIST::FUNCTION:\ni2d_ASN1_SET_OF_PKCS7 2328\tNOEXIST::FUNCTION:\nBIO_vfree 2334\tEXIST::FUNCTION:\nd2i_ASN1_SET_OF_ASN1_INTEGER 2339\tNOEXIST::FUNCTION:\nd2i_ASN1_SET_OF_PKCS12_SAFEBAG 2341\tNOEXIST::FUNCTION:\nASN1_UTCTIME_get 2350\tNOEXIST::FUNCTION:\nX509_REQ_digest 2362\tEXIST::FUNCTION:EVP\nX509_CRL_digest 2391\tEXIST::FUNCTION:EVP\nd2i_ASN1_SET_OF_PKCS7 2397\tNOEXIST::FUNCTION:\nX509_ALGOR_cmp 2398\tEXIST::FUNCTION:\nEVP_CIPHER_CTX_set_key_length 2399\tEXIST::FUNCTION:\nEVP_CIPHER_CTX_ctrl 2400\tEXIST::FUNCTION:\nBN_mod_exp_mont_word 2401\tEXIST::FUNCTION:\nRAND_egd_bytes 2402\tEXIST::FUNCTION:\nX509_REQ_get1_email 2403\tEXIST::FUNCTION:\nX509_get1_email 2404\tEXIST::FUNCTION:\nX509_email_free \n/* ... truncated ... */\n```\n\n\n## Upstream Fix\n```diff\ncommit 59a908f1e8380412a81392c468b83bf6071beb2a\nAuthor: Emilia Kasper <emilia@openssl.org>\nDate: Wed Feb 24 12:59:59 2016 +0100\n\n CVE-2016-0798: avoid memory leak in SRP\n \n The SRP user database lookup method SRP_VBASE_get_by_user had confusing\n memory management semantics; the returned pointer was sometimes newly\n allocated, and sometimes owned by the callee. The calling code has no\n way of distinguishing these two cases.\n \n Specifically, SRP servers that configure a secret seed to hide valid\n login information are vulnerable to a memory leak: an attacker\n connecting with an invalid username can cause a memory leak of around\n 300 bytes per connection.\n \n Servers that do not configure SRP, or configure SRP but do not configure\n a seed are not vulnerable.\n \n In Apache, the seed directive is known as SSLSRPUnknownUserSeed.\n \n To mitigate the memory leak, the seed handling in SRP_VBASE_get_by_user\n is now disabled even if the user has configured a seed.\n \n Applications are advised to migrate to SRP_VBASE_get1_by_user. However,\n note that OpenSSL makes no strong guarantees about the\n indistinguishability of valid and invalid logins. In particular,\n computations are currently not carried out in constant time.\n \n Reviewed-by: Rich Salz <rsalz@openssl.org>\n\nIndex: openssl-1.0.1k/apps/s_server.c\n===================================================================\n--- openssl-1.0.1k.orig/apps/s_server.c\t2016-03-01 11:22:56.364551503 +0100\n+++ openssl-1.0.1k/apps/s_server.c\t2016-03-01 11:22:56.443552756 +0100\n@@ -413,6 +413,8 @@ typedef struct srpsrvparm_st\n static int MS_CALLBACK ssl_srp_server_param_cb(SSL *s, int *ad, void *arg)\n \t{\n \tsrpsrvparm *p = (srpsrvparm *)arg;\n+ int ret = SSL3_AL_FATAL;\n+\n \tif (p->login == NULL && p->user == NULL )\n \t\t{\n \t\tp->login = SSL_get_srp_username(s);\n@@ -423,19 +425,23 @@ static int MS_CALLBACK ssl_srp_server_pa\n \tif (p->user == NULL)\n \t\t{\n \t\tBIO_printf(bio_err, \"User %s doesn't exist\\n\", p->login);\n-\t\treturn SSL3_AL_FATAL;\n+ goto err;\n \t\t}\n+\n \tif (SSL_set_srp_server_param(s, p->user->N, p->user->g, p->user->s, p->user->v,\n \t\t\t\t p->user->info) < 0)\n \t\t{\n \t\t*ad = SSL_AD_INTERNAL_ERROR;\n-\t\treturn SSL3_AL_FATAL;\n+ goto err;\n \t\t}\n \tBIO_printf(bio_err, \"SRP parameters set: username = \\\"%s\\\" info=\\\"%s\\\" \\n\", p->login,p->user->info);\n-\t/* need to check whether there are memory leaks */\n+ ret = SSL_ERROR_NONE;\n+\n+err:\n+ SRP_user_pwd_free(p->user);\n \tp->user = NULL;\n \tp->login = NULL;\n-\treturn SSL_ERROR_NONE;\n+\treturn ret;\n \t}\n \n #endif\n@@ -2316,7 +2322,8 @@ static int sv_body(char *hostname, int s\n \t\t\t\twhile (SSL_get_error(con,k) == SSL_ERROR_WANT_X509_LOOKUP)\n \t\t\t\t\t{\n \t\t\t\t\tBIO_printf(bio_s_out,\"LOOKUP renego during write\\n\");\n-\t\t\t\t\tsrp_callback_parm.user = SRP_VBASE_get_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n+ SRP_user_pwd_free(srp_callback_parm.user);\n+\t\t\t\t\tsrp_callback_parm.user = SRP_VBASE_get1_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n \t\t\t\t\tif (srp_callback_parm.user) \n \t\t\t\t\t\tBIO_printf(bio_s_out,\"LOOKUP done %s\\n\",srp_callback_parm.user->info);\n \t\t\t\t\telse \n@@ -2375,7 +2382,8 @@ again:\n \t\t\t\twhile (SSL_get_error(con,i) == SSL_ERROR_WANT_X509_LOOKUP)\n \t\t\t\t\t{\n \t\t\t\t\tBIO_printf(bio_s_out,\"LOOKUP renego during read\\n\");\n-\t\t\t\t\tsrp_callback_parm.user = SRP_VBASE_get_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n+ SRP_user_pwd_free(srp_callback_parm.user);\n+\t\t\t\t\tsrp_callback_parm.user = SRP_VBASE_get1_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n \t\t\t\t\tif (srp_callback_parm.user) \n \t\t\t\t\t\tBIO_printf(bio_s_out,\"LOOKUP done %s\\n\",srp_callback_parm.user->info);\n \t\t\t\t\telse \n@@ -2464,7 +2472,8 @@ static int init_ssl_connection(SSL *con)\n \twhile (i <= 0 && SSL_get_error(con,i) == SSL_ERROR_WANT_X509_LOOKUP) \n \t\t{\n \t\t\tBIO_printf(bio_s_out,\"LOOKUP during accept %s\\n\",srp_callback_parm.login);\n-\t\t\tsrp_callback_parm.user = SRP_VBASE_get_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n+ SRP_user_pwd_free(srp_callback_parm.user);\n+\t\t\tsrp_callback_parm.user = SRP_VBASE_get1_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n \t\t\tif (srp_callback_parm.user) \n \t\t\t\tBIO_printf(bio_s_out,\"LOOKUP done %s\\n\",srp_callback_parm.user->info);\n \t\t\telse \n@@ -2706,7 +2715,8 @@ static int www_body(char *hostname, int\n \t\t\twhile (i <= 0 && SSL_get_error(con,i) == SSL_ERROR_WANT_X509_LOOKUP) \n \t\t{\n \t\t\tBIO_printf(bio_s_out,\"LOOKUP during accept %s\\n\",srp_callback_parm.login);\n-\t\t\tsrp_callback_parm.user = SRP_VBASE_get_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n+ SRP_user_pwd_free(srp_callback_parm.user);\n+\t\t\tsrp_callback_parm.user = SRP_VBASE_get1_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n \t\t\tif (srp_callback_parm.user) \n \t\t\t\tBIO_printf(bio_s_out,\"LOOKUP done %s\\n\",srp_callback_parm.user->info);\n \t\t\telse \nIndex: openssl-1.0.1k/crypto/srp/srp.h\n===================================================================\n--- openssl-1.0.1k.orig/crypto/srp/srp.h\t2015-01-08 15:00:36.000000000 +0100\n+++ openssl-1.0.1k/crypto/srp/srp.h\t2016-03-01 11:22:56.443552756 +0100\n@@ -83,16 +83,21 @@ DECLARE_STACK_OF(SRP_gN_cache)\n \n typedef struct SRP_user_pwd_st\n \t{\n+ /* Owned by us. */\n \tchar *id;\n \tBIGNUM *s;\n \tBIGNUM *v;\n+ /* Not owned by us. */\n \tconst BIGNUM *g;\n \tconst BIGNUM *N;\n+ /* Owned by us. */\n \tchar *info;\n \t} SRP_user_pwd;\n \n DECLARE_STACK_OF(SRP_user_pwd)\n \n+void SRP_user_pwd_free(SRP_user_pwd *user_pwd);\n+\n typedef struct SRP_VBASE_st\n \t{\n \tSTACK_OF(SRP_user_pwd) *users_pwd;\n@@ -117,7 +122,12 @@ DECLARE_STACK_OF(SRP_gN)\n SRP_VBASE *SRP_VBASE_new(char *seed_key);\n int SRP_VBASE_free(SRP_VBASE *vb);\n int SRP_VBASE_init(SRP_VBASE *vb, char * verifier_file);\n+\n+/* This method ignores the configured seed and fails for an unknown user. */\n SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username);\n+/* NOTE: unlike in SRP_VBASE_get_by_user, caller owns the returned pointer.*/\n+SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username);\n+\n char *SRP_create_verifier(const char *user, const char *pass, char **salt,\n \t\t\t char **verifier, const char *N, const char *g);\n int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt, BIGNUM **verifier, BIGNUM *N, BIGNUM *g);\nIndex: openssl-1.0.1k/crypto/srp/srp_vfy.c\n===================================================================\n--- openssl-1.0.1k.orig/crypto/srp/srp_vfy.c\t2015-01-08 15:00:36.000000000 +0100\n+++ openssl-1.0.1k/crypto/srp/srp_vfy.c\t2016-03-01 11:22:56.443552756 +0100\n@@ -182,7 +182,7 @@ static char *t_tob64(char *dst, const un\n \treturn olddst;\n \t}\n \n-static void SRP_user_pwd_free(SRP_user_pwd *user_pwd)\n+void SRP_user_pwd_free(SRP_user_pwd *user_pwd)\n \t{\n \tif (user_pwd == NULL) \n \t\treturn;\n@@ -244,6 +244,24 @@ static int SRP_user_pwd_set_sv_BN(SRP_us\n \treturn (vinfo->s != NULL && vinfo->v != NULL) ;\n \t}\n \n+static SRP_user_pwd *srp_user_pwd_dup(SRP_user_pwd *src)\n+{\n+ SRP_user_pwd *ret;\n+\n+ if (src == NULL)\n+ return NULL;\n+ if ((ret = SRP_user_pwd_new()) == NULL)\n+ return NULL;\n+\n+ SRP_user_pwd_set_gN(ret, src->g, src->N);\n+ if (!SRP_user_pwd_set_ids(ret, src->id, src->info)\n+ || !SRP_user_pwd_set_sv_BN(ret, BN_dup(src->s), BN_dup(src->v))) {\n+ SRP_user_pwd_free(ret);\n+ return NULL;\n+ }\n+ return ret;\n+}\n+\n SRP_VBASE *SRP_VBASE_new(char *seed_key)\n \t{\n \tSRP_VBASE *vb = (SRP_VBASE *) OPENSSL_malloc(sizeof(SRP_VBASE));\n@@ -474,23 +492,51 @@ int SRP_VBASE_init(SRP_VBASE *vb, char *\n \n \t}\n \n-\n-SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username)\n+static SRP_user_pwd *find_user(SRP_VBASE *vb, char *username)\n \t{\n \tint i;\n \tSRP_user_pwd *user;\n-\tunsigned char digv[SHA_DIGEST_LENGTH];\n-\tunsigned char digs[SHA_DIGEST_LENGTH];\n-\tEVP_MD_CTX ctxt;\n \n \tif (vb == NULL)\n \t\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "commit 59a908f1e8380412a81392c468b83bf6071beb2a\nAuthor: Emilia Kasper <emilia@openssl.org>\nDate: Wed Feb 24 12:59:59 2016 +0100\n\n CVE-2016-0798: avoid memory leak in SRP\n \n The SRP user database lookup method SRP_VBASE_get_by_user had confusing\n memory management semantics; the returned pointer was sometimes newly\n allocated, and sometimes owned by the callee. The calling code has no\n way of distinguishing these two cases.\n \n Specifically, SRP servers that configure a secret seed to hide valid\n login information are vulnerable to a memory leak: an attacker\n connecting with an invalid username can cause a memory leak of around\n 300 bytes per connection.\n \n Servers that do not configure SRP, or configure SRP but do not configure\n a seed are not vulnerable.\n \n In Apache, the seed directive is known as SSLSRPUnknownUserSeed.\n \n To mitigate the memory leak, the seed handling in SRP_VBASE_get_by_user\n is now disabled even if the user has configured a seed.\n \n Applications are advised to migrate to SRP_VBASE_get1_by_user. However,\n note that OpenSSL makes no strong guarantees about the\n indistinguishability of valid and invalid logins. In particular,\n computations are currently not carried out in constant time.\n \n Reviewed-by: Rich Salz <rsalz@openssl.org>\n\nIndex: openssl-1.0.1k/apps/s_server.c\n===================================================================\n--- openssl-1.0.1k.orig/apps/s_server.c\t2016-03-01 11:22:56.364551503 +0100\n+++ openssl-1.0.1k/apps/s_server.c\t2016-03-01 11:22:56.443552756 +0100\n@@ -413,6 +413,8 @@ typedef struct srpsrvparm_st\n static int MS_CALLBACK ssl_srp_server_param_cb(SSL *s, int *ad, void *arg)\n \t{\n \tsrpsrvparm *p = (srpsrvparm *)arg;\n+ int ret = SSL3_AL_FATAL;\n+\n \tif (p->login == NULL && p->user == NULL )\n \t\t{\n \t\tp->login = SSL_get_srp_username(s);\n@@ -423,19 +425,23 @@ static int MS_CALLBACK ssl_srp_server_pa\n \tif (p->user == NULL)\n \t\t{\n \t\tBIO_printf(bio_err, \"User %s doesn't exist\\n\", p->login);\n-\t\treturn SSL3_AL_FATAL;\n+ goto err;\n \t\t}\n+\n \tif (SSL_set_srp_server_param(s, p->user->N, p->user->g, p->user->s, p->user->v,\n \t\t\t\t p->user->info) < 0)\n \t\t{\n \t\t*ad = SSL_AD_INTERNAL_ERROR;\n-\t\treturn SSL3_AL_FATAL;\n+ goto err;\n \t\t}\n \tBIO_printf(bio_err, \"SRP parameters set: username = \\\"%s\\\" info=\\\"%s\\\" \\n\", p->login,p->user->info);\n-\t/* need to check whether there are memory leaks */\n+ ret = SSL_ERROR_NONE;\n+\n+err:\n+ SRP_user_pwd_free(p->user);\n \tp->user = NULL;\n \tp->login = NULL;\n-\treturn SSL_ERROR_NONE;\n+\treturn ret;\n \t}\n \n #endif\n@@ -2316,7 +2322,8 @@ static int sv_body(char *hostname, int s\n \t\t\t\twhile (SSL_get_error(con,k) == SSL_ERROR_WANT_X509_LOOKUP)\n \t\t\t\t\t{\n \t\t\t\t\tBIO_printf(bio_s_out,\"LOOKUP renego during write\\n\");\n-\t\t\t\t\tsrp_callback_parm.user = SRP_VBASE_get_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n+ SRP_user_pwd_free(srp_callback_parm.user);\n+\t\t\t\t\tsrp_callback_parm.user = SRP_VBASE_get1_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n \t\t\t\t\tif (srp_callback_parm.user) \n \t\t\t\t\t\tBIO_printf(bio_s_out,\"LOOKUP done %s\\n\",srp_callback_parm.user->info);\n \t\t\t\t\telse \n@@ -2375,7 +2382,8 @@ again:\n \t\t\t\twhile (SSL_get_error(con,i) == SSL_ERROR_WANT_X509_LOOKUP)\n \t\t\t\t\t{\n \t\t\t\t\tBIO_printf(bio_s_out,\"LOOKUP renego during read\\n\");\n-\t\t\t\t\tsrp_callback_parm.user = SRP_VBASE_get_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n+ SRP_user_pwd_free(srp_callback_parm.user);\n+\t\t\t\t\tsrp_callback_parm.user = SRP_VBASE_get1_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n \t\t\t\t\tif (srp_callback_parm.user) \n \t\t\t\t\t\tBIO_printf(bio_s_out,\"LOOKUP done %s\\n\",srp_callback_parm.user->info);\n \t\t\t\t\telse \n@@ -2464,7 +2472,8 @@ static int init_ssl_connection(SSL *con)\n \twhile (i <= 0 && SSL_get_error(con,i) == SSL_ERROR_WANT_X509_LOOKUP) \n \t\t{\n \t\t\tBIO_printf(bio_s_out,\"LOOKUP during accept %s\\n\",srp_callback_parm.login);\n-\t\t\tsrp_callback_parm.user = SRP_VBASE_get_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n+ SRP_user_pwd_free(srp_callback_parm.user);\n+\t\t\tsrp_callback_parm.user = SRP_VBASE_get1_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n \t\t\tif (srp_callback_parm.user) \n \t\t\t\tBIO_printf(bio_s_out,\"LOOKUP done %s\\n\",srp_callback_parm.user->info);\n \t\t\telse \n@@ -2706,7 +2715,8 @@ static int www_body(char *hostname, int\n \t\t\twhile (i <= 0 && SSL_get_error(con,i) == SSL_ERROR_WANT_X509_LOOKUP) \n \t\t{\n \t\t\tBIO_printf(bio_s_out,\"LOOKUP during accept %s\\n\",srp_callback_parm.login);\n-\t\t\tsrp_callback_parm.user = SRP_VBASE_get_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n+ SRP_user_pwd_free(srp_callback_parm.user);\n+\t\t\tsrp_callback_parm.user = SRP_VBASE_get1_by_user(srp_callback_parm.vb, srp_callback_parm.login); \n \t\t\tif (srp_callback_parm.user) \n \t\t\t\tBIO_printf(bio_s_out,\"LOOKUP done %s\\n\",srp_callback_parm.user->info);\n \t\t\telse \nIndex: openssl-1.0.1k/crypto/srp/srp.h\n===================================================================\n--- openssl-1.0.1k.orig/crypto/srp/srp.h\t2015-01-08 15:00:36.000000000 +0100\n+++ openssl-1.0.1k/crypto/srp/srp.h\t2016-03-01 11:22:56.443552756 +0100\n@@ -83,16 +83,21 @@ DECLARE_STACK_OF(SRP_gN_cache)\n \n typedef struct SRP_user_pwd_st\n \t{\n+ /* Owned by us. */\n \tchar *id;\n \tBIGNUM *s;\n \tBIGNUM *v;\n+ /* Not owned by us. */\n \tconst BIGNUM *g;\n \tconst BIGNUM *N;\n+ /* Owned by us. */\n \tchar *info;\n \t} SRP_user_pwd;\n \n DECLARE_STACK_OF(SRP_user_pwd)\n \n+void SRP_user_pwd_free(SRP_user_pwd *user_pwd);\n+\n typedef struct SRP_VBASE_st\n \t{\n \tSTACK_OF(SRP_user_pwd) *users_pwd;\n@@ -117,7 +122,12 @@ DECLARE_STACK_OF(SRP_gN)\n SRP_VBASE *SRP_VBASE_new(char *seed_key);\n int SRP_VBASE_free(SRP_VBASE *vb);\n int SRP_VBASE_init(SRP_VBASE *vb, char * verifier_file);\n+\n+/* This method ignores the configured seed and fails for an unknown user. */\n SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username);\n+/* NOTE: unlike in SRP_VBASE_get_by_user, caller owns the returned pointer.*/\n+SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username);\n+\n char *SRP_create_verifier(const char *user, const char *pass, char **salt,\n \t\t\t char **verifier, const char *N, const char *g);\n int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt, BIGNUM **verifier, BIGNUM *N, BIGNUM *g);\nIndex: openssl-1.0.1k/crypto/srp/srp_vfy.c\n===================================================================\n--- openssl-1.0.1k.orig/crypto/srp/srp_vfy.c\t2015-01-08 15:00:36.000000000 +0100\n+++ openssl-1.0.1k/crypto/srp/srp_vfy.c\t2016-03-01 11:22:56.443552756 +0100\n@@ -182,7 +182,7 @@ static char *t_tob64(char *dst, const un\n \treturn olddst;\n \t}\n \n-static void SRP_user_pwd_free(SRP_user_pwd *user_pwd)\n+void SRP_user_pwd_free(SRP_user_pwd *user_pwd)\n \t{\n \tif (user_pwd == NULL) \n \t\treturn;\n@@ -244,6 +244,24 @@ static int SRP_user_pwd_set_sv_BN(SRP_us\n \treturn (vinfo->s != NULL && vinfo->v != NULL) ;\n \t}\n \n+static SRP_user_pwd *srp_user_pwd_dup(SRP_user_pwd *src)\n+{\n+ SRP_user_pwd *ret;\n+\n+ if (src == NULL)\n+ return NULL;\n+ if ((ret = SRP_user_pwd_new()) == NULL)\n+ return NULL;\n+\n+ SRP_user_pwd_set_gN(ret, src->g, src->N);\n+ if (!SRP_user_pwd_set_ids(ret, src->id, src->info)\n+ || !SRP_user_pwd_set_sv_BN(ret, BN_dup(src->s), BN_dup(src->v))) {\n+ SRP_user_pwd_free(ret);\n+ return NULL;\n+ }\n+ return ret;\n+}\n+\n SRP_VBASE *SRP_VBASE_new(char *seed_key)\n \t{\n \tSRP_VBASE *vb = (SRP_VBASE *) OPENSSL_malloc(sizeof(SRP_VBASE));\n@@ -474,23 +492,51 @@ int SRP_VBASE_init(SRP_VBASE *vb, char *\n \n \t}\n \n-\n-SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username)\n+static SRP_user_pwd *find_user(SRP_VBASE *vb, char *username)\n \t{\n \tint i;\n \tSRP_user_pwd *user;\n-\tunsigned char digv[SHA_DIGEST_LENGTH];\n-\tunsigned char digs[SHA_DIGEST_LENGTH];\n-\tEVP_MD_CTX ctxt;\n \n \tif (vb == NULL)\n \t\treturn NULL;\n+\n \tfor(i = 0; i < sk_SRP_user_pwd_num(vb->users_pwd); i++)\n \t\t{\n \t\tuser = sk_SRP_user_pwd_value(vb->users_pwd, i);\n \t\tif (strcmp(user->id,username)==0)\n \t\t\treturn user;\n \t\t}\n+\n+ return NULL;\n+}\n+\n+/*\n+ * This method ignores the configured seed and fails for an unknown user.\n+ * Ownership of the returned pointer is not released to the caller.\n+ * In other words, caller must not free the result.\n+ */\n+SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username)\n+{\n+ return find_user(vb, username);\n+}\n+\n+/*\n+ * Ownership of the returned pointer is released to the caller.\n+ * In other words, caller must free the result once done.\n+ */\n+SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username)\n+{\n+ SRP_user_pwd *user;\n+ unsigned char digv[SHA_DIGEST_LENGTH];\n+ unsigned char digs[SHA_DIGEST_LENGTH];\n+ EVP_MD_CTX ctxt;\n+\n+ if (vb == NULL)\n+ return NULL;\n+\n+ if ((user = find_user(vb, username)) != NULL)\n+ return srp_user_pwd_dup(user);\n+\n \tif ((vb->seed_key == NULL) ||\n \t\t(vb->default_g == NULL) ||\n \t\t(vb->default_N == NULL))\nIndex: openssl-1.0.1k/util/libeay.num\n===================================================================\n--- openssl-1.0.1k.orig/util/libeay.num\t2015-01-08 15:03:26.000000000 +0100\n+++ openssl-1.0.1k/util/libeay.num\t2016-03-01 11:22:56.444552772 +0100\n@@ -1806,6 +1806,8 @@ d2i_ASN1_SET_OF_PKCS12_SAFEBAG\n ASN1_UTCTIME_get 2350\tNOEXIST::FUNCTION:\n X509_REQ_digest 2362\tEXIST::FUNCTION:EVP\n X509_CRL_digest 2391\tEXIST::FUNCTION:EVP\n+SRP_VBASE_get1_by_user 2393\tEXIST::FUNCTION:SRP\n+SRP_user_pwd_free 2394\tEXIST::FUNCTION:SRP\n d2i_ASN1_SET_OF_PKCS7 2397\tNOEXIST::FUNCTION:\n X509_ALGOR_cmp 2398\tEXIST::FUNCTION:\n EVP_CIPHER_CTX_set_key_length 2399\tEXIST::FUNCTION:" } ]
{ "id": "openssl-5042-openssl-CVE-2016-0798-101.patc", "cve_id": "CVE-2016-2105", "package": "openssl", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": true, "license": "OpenSSL", "context_tokens_est": 2501, "context_files": 4 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2013-5653\n\nThe getenv and filenameforall functions in Ghostscript 9.10 ignore the \"-dSAFER\" argument, which allows remote attackers to read data via a crafted postscript file.\n\n## Package\nghostscript\n\n## Files to modify\n- ghostscript-9.15.orig/psi/zdscpars.c\n- psi/zdscpars.c\n\n## Upstream Fix\n```diff\nFrom 875a0095f37626a721c7ff57d606a0f95af03913 Mon Sep 17 00:00:00 2001\nFrom: Ken Sharp <ken.sharp@artifex.com>\nDate: Wed, 5 Oct 2016 10:10:58 +0100\nSubject: [PATCH] DSC parser - validate parameters\n\nBug #697190 \".initialize_dsc_parser doesn't validate the parameter is a dict type before using it.\"\n\nRegardless of any security implications, its simply wrong for a PostScript\noperator not to validate its parameter(s).\n\nNo differences expected.\n---\n psi/zdscpars.c | 13 +++++++++----\n 1 file changed, 9 insertions(+), 4 deletions(-)\n\ndiff --git a/psi/zdscpars.c b/psi/zdscpars.c\nindex c05e15418f..9b4b6059a2 100644\n--- a/psi/zdscpars.c\n+++ b/psi/zdscpars.c\n@@ -150,11 +150,16 @@ zinitialize_dsc_parser(i_ctx_t *i_ctx_p)\n ref local_ref;\n int code;\n os_ptr const op = osp;\n- dict * const pdict = op->value.pdict;\n- gs_memory_t * const mem = (gs_memory_t *)dict_memory(pdict);\n- dsc_data_t * const data =\n- gs_alloc_struct(mem, dsc_data_t, &st_dsc_data_t, \"DSC parser init\");\n+ dict *pdict;\n+ gs_memory_t *mem;\n+ dsc_data_t *data;\n \n+ check_read_type(*op, t_dictionary);\n+\n+ pdict = op->value.pdict;\n+ mem = (gs_memory_t *)dict_memory(pdict);\n+\n+ data = gs_alloc_struct(mem, dsc_data_t, &st_dsc_data_t, \"DSC parser init\");\n if (!data)\n return_error(gs_error_VMerror);\n data->document_level = 0;\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 875a0095f37626a721c7ff57d606a0f95af03913 Mon Sep 17 00:00:00 2001\nFrom: Ken Sharp <ken.sharp@artifex.com>\nDate: Wed, 5 Oct 2016 10:10:58 +0100\nSubject: [PATCH] DSC parser - validate parameters\n\nBug #697190 \".initialize_dsc_parser doesn't validate the parameter is a dict type before using it.\"\n\nRegardless of any security implications, its simply wrong for a PostScript\noperator not to validate its parameter(s).\n\nNo differences expected.\n\nCVE-2016-7979\n---\n psi/zdscpars.c | 13 +++++++++----\n 1 file changed, 9 insertions(+), 4 deletions(-)\n--- ghostscript-9.15.orig/psi/zdscpars.c\t2014-09-22 12:17:33.000000000 +0200\n+++ ghostscript-9.15.orig/psi/zdscpars.c\t2016-10-08 21:26:14.726676991 +0200\n@@ -150,11 +150,16 @@ zinitialize_dsc_parser(i_ctx_t *i_ctx_p)\n ref local_ref;\n int code;\n os_ptr const op = osp;\n- dict * const pdict = op->value.pdict;\n- gs_memory_t * const mem = (gs_memory_t *)dict_memory(pdict);\n- dsc_data_t * const data =\n- gs_alloc_struct(mem, dsc_data_t, &st_dsc_data_t, \"DSC parser init\");\n+ dict *pdict;\n+ gs_memory_t *mem;\n+ dsc_data_t *data;\n \n+ check_read_type(*op, t_dictionary);\n+\n+ pdict = op->value.pdict;\n+ mem = (gs_memory_t *)dict_memory(pdict);\n+\n+ data = gs_alloc_struct(mem, dsc_data_t, &st_dsc_data_t, \"DSC parser init\");\n if (!data)\n return_error(e_VMerror);\n data->document_level = 0;" } ]
{ "id": "ghostscript-5881-CVE-2016-7979.patch", "cve_id": "CVE-2013-5653", "package": "ghostscript", "upstream_enriched": true, "upstream_commit": "875a0095f37626a721c7ff57d606a0f95af03913", "upstream_repo": "ArtifexSoftware/ghostpdl", "tier": "adapted", "has_source_context": false, "license": "AGPL-3.0-only", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-5276\n\nThe std::random_device class in libstdc++ in the GNU Compiler Collection (aka GCC) before 4.9.4 does not properly handle short reads from blocking sources, which makes it easier for context-dependent attackers to predict the random values via unspecified vectors.\n\n## Package\ngcc5\n\n## Files to modify\n- gcc/gcc.c\n\n## Upstream Fix\n```diff\nIndex: gcc/gcc.c\n===================================================================\n--- gcc/gcc.c.orig\t2013-11-26 15:41:59.000000000 +0100\n+++ gcc/gcc.c\t2013-11-26 16:40:35.780548125 +0100\n@@ -258,6 +258,7 @@ static const char *replace_outfile_spec_\n static const char *remove_outfile_spec_function (int, const char **);\n static const char *version_compare_spec_function (int, const char **);\n static const char *include_spec_function (int, const char **);\n+static const char *include_noerr_spec_function (int, const char **);\n static const char *find_file_spec_function (int, const char **);\n static const char *find_plugindir_spec_function (int, const char **);\n static const char *print_asm_header_spec_function (int, const char **);\n@@ -1357,6 +1358,7 @@ static const struct spec_function static\n { \"remove-outfile\",\t\tremove_outfile_spec_function },\n { \"version-compare\",\t\tversion_compare_spec_function },\n { \"include\",\t\t\tinclude_spec_function },\n+ { \"include_noerr\", include_noerr_spec_function },\n { \"find-file\",\t\tfind_file_spec_function },\n { \"find-plugindir\",\t\tfind_plugindir_spec_function },\n { \"print-asm-header\",\t\tprint_asm_header_spec_function },\n@@ -6480,6 +6482,8 @@ main (int argc, char **argv)\n if (access (specs_file, R_OK) == 0)\n read_specs (specs_file, true, false);\n \n+ do_self_spec (\"%:include_noerr(defaults.spec)%(default_spec)\");\n+\n /* Process any configure-time defaults specified for the command line\n options, via OPTION_DEFAULT_SPECS. */\n for (i = 0; i < ARRAY_SIZE (option_default_specs); i++)\n@@ -8401,6 +8405,21 @@ get_random_number (void)\n return ret ^ getpid ();\n }\n \n+static const char *\n+include_noerr_spec_function (int argc, const char **argv)\n+{\n+ char *file;\n+\n+ if (argc != 1)\n+ abort ();\n+\n+ file = find_a_file (&startfile_prefixes, argv[0], R_OK, 0);\n+ if (file)\n+ read_specs (file, FALSE, TRUE);\n+\n+ return NULL;\n+}\n+\n /* %:compare-debug-dump-opt spec function. Save the last argument,\n expected to be the last -fdump-final-insns option, or generate a\n temporary. */\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "Index: gcc/gcc.c\n===================================================================\n--- gcc/gcc.c.orig\t2013-11-26 15:41:59.000000000 +0100\n+++ gcc/gcc.c\t2013-11-26 16:40:35.780548125 +0100\n@@ -258,6 +258,7 @@ static const char *replace_outfile_spec_\n static const char *remove_outfile_spec_function (int, const char **);\n static const char *version_compare_spec_function (int, const char **);\n static const char *include_spec_function (int, const char **);\n+static const char *include_noerr_spec_function (int, const char **);\n static const char *find_file_spec_function (int, const char **);\n static const char *find_plugindir_spec_function (int, const char **);\n static const char *print_asm_header_spec_function (int, const char **);\n@@ -1357,6 +1358,7 @@ static const struct spec_function static\n { \"remove-outfile\",\t\tremove_outfile_spec_function },\n { \"version-compare\",\t\tversion_compare_spec_function },\n { \"include\",\t\t\tinclude_spec_function },\n+ { \"include_noerr\", include_noerr_spec_function },\n { \"find-file\",\t\tfind_file_spec_function },\n { \"find-plugindir\",\t\tfind_plugindir_spec_function },\n { \"print-asm-header\",\t\tprint_asm_header_spec_function },\n@@ -6480,6 +6482,8 @@ main (int argc, char **argv)\n if (access (specs_file, R_OK) == 0)\n read_specs (specs_file, true, false);\n \n+ do_self_spec (\"%:include_noerr(defaults.spec)%(default_spec)\");\n+\n /* Process any configure-time defaults specified for the command line\n options, via OPTION_DEFAULT_SPECS. */\n for (i = 0; i < ARRAY_SIZE (option_default_specs); i++)\n@@ -8401,6 +8405,21 @@ get_random_number (void)\n return ret ^ getpid ();\n }\n \n+static const char *\n+include_noerr_spec_function (int argc, const char **argv)\n+{\n+ char *file;\n+\n+ if (argc != 1)\n+ abort ();\n+\n+ file = find_a_file (&startfile_prefixes, argv[0], R_OK, 0);\n+ if (file)\n+ read_specs (file, FALSE, TRUE);\n+\n+ return NULL;\n+}\n+\n /* %:compare-debug-dump-opt spec function. Save the last argument,\n expected to be the last -fdump-final-insns option, or generate a\n temporary. */" } ]
{ "id": "gcc5-4931-gcc-add-defaultsspec.diff", "cve_id": "CVE-2015-5276", "package": "gcc5", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": false, "license": "GPL-3.0-or-later", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2012-2806\n\nHeap-based buffer overflow in the get_sos function in jdmarker.c in libjpeg-turbo 1.2.0 allows remote attackers to cause a denial of service (application crash) and possibly execute arbitrary code via a large component count in the header of a JPEG image.\n\n## Package\nlibjpeg-turbo\n\n## Files to modify\n- jdmarker.c\n\n## Upstream Fix\n```diff\nIndex: jdmarker.c\n===================================================================\n--- jdmarker.c.orig\n+++ jdmarker.c\n@@ -276,7 +276,7 @@ get_sof (j_decompress_ptr cinfo, boolean\n \t\t\t((j_common_ptr) cinfo, JPOOL_IMAGE,\n \t\t\t cinfo->num_components * SIZEOF(jpeg_component_info));\n \n- for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components && ci < MAX_COMPS_IN_SCAN;\n ci++, compptr++) {\n compptr->component_index = ci;\n INPUT_BYTE(cinfo, compptr->component_id, return FALSE);\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "Index: jdmarker.c\n===================================================================\n--- jdmarker.c.orig\n+++ jdmarker.c\n@@ -276,7 +276,7 @@ get_sof (j_decompress_ptr cinfo, boolean\n \t\t\t((j_common_ptr) cinfo, JPOOL_IMAGE,\n \t\t\t cinfo->num_components * SIZEOF(jpeg_component_info));\n \n- for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components && ci < MAX_COMPS_IN_SCAN;\n ci++, compptr++) {\n compptr->component_index = ci;\n INPUT_BYTE(cinfo, compptr->component_id, return FALSE);" } ]
{ "id": "libjpeg-turbo-687-libjpeg-turbo-1.1.1-CVE-2012-2", "cve_id": "CVE-2012-2806", "package": "libjpeg-turbo", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": false, "license": "BSD-3-Clause", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-7978\n\nUse-after-free vulnerability in Ghostscript 9.20 might allow remote attackers to execute arbitrary code via vectors related to a reference leak in .setdevice.\n\n## Package\nghostscript-mini\n\n## Files to modify\n- base/gp_psync.c\n- ghostscript-9.15.orig/base/gp_psync.c\n\n## Target Source Code\n\n### configure.ac\n\n#### AC_CHECK_LIB() [lines 455-487]\n```c\nif test -z \"$no_x\"; then\n # workaround autoconf bug which used to depend on xmkmf to set the\n # $x_includes directory. Danger quadrigraph ahead!\n if test ! -z \"$x_libraries && test -z \"$x_includes; then\n includedir=\"include\"\n x_includes=$(echo $x_libraries | sed 's|@<:@^/@:>@*$||')\n x_includes=\"$x_includes$includedir\"\n fi\n if test ! -z \"$x_includes\"; then\n XINCLUDE=-I$x_includes\n fi\n if test ! -z \"$x_libraries\"; then\n XLIBDIRS=-L$x_libraries\n XLIBDIR=-L$x_libraries\n fi\n XLIBS=\"Xt SM ICE Xext X11\"\n X11DEVS='$(DD)x11.dev $(DD)x11alpha.dev $(DD)x11mono.dev $(DD)x11cmyk.dev'\nfi\n\nif test \"x$ac_cv_header_sys_time_h\" = xyes; then\n HAVE_SYS_TIME_H=\"-DHAVE_SYS_TIME_H=1\"\nfi\n\nAC_SUBST(HAVE_SYS_TIME_H)\n\nAC_SUBST(XINCLUDE)\nAC_SUBST(XLIBDIRS)\nAC_SUBST(XLIBDIR)\nAC_SUBST(XLIBS)\nAC_SUBST(X11DEVS)\nAC_SUBST(GCFLAGS)\nAC_OUTPUT(config.mak)\n\n```\n\n#### region() [lines 465-487]\n```c\n fi\n if test ! -z \"$x_libraries\"; then\n XLIBDIRS=-L$x_libraries\n XLIBDIR=-L$x_libraries\n fi\n XLIBS=\"Xt SM ICE Xext X11\"\n X11DEVS='$(DD)x11.dev $(DD)x11alpha.dev $(DD)x11mono.dev $(DD)x11cmyk.dev'\nfi\n\nif test \"x$ac_cv_header_sys_time_h\" = xyes; then\n HAVE_SYS_TIME_H=\"-DHAVE_SYS_TIME_H=1\"\nfi\n\nAC_SUBST(HAVE_SYS_TIME_H)\n\nAC_SUBST(XINCLUDE)\nAC_SUBST(XLIBDIRS)\nAC_SUBST(XLIBDIR)\nAC_SUBST(XLIBS)\nAC_SUBST(X11DEVS)\nAC_SUBST(GCFLAGS)\nAC_OUTPUT(config.mak)\n\n```\n\n### Makefile.in\n\n#### region() [lines 103-190]\n```c\n\n# Define the name of the interpreter initialization file.\n# (There is no reason to change this.)\n\nGS_INIT=gs_init.ps\n\n# Choose generic configuration options.\n\nTARGET_ARCH_FILE=@ARCH_CONF_HEADER@\n\n# -DDEBUG\n#\tincludes debugging features (-Z switch) in the code.\n#\t Code runs substantially slower even if no debugging switches\n#\t are set.\n\nGENOPT=\n\n# Choose capability options.\n\n# -DHAVE_BSWAP32\n# use bswap32 intrinsic\n# -DHAVE_BYTESWAP_H\n# use byteswap.h functions\n#\n# -DHAVE_MKSTEMP\n#\tuses mkstemp instead of mktemp\n#\t\tThis uses the more secure temporary file creation call\n#\t\tEnable this if it is available on your platform.\n# -DHAVE_FILE64\n#\tuse marked versions of the stdio FILE calls, fopen64() et al.\n#\n# -DHAVE_MKSTEMP64\n#\tuse non-standard function mkstemp64()\n#\n# -DHAVE_LIBIDN\n#\tuse libidn to canonicalize Unicode passwords\n#\n# -DHAVE_SETLOCALE\n#\tcall setlocale(LC_CTYPE) when running as a standalone app\n# -DHAVE_SSE2\n# use sse2 intrinsics\n\nCAPOPT= @HAVE_MKSTEMP@ @HAVE_FILE64@ @HAVE_FSEEKO@ @HAVE_MKSTEMP64@ @HAVE_FONTCONFIG@ @HAVE_LIBIDN@ @HAVE_SETLOCALE@ @HAVE_SSE2@ @HAVE_DBUS@ @HAVE_BSWAP32@ @HAVE_BYTESWAP_H@ @HAVE_STRERROR@\n\n# Define the name of the executable file.\n\nGS=@GS@@EXEEXT@\nGS_SO_BASE=@GS@\nXE=@EXEEXT@\nXEAUX=@EXEEXT@\n\n# Define the directories for debugging and profiling binaries, relative to\n# the standard binaries.\n\nDEBUGDIRPREFIX=debug\nMEMENTODIRPREFIX=mem\nPGDIRPREFIX=pg\n\n# Define whether to compile in the FreeType library, and if so, where\n# the source tree is location. Otherwise, what library name to use\n# in linking to a shared implementation.\n\nFT_BRIDGE=@FT_BRIDGE@\nSHARE_FT=@SHARE_FT@\nFTSRCDIR=@FTSRCDIR@\nFT_CFLAGS=@FT_CFLAGS@\nFT_LIBS=@FT_LIBS@\nFT_CONFIG_SYSTEM_ZLIB=@FT_SYS_ZLIB@\n\n# Define whether to compile in UFST. Note that freetype will/must be disabled.\n# FAPI/UFST depends on UFST_BRIDGE being undefined - hence the construct below.\n# (i.e. use \"UFST_BRIDGE=1\" or *not to define UFST_BRIDGE to anything*)\n@INSERT_UFST_BRIDGE_EQUAL_ONE@\nUFST_ROOT=@UFST_ROOT@\nUFST_LIB_EXT=@UFST_LIB_EXT@\n\nUFST_ROMFS_ARGS?=-b \\\n -P $(UFST_ROOT)/fontdata/mtfonts/pcl45/mt3/ -d fontdata/mtfonts/pcl45/mt3/ pcl___xj.fco plug__xi.fco wd____xh.fco \\\n -P $(UFST_ROOT)/fontdata/mtfonts/pclps2/mt3/ -d fontdata/mtfonts/pclps2/mt3/ pclp2_xj.fco \\\n -c -P $(PSSRCDIR)/../lib/ -d Resource/Init/ FAPIconfig-FCO\n\nUFSTROMFONTDIR=\\\"%rom%fontdata/\\\"\nUFSTDISCFONTDIR?=\\\"$(UFST_ROOT)/fontdata/\\\"\n\n\nUFST_CFLAGS=@UFST_CFLAGS@\n\n# Define the directory where the IJG JPEG library sources are stored,\n```\n\n### base/gp_psync.c\n\n#### gp_semaphore_signal() [lines 109-128]\n```c\n}\n\nint\ngp_semaphore_signal(gp_semaphore * sema)\n{\n pt_semaphore_t * const sem = (pt_semaphore_t *)sema;\n int scode, scode2;\n\n scode = pthread_mutex_lock(&sem->mutex);\n if (scode != 0)\n return SEM_ERROR_CODE(scode);\n if (sem->count++ == 0)\n scode = pthread_cond_signal(&sem->cond);\n scode2 = pthread_mutex_unlock(&sem->mutex);\n if (scode == 0)\n scode = scode2;\n return SEM_ERROR_CODE(scode);\n}\n\n/* Monitor supports enter/leave semantics */\n```\n\n#### gp_monitor_open() [lines 144-160]\n```c\n}\n\nint\ngp_monitor_open(gp_monitor * mona)\n{\n pthread_mutex_t *mon;\n int scode;\n\n if (!mona)\n return -1;\t\t/* monitors are not movable */\n mon = &((gp_pthread_recursive_t *)mona)->mutex;\n ((gp_pthread_recursive_t *)mona)->self_id = 0;\t/* Not valid unless mutex is locked */\n scode = pthread_mutex_init(mon, NULL);\n return SEM_ERROR_CODE(scode);\n}\n\nint\n```\n\n#### gp_monitor_enter() [lines 168-191]\n```c\n}\n\nint\ngp_monitor_enter(gp_monitor * mona)\n{\n pthread_mutex_t * const mon = (pthread_mutex_t *)mona;\n int scode;\n\n if ((scode = pthread_mutex_trylock(mon)) == 0) {\n ((gp_pthread_recursive_t *)mona)->self_id = pthread_self();\n return SEM_ERROR_CODE(scode);\n } else {\n if (pthread_equal(pthread_self(),((gp_pthread_recursive_t *)mona)->self_id))\n return 0;\n else {\n /* we were not the owner, wait */\n scode = pthread_mutex_lock(mon);\n ((gp_pthread_recursive_t *)mona)->self_id = pthread_self();\n return SEM_ERROR_CODE(scode);\n }\n }\n}\n\nint\n```\n\n\n## Upstream Fix\n```diff\nFrom 444e0bf9c43bae0261660e6318ba0e514c18d41e Mon Sep 17 00:00:00 2001\nFrom: Chris Liddell <chris.liddell@artifex.com>\nDate: Mon, 16 Mar 2015 12:52:49 +0000\nSubject: [PATCH] Bug 695862: use PTHREAD_MUTEX_RECURSIVE(_NP) if available\n\nor properly emulate recursive mutexes ourselves.\n\nNo cluster differences\n---\n config.mak.in | 2 +-\n configure.ac | 37 +++++++++++++++---------\n gs/Makefile.in | 2 +-\n gs/base/gp_psync.c | 70 ++++++++++++++++++++++++++++++++++++++--------\n gs/configure.ac | 37 +++++++++++++++---------\n 5 files changed, 108 insertions(+), 40 deletions(-)\n\ndiff --git a/config.mak.in b/config.mak.in\nindex ccb84aee8e..d962dda20f 100644\n--- a/config.mak.in\n+++ b/config.mak.in\n@@ -17,7 +17,7 @@ CC=@CC@\n CCAUX=@CC@\n \n CONFDEFS?=@HAVE_MKSTEMP@ @HAVE_SSE2@ @HAVE_BSWAP32@ @HAVE_BYTESWAP_H@ @HAVE_SYS_TIME_H@ @HAVE_FSEEKO@ @HAVE_INTTYPES@ @HAVE_MKSTEMP64@ \\\n-@HAVE_FILE64@ @HAVE_PREAD_PWRITE@\n+@HAVE_FILE64@ @HAVE_PREAD_PWRITE@ @RECURSIVE_MUTEXATTR@\n \n ACCFLAGS?=@GCFLAGS@\n \ndiff --git a/configure.ac b/configure.ac\nindex 44b725256e..5da03cab1e 100644\n--- a/configure.ac\n+++ b/configure.ac\n@@ -460,25 +460,36 @@ AC_SUBST(HAVE_PREAD_PWRITE)\n SYNC=\"nosync\"\n PTHREAD_LIBS=\"\"\n \n-# if you haven't got pread/pwrite, we can't use multithreading\n-if test \"x$HAVE_PREAD_PWRITE\" != \"x\"; then\n+AC_ARG_ENABLE([threading], AC_HELP_STRING([--disable-threading],\n+ [disable support for multithreaded rendering]))\n \n- case `uname` in\n- MINGW*)\n- AC_MSG_WARN([disabling support for pthreads......])\n- ;;\n- *)\n- AC_CHECK_LIB(pthread, pthread_create, [\n- SYNC=posync;\n- PTHREAD_LIBS=\"-lpthread\"\n- ])\n- ;;\n- esac\n \n+# if you haven't got pread/pwrite, we can't use multithreading\n+if test \"x$HAVE_PREAD_PWRITE\" != \"x\"; then\n+ if test \"$enable_fontconfig\" != \"no\"; then\n+ case `uname` in\n+ MINGW*)\n+ AC_MSG_WARN([disabling support for pthreads......])\n+ ;;\n+ *)\n+ AC_CHECK_LIB(pthread, pthread_create, [\n+ SYNC=posync;\n+ PTHREAD_LIBS=\"-lpthread\"\n+ ])\n+ AC_TRY_COMPILE([#include <pthread.h>],\n+ [static int k = PTHREAD_MUTEX_RECURSIVE;],\n+ [RECURSIVE_MUTEXATTR=\"-DGS_RECURSIVE_MUTEXATTR=PTHREAD_MUTEX_RECURSIVE\"],\n+ [AC_TRY_COMPILE([#include <pthread.h>],\n+ [static int k = PTHREAD_MUTEX_RECURSIVE_NP;],\n+ [RECURSIVE_MUTEXATTR=\"-DGS_RECURSIVE_MUTEXATTR=PTHREAD_MUTEX_RECURSIVE_NP\"])])\n+ ;;\n+ esac\n+ fi\n fi\n \n AC_SUBST(SYNC)\n AC_SUBST(PTHREAD_LIBS)\n+AC_SUBST(RECURSIVE_MUTEXATTR)\n \n AC_PATH_X\n \ndiff --git a/gs/Makefile.in b/gs/Makefile.in\nindex c134622662..68f3dc598d 100644\n--- a/gs/Makefile.in\n+++ b/gs/Makefile.in\n@@ -142,7 +142,7 @@ GENOPT=\n # -DHAVE_SSE2\n # use sse2 intrinsics\n \n-CAPOPT= @HAVE_MKSTEMP@ @HAVE_FILE64@ @HAVE_FSEEKO@ @HAVE_MKSTEMP64@ @HAVE_FONTCONFIG@ @HAVE_LIBIDN@ @HAVE_SETLOCALE@ @HAVE_SSE2@ @HAVE_DBUS@ @HAVE_BSWAP32@ @HAVE_BYTESWAP_H@ @HAVE_STRERROR@ @HAVE_PREAD_PWRITE@\n+CAPOPT= @HAVE_MKSTEMP@ @HAVE_FILE64@ @HAVE_FSEEKO@ @HAVE_MKSTEMP64@ @HAVE_FONTCONFIG@ @HAVE_LIBIDN@ @HAVE_SETLOCALE@ @HAVE_SSE2@ @HAVE_DBUS@ @HAVE_BSWAP32@ @HAVE_BYTESWAP_H@ @HAVE_STRERROR@ @HAVE_PREAD_PWRITE@ @RECURSIVE_MUTEXATTR@\n \n # Define the name of the executable file.\n \ndiff --git a/gs/base/gp_psync.c b/gs/base/gp_psync.c\nindex 60f697763d..6ddf26653a 100644\n--- a/gs/base/gp_psync.c\n+++ b/gs/base/gp_psync.c\n@@ -128,13 +128,20 @@ gp_semaphore_signal(gp_semaphore * sema)\n /* Monitor supports enter/leave semantics */\n \n /*\n- * We need PTHREAD_MUTEX_RECURSIVE behavior, but this isn't totally portable\n- * so we implement it in a more portable fashion, keeping track of the\n- * owner thread using 'pthread_self()'\n+ * We need PTHREAD_MUTEX_RECURSIVE behavior, but this isn't\n+ * supported on all pthread platforms, so if it's available\n+ * we'll use it, otherwise we'll emulate it.\n+ * GS_RECURSIVE_MUTEXATTR is set by the configure script\n+ * on Unix-like machines to the attribute setting for\n+ * PTHREAD_MUTEX_RECURSIVE - on linux this is usually\n+ * PTHREAD_MUTEX_RECURSIVE_NP\n */\n typedef struct gp_pthread_recursive_s {\n pthread_mutex_t mutex;\t/* actual mutex */\n+#ifndef GS_RECURSIVE_MUTEXATTR\n pthread_t\tself_id;\t/* owner */\n+ int lcount;\n+#endif\n } gp_pthread_recursive_t;\n \n uint\n@@ -148,12 +155,32 @@ gp_monitor_open(gp_monitor * mona)\n {\n pthread_mutex_t *mon;\n int scode;\n+ pthread_mutexattr_t attr;\n+ pthread_mutexattr_t *attrp = NULL;\n \n if (!mona)\n return -1;\t\t/* monitors are not movable */\n- mon = &((gp_pthread_recursive_t *)mona)->mutex;\n+\n+\n+#ifdef GS_RECURSIVE_MUTEXATTR\n+ attrp = &attr;\n+ scode = pthread_mutexattr_init(attrp);\n+ if (scode < 0) goto done;\n+\n+ scode = pthread_mutexattr_settype(attrp, GS_RECURSIVE_MUTEXATTR);\n+ if (scode < 0) {\n+ goto done;\n+ }\n+#else \n ((gp_pthread_recursive_t *)mona)->self_id = 0;\t/* Not valid unless mutex is locked */\n- scode = pthread_mutex_init(mon, NULL);\n+ ((gp_pthread_recursive_t *)mona)->lcount = 0;\n+#endif\n+\n+ mon = &((gp_pthread_recursive_t *)mona)->mutex;\n+ scode = pthread_mutex_init(mon, attrp);\n+ if (attrp)\n+ (void)pthread_mutexattr_destroy(attrp);\n+done:\n return SEM_ERROR_CODE(scode);\n }\n \n@@ -173,29 +200,48 @@ gp_monitor_enter(gp_monitor * mona)\n pthread_mutex_t * const mon = (pthread_mutex_t *)mona;\n int scode;\n \n+#ifdef GS_RECURSIVE_MUTEXATTR\n+ scode = pthread_mutex_lock(mon);\n+#else\n if ((scode = pthread_mutex_trylock(mon)) == 0) {\n ((gp_pthread_recursive_t *)mona)->self_id = pthread_self();\n- return SEM_ERROR_CODE(scode);\n+ ((gp_pthread_recursive_t *)mona)->lcount++;\n } else {\n- if (pthread_equal(pthread_self(),((gp_pthread_recursive_t *)mona)->self_id))\n- return 0;\n+ if (pthread_equal(pthread_self(),((gp_pthread_recursive_t *)mona)->self_id)) {\n+ ((gp_pthread_recursive_t *)mona)->lcount++;\n+ scode = 0;\n+ }\n else {\n /* we were not the owner, wait */\n scode = pthread_mutex_lock(mon);\n ((gp_pthread_recursive_t *)mona)->self_id = pthread_self();\n- return SEM_ERROR_CODE(scode);\n+ ((gp_pthread_recursive_t *)mona)->lcount++;\n }\n }\n+#endif\n+ return SEM_ERROR_CODE(scode);\n }\n \n int\n gp_monitor_leave(gp_monitor * mona)\n {\n pthread_mutex_t * const mon = (pthread_mutex_t *)mona;\n- int scode;\n+ int scode = 0;\n \n- scode = pthread_mutex_unlock(mon);\n- ((gp_pthread_recursive_t *)mona)->self_id = 0;\t/* Not valid unless mutex is locked */\n+#ifdef GS_RECURSIVE_MUTEXATTR\n+ scode = pthread_mutex_lock(mon);\n+#else\n+ if (pthread_equal(pthread_self(),((gp_pthread_recursive_t *)mona)->self_id)) {\n+ if ((--((gp_pthread_recursive_t *)mona)->lcount) == 0) {\n+ scode = pthread_mutex_unlock(mon);\n+ ((gp_pthread_recursive_t *)mona)->self_id = 0;\t/* Not valid unless mutex is locked */\n+\n+ }\n+ }\n+ else {\n+ scode = -1 /* should be EPERM */;\n+ }\n+#endif\n return SEM_ERROR_CODE(scode);\n }\n \ndiff --git a/gs/configure.ac b/gs/configure.ac\nindex 5f64dd2213..233129a904 100644\n--- a/gs/configure.ac\n+++ b/gs/configure.ac\n@@ -498,26 +498,37 @@ AC_SUBST(HAVE_PREAD_PWRITE)\n \n SYNC=\"nosync\"\n PTHREAD_LIBS=\"\"\n+RECURSIVE_MUTEXATTR=\"\"\n+\n+AC_ARG_ENABLE([threading], AC_HELP_STRING([--disable-threading],\n+ [disable support for multithreaded rendering]))\n \n # if you haven't got pread/pwrite, we can't use multithreading\n if test \"x$HAVE_PREAD_PWRITE\" != \"x\"; then\n-\n- case `uname` in\n- MINGW*)\n- AC_MSG_WARN([disabling support for pthreads......])\n- ;;\n- *)\n- AC_CHECK_LIB(pthread, pthread_create, [\n- SYNC=posync;\n- PTHREAD_LIBS=\"-lpthread\"\n- ])\n- ;;\n- esac\n-\n+ if test \"$enable_fontconfig\" != \"no\"; then\n+ case `uname` in\n+ MINGW*)\n+ AC_MSG_WARN([disabling support for pthreads......])\n+ ;;\n+ *)\n+ AC_CHECK_LIB(pthread, pthread_create, [\n+ SYNC=posync;\n+ PTHREAD_LIBS=\"-lpthread\"\n+ ])\n+ AC_TRY_COMPILE([#include <pthread.h>],\n+ [static int k = PTHREAD_MUTEX_RECURSIVE;],\n+ [RECURSIVE_MUTEXATTR=\"-DGS_RECURSIVE_MUTEXATTR=PTHREAD_MUTEX_RECURSIVE\"],\n+ [AC_TRY_COMPILE([#include <pthread.h>],\n+ [static int k = PTHREAD_MUTEX_RECURSIVE_NP;],\n+ [RECURSIVE_MUTEXATTR=\"-DGS_RECURSIVE_MUTEXATTR=PTHREAD_MUTEX_RECURSIVE_NP\"])])\n+ ;;\n+ esac\n+ fi\n fi\n \n AC_SUBST(SYNC)\n AC_SUBST(PTHREAD_LIBS)\n+AC_SUBST(RECURSIVE_MUTEXATTR)\n \n AC_MSG_CHECKING([for local trio library source])\n if test -f $srcdir/trio/trio.h; then\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 444e0bf9c43bae0261660e6318ba0e514c18d41e Mon Sep 17 00:00:00 2001\nFrom: Chris Liddell <chris.liddell@artifex.com>\nDate: Mon, 16 Mar 2015 12:52:49 +0000\nSubject: [PATCH] Bug 695862: use PTHREAD_MUTEX_RECURSIVE(_NP) if available\n\nor properly emulate recursive mutexes ourselves.\n\nNo cluster differences\n---\n config.mak.in | 2 +-\n configure.ac | 37 +++++++++++++++++++----------\n gs/Makefile.in | 2 +-\n gs/base/gp_psync.c | 70 ++++++++++++++++++++++++++++++++++++++++++++----------\n gs/configure.ac | 37 +++++++++++++++++++----------\n 5 files changed, 108 insertions(+), 40 deletions(-)\n\nIndex: ghostscript-9.15/configure.ac\n===================================================================\n--- ghostscript-9.15.orig/configure.ac\n+++ ghostscript-9.15/configure.ac\n@@ -494,8 +494,13 @@ AC_CHECK_LIB(m, cos)\n \n SYNC=\"nosync\"\n PTHREAD_LIBS=\"\"\n+RECURSIVE_MUTEXATTR=\"\"\n \n-case `uname` in\n+AC_ARG_ENABLE([threading], AC_HELP_STRING([--disable-threading],\n+ [disable support for multithreaded rendering]))\n+\n+if test \"$enable_threading\" != \"no\"; then\n+ case `uname` in\n MINGW*)\n AC_MSG_WARN([disabling support for pthreads......])\n ;;\n@@ -504,11 +509,19 @@ case `uname` in\n SYNC=posync;\n PTHREAD_LIBS=\"-lpthread\"\n ])\n+ AC_TRY_COMPILE([#include <pthread.h>],\n+ [static int k = PTHREAD_MUTEX_RECURSIVE;],\n+ [RECURSIVE_MUTEXATTR=\"-DGS_RECURSIVE_MUTEXATTR=PTHREAD_MUTEX_RECURSIVE\"],\n+ [AC_TRY_COMPILE([#include <pthread.h>],\n+ [static int k = PTHREAD_MUTEX_RECURSIVE_NP;],\n+ [RECURSIVE_MUTEXATTR=\"-DGS_RECURSIVE_MUTEXATTR=PTHREAD_MUTEX_RECURSIVE_NP\"])])\n ;;\n-esac\n+ esac\n+fi\n \n AC_SUBST(SYNC)\n AC_SUBST(PTHREAD_LIBS)\n+AC_SUBST(RECURSIVE_MUTEXATTR)\n \n AC_MSG_CHECKING([for local trio library source])\n if test -f $srcdir/trio/trio.h; then\nIndex: ghostscript-9.15/Makefile.in\n===================================================================\n--- ghostscript-9.15.orig/Makefile.in\n+++ ghostscript-9.15/Makefile.in\n@@ -142,7 +142,7 @@ GENOPT=\n # -DHAVE_SSE2\n # use sse2 intrinsics\n \n-CAPOPT= @HAVE_MKSTEMP@ @HAVE_FILE64@ @HAVE_FSEEKO@ @HAVE_MKSTEMP64@ @HAVE_FONTCONFIG@ @HAVE_LIBIDN@ @HAVE_SETLOCALE@ @HAVE_SSE2@ @HAVE_DBUS@ @HAVE_BSWAP32@ @HAVE_BYTESWAP_H@ @HAVE_STRERROR@\n+CAPOPT= @HAVE_MKSTEMP@ @HAVE_FILE64@ @HAVE_FSEEKO@ @HAVE_MKSTEMP64@ @HAVE_FONTCONFIG@ @HAVE_LIBIDN@ @HAVE_SETLOCALE@ @HAVE_SSE2@ @HAVE_DBUS@ @HAVE_BSWAP32@ @HAVE_BYTESWAP_H@ @HAVE_STRERROR@ @RECURSIVE_MUTEXATTR@\n \n # Define the name of the executable file.\n \nIndex: ghostscript-9.15/base/gp_psync.c\n===================================================================\n--- ghostscript-9.15.orig/base/gp_psync.c\n+++ ghostscript-9.15/base/gp_psync.c\n@@ -128,13 +128,20 @@ gp_semaphore_signal(gp_semaphore * sema)\n /* Monitor supports enter/leave semantics */\n \n /*\n- * We need PTHREAD_MUTEX_RECURSIVE behavior, but this isn't totally portable\n- * so we implement it in a more portable fashion, keeping track of the\n- * owner thread using 'pthread_self()'\n+ * We need PTHREAD_MUTEX_RECURSIVE behavior, but this isn't\n+ * supported on all pthread platforms, so if it's available\n+ * we'll use it, otherwise we'll emulate it.\n+ * GS_RECURSIVE_MUTEXATTR is set by the configure script\n+ * on Unix-like machines to the attribute setting for\n+ * PTHREAD_MUTEX_RECURSIVE - on linux this is usually\n+ * PTHREAD_MUTEX_RECURSIVE_NP\n */\n typedef struct gp_pthread_recursive_s {\n pthread_mutex_t mutex;\t/* actual mutex */\n+#ifndef GS_RECURSIVE_MUTEXATTR\n pthread_t\tself_id;\t/* owner */\n+ int lcount;\n+#endif\n } gp_pthread_recursive_t;\n \n uint\n@@ -148,12 +155,32 @@ gp_monitor_open(gp_monitor * mona)\n {\n pthread_mutex_t *mon;\n int scode;\n+ pthread_mutexattr_t attr;\n+ pthread_mutexattr_t *attrp = NULL;\n \n if (!mona)\n return -1;\t\t/* monitors are not movable */\n- mon = &((gp_pthread_recursive_t *)mona)->mutex;\n+\n+\n+#ifdef GS_RECURSIVE_MUTEXATTR\n+ attrp = &attr;\n+ scode = pthread_mutexattr_init(attrp);\n+ if (scode < 0) goto done;\n+\n+ scode = pthread_mutexattr_settype(attrp, GS_RECURSIVE_MUTEXATTR);\n+ if (scode < 0) {\n+ goto done;\n+ }\n+#else \n ((gp_pthread_recursive_t *)mona)->self_id = 0;\t/* Not valid unless mutex is locked */\n- scode = pthread_mutex_init(mon, NULL);\n+ ((gp_pthread_recursive_t *)mona)->lcount = 0;\n+#endif\n+\n+ mon = &((gp_pthread_recursive_t *)mona)->mutex;\n+ scode = pthread_mutex_init(mon, attrp);\n+ if (attrp)\n+ (void)pthread_mutexattr_destroy(attrp);\n+done:\n return SEM_ERROR_CODE(scode);\n }\n \n@@ -173,29 +200,48 @@ gp_monitor_enter(gp_monitor * mona)\n pthread_mutex_t * const mon = (pthread_mutex_t *)mona;\n int scode;\n \n+#ifdef GS_RECURSIVE_MUTEXATTR\n+ scode = pthread_mutex_lock(mon);\n+#else\n if ((scode = pthread_mutex_trylock(mon)) == 0) {\n ((gp_pthread_recursive_t *)mona)->self_id = pthread_self();\n- return SEM_ERROR_CODE(scode);\n+ ((gp_pthread_recursive_t *)mona)->lcount++;\n } else {\n- if (pthread_equal(pthread_self(),((gp_pthread_recursive_t *)mona)->self_id))\n- return 0;\n+ if (pthread_equal(pthread_self(),((gp_pthread_recursive_t *)mona)->self_id)) {\n+ ((gp_pthread_recursive_t *)mona)->lcount++;\n+ scode = 0;\n+ }\n else {\n /* we were not the owner, wait */\n scode = pthread_mutex_lock(mon);\n ((gp_pthread_recursive_t *)mona)->self_id = pthread_self();\n- return SEM_ERROR_CODE(scode);\n+ ((gp_pthread_recursive_t *)mona)->lcount++;\n }\n }\n+#endif\n+ return SEM_ERROR_CODE(scode);\n }\n \n int\n gp_monitor_leave(gp_monitor * mona)\n {\n pthread_mutex_t * const mon = (pthread_mutex_t *)mona;\n- int scode;\n+ int scode = 0;\n \n+#ifdef GS_RECURSIVE_MUTEXATTR\n scode = pthread_mutex_unlock(mon);\n- ((gp_pthread_recursive_t *)mona)->self_id = 0;\t/* Not valid unless mutex is locked */\n+#else\n+ if (pthread_equal(pthread_self(),((gp_pthread_recursive_t *)mona)->self_id)) {\n+ if ((--((gp_pthread_recursive_t *)mona)->lcount) == 0) {\n+ scode = pthread_mutex_unlock(mon);\n+ ((gp_pthread_recursive_t *)mona)->self_id = 0;\t/* Not valid unless mutex is locked */\n+\n+ }\n+ }\n+ else {\n+ scode = -1 /* should be EPERM */;\n+ }\n+#endif\n return SEM_ERROR_CODE(scode);\n }" } ]
{ "id": "ghostscript-mini-5706-fix-mutex-crash.patch", "cve_id": "CVE-2016-7978", "package": "ghostscript-mini", "upstream_enriched": true, "upstream_commit": "444e0bf9c43bae0261660e6318ba0e514c18d41e", "upstream_repo": "ArtifexSoftware/ghostpdl", "tier": "adapted", "has_source_context": true, "license": "AGPL-3.0-only", "context_tokens_est": 1423, "context_files": 3 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-5276\n\nThe std::random_device class in libstdc++ in the GNU Compiler Collection (aka GCC) before 4.9.4 does not properly handle short reads from blocking sources, which makes it easier for context-dependent attackers to predict the random values via unspecified vectors.\n\n## Package\ngcc5-testresults\n\n## Files to modify\n- gcc/config/i386/linux.h\n\n## Upstream Fix\n```diff\nFor i?86 negative offsets to %fs segment accesses cause a hypervisor\ntrap for Xen. Avoid this by making accesses indirect.\n\n??? Note that similar to the behavior on SLE11 this only affects\nthe compiler built on %ix86, not that on x86_64, even with -m32.\n\nIndex: gcc/config/i386/linux.h\n===================================================================\n--- gcc/config/i386/linux.h\t(revision 209175)\n+++ gcc/config/i386/linux.h\t(working copy)\n@@ -21,3 +21,9 @@ along with GCC; see the file COPYING3.\n \n #define GNU_USER_LINK_EMULATION \"elf_i386\"\n #define GLIBC_DYNAMIC_LINKER \"/lib/ld-linux.so.2\"\n+\n+/* This slows down Xen, so take a very small general performance hit\n+ for not accessing the %fs segment with negative offsets by making\n+ GCC not emit direct accesses to %fs at all. */\n+#undef TARGET_TLS_DIRECT_SEG_REFS_DEFAULT\n+#define TARGET_TLS_DIRECT_SEG_REFS_DEFAULT 0\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "For i?86 negative offsets to %fs segment accesses cause a hypervisor\ntrap for Xen. Avoid this by making accesses indirect.\n\n??? Note that similar to the behavior on SLE11 this only affects\nthe compiler built on %ix86, not that on x86_64, even with -m32.\n\nIndex: gcc/config/i386/linux.h\n===================================================================\n--- gcc/config/i386/linux.h\t(revision 209175)\n+++ gcc/config/i386/linux.h\t(working copy)\n@@ -21,3 +21,9 @@ along with GCC; see the file COPYING3.\n \n #define GNU_USER_LINK_EMULATION \"elf_i386\"\n #define GLIBC_DYNAMIC_LINKER \"/lib/ld-linux.so.2\"\n+\n+/* This slows down Xen, so take a very small general performance hit\n+ for not accessing the %fs segment with negative offsets by making\n+ GCC not emit direct accesses to %fs at all. */\n+#undef TARGET_TLS_DIRECT_SEG_REFS_DEFAULT\n+#define TARGET_TLS_DIRECT_SEG_REFS_DEFAULT 0" } ]
{ "id": "gcc5-testresults-4931-tls-no-direct.diff", "cve_id": "CVE-2015-5276", "package": "gcc5-testresults", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": false, "license": "GPL-3.0-or-later", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2014-9512\n\nrsync 3.1.1 allows remote attackers to write to arbitrary files via a symlink attack on a file in the synchronization path.\n\n## Package\nrsync\n\n## Files to modify\n- options.c\n- rsync-3.1.0.orig/checksum.c\n- compat.c\n- checksum.c\n- rsync-3.1.0.orig/options.c\n\n## Upstream Fix\n```diff\nFrom eac858085e3ac94ec0ab5061d11f52652c90a869 Mon Sep 17 00:00:00 2001\nFrom: Wayne Davison <wayned@samba.org>\nDate: Mon, 11 May 2015 12:36:20 -0700\nSubject: [PATCH] Add compat flag to allow proper seed checksum order. Fixes\n the equivalent of librsync's CVE-2014-8242 issue.\n\n---\n checksum.c | 17 +++++++++++++----\n compat.c | 5 +++++\n options.c | 1 +\n 3 files changed, 19 insertions(+), 4 deletions(-)\n\ndiff --git a/checksum.c b/checksum.c\nindex a1c2aa244..933b514b3 100644\n--- a/checksum.c\n+++ b/checksum.c\n@@ -23,6 +23,7 @@\n \n extern int checksum_seed;\n extern int protocol_version;\n+extern int proper_seed_order;\n \n /*\n a simple 32 bit checksum that can be upadted from either end\n@@ -54,10 +55,18 @@ void get_checksum2(char *buf, int32 len, char *sum)\n \tif (protocol_version >= 30) {\n \t\tuchar seedbuf[4];\n \t\tmd5_begin(&m);\n-\t\tmd5_update(&m, (uchar *)buf, len);\n-\t\tif (checksum_seed) {\n-\t\t\tSIVALu(seedbuf, 0, checksum_seed);\n-\t\t\tmd5_update(&m, seedbuf, 4);\n+\t\tif (proper_seed_order) {\n+\t\t\tif (checksum_seed) {\n+\t\t\t\tSIVALu(seedbuf, 0, checksum_seed);\n+\t\t\t\tmd5_update(&m, seedbuf, 4);\n+\t\t\t}\n+\t\t\tmd5_update(&m, (uchar *)buf, len);\n+\t\t} else {\n+\t\t\tmd5_update(&m, (uchar *)buf, len);\n+\t\t\tif (checksum_seed) {\n+\t\t\t\tSIVALu(seedbuf, 0, checksum_seed);\n+\t\t\t\tmd5_update(&m, seedbuf, 4);\n+\t\t\t}\n \t\t}\n \t\tmd5_result(&m, (uchar *)sum);\n \t} else {\ndiff --git a/compat.c b/compat.c\nindex 2454937f8..f89d466b9 100644\n--- a/compat.c\n+++ b/compat.c\n@@ -27,6 +27,7 @@ int inc_recurse = 0;\n int compat_flags = 0;\n int use_safe_inc_flist = 0;\n int want_xattr_optim = 0;\n+int proper_seed_order = 0;\n \n extern int am_server;\n extern int am_sender;\n@@ -78,6 +79,7 @@ int filesfrom_convert = 0;\n #define CF_SYMLINK_ICONV (1<<2)\n #define CF_SAFE_FLIST\t (1<<3)\n #define CF_AVOID_XATTR_OPTIM (1<<4)\n+#define CF_CHKSUM_SEED_FIX (1<<5)\n \n static const char *client_info;\n \n@@ -271,12 +273,15 @@ void setup_protocol(int f_out,int f_in)\n \t\t\t\tcompat_flags |= CF_SAFE_FLIST;\n \t\t\tif (local_server || strchr(client_info, 'x') != NULL)\n \t\t\t\tcompat_flags |= CF_AVOID_XATTR_OPTIM;\n+\t\t\tif (local_server || strchr(client_info, 'C') != NULL)\n+\t\t\t\tcompat_flags |= CF_CHKSUM_SEED_FIX;\n \t\t\twrite_byte(f_out, compat_flags);\n \t\t} else\n \t\t\tcompat_flags = read_byte(f_in);\n \t\t/* The inc_recurse var MUST be set to 0 or 1. */\n \t\tinc_recurse = compat_flags & CF_INC_RECURSE ? 1 : 0;\n \t\twant_xattr_optim = protocol_version >= 31 && !(compat_flags & CF_AVOID_XATTR_OPTIM);\n+\t\tproper_seed_order = compat_flags & CF_CHKSUM_SEED_FIX ? 1 : 0;\n \t\tif (am_sender) {\n \t\t\treceiver_symlink_times = am_server\n \t\t\t ? strchr(client_info, 'L') != NULL\ndiff --git a/options.c b/options.c\nindex 19c2b7db1..4128b598d 100644\n--- a/options.c\n+++ b/options.c\n@@ -2503,6 +2503,7 @@ void server_options(char **args, int *argc_p)\n #endif\n \t\teFlags[x++] = 'f'; /* flist I/O-error safety support */\n \t\teFlags[x++] = 'x'; /* xattr hardlink optimization not desired */\n+\t\teFlags[x++] = 'C'; /* support checksum seed order fix */\n #undef eFlags\n \t}\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From eac858085e3ac94ec0ab5061d11f52652c90a869 Mon Sep 17 00:00:00 2001\nFrom: Wayne Davison <wayned@samba.org>\nDate: Mon, 11 May 2015 12:36:20 -0700\nSubject: [PATCH] Add compat flag to allow proper seed checksum order. Fixes\n the equivalent of librsync's CVE-2014-8242 issue.\n\n---\n checksum.c | 17 +++++++++++++----\n compat.c | 5 +++++\n options.c | 1 +\n 3 files changed, 19 insertions(+), 4 deletions(-)\n\nIndex: rsync-3.1.0/checksum.c\n===================================================================\n--- rsync-3.1.0.orig/checksum.c\t2015-10-07 15:26:37.725611538 +0200\n+++ rsync-3.1.0/checksum.c\t2015-10-07 15:26:38.822626286 +0200\n@@ -23,6 +23,7 @@\n \n extern int checksum_seed;\n extern int protocol_version;\n+extern int proper_seed_order;\n \n /*\n a simple 32 bit checksum that can be upadted from either end\n@@ -54,10 +55,18 @@ void get_checksum2(char *buf, int32 len,\n \tif (protocol_version >= 30) {\n \t\tuchar seedbuf[4];\n \t\tmd5_begin(&m);\n-\t\tmd5_update(&m, (uchar *)buf, len);\n-\t\tif (checksum_seed) {\n-\t\t\tSIVALu(seedbuf, 0, checksum_seed);\n-\t\t\tmd5_update(&m, seedbuf, 4);\n+\t\tif (proper_seed_order) {\n+\t\t\tif (checksum_seed) {\n+\t\t\t\tSIVALu(seedbuf, 0, checksum_seed);\n+\t\t\t\tmd5_update(&m, seedbuf, 4);\n+\t\t\t}\n+\t\t\tmd5_update(&m, (uchar *)buf, len);\n+\t\t} else {\n+\t\t\tmd5_update(&m, (uchar *)buf, len);\n+\t\t\tif (checksum_seed) {\n+\t\t\t\tSIVALu(seedbuf, 0, checksum_seed);\n+\t\t\t\tmd5_update(&m, seedbuf, 4);\n+\t\t\t}\n \t\t}\n \t\tmd5_result(&m, (uchar *)sum);\n \t} else {\nIndex: rsync-3.1.0/compat.c\n===================================================================\n--- rsync-3.1.0.orig/compat.c\t2015-10-07 15:26:38.822626286 +0200\n+++ rsync-3.1.0/compat.c\t2015-10-07 15:28:45.553329106 +0200\n@@ -26,6 +26,7 @@ int file_extra_cnt = 0; /* count of file\n int inc_recurse = 0;\n int compat_flags = 0;\n int use_safe_inc_flist = 0;\n+int proper_seed_order = 0;\n \n extern int am_server;\n extern int am_sender;\n@@ -76,6 +77,7 @@ int filesfrom_convert = 0;\n #define CF_SYMLINK_TIMES (1<<1)\n #define CF_SYMLINK_ICONV (1<<2)\n #define CF_SAFE_FLIST\t (1<<3)\n+#define CF_CHKSUM_SEED_FIX (1<<5)\n \n static const char *client_info;\n \n@@ -253,11 +255,14 @@ void setup_protocol(int f_out,int f_in)\n #endif\n \t\t\tif (local_server || strchr(client_info, 'f') != NULL)\n \t\t\t\tcompat_flags |= CF_SAFE_FLIST;\n+\t\t\tif (local_server || strchr(client_info, 'C') != NULL)\n+\t\t\t\tcompat_flags |= CF_CHKSUM_SEED_FIX;\n \t\t\twrite_byte(f_out, compat_flags);\n \t\t} else\n \t\t\tcompat_flags = read_byte(f_in);\n \t\t/* The inc_recurse var MUST be set to 0 or 1. */\n \t\tinc_recurse = compat_flags & CF_INC_RECURSE ? 1 : 0;\n+\t\tproper_seed_order = compat_flags & CF_CHKSUM_SEED_FIX ? 1 : 0;\n \t\tif (am_sender) {\n \t\t\treceiver_symlink_times = am_server\n \t\t\t ? strchr(client_info, 'L') != NULL\nIndex: rsync-3.1.0/options.c\n===================================================================\n--- rsync-3.1.0.orig/options.c\t2015-10-07 15:26:38.823626300 +0200\n+++ rsync-3.1.0/options.c\t2015-10-07 15:30:33.161773618 +0200\n@@ -2481,6 +2481,7 @@ void server_options(char **args, int *ar\n #ifdef ICONV_OPTION\n \t\targstr[x++] = 's';\n #endif\n+\t\targstr[x++] = 'C'; /* support checksum seed order fix */\n \t}\n \n \tif (x >= (int)sizeof argstr) { /* Not possible... */" } ]
{ "id": "rsync-5241-rsync-equivalent_of_CVE-2014-8", "cve_id": "CVE-2014-9512", "package": "rsync", "upstream_enriched": true, "upstream_commit": "eac858085e3ac94ec0ab5061d11f52652c90a869", "upstream_repo": "RsyncProject/rsync", "tier": "adapted", "has_source_context": false, "license": "GPL-3.0-or-later", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-8629\n\nThe xdr_nullstring function in lib/kadm5/kadm_rpc_xdr.c in kadmind in MIT Kerberos 5 (aka krb5) before 1.13.4 and 1.14.x before 1.14.1 does not verify whether '\\0' characters exist as expected, which allows remote authenticated users to obtain sensitive information or cause a denial of service (out-of-bounds read) via a crafted string.\n\n## Package\nkrb5\n\n## Files to modify\n- src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c\n\n## Upstream Fix\n```diff\nFrom d1f707024f1d0af6e54a18885322d70fa15ec4d3 Mon Sep 17 00:00:00 2001\nFrom: Greg Hudson <ghudson@mit.edu>\nDate: Fri, 5 Dec 2014 14:01:39 -0500\nSubject: [PATCH] Fix LDAP misused policy name crash [CVE-2014-5353]\n\nIn krb5_ldap_get_password_policy_from_dn, if LDAP_SEARCH returns\nsuccessfully with no results, return KRB5_KDB_NOENTRY instead of\nreturning success with a zeroed-out policy object. This fixes a null\ndereference when an admin attempts to use an LDAP ticket policy name\nas a password policy name.\n\nCVE-2014-5353:\n\nIn MIT krb5, when kadmind is configured to use LDAP for the KDC\ndatabase, an authenticated remote attacker can cause a NULL dereference\nby attempting to use a named ticket policy object as a password policy\nfor a principal. The attacker needs to be authenticated as a user who\nhas the elevated privilege for setting password policy by adding or\nmodifying principals.\n\nQueries to LDAP scoped to the krbPwdPolicy object class will correctly\nnot return entries of other classes, such as ticket policy objects, but\nmay return success with no returned elements if an object with the\nrequested DN exists in a different object class. In this case, the\nroutine to retrieve a password policy returned success with a password\npolicy object that consisted entirely of zeroed memory. In particular,\naccesses to the policy name will dereference a NULL pointer. KDC\noperation does not access the policy name field, but most kadmin\noperations involving the principal with incorrect password policy\nwill trigger the crash.\n\nThanks to Patrik Kis for reporting this problem.\n\nCVSSv2 Vector: AV:N/AC:M/Au:S/C:N/I:N/A:C/E:H/RL:OF/RC:C\n\n[kaduk@mit.edu: CVE description and CVSS score]\n\nticket: 8051 (new)\ntarget_version: 1.13.1\ntags: pullup\n---\n src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c b/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c\nindex 522773e95b9..6779f51c7bf 100644\n--- a/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c\n+++ b/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c\n@@ -314,10 +314,11 @@ krb5_ldap_get_password_policy_from_dn(krb5_context context, char *pol_name,\n LDAP_SEARCH(pol_dn, LDAP_SCOPE_BASE, \"(objectclass=krbPwdPolicy)\", password_policy_attributes);\n \n ent=ldap_first_entry(ld, result);\n- if (ent != NULL) {\n- if ((st = populate_policy(context, ld, ent, pol_name, *policy)) != 0)\n- goto cleanup;\n+ if (ent == NULL) {\n+ st = KRB5_KDB_NOENTRY;\n+ goto cleanup;\n }\n+ st = populate_policy(context, ld, ent, pol_name, *policy);\n \n cleanup:\n ldap_msgfree(result);\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From d1f707024f1d0af6e54a18885322d70fa15ec4d3 Mon Sep 17 00:00:00 2001\nFrom: Greg Hudson <ghudson@mit.edu>\nDate: Fri, 5 Dec 2014 14:01:39 -0500\nSubject: [PATCH] Fix LDAP misused policy name crash [CVE-2014-5353]\n\nIn krb5_ldap_get_password_policy_from_dn, if LDAP_SEARCH returns\nsuccessfully with no results, return KRB5_KDB_NOENTRY instead of\nreturning success with a zeroed-out policy object. This fixes a null\ndereference when an admin attempts to use an LDAP ticket policy name\nas a password policy name.\n\nCVE-2014-5353:\n\nIn MIT krb5, when kadmind is configured to use LDAP for the KDC\ndatabase, an authenticated remote attacker can cause a NULL dereference\nby attempting to use a named ticket policy object as a password policy\nfor a principal. The attacker needs to be authenticated as a user who\nhas the elevated privilege for setting password policy by adding or\nmodifying principals.\n\nQueries to LDAP scoped to the krbPwdPolicy object class will correctly\nnot return entries of other classes, such as ticket policy objects, but\nmay return success with no returned elements if an object with the\nrequested DN exists in a different object class. In this case, the\nroutine to retrieve a password policy returned success with a password\npolicy object that consisted entirely of zeroed memory. In particular,\naccesses to the policy name will dereference a NULL pointer. KDC\noperation does not access the policy name field, but most kadmin\noperations involving the principal with incorrect password policy\nwill trigger the crash.\n\nThanks to Patrik Kis for reporting this problem.\n\nCVSSv2 Vector: AV:N/AC:M/Au:S/C:N/I:N/A:C/E:H/RL:OF/RC:C\n\n[kaduk@mit.edu: CVE description and CVSS score]\n\nticket: 8051 (new)\ntarget_version: 1.13.1\ntags: pullup\n---\n src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c b/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c\nindex 522773e..6779f51 100644\n--- a/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c\n+++ b/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c\n@@ -314,10 +314,11 @@ krb5_ldap_get_password_policy_from_dn(krb5_context context, char *pol_name,\n LDAP_SEARCH(pol_dn, LDAP_SCOPE_BASE, \"(objectclass=krbPwdPolicy)\", password_policy_attributes);\n \n ent=ldap_first_entry(ld, result);\n- if (ent != NULL) {\n- if ((st = populate_policy(context, ld, ent, pol_name, *policy)) != 0)\n- goto cleanup;\n+ if (ent == NULL) {\n+ st = KRB5_KDB_NOENTRY;\n+ goto cleanup;\n }\n+ st = populate_policy(context, ld, ent, pol_name, *policy);\n \n cleanup:\n ldap_msgfree(result);" } ]
{ "id": "krb5-4670-krb5-1.12.2-CVE-2014-5353.patc", "cve_id": "CVE-2015-8629", "package": "krb5", "upstream_enriched": true, "upstream_commit": "d1f707024f1d0af6e54a18885322d70fa15ec4d3", "upstream_repo": "krb5/krb5", "tier": "adapted", "has_source_context": false, "license": "MIT", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-3119\n\nThe process_db_args function in plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c in the LDAP KDB module in kadmind in MIT Kerberos 5 (aka krb5) through 1.13.4 and 1.14.x through 1.14.1 mishandles the DB argument, which allows remote authenticated users to cause a denial of service (NULL pointer dereference and daemon crash) via a crafted request to modify a principal.\n\n## Package\nkrb5\n\n## Files to modify\n- krb5/src/clients/ksu/main.c\n- krb5/src/clients/ksu/pam.c\n- krb5/src/clients/ksu/pam.h\n\n## Upstream Fix\n```diff\nModify ksu so that it performs account and session management on behalf of\nthe target user account, mimicking the action of regular su. The default\nservice name is \"ksu\", because on Fedora at least the configuration used\nis determined by whether or not a login shell is being opened, and so\nthis may need to vary, too. At run-time, ksu's behavior can be reset to\nthe earlier, non-PAM behavior by setting \"use_pam\" to false in the [ksu]\nsection of /etc/krb5.conf.\n\nWhen enabled, ksu gains a dependency on libpam.\n\nOriginally RT#5939, though it's changed since then to perform the account\nand session management before dropping privileges.\n\ndiff -Naur krb5/src/aclocal.m4 krb5/src/aclocal.m4\n--- krb5/src/aclocal.m4\t2014-01-13 17:12:47.509022000 +0100\n+++ krb5/src/aclocal.m4\t2014-01-13 17:13:24.552689000 +0100\n@@ -1668,3 +1668,70 @@\n ]))\n ])dnl\n dnl\n+dnl\n+dnl Use PAM instead of local crypt() compare for checking local passwords,\n+dnl and perform PAM account, session management, and password-changing where\n+dnl appropriate.\n+dnl \n+AC_DEFUN(KRB5_WITH_PAM,[\n+AC_ARG_WITH(pam,[AC_HELP_STRING(--with-pam,[compile with PAM support])],\n+\t withpam=\"$withval\",withpam=auto)\n+AC_ARG_WITH(pam-ksu-service,[AC_HELP_STRING(--with-ksu-service,[PAM service name for ksu [\"ksu\"]])],\n+\t withksupamservice=\"$withval\",withksupamservice=ksu)\n+old_LIBS=\"$LIBS\"\n+if test \"$withpam\" != no ; then\n+\tAC_MSG_RESULT([checking for PAM...])\n+\tPAM_LIBS=\n+\n+\tAC_CHECK_HEADERS(security/pam_appl.h)\n+\tif test \"x$ac_cv_header_security_pam_appl_h\" != xyes ; then\n+\t\tif test \"$withpam\" = auto ; then\n+\t\t\tAC_MSG_RESULT([Unable to locate security/pam_appl.h.])\n+\t\t\twithpam=no\n+\t\telse\n+\t\t\tAC_MSG_ERROR([Unable to locate security/pam_appl.h.])\n+\t\tfi\n+\tfi\n+\n+\tLIBS=\n+\tunset ac_cv_func_pam_start\n+\tAC_CHECK_FUNCS(putenv pam_start)\n+\tif test \"x$ac_cv_func_pam_start\" = xno ; then\n+\t\tunset ac_cv_func_pam_start\n+\t\tAC_CHECK_LIB(dl,dlopen)\n+\t\tAC_CHECK_FUNCS(pam_start)\n+\t\tif test \"x$ac_cv_func_pam_start\" = xno ; then\n+\t\t\tAC_CHECK_LIB(pam,pam_start)\n+\t\t\tunset ac_cv_func_pam_start\n+\t\t\tunset ac_cv_func_pam_getenvlist\n+\t\t\tAC_CHECK_FUNCS(pam_start pam_getenvlist)\n+\t\t\tif test \"x$ac_cv_func_pam_start\" = xyes ; then\n+\t\t\t\tPAM_LIBS=\"$LIBS\"\n+\t\t\telse\n+\t\t\t\tif test \"$withpam\" = auto ; then\n+\t\t\t\t\tAC_MSG_RESULT([Unable to locate libpam.])\n+\t\t\t\t\twithpam=no\n+\t\t\t\telse\n+\t\t\t\t\tAC_MSG_ERROR([Unable to locate libpam.])\n+\t\t\t\tfi\n+\t\t\tfi\n+\t\tfi\n+\tfi\n+\tif test \"$withpam\" != no ; then\n+\t\tAC_MSG_NOTICE([building with PAM support])\n+\t\tAC_DEFINE(USE_PAM,1,[Define if Kerberos-aware tools should support PAM])\n+\t\tAC_DEFINE_UNQUOTED(KSU_PAM_SERVICE,\"$withksupamservice\",\n+\t\t\t\t [Define to the name of the PAM service name to be used by ksu.])\n+\t\tPAM_LIBS=\"$LIBS\"\n+\t\tNON_PAM_MAN=\".\\\\\\\" \"\n+\t\tPAM_MAN=\n+\telse\n+\t\tPAM_MAN=\".\\\\\\\" \"\n+\t\tNON_PAM_MAN=\n+\tfi\n+fi\n+LIBS=\"$old_LIBS\"\n+AC_SUBST(PAM_LIBS)\n+AC_SUBST(PAM_MAN)\n+AC_SUBST(NON_PAM_MAN)\n+])dnl\ndiff -Naur krb5/src/clients/ksu/main.c krb5/src/clients/ksu/main.c\n--- krb5/src/clients/ksu/main.c\t2014-01-13 17:12:44.864970000 +0100\n+++ krb5/src/clients/ksu/main.c\t2014-01-13 17:13:24.563692000 +0100\n@@ -26,6 +26,7 @@\n * KSU was writen by: Ari Medvinsky, ari@isi.edu\n */\n \n+#include \"autoconf.h\"\n #include \"ksu.h\"\n #include \"adm_proto.h\"\n #include <sys/types.h>\n@@ -33,6 +34,10 @@\n #include <signal.h>\n #include <grp.h>\n \n+#ifdef USE_PAM\n+#include \"pam.h\"\n+#endif\n+\n /* globals */\n char * prog_name;\n int auth_debug =0;\n@@ -40,6 +45,7 @@\n char k5users_path[MAXPATHLEN];\n char * gb_err = NULL;\n int quiet = 0;\n+int force_fork = 0;\n /***********/\n \n #define _DEF_CSH \"/bin/csh\"\n@@ -584,6 +590,25 @@\n prog_name,target_user,client_name,\n source_user,ontty());\n \n+#ifdef USE_PAM\n+ if (appl_pam_enabled(ksu_context, \"ksu\")) {\n+ if (appl_pam_acct_mgmt(KSU_PAM_SERVICE, 1, target_user, NULL,\n+ NULL, source_user,\n+ ttyname(STDERR_FILENO)) != 0) {\n+ fprintf(stderr, \"Access denied for %s.\\n\", target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+ if (appl_pam_requires_chauthtok()) {\n+ fprintf(stderr, \"Password change required for %s.\\n\",\n+ target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+ force_fork++;\n+ }\n+#endif\n+\n /* Run authorization as target.*/\n if (krb5_seteuid(target_uid)) {\n com_err(prog_name, errno, _(\"while switching to target for \"\n@@ -648,6 +673,26 @@\n sweep_up(ksu_context, cc_target);\n exit(1);\n }\n+#ifdef USE_PAM\n+ } else {\n+ /* we always do PAM account management, even for root */\n+ if (appl_pam_enabled(ksu_context, \"ksu\")) {\n+ if (appl_pam_acct_mgmt(KSU_PAM_SERVICE, 1, target_user, NULL,\n+ NULL, source_user,\n+ ttyname(STDERR_FILENO)) != 0) {\n+ fprintf(stderr, \"Access denied for %s.\\n\", target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+ if (appl_pam_requires_chauthtok()) {\n+ fprintf(stderr, \"Password change required for %s.\\n\",\n+ target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+ force_fork++;\n+ }\n+#endif\n }\n \n if( some_rest_copy){\n@@ -717,6 +762,32 @@\n exit(1);\n }\n \n+#ifdef USE_PAM\n+ if (appl_pam_enabled(ksu_context, \"ksu\")) {\n+ if (appl_pam_session_open() != 0) {\n+ fprintf(stderr, \"Error opening session for %s.\\n\", target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+#ifdef DEBUG\n+ if (auth_debug){\n+ printf(\" Opened PAM session.\\n\");\n+ }\n+#endif\n+ if (appl_pam_cred_init()) {\n+ fprintf(stderr, \"Error initializing credentials for %s.\\n\",\n+ target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+#ifdef DEBUG\n+ if (auth_debug){\n+ printf(\" Initialized PAM credentials.\\n\");\n+ }\n+#endif\n+ }\n+#endif\n+\n /* set permissions */\n if (setgid(target_pwd->pw_gid) < 0) {\n perror(\"ksu: setgid\");\n@@ -789,7 +860,7 @@\n fprintf(stderr, \"program to be execed %s\\n\",params[0]);\n }\n \n- if( keep_target_cache ) {\n+ if( keep_target_cache && !force_fork ) {\n execv(params[0], params);\n com_err(prog_name, errno, _(\"while trying to execv %s\"), params[0]);\n sweep_up(ksu_context, cc_target);\n@@ -819,16 +890,35 @@\n if (ret_pid == -1) {\n com_err(prog_name, errno, _(\"while calling waitpid\"));\n }\n- sweep_up(ksu_context, cc_target);\n+ if( !keep_target_cache ) {\n+ sweep_up(ksu_context, cc_target);\n+ }\n exit (statusp);\n case -1:\n com_err(prog_name, errno, _(\"while trying to fork.\"));\n sweep_up(ksu_context, cc_target);\n exit (1);\n case 0:\n+#ifdef USE_PAM\n+ if (appl_pam_enabled(ksu_context, \"ksu\")) {\n+ if (appl_pam_setenv() != 0) {\n+ fprintf(stderr, \"Error setting up environment for %s.\\n\",\n+ target_user);\n+ exit (1);\n+ }\n+#ifdef DEBUG\n+ if (auth_debug){\n+ printf(\" Set up PAM environment.\\n\");\n+ }\n+#endif\n+ }\n+#endif\n execv(params[0], params);\n com_err(prog_name, errno, _(\"while trying to execv %s\"),\n params[0]);\n+ if( keep_target_cache ) {\n+ sweep_up(ksu_context, cc_target);\n+ }\n exit (1);\n }\n }\ndiff -Naur krb5/src/clients/ksu/Makefil\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "Modify ksu so that it performs account and session management on behalf of\nthe target user account, mimicking the action of regular su. The default\nservice name is \"ksu\", because on Fedora at least the configuration used\nis determined by whether or not a login shell is being opened, and so\nthis may need to vary, too. At run-time, ksu's behavior can be reset to\nthe earlier, non-PAM behavior by setting \"use_pam\" to false in the [ksu]\nsection of /etc/krb5.conf.\n\nWhen enabled, ksu gains a dependency on libpam.\n\nOriginally RT#5939, though it's changed since then to perform the account\nand session management before dropping privileges.\n\ndiff -Naur krb5/src/aclocal.m4 krb5/src/aclocal.m4\n--- krb5/src/aclocal.m4\t2014-01-13 17:12:47.509022000 +0100\n+++ krb5/src/aclocal.m4\t2014-01-13 17:13:24.552689000 +0100\n@@ -1668,3 +1668,70 @@\n ]))\n ])dnl\n dnl\n+dnl\n+dnl Use PAM instead of local crypt() compare for checking local passwords,\n+dnl and perform PAM account, session management, and password-changing where\n+dnl appropriate.\n+dnl \n+AC_DEFUN(KRB5_WITH_PAM,[\n+AC_ARG_WITH(pam,[AC_HELP_STRING(--with-pam,[compile with PAM support])],\n+\t withpam=\"$withval\",withpam=auto)\n+AC_ARG_WITH(pam-ksu-service,[AC_HELP_STRING(--with-ksu-service,[PAM service name for ksu [\"ksu\"]])],\n+\t withksupamservice=\"$withval\",withksupamservice=ksu)\n+old_LIBS=\"$LIBS\"\n+if test \"$withpam\" != no ; then\n+\tAC_MSG_RESULT([checking for PAM...])\n+\tPAM_LIBS=\n+\n+\tAC_CHECK_HEADERS(security/pam_appl.h)\n+\tif test \"x$ac_cv_header_security_pam_appl_h\" != xyes ; then\n+\t\tif test \"$withpam\" = auto ; then\n+\t\t\tAC_MSG_RESULT([Unable to locate security/pam_appl.h.])\n+\t\t\twithpam=no\n+\t\telse\n+\t\t\tAC_MSG_ERROR([Unable to locate security/pam_appl.h.])\n+\t\tfi\n+\tfi\n+\n+\tLIBS=\n+\tunset ac_cv_func_pam_start\n+\tAC_CHECK_FUNCS(putenv pam_start)\n+\tif test \"x$ac_cv_func_pam_start\" = xno ; then\n+\t\tunset ac_cv_func_pam_start\n+\t\tAC_CHECK_LIB(dl,dlopen)\n+\t\tAC_CHECK_FUNCS(pam_start)\n+\t\tif test \"x$ac_cv_func_pam_start\" = xno ; then\n+\t\t\tAC_CHECK_LIB(pam,pam_start)\n+\t\t\tunset ac_cv_func_pam_start\n+\t\t\tunset ac_cv_func_pam_getenvlist\n+\t\t\tAC_CHECK_FUNCS(pam_start pam_getenvlist)\n+\t\t\tif test \"x$ac_cv_func_pam_start\" = xyes ; then\n+\t\t\t\tPAM_LIBS=\"$LIBS\"\n+\t\t\telse\n+\t\t\t\tif test \"$withpam\" = auto ; then\n+\t\t\t\t\tAC_MSG_RESULT([Unable to locate libpam.])\n+\t\t\t\t\twithpam=no\n+\t\t\t\telse\n+\t\t\t\t\tAC_MSG_ERROR([Unable to locate libpam.])\n+\t\t\t\tfi\n+\t\t\tfi\n+\t\tfi\n+\tfi\n+\tif test \"$withpam\" != no ; then\n+\t\tAC_MSG_NOTICE([building with PAM support])\n+\t\tAC_DEFINE(USE_PAM,1,[Define if Kerberos-aware tools should support PAM])\n+\t\tAC_DEFINE_UNQUOTED(KSU_PAM_SERVICE,\"$withksupamservice\",\n+\t\t\t\t [Define to the name of the PAM service name to be used by ksu.])\n+\t\tPAM_LIBS=\"$LIBS\"\n+\t\tNON_PAM_MAN=\".\\\\\\\" \"\n+\t\tPAM_MAN=\n+\telse\n+\t\tPAM_MAN=\".\\\\\\\" \"\n+\t\tNON_PAM_MAN=\n+\tfi\n+fi\n+LIBS=\"$old_LIBS\"\n+AC_SUBST(PAM_LIBS)\n+AC_SUBST(PAM_MAN)\n+AC_SUBST(NON_PAM_MAN)\n+])dnl\ndiff -Naur krb5/src/clients/ksu/main.c krb5/src/clients/ksu/main.c\n--- krb5/src/clients/ksu/main.c\t2014-01-13 17:12:44.864970000 +0100\n+++ krb5/src/clients/ksu/main.c\t2014-01-13 17:13:24.563692000 +0100\n@@ -26,6 +26,7 @@\n * KSU was writen by: Ari Medvinsky, ari@isi.edu\n */\n \n+#include \"autoconf.h\"\n #include \"ksu.h\"\n #include \"adm_proto.h\"\n #include <sys/types.h>\n@@ -33,6 +34,10 @@\n #include <signal.h>\n #include <grp.h>\n \n+#ifdef USE_PAM\n+#include \"pam.h\"\n+#endif\n+\n /* globals */\n char * prog_name;\n int auth_debug =0;\n@@ -40,6 +45,7 @@\n char k5users_path[MAXPATHLEN];\n char * gb_err = NULL;\n int quiet = 0;\n+int force_fork = 0;\n /***********/\n \n #define _DEF_CSH \"/bin/csh\"\n@@ -584,6 +590,25 @@\n prog_name,target_user,client_name,\n source_user,ontty());\n \n+#ifdef USE_PAM\n+ if (appl_pam_enabled(ksu_context, \"ksu\")) {\n+ if (appl_pam_acct_mgmt(KSU_PAM_SERVICE, 1, target_user, NULL,\n+ NULL, source_user,\n+ ttyname(STDERR_FILENO)) != 0) {\n+ fprintf(stderr, \"Access denied for %s.\\n\", target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+ if (appl_pam_requires_chauthtok()) {\n+ fprintf(stderr, \"Password change required for %s.\\n\",\n+ target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+ force_fork++;\n+ }\n+#endif\n+\n /* Run authorization as target.*/\n if (krb5_seteuid(target_uid)) {\n com_err(prog_name, errno, _(\"while switching to target for \"\n@@ -648,6 +673,26 @@\n sweep_up(ksu_context, cc_target);\n exit(1);\n }\n+#ifdef USE_PAM\n+ } else {\n+ /* we always do PAM account management, even for root */\n+ if (appl_pam_enabled(ksu_context, \"ksu\")) {\n+ if (appl_pam_acct_mgmt(KSU_PAM_SERVICE, 1, target_user, NULL,\n+ NULL, source_user,\n+ ttyname(STDERR_FILENO)) != 0) {\n+ fprintf(stderr, \"Access denied for %s.\\n\", target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+ if (appl_pam_requires_chauthtok()) {\n+ fprintf(stderr, \"Password change required for %s.\\n\",\n+ target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+ force_fork++;\n+ }\n+#endif\n }\n \n if( some_rest_copy){\n@@ -717,6 +762,32 @@\n exit(1);\n }\n \n+#ifdef USE_PAM\n+ if (appl_pam_enabled(ksu_context, \"ksu\")) {\n+ if (appl_pam_session_open() != 0) {\n+ fprintf(stderr, \"Error opening session for %s.\\n\", target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+#ifdef DEBUG\n+ if (auth_debug){\n+ printf(\" Opened PAM session.\\n\");\n+ }\n+#endif\n+ if (appl_pam_cred_init()) {\n+ fprintf(stderr, \"Error initializing credentials for %s.\\n\",\n+ target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+#ifdef DEBUG\n+ if (auth_debug){\n+ printf(\" Initialized PAM credentials.\\n\");\n+ }\n+#endif\n+ }\n+#endif\n+\n /* set permissions */\n if (setgid(target_pwd->pw_gid) < 0) {\n perror(\"ksu: setgid\");\n@@ -789,7 +860,7 @@\n fprintf(stderr, \"program to be execed %s\\n\",params[0]);\n }\n \n- if( keep_target_cache ) {\n+ if( keep_target_cache && !force_fork ) {\n execv(params[0], params);\n com_err(prog_name, errno, _(\"while trying to execv %s\"), params[0]);\n sweep_up(ksu_context, cc_target);\n@@ -819,16 +890,35 @@\n if (ret_pid == -1) {\n com_err(prog_name, errno, _(\"while calling waitpid\"));\n }\n- sweep_up(ksu_context, cc_target);\n+ if( !keep_target_cache ) {\n+ sweep_up(ksu_context, cc_target);\n+ }\n exit (statusp);\n case -1:\n com_err(prog_name, errno, _(\"while trying to fork.\"));\n sweep_up(ksu_context, cc_target);\n exit (1);\n case 0:\n+#ifdef USE_PAM\n+ if (appl_pam_enabled(ksu_context, \"ksu\")) {\n+ if (appl_pam_setenv() != 0) {\n+ fprintf(stderr, \"Error setting up environment for %s.\\n\",\n+ target_user);\n+ exit (1);\n+ }\n+#ifdef DEBUG\n+ if (auth_debug){\n+ printf(\" Set up PAM environment.\\n\");\n+ }\n+#endif\n+ }\n+#endif\n execv(params[0], params);\n com_err(prog_name, errno, _(\"while trying to execv %s\"),\n params[0]);\n+ if( keep_target_cache ) {\n+ sweep_up(ksu_context, cc_target);\n+ }\n exit (1);\n }\n }\ndiff -Naur krb5/src/clients/ksu/Makefile.in krb5/src/clients/ksu/Makefile.in\n--- krb5/src/clients/ksu/Makefile.in\t2014-01-13 17:12:44.868981000 +0100\n+++ krb5/src/clients/ksu/Makefile.in\t2014-01-13 17:13:24.580690000 +0100\n@@ -3,12 +3,14 @@\n DEFINES = -DGET_TGT_VIA_PASSWD -DPRINC_LOOK_AHEAD -DCMD_PATH='\"/bin /local/bin\"'\n \n KSU_LIBS=@KSU_LIBS@\n+PAM_LIBS=@PAM_LIBS@\n \n SRCS = \\\n \t$(srcdir)/krb_auth_su.c \\\n \t$(srcdir)/ccache.c \\\n \t$(srcdir)/authorization.c \\\n \t$(srcdir)/main.c \\\n+\t$(srcdir)/pam.c \\\n \t$(srcdir)/heuristic.c \\\n \t$(srcdir)/xmalloc.c \\\n \t$(srcdir)/setenv.c\n@@ -17,13 +19,17 @@\n \tccache.o \\\n \tauthorization.o \\\n \tmain.o \\\n+\tpam.o \\\n \theuristic.o \\\n \txmalloc.o @SETENVOBJ@\n \n all:: ksu\n \n ksu: $(OBJS) $(KRB5_BASE_DEPLIBS)\n-\t$(CC_LINK) -o $@ $(OBJS) $(KRB5_BASE_LIBS) $(KSU_LIBS)\n+\t$(CC_LINK) -o $@ $(OBJS) $(KRB5_BASE_LIBS) $(KSU_LIBS) $(PAM_LIBS)\n+\n+pam.o: pam.c\n+\t$(CC) $(ALL_CFLAGS) -c $<\n \n clean::\n \t$(RM) ksu\ndiff -Naur krb5/src/clients/ksu/pam.c krb5/src/clients/ksu/pam.c\n--- krb5/src/clients/ksu/pam.c\t1970-01-01 01:00:00.000000000 +0100\n+++ krb5/src/clients/ksu/pam.c\t2014-01-13 17:13:24.589692000 +0100\n@@ -0,0 +1,389 @@\n+/*\n+ * src/clients/ksu/pam.c\n+ *\n+ * Copyright 2007,2009,2010 Red Hat, Inc.\n+ *\n+ * All Rights Reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions are met:\n+ *\n+ * Redistributions of source code must retain the above copyright notice, this\n+ * list of conditions and the following disclaimer.\n+ *\n+ * Redistributions in binary form must reproduce the above copyright notice,\n+ * this list of conditions and the following disclaimer in the documentation\n+ * and/or other materials provided with the distribution.\n+ *\n+ * Neither the name of Red Hat, Inc. nor the names of its contributors may be\n+ * used to endorse or promote products derived from this software without\n+ * specific prior written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\n+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n+ * POSSIBILITY OF SUCH DAMAGE.\n+ * \n+ * Convenience wrappers for using PAM.\n+ */\n+\n+#include \"autoconf.h\"\n+#ifdef USE_PAM\n+#include <sys/types.h>\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <string.h>\n+#include <unistd.h>\n+#include \"k5-int.h\"\n+#include \"pam.h\"\n+\n+#ifndef MAXPWSIZE\n+#define MAXPWSIZE 128\n+#endif\n+\n+static int appl_pam_started;\n+static pid_t appl_pam_starter = -1;\n+static int appl_pam_session_opened;\n+static int appl_pam_creds_initialized;\n+static int appl_pam_pwchange_required;\n+static pam_handle_t *appl_pamh;\n+static struct pam_conv appl_pam_conv;\n+static char *appl_pam_user;\n+struct appl_pam_non_interactive_args {\n+\tconst char *user;\n+\tconst char *password;\n+};\n+\n+int\n+appl_pam_enabled(krb5_context context, const char *section)\n+{\n+\tint enabled = 1;\n+\tif ((context != NULL) && (context->profile != NULL)) {\n+\t\tif (profile_get_boolean(context->profile,\n+\t\t\t\t\tsection,\n+\t\t\t\t\tUSE_PAM_CONFIGURATION_KEYWORD,\n+\t\t\t\t\tNULL,\n+\t\t\t\t\tenabled, &enabled) != 0) {\n+\t\t\tenabled = 1;\n+\t\t}\n+\t}\n+\treturn enabled;\n+}\n+\n+void\n+appl_pam_cleanup(void)\n+{\n+\tif (getpid() != appl_pam_starter) {\n+\t\treturn;\n+\t}\n+#ifdef DEBUG\n+\tprintf(\"Called to clean up PAM.\\n\");\n+#endif\n+\tif (appl_pam_creds_initialized) {\n+#ifdef DEBUG\n+\t\tprintf(\"Deleting PAM credentials.\\n\");\n+#endif\n+\t\tpam_setcred(appl_pamh, PAM_DELETE_CRED);\n+\t\tappl_pam_creds_initialized = 0;\n+\t}\n+\tif (appl_pam_session_opened) {\n+#ifdef DEBUG\n+\t\tprintf(\"Closing PAM session.\\n\");\n+#endif\n+\t\tpam_close_session(appl_pamh, 0);\n+\t\tappl_pam_session_opened = 0;\n+\t}\n+\tappl_pam_pwchange_required = 0;\n+\tif (appl_pam_started) {\n+#ifdef DEBUG\n+\t\tprintf(\"Shutting down PAM.\\n\");\n+#endif\n+\t\tpam_end(appl_pamh, 0);\n+\t\tappl_pam_started = 0;\n+\t\tappl_pam_starter = -1;\n+\t\tfree(appl_pam_user);\n+\t\tappl_pam_user = NULL;\n+\t}\n+}\n+static int\n+appl_pam_interactive_converse(int num_msg, const struct pam_message **msg,\n+\t\t\t struct pam_response **presp, void *appdata_ptr)\n+{\n+\tconst struct pam_message *message;\n+\tstruct pam_response *resp;\n+\tint i, code;\n+\tchar *pwstring, pwbuf[MAXPWSIZE];\n+\tunsigned int pwsize;\n+\tresp = malloc(sizeof(struct pam_response) * num_msg);\n+\tif (resp == NULL) {\n+\t\treturn PAM_BUF_ERR;\n+\t}\n+\tmemset(resp, 0, sizeof(struct pam_response) * num_msg);\n+\tcode = PAM_SUCCESS;\n+\tfor (i = 0; i < num_msg; i++) {\n+\t\tmessage = &(msg[0][i]); /* XXX */\n+\t\tmessage = msg[i]; /* XXX */\n+\t\tpwstring = NULL;\n+\t\tswitch (message->msg_style) {\n+\t\tcase PAM_TEXT_INFO:\n+\t\tcase PAM_ERROR_MSG:\n+\t\t\tprintf(\"[%s]\\n\", message->msg ? message->msg : \"\");\n+\t\t\tfflush(stdout);\n+\t\t\tresp[i].resp = NULL;\n+\t\t\tresp[i].resp_retcode = PAM_SUCCESS;\n+\t\t\tbreak;\n+\t\tcase PAM_PROMPT_ECHO_ON:\n+\t\tcase PAM_PROMPT_ECHO_OFF:\n+\t\t\tif (message->msg_style == PAM_PROMPT_ECHO_ON) {\n+\t\t\t\tif (fgets(pwbuf, sizeof(pwbuf),\n+\t\t\t\t\t stdin) != NULL) {\n+\t\t\t\t\tpwbuf[strcspn(pwbuf, \"\\r\\n\")] = '\\0';\n+\t\t\t\t\tpwstring = pwbuf;\n+\t\t\t\t}\n+\t\t\t} else {\n+\t\t\t\tpwstring = getpass(message->msg ?\n+\t\t\t\t\t\t message->msg :\n+\t\t\t\t\t\t \"\");\n+\t\t\t}\n+\t\t\tif ((pwstring != NULL) && (pwstring[0] != '\\0')) {\n+\t\t\t\tpwsize = strlen(pwstring);\n+\t\t\t\tresp[i].resp = malloc(pwsize + 1);\n+\t\t\t\tif (resp[i].resp == NULL) {\n+\t\t\t\t\tresp[i].resp_retcode = PAM_BUF_ERR;\n+\t\t\t\t} else {\n+\t\t\t\t\tmemcpy(resp[i].resp, pwstring, pwsize);\n+\t\t\t\t\tresp[i].resp[pwsize] = '\\0';\n+\t\t\t\t\tresp[i].resp_retcode = PAM_SUCCESS;\n+\t\t\t\t}\n+\t\t\t} else {\n+\t\t\t\tresp[i].resp_retcode = PAM_CONV_ERR;\n+\t\t\t\tcode = PAM_CONV_ERR;\n+\t\t\t}\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\t*presp = resp;\n+\treturn code;\n+}\n+static int\n+appl_pam_non_interactive_converse(int num_msg,\n+\t\t\t\t const struct pam_message **msg,\n+\t\t\t\t struct pam_response **presp,\n+\t\t\t\t void *appdata_ptr)\n+{\n+\tconst struct pam_message *message;\n+\tstruct pam_response *resp;\n+\tint i, code;\n+\tunsigned int pwsize;\n+\tstruct appl_pam_non_interactive_args *args;\n+\tconst char *pwstring;\n+\tresp = malloc(sizeof(struct pam_response) * num_msg);\n+\tif (resp == NULL) {\n+\t\treturn PAM_BUF_ERR;\n+\t}\n+\targs = appdata_ptr;\n+\tmemset(resp, 0, sizeof(struct pam_response) * num_msg);\n+\tcode = PAM_SUCCESS;\n+\tfor (i = 0; i < num_msg; i++) {\n+\t\tmessage = &((*msg)[i]);\n+\t\tmessage = msg[i];\n+\t\tpwstring = NULL;\n+\t\tswitch (message->msg_style) {\n+\t\tcase PAM_TEXT_INFO:\n+\t\tcase PAM_ERROR_MSG:\n+\t\t\tbreak;\n+\t\tcase PAM_PROMPT_ECHO_ON:\n+\t\tcase PAM_PROMPT_ECHO_OFF:\n+\t\t\tif (message->msg_style == PAM_PROMPT_ECHO_ON) {\n+\t\t\t\t/* assume \"user\" */\n+\t\t\t\tpwstring = args->user;\n+\t\t\t} else {\n+\t\t\t\t/* assume \"password\" */\n+\t\t\t\tpwstring = args->password;\n+\t\t\t}\n+\t\t\tif ((pwstring != NULL) && (pwstring[0] != '\\0')) {\n+\t\t\t\tpwsize = strlen(pwstring);\n+\t\t\t\tresp[i].resp = malloc(pwsize + 1);\n+\t\t\t\tif (resp[i].resp == NULL) {\n+\t\t\t\t\tresp[i].resp_retcode = PAM_BUF_ERR;\n+\t\t\t\t} else {\n+\t\t\t\t\tmemcpy(resp[i].resp, pwstring, pwsize);\n+\t\t\t\t\tresp[i].resp[pwsize] = '\\0';\n+\t\t\t\t\tresp[i].resp_retcode = PAM_SUCCESS;\n+\t\t\t\t}\n+\t\t\t} else {\n+\t\t\t\tresp[i].resp_retcode = PAM_CONV_ERR;\n+\t\t\t\tcode = PAM_CONV_ERR;\n+\t\t\t}\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\t*presp = resp;\n+\treturn code;\n+}\n+static int\n+appl_pam_start(const char *service, int interactive,\n+\t const char *login_username,\n+\t const char *non_interactive_password,\n+\t const char *hostname,\n+\t const char *ruser,\n+\t const char *tty)\n+{\n+\tstatic int exit_handler_registered;\n+\tstatic struct appl_pam_non_interactive_args args;\n+\tint ret = 0;\n+\tif (appl_pam_started &&\n+\t (strcmp(login_username, appl_pam_user) != 0)) {\n+\t\tappl_pam_cleanup();\n+\t\tappl_pam_user = NULL;\n+\t}\n+\tif (!appl_pam_started) {\n+#ifdef DEBUG\n+\t\tprintf(\"Starting PAM up (service=\\\"%s\\\",user=\\\"%s\\\").\\n\",\n+\t\t service, login_username);\n+#endif\n+\t\tmemset(&appl_pam_conv, 0, sizeof(appl_pam_conv));\n+\t\tappl_pam_conv.conv = interactive ?\n+\t\t\t\t &appl_pam_interactive_converse :\n+\t\t\t\t &appl_pam_non_interactive_converse;\n+\t\tmemset(&args, 0, sizeof(args));\n+\t\targs.user = strdup(login_username);\n+\t\targs.password = non_interactive_password ?\n+\t\t\t\tstrdup(non_interactive_password) :\n+\t\t\t\tNULL;\n+\t\tappl_pam_conv.appdata_ptr = &args;\n+\t\tret = pam_start(service, login_username,\n+\t\t\t\t&appl_pam_conv, &appl_pamh);\n+\t\tif (ret == 0) {\n+\t\t\tif (hostname != NULL) {\n+#ifdef DEBUG\n+\t\t\t\tprintf(\"Setting PAM_RHOST to \\\"%s\\\".\\n\", hostname);\n+#endif\n+\t\t\t\tpam_set_item(appl_pamh, PAM_RHOST, hostname);\n+\t\t\t}\n+\t\t\tif (ruser != NULL) {\n+#ifdef DEBUG\n+\t\t\t\tprintf(\"Setting PAM_RUSER to \\\"%s\\\".\\n\", ruser);\n+#endif\n+\t\t\t\tpam_set_item(appl_pamh, PAM_RUSER, ruser);\n+\t\t\t}\n+\t\t\tif (tty != NULL) {\n+#ifdef DEBUG\n+\t\t\t\tprintf(\"Setting PAM_TTY to \\\"%s\\\".\\n\", tty);\n+#endif\n+\t\t\t\tpam_set_item(appl_pamh, PAM_TTY, tty);\n+\t\t\t}\n+\t\t\tif (!exit_handler_registered &&\n+\t\t\t (atexit(appl_pam_cleanup) != 0)) {\n+\t\t\t\tpam_end(appl_pamh, 0);\n+\t\t\t\tappl_pamh = NULL;\n+\t\t\t\tret = -1;\n+\t\t\t} else {\n+\t\t\t\tappl_pam_started = 1;\n+\t\t\t\tappl_pam_starter = getpid();\n+\t\t\t\tappl_pam_user = strdup(login_username);\n+\t\t\t\texit_handler_registered = 1;\n+\t\t\t}\n+\t\t}\n+\t}\n+\treturn ret;\n+}\n+int\n+appl_pam_acct_mgmt(const char *service, int interactive,\n+\t\t const char *login_username,\n+\t\t const char *non_interactive_password,\n+\t\t const char *hostname,\n+\t\t const char *ruser,\n+\t\t const char *tty)\n+{\n+\tint ret;\n+\tappl_pam_pwchange_required = 0;\n+\tret = appl_pam_start(service, interactive, login_username,\n+\t\t\t non_interactive_password, hostname, ruser, tty);\n+\tif (ret == 0) {\n+#ifdef DEBUG\n+\t\tprintf(\"Calling pam_acct_mgmt().\\n\");\n+#endif\n+\t\tret = pam_acct_mgmt(appl_pamh, 0);\n+\t\tswitch (ret) {\n+\t\tcase PAM_IGNORE:\n+\t\t\tret = 0;\n+\t\t\tbreak;\n+\t\tcase PAM_NEW_AUTHTOK_REQD:\n+\t\t\tappl_pam_pwchange_required = 1;\n+\t\t\tret = 0;\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\treturn ret;\n+}\n+int\n+appl_pam_requires_chauthtok(void)\n+{\n+\treturn appl_pam_pwchange_required;\n+}\n+int\n+appl_pam_session_open(void)\n+{\n+\tint ret = 0;\n+\tif (appl_pam_started) {\n+#ifdef DEBUG\n+\t\tprintf(\"Opening PAM session.\\n\");\n+#endif\n+\t\tret = pam_open_session(appl_pamh, 0);\n+\t\tif (ret == 0) {\n+\t\t\tappl_pam_session_opened = 1;\n+\t\t}\n+\t}\n+\treturn ret;\n+}\n+int\n+appl_pam_setenv(void)\n+{\n+\tint ret = 0;\n+#ifdef HAVE_PAM_GETENVLIST\n+#ifdef HAVE_PUTENV\n+\tint i;\n+\tchar **list;\n+\tif (appl_pam_started) {\n+\t\tlist = pam_getenvlist(appl_pamh);\n+\t\tfor (i = 0; ((list != NULL) && (list[i] != NULL)); i++) {\n+#ifdef DEBUG\n+\t\t\tprintf(\"Setting \\\"%s\\\" in environment.\\n\", list[i]);\n+#endif\n+\t\t\tputenv(list[i]);\n+\t\t}\n+\t}\n+#endif\n+#endif\n+\treturn ret;\n+}\n+int\n+appl_pam_cred_init(void)\n+{\n+\tint ret = 0;\n+\tif (appl_pam_started) {\n+#ifdef DEBUG\n+\t\tprintf(\"Initializing PAM credentials.\\n\");\n+#endif\n+\t\tret = pam_setcred(appl_pamh, PAM_ESTABLISH_CRED);\n+\t\tif (ret == 0) {\n+\t\t\tappl_pam_creds_initialized = 1;\n+\t\t}\n+\t}\n+\treturn ret;\n+}\n+#endif\ndiff -Naur krb5/src/clients/ksu/pam.h krb5/src/clients/ksu/pam.h\n--- krb5/src/clients/ksu/pam.h\t1970-01-01 01:00:00.000000000 +0100\n+++ krb5/src/clients/ksu/pam.h\t2014-01-13 17:13:24.595690000 +0100\n@@ -0,0 +1,57 @@\n+/*\n+ * src/clients/ksu/pam.h\n+ *\n+ * Copyright 2007,2009,2010 Red Hat, Inc.\n+ *\n+ * All Rights Reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions are met:\n+ *\n+ * Redistributions of source code must retain the above copyright notice, this\n+ * list of conditions and the following disclaimer.\n+ *\n+ * Redistributions in binary form must reproduce the above copyright notice,\n+ * this list of conditions and the following disclaimer in the documentation\n+ * and/or other materials provided with the distribution.\n+ *\n+ * Neither the name of Red Hat, Inc. nor the names of its contributors may be\n+ * used to endorse or promote products derived from this software without\n+ * specific prior written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\n+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n+ * POSSIBILITY OF SUCH DAMAGE.\n+ * \n+ * Convenience wrappers for using PAM.\n+ */\n+\n+#include <krb5.h>\n+#ifdef HAVE_SECURITY_PAM_APPL_H\n+#include <security/pam_appl.h>\n+#endif\n+\n+#define USE_PAM_CONFIGURATION_KEYWORD \"use_pam\"\n+\n+#ifdef USE_PAM\n+int appl_pam_enabled(krb5_context context, const char *section);\n+int appl_pam_acct_mgmt(const char *service, int interactive,\n+\t\t const char *local_username,\n+\t\t const char *non_interactive_password,\n+\t\t const char *hostname,\n+\t\t const char *ruser,\n+\t\t const char *tty);\n+int appl_pam_requires_chauthtok(void);\n+int appl_pam_session_open(void);\n+int appl_pam_setenv(void);\n+int appl_pam_cred_init(void);\n+void appl_pam_cleanup(void);\n+#endif\ndiff -Naur krb5/src/configure.in krb5/src/configure.in\n--- krb5/src/configure.in\t2014-01-13 17:12:48.401059000 +0100\n+++ krb5/src/configure.in\t2014-01-13 17:13:24.603693000 +0100\n@@ -1281,6 +1281,8 @@\n \n AC_PATH_PROG(GROFF, groff)\n \n+KRB5_WITH_PAM\n+\n # Make localedir work in autoconf 2.5x.\n if test \"${localedir+set}\" != set; then\n localedir='$(datadir)/locale'" } ]
{ "id": "krb5-4938-krb5-1.12-pam.patch", "cve_id": "CVE-2016-3119", "package": "krb5", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": false, "license": "MIT", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-9840\n\ninftrees.c in zlib 1.2.8 might allow context-dependent attackers to have unspecified impact by leveraging improper pointer arithmetic.\n\n## Package\nzlib\n\n## Files to modify\n- zlib-1.2.7.orig/zlib.h\n- zlib.h\n\n## Upstream Fix\n```diff\nFrom: meissner@suse.de\nSubject: supply format arguments to gzprintf().\n\nIndex: zlib-1.2.7/zlib.h\n===================================================================\n--- zlib-1.2.7.orig/zlib.h\t2012-05-03 06:12:35.000000000 +0200\n+++ zlib-1.2.7/zlib.h\t2012-09-27 13:12:58.187146312 +0200\n@@ -1329,7 +1329,11 @@\n error.\n */\n \n-ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...));\n+ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...))\n+#ifdef __GNUC__\n+\t__attribute__((__format__(__printf__,2,3)))\n+#endif\n+;\n /*\n Converts, formats, and writes the arguments to the compressed file under\n control of the format string, as in fprintf. gzprintf returns the number of\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From: meissner@suse.de\nSubject: supply format arguments to gzprintf().\n\nIndex: zlib-1.2.7/zlib.h\n===================================================================\n--- zlib-1.2.7.orig/zlib.h\t2012-05-03 06:12:35.000000000 +0200\n+++ zlib-1.2.7/zlib.h\t2012-09-27 13:12:58.187146312 +0200\n@@ -1329,7 +1329,11 @@\n error.\n */\n \n-ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...));\n+ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...))\n+#ifdef __GNUC__\n+\t__attribute__((__format__(__printf__,2,3)))\n+#endif\n+;\n /*\n Converts, formats, and writes the arguments to the compressed file under\n control of the format string, as in fprintf. gzprintf returns the number of" } ]
{ "id": "zlib-6007-zlib-format.patch", "cve_id": "CVE-2016-9840", "package": "zlib", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": false, "license": "Zlib", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-3119\n\nThe process_db_args function in plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c in the LDAP KDB module in kadmind in MIT Kerberos 5 (aka krb5) through 1.13.4 and 1.14.x through 1.14.1 mishandles the DB argument, which allows remote authenticated users to cause a denial of service (NULL pointer dereference and daemon crash) via a crafted request to modify a principal.\n\n## Package\nkrb5-mini\n\n## Files to modify\n- src/lib/gssapi/spnego/spnego_mech.c\n\n## Upstream Fix\n```diff\nFrom f18ddf5d82de0ab7591a36e465bc24225776940f Mon Sep 17 00:00:00 2001\nFrom: David Woodhouse <David.Woodhouse@intel.com>\nDate: Tue, 15 Jul 2014 12:54:15 -0400\nSubject: [PATCH] Fix double-free in SPNEGO [CVE-2014-4343]\n\nIn commit cd7d6b08 (\"Verify acceptor's mech in SPNEGO initiator\") the\npointer sc->internal_mech became an alias into sc->mech_set->elements,\nwhich should be considered constant for the duration of the SPNEGO\ncontext. So don't free it.\n\nCVE-2014-4343:\n\nIn MIT krb5 releases 1.10 and newer, an unauthenticated remote\nattacker with the ability to spoof packets appearing to be from a\nGSSAPI acceptor can cause a double-free condition in GSSAPI initiators\n(clients) which are using the SPNEGO mechanism, by returning a\ndifferent underlying mechanism than was proposed by the initiator. At\nthis stage of the negotiation, the acceptor is unauthenticated, and\nthe acceptor's response could be spoofed by an attacker with the\nability to inject traffic to the initiator.\n\nHistorically, some double-free vulnerabilities can be translated into\nremote code execution, though the necessary exploits must be tailored\nto the individual application and are usually quite\ncomplicated. Double-frees can also be exploited to cause an\napplication crash, for a denial of service. However, most GSSAPI\nclient applications are not vulnerable, as the SPNEGO mechanism is not\nused by default (when GSS_C_NO_OID is passed as the mech_type argument\nto gss_init_sec_context()). The most common use of SPNEGO is for\nHTTP-Negotiate, used in web browsers and other web clients. Most such\nclients are believed to not offer HTTP-Negotiate by default, instead\nrequiring a whitelist of sites for which it may be used to be\nconfigured. If the whitelist is configured to only allow\nHTTP-Negotiate over TLS connections (\"https://\"), a successful\nattacker must also spoof the web server's SSL certificate, due to the\nway the WWW-Authenticate header is sent in a 401 (Unauthorized)\nresponse message. Unfortunately, many instructions for enabling\nHTTP-Negotiate in common web browsers do not include a TLS\nrequirement.\n\n CVSSv2 Vector: AV:N/AC:H/Au:N/C:C/I:C/A:C/E:POC/RL:OF/RC:C\n\n[kaduk@mit.edu: CVE summary and CVSSv2 vector]\n\nticket: 7969 (new)\ntarget_version: 1.12.2\ntags: pullup\n---\n src/lib/gssapi/spnego/spnego_mech.c | 1 -\n 1 file changed, 1 deletion(-)\n\ndiff --git a/src/lib/gssapi/spnego/spnego_mech.c b/src/lib/gssapi/spnego/spnego_mech.c\nindex 173c6d2939a..8f829d8c592 100644\n--- a/src/lib/gssapi/spnego/spnego_mech.c\n+++ b/src/lib/gssapi/spnego/spnego_mech.c\n@@ -818,7 +818,6 @@ init_ctx_reselect(OM_uint32 *minor_status, spnego_gss_ctx_id_t sc,\n \tOM_uint32 tmpmin;\n \tsize_t i;\n \n-\tgeneric_gss_release_oid(&tmpmin, &sc->internal_mech);\n \tgss_delete_sec_context(&tmpmin, &sc->ctx_handle,\n \t\t\t GSS_C_NO_BUFFER);\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From f18ddf5d82de0ab7591a36e465bc24225776940f Mon Sep 17 00:00:00 2001\nFrom: David Woodhouse <David.Woodhouse@intel.com>\nDate: Tue, 15 Jul 2014 12:54:15 -0400\nSubject: [PATCH] Fix double-free in SPNEGO [CVE-2014-4343]\n\nIn commit cd7d6b08 (\"Verify acceptor's mech in SPNEGO initiator\") the\npointer sc->internal_mech became an alias into sc->mech_set->elements,\nwhich should be considered constant for the duration of the SPNEGO\ncontext. So don't free it.\n\nCVE-2014-4343:\n\nIn MIT krb5 releases 1.10 and newer, an unauthenticated remote\nattacker with the ability to spoof packets appearing to be from a\nGSSAPI acceptor can cause a double-free condition in GSSAPI initiators\n(clients) which are using the SPNEGO mechanism, by returning a\ndifferent underlying mechanism than was proposed by the initiator. At\nthis stage of the negotiation, the acceptor is unauthenticated, and\nthe acceptor's response could be spoofed by an attacker with the\nability to inject traffic to the initiator.\n\nHistorically, some double-free vulnerabilities can be translated into\nremote code execution, though the necessary exploits must be tailored\nto the individual application and are usually quite\ncomplicated. Double-frees can also be exploited to cause an\napplication crash, for a denial of service. However, most GSSAPI\nclient applications are not vulnerable, as the SPNEGO mechanism is not\nused by default (when GSS_C_NO_OID is passed as the mech_type argument\nto gss_init_sec_context()). The most common use of SPNEGO is for\nHTTP-Negotiate, used in web browsers and other web clients. Most such\nclients are believed to not offer HTTP-Negotiate by default, instead\nrequiring a whitelist of sites for which it may be used to be\nconfigured. If the whitelist is configured to only allow\nHTTP-Negotiate over TLS connections (\"https://\"), a successful\nattacker must also spoof the web server's SSL certificate, due to the\nway the WWW-Authenticate header is sent in a 401 (Unauthorized)\nresponse message. Unfortunately, many instructions for enabling\nHTTP-Negotiate in common web browsers do not include a TLS\nrequirement.\n\n CVSSv2 Vector: AV:N/AC:H/Au:N/C:C/I:C/A:C/E:POC/RL:OF/RC:C\n\n[kaduk@mit.edu: CVE summary and CVSSv2 vector]\n\nticket: 7969 (new)\ntarget_version: 1.12.2\ntags: pullup\n---\n src/lib/gssapi/spnego/spnego_mech.c | 1 -\n 1 file changed, 1 deletion(-)\n\ndiff --git a/src/lib/gssapi/spnego/spnego_mech.c b/src/lib/gssapi/spnego/spnego_mech.c\nindex 173c6d2..8f829d8 100644\n--- a/src/lib/gssapi/spnego/spnego_mech.c\n+++ b/src/lib/gssapi/spnego/spnego_mech.c\n@@ -818,7 +818,6 @@ init_ctx_reselect(OM_uint32 *minor_status, spnego_gss_ctx_id_t sc,\n \tOM_uint32 tmpmin;\n \tsize_t i;\n \n-\tgeneric_gss_release_oid(&tmpmin, &sc->internal_mech);\n \tgss_delete_sec_context(&tmpmin, &sc->ctx_handle,\n \t\t\t GSS_C_NO_BUFFER);\n \n-- \n1.9.3" } ]
{ "id": "krb5-mini-4938-krb5-1.12-CVE-2014-4343-Fix-do", "cve_id": "CVE-2016-3119", "package": "krb5-mini", "upstream_enriched": true, "upstream_commit": "f18ddf5d82de0ab7591a36e465bc24225776940f", "upstream_repo": "krb5/krb5", "tier": "adapted", "has_source_context": false, "license": "MIT", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-3706\n\nStack-based buffer overflow in the getaddrinfo function in sysdeps/posix/getaddrinfo.c in the GNU C Library (aka glibc or libc6) allows remote attackers to cause a denial of service (crash) via vectors involving hostent conversion. NOTE: this vulnerability exists because of an incomplete fix for CVE-2013-4458.\n\n## Package\nglibc-utils\n\n## Files to modify\n- resolv/res_init.c\n- glibc-2.19.orig/resolv/res_init.c\n\n## Target Source Code\n\n### resolv/res_init.c\n\n#### __res_iclose() [lines 598-627]\n```c\n * This routine is not expected to be user visible.\n */\nvoid\n__res_iclose(res_state statp, bool free_addr) {\n\tint ns;\n\n\tif (statp->_vcsock >= 0) {\n\t\tclose_not_cancel_no_status(statp->_vcsock);\n\t\tstatp->_vcsock = -1;\n\t\tstatp->_flags &= ~(RES_F_VC | RES_F_CONN);\n\t}\n#ifdef _LIBC\n\tfor (ns = 0; ns < MAXNS; ns++)\n#else\n\tfor (ns = 0; ns < statp->_u._ext.nscount; ns++)\n#endif\n\t\tif (statp->_u._ext.nsaddrs[ns]) {\n\t\t\tif (statp->_u._ext.nssocks[ns] != -1) {\n\t\t\t\tclose_not_cancel_no_status(statp->_u._ext.nssocks[ns]);\n\t\t\t\tstatp->_u._ext.nssocks[ns] = -1;\n\t\t\t}\n\t\t\tif (free_addr) {\n\t\t\t\tfree (statp->_u._ext.nsaddrs[ns]);\n\t\t\t\tstatp->_u._ext.nsaddrs[ns] = NULL;\n\t\t\t}\n\t\t}\n\tstatp->_u._ext.nsinit = 0;\n}\nlibc_hidden_def (__res_iclose)\n\n```\n\n\n## Upstream Fix\n```diff\nFix resource leak in resolver (bug 19257)\n\n\t* resolv/res_init.c (__res_iclose): Use statp->nscount instead of\n\tstatp->_u._ext.nscount as loop count.\n---\n resolv/res_init.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\nIndex: glibc-2.19/resolv/res_init.c\n===================================================================\n--- glibc-2.19.orig/resolv/res_init.c\n+++ glibc-2.19/resolv/res_init.c\n@@ -593,7 +593,7 @@ __res_iclose(res_state statp, bool free_\n \t\tstatp->_vcsock = -1;\n \t\tstatp->_flags &= ~(RES_F_VC | RES_F_CONN);\n \t}\n-\tfor (ns = 0; ns < statp->_u._ext.nscount; ns++)\n+\tfor (ns = 0; ns < statp->nscount; ns++)\n \t\tif (statp->_u._ext.nsaddrs[ns]) {\n \t\t\tif (statp->_u._ext.nssocks[ns] != -1) {\n \t\t\t\tclose_not_cancel_no_status(statp->_u._ext.nssocks[ns]);\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "Fix resource leak in resolver (bug 19257)\n\n\t* resolv/res_init.c (__res_iclose): Use statp->nscount instead of\n\tstatp->_u._ext.nscount as loop count.\n---\n resolv/res_init.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\nIndex: glibc-2.19/resolv/res_init.c\n===================================================================\n--- glibc-2.19.orig/resolv/res_init.c\n+++ glibc-2.19/resolv/res_init.c\n@@ -593,7 +593,7 @@ __res_iclose(res_state statp, bool free_\n \t\tstatp->_vcsock = -1;\n \t\tstatp->_flags &= ~(RES_F_VC | RES_F_CONN);\n \t}\n-\tfor (ns = 0; ns < statp->_u._ext.nscount; ns++)\n+\tfor (ns = 0; ns < statp->nscount; ns++)\n \t\tif (statp->_u._ext.nsaddrs[ns]) {\n \t\t\tif (statp->_u._ext.nssocks[ns] != -1) {\n \t\t\t\tclose_not_cancel_no_status(statp->_u._ext.nssocks[ns]);" } ]
{ "id": "glibc-utils-5322-resolv-mem-leak.patch", "cve_id": "CVE-2016-3706", "package": "glibc-utils", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 197, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2012-1180\n\nUse-after-free vulnerability in nginx before 1.0.14 and 1.1.x before 1.1.17 allows remote HTTP servers to obtain sensitive information from process memory via a crafted backend response, in conjunction with a client request.\n\n## Package\nnginx-1\n\n## Files to modify\n- src/http/modules/ngx_http_scgi_module.c\n- src/http/modules/ngx_http_proxy_module.c\n- src/http/modules/ngx_http_fastcgi_module.c\n- src/http/modules/ngx_http_uwsgi_module.c\n- src/http/ngx_http_parse.c\n\n## Upstream Fix\n```diff\n--- src/http/modules/ngx_http_fastcgi_module.c\n+++ src/http/modules/ngx_http_fastcgi_module.c\n@@ -1442,10 +1442,10 @@\n h->lowcase_key = h->key.data + h->key.len + 1\n + h->value.len + 1;\n \n- ngx_cpystrn(h->key.data, r->header_name_start,\n- h->key.len + 1);\n- ngx_cpystrn(h->value.data, r->header_start,\n- h->value.len + 1);\n+ ngx_memcpy(h->key.data, r->header_name_start, h->key.len);\n+ h->key.data[h->key.len] = '\\0';\n+ ngx_memcpy(h->value.data, r->header_start, h->value.len);\n+ h->value.data[h->value.len] = '\\0';\n }\n \n h->hash = r->header_hash;\n--- src/http/modules/ngx_http_proxy_module.c\n+++ src/http/modules/ngx_http_proxy_module.c\n@@ -1277,8 +1277,10 @@\n h->value.data = h->key.data + h->key.len + 1;\n h->lowcase_key = h->key.data + h->key.len + 1 + h->value.len + 1;\n \n- ngx_cpystrn(h->key.data, r->header_name_start, h->key.len + 1);\n- ngx_cpystrn(h->value.data, r->header_start, h->value.len + 1);\n+ ngx_memcpy(h->key.data, r->header_name_start, h->key.len);\n+ h->key.data[h->key.len] = '\\0';\n+ ngx_memcpy(h->value.data, r->header_start, h->value.len);\n+ h->value.data[h->value.len] = '\\0';\n \n if (h->key.len == r->lowcase_index) {\n ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len);\n--- src/http/modules/ngx_http_scgi_module.c\n+++ src/http/modules/ngx_http_scgi_module.c\n@@ -894,8 +894,10 @@\n h->value.data = h->key.data + h->key.len + 1;\n h->lowcase_key = h->key.data + h->key.len + 1 + h->value.len + 1;\n \n- ngx_cpystrn(h->key.data, r->header_name_start, h->key.len + 1);\n- ngx_cpystrn(h->value.data, r->header_start, h->value.len + 1);\n+ ngx_memcpy(h->key.data, r->header_name_start, h->key.len);\n+ h->key.data[h->key.len] = '\\0';\n+ ngx_memcpy(h->value.data, r->header_start, h->value.len);\n+ h->value.data[h->value.len] = '\\0';\n \n if (h->key.len == r->lowcase_index) {\n ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len);\n--- src/http/modules/ngx_http_uwsgi_module.c\n+++ src/http/modules/ngx_http_uwsgi_module.c\n@@ -944,8 +944,10 @@\n h->value.data = h->key.data + h->key.len + 1;\n h->lowcase_key = h->key.data + h->key.len + 1 + h->value.len + 1;\n \n- ngx_cpystrn(h->key.data, r->header_name_start, h->key.len + 1);\n- ngx_cpystrn(h->value.data, r->header_start, h->value.len + 1);\n+ ngx_memcpy(h->key.data, r->header_name_start, h->key.len);\n+ h->key.data[h->key.len] = '\\0';\n+ ngx_memcpy(h->value.data, r->header_start, h->value.len);\n+ h->value.data[h->value.len] = '\\0';\n \n if (h->key.len == r->lowcase_index) {\n ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len);\n--- src/http/ngx_http_parse.c\n+++ src/http/ngx_http_parse.c\n@@ -813,6 +813,10 @@\n break;\n }\n \n+ if (ch == '\\0') {\n+ return NGX_HTTP_PARSE_INVALID_HEADER;\n+ }\n+\n r->invalid_header = 1;\n \n break;\n@@ -875,6 +879,10 @@\n break;\n }\n \n+ if (ch == '\\0') {\n+ return NGX_HTTP_PARSE_INVALID_HEADER;\n+ }\n+\n r->invalid_header = 1;\n \n break;\n@@ -893,6 +901,8 @@\n r->header_start = p;\n r->header_end = p;\n goto done;\n+ case '\\0':\n+ return NGX_HTTP_PARSE_INVALID_HEADER;\n default:\n r->header_start = p;\n state = sw_value;\n@@ -914,6 +924,8 @@\n case LF:\n r->header_end = p;\n goto done;\n+ case '\\0':\n+ return NGX_HTTP_PARSE_INVALID_HEADER;\n }\n break;\n \n@@ -927,6 +939,8 @@\n break;\n case LF:\n goto done;\n+ case '\\0':\n+ return NGX_HTTP_PARSE_INVALID_HEADER;\n default:\n state = sw_value;\n break;\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "--- src/http/modules/ngx_http_fastcgi_module.c\n+++ src/http/modules/ngx_http_fastcgi_module.c\n@@ -1442,10 +1442,10 @@\n h->lowcase_key = h->key.data + h->key.len + 1\n + h->value.len + 1;\n \n- ngx_cpystrn(h->key.data, r->header_name_start,\n- h->key.len + 1);\n- ngx_cpystrn(h->value.data, r->header_start,\n- h->value.len + 1);\n+ ngx_memcpy(h->key.data, r->header_name_start, h->key.len);\n+ h->key.data[h->key.len] = '\\0';\n+ ngx_memcpy(h->value.data, r->header_start, h->value.len);\n+ h->value.data[h->value.len] = '\\0';\n }\n \n h->hash = r->header_hash;\n--- src/http/modules/ngx_http_proxy_module.c\n+++ src/http/modules/ngx_http_proxy_module.c\n@@ -1277,8 +1277,10 @@\n h->value.data = h->key.data + h->key.len + 1;\n h->lowcase_key = h->key.data + h->key.len + 1 + h->value.len + 1;\n \n- ngx_cpystrn(h->key.data, r->header_name_start, h->key.len + 1);\n- ngx_cpystrn(h->value.data, r->header_start, h->value.len + 1);\n+ ngx_memcpy(h->key.data, r->header_name_start, h->key.len);\n+ h->key.data[h->key.len] = '\\0';\n+ ngx_memcpy(h->value.data, r->header_start, h->value.len);\n+ h->value.data[h->value.len] = '\\0';\n \n if (h->key.len == r->lowcase_index) {\n ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len);\n--- src/http/modules/ngx_http_scgi_module.c\n+++ src/http/modules/ngx_http_scgi_module.c\n@@ -894,8 +894,10 @@\n h->value.data = h->key.data + h->key.len + 1;\n h->lowcase_key = h->key.data + h->key.len + 1 + h->value.len + 1;\n \n- ngx_cpystrn(h->key.data, r->header_name_start, h->key.len + 1);\n- ngx_cpystrn(h->value.data, r->header_start, h->value.len + 1);\n+ ngx_memcpy(h->key.data, r->header_name_start, h->key.len);\n+ h->key.data[h->key.len] = '\\0';\n+ ngx_memcpy(h->value.data, r->header_start, h->value.len);\n+ h->value.data[h->value.len] = '\\0';\n \n if (h->key.len == r->lowcase_index) {\n ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len);\n--- src/http/modules/ngx_http_uwsgi_module.c\n+++ src/http/modules/ngx_http_uwsgi_module.c\n@@ -944,8 +944,10 @@\n h->value.data = h->key.data + h->key.len + 1;\n h->lowcase_key = h->key.data + h->key.len + 1 + h->value.len + 1;\n \n- ngx_cpystrn(h->key.data, r->header_name_start, h->key.len + 1);\n- ngx_cpystrn(h->value.data, r->header_start, h->value.len + 1);\n+ ngx_memcpy(h->key.data, r->header_name_start, h->key.len);\n+ h->key.data[h->key.len] = '\\0';\n+ ngx_memcpy(h->value.data, r->header_start, h->value.len);\n+ h->value.data[h->value.len] = '\\0';\n \n if (h->key.len == r->lowcase_index) {\n ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len);\n--- src/http/ngx_http_parse.c\n+++ src/http/ngx_http_parse.c\n@@ -813,6 +813,10 @@\n break;\n }\n \n+ if (ch == '\\0') {\n+ return NGX_HTTP_PARSE_INVALID_HEADER;\n+ }\n+\n r->invalid_header = 1;\n \n break;\n@@ -875,6 +879,10 @@\n break;\n }\n \n+ if (ch == '\\0') {\n+ return NGX_HTTP_PARSE_INVALID_HEADER;\n+ }\n+\n r->invalid_header = 1;\n \n break;\n@@ -893,6 +901,8 @@\n r->header_start = p;\n r->header_end = p;\n goto done;\n+ case '\\0':\n+ return NGX_HTTP_PARSE_INVALID_HEADER;\n default:\n r->header_start = p;\n state = sw_value;\n@@ -914,6 +924,8 @@\n case LF:\n r->header_end = p;\n goto done;\n+ case '\\0':\n+ return NGX_HTTP_PARSE_INVALID_HEADER;\n }\n break;\n \n@@ -927,6 +939,8 @@\n break;\n case LF:\n goto done;\n+ case '\\0':\n+ return NGX_HTTP_PARSE_INVALID_HEADER;\n default:\n state = sw_value;\n break;" } ]
{ "id": "nginx-1-387-nginx-CVE-2012-1180.patch", "cve_id": "CVE-2012-1180", "package": "nginx-1", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": false, "license": "BSD-2-Clause", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2014-8564\n\nThe _gnutls_ecc_ansi_x963_export function in gnutls_ecc.c in GnuTLS 3.x before 3.1.28, 3.2.x before 3.2.20, and 3.3.x before 3.3.10 allows remote attackers to cause a denial of service (out-of-bounds write) via a crafted (1) Elliptic Curve Cryptography (ECC) certificate or (2) certificate signing requests (CSR), related to generating key IDs.\n\n## Package\ngnutls\n\n## Files to modify\n- gnutls-3.2.18.orig/lib/x509/x509.c\n- lib/x509/x509.c\n\n## Target Source Code\n\n### lib/x509/x509.c\n\n#### gnutls_x509_crt_import() [lines 155-255]\n```c\n * negative error value.\n **/\nint\ngnutls_x509_crt_import(gnutls_x509_crt_t cert,\n\t\t const gnutls_datum_t * data,\n\t\t gnutls_x509_crt_fmt_t format)\n{\n\tint result = 0;\n\n\tif (cert == NULL) {\n\t\tgnutls_assert();\n\t\treturn GNUTLS_E_INVALID_REQUEST;\n\t}\n\n\tif (cert->der.data) {\n\t\tgnutls_free(cert->der.data);\n\t\tcert->der.data = NULL;\n\t}\n\n\t/* If the Certificate is in PEM format then decode it\n\t */\n\tif (format == GNUTLS_X509_FMT_PEM) {\n\t\t/* Try the first header */\n\t\tresult =\n\t\t _gnutls_fbase64_decode(PEM_X509_CERT2, data->data,\n\t\t\t\t\t data->size, &cert->der);\n\n\t\tif (result <= 0) {\n\t\t\t/* try for the second header */\n\t\t\tresult =\n\t\t\t _gnutls_fbase64_decode(PEM_X509_CERT,\n\t\t\t\t\t\t data->data, data->size,\n\t\t\t\t\t\t &cert->der);\n\n\t\t\tif (result < 0) {\n\t\t\t\tgnutls_assert();\n\t\t\t\treturn result;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tresult = _gnutls_set_datum(&cert->der, data->data, data->size);\n\t\tif (result < 0) {\n\t\t\tgnutls_assert();\n\t\t\treturn result;\n\t\t}\n\t}\n\n\tif (cert->expanded) {\n\t\t/* Any earlier asn1_der_decoding will modify the ASN.1\n\t\t structure, so we need to replace it with a fresh\n\t\t structure. */\n\t\tasn1_delete_structure(&cert->cert);\n\n\t\tresult = asn1_create_element(_gnutls_get_pkix(),\n\t\t\t\t\t \"PKIX1.Certificate\",\n\t\t\t\t\t &cert->cert);\n\t\tif (result != ASN1_SUCCESS) {\n\t\t\tresult = _gnutls_asn2err(result);\n\t\t\tgnutls_assert();\n\t\t\tgoto cleanup;\n\t\t}\n\t}\n\n\tresult =\n\t asn1_der_decoding(&cert->cert, cert->der.data, cert->der.size, NULL);\n\tif (result != ASN1_SUCCESS) {\n\t\tresult = _gnutls_asn2err(result);\n\t\tgnutls_assert();\n\t\tgoto cleanup;\n\t}\n\n\tresult = _gnutls_x509_get_raw_dn2(cert->cert, &cert->der,\n\t\t\t\t\t \"tbsCertificate.issuer.rdnSequence\",\n\t\t\t\t\t &cert->raw_issuer_dn);\n\tif (result < 0) {\n\t\tgnutls_assert();\n\t\tgoto cleanup;\n\t}\n\n\tresult = _gnutls_x509_get_raw_dn2(cert->cert, &cert->der,\n\t\t\t\t\t \"tbsCertificate.subject.rdnSequence\",\n\t\t\t\t\t &cert->raw_dn);\n\tif (result < 0) {\n\t\tgnutls_assert();\n\t\tgoto cleanup;\n\t}\n\n\tcert->expanded = 1;\n\n\t/* Since we do not want to disable any extension\n\t */\n\tcert->use_extensions = 1;\n\n\treturn 0;\n\n cleanup:\n\t_gnutls_free_datum(&cert->der);\n\treturn result;\n}\n\n\n```\n\n\n## Upstream Fix\n```diff\nFrom 6e76e9b9fa845b76b0b9a45f05f4b54a052578ff Mon Sep 17 00:00:00 2001\nFrom: Nikos Mavrogiannopoulos <nmav@redhat.com>\nDate: Mon, 19 Jan 2015 09:29:31 +0100\nSubject: [PATCH] on certificate import check whether the two signature\n algorithms match\n\n---\n lib/x509/x509.c | 19 ++++++++++++++++++-\n 1 file changed, 18 insertions(+), 1 deletion(-)\n\ndiff --git a/lib/x509/x509.c b/lib/x509/x509.c\nindex a06cca12e8..5dcde4bc0d 100644\n--- a/lib/x509/x509.c\n+++ b/lib/x509/x509.c\n@@ -186,7 +186,7 @@ gnutls_x509_crt_import(gnutls_x509_crt_t cert,\n \t\t gnutls_x509_crt_fmt_t format)\n {\n \tint result = 0;\n-\tint version;\n+\tint version, s2;\n \n \tif (cert == NULL) {\n \t\tgnutls_assert();\n@@ -247,6 +247,23 @@ gnutls_x509_crt_import(gnutls_x509_crt_t cert,\n \t\tgoto cleanup;\n \t}\n \n+\tresult = _gnutls_x509_get_signature_algorithm(cert->cert,\n+\t\t\t\t\t\t \"signatureAlgorithm.algorithm\");\n+\tif (result < 0) {\n+\t\tgnutls_assert();\n+\t\tgoto cleanup;\n+\t}\n+\n+\ts2 = _gnutls_x509_get_signature_algorithm(cert->cert,\n+\t\t\t\t\t\t \"tbsCertificate.signature.algorithm\");\n+\tif (result != s2) {\n+\t\t_gnutls_debug_log(\"signatureAlgorithm.algorithm differs from tbsCertificate.signature.algorithm: %s, %s\\n\",\n+\t\t\tgnutls_sign_get_name(result), gnutls_sign_get_name(s2));\n+\t\tgnutls_assert();\n+\t\tresult = GNUTLS_E_CERTIFICATE_ERROR;\n+\t\tgoto cleanup;\n+\t}\n+\n \tresult = _gnutls_x509_get_raw_field2(cert->cert, &cert->der,\n \t\t\t\t\t \"tbsCertificate.issuer.rdnSequence\",\n \t\t\t\t\t &cert->raw_issuer_dn);\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 6e76e9b9fa845b76b0b9a45f05f4b54a052578ff Mon Sep 17 00:00:00 2001\nFrom: Nikos Mavrogiannopoulos <nmav@redhat.com>\nDate: Mon, 19 Jan 2015 09:29:31 +0100\nSubject: [PATCH] on certificate import check whether the two signature algorithms match\n\n---\n lib/x509/x509.c | 19 ++++++++++++++++++-\n 1 files changed, 18 insertions(+), 1 deletions(-)\n\nIndex: gnutls-3.2.18/lib/x509/x509.c\n===================================================================\n--- gnutls-3.2.18.orig/lib/x509/x509.c\t2015-03-20 19:00:25.750775199 +0100\n+++ gnutls-3.2.18/lib/x509/x509.c\t2015-03-20 19:23:35.730665213 +0100\n@@ -160,6 +160,7 @@ gnutls_x509_crt_import(gnutls_x509_crt_t\n \t\t gnutls_x509_crt_fmt_t format)\n {\n \tint result = 0;\n+\tint s2;\n \n \tif (cert == NULL) {\n \t\tgnutls_assert();\n@@ -223,6 +224,23 @@ gnutls_x509_crt_import(gnutls_x509_crt_t\n \t\tgoto cleanup;\n \t}\n \n+\tresult = _gnutls_x509_get_signature_algorithm(cert->cert,\n+\t\t\t\t\t\t \"signatureAlgorithm.algorithm\");\n+\tif (result < 0) {\n+\t\tgnutls_assert();\n+\t\tgoto cleanup;\n+\t}\n+\n+\ts2 = _gnutls_x509_get_signature_algorithm(cert->cert,\n+\t\t\t\t\t\t \"tbsCertificate.signature.algorithm\");\n+\tif (result != s2) {\n+\t\t_gnutls_debug_log(\"signatureAlgorithm.algorithm differs from tbsCertificate.signature.algorithm: %s, %s\\n\",\n+\t\t\tgnutls_sign_get_name(result), gnutls_sign_get_name(s2));\n+\t\tgnutls_assert();\n+\t\tresult = GNUTLS_E_CERTIFICATE_ERROR;\n+\t\tgoto cleanup;\n+\t}\n+\n \tresult = _gnutls_x509_get_raw_dn2(cert->cert, &cert->der,\n \t\t\t\t\t \"tbsCertificate.issuer.rdnSequence\",\n \t\t\t\t\t &cert->raw_issuer_dn);" } ]
{ "id": "gnutls-3193-gnutls-CVE-2015-0294.patch", "cve_id": "CVE-2014-8564", "package": "gnutls", "upstream_enriched": true, "upstream_commit": "6e76e9b9fa845b76b0b9a45f05f4b54a052578ff", "upstream_repo": "gnutls/gnutls", "tier": "adapted", "has_source_context": true, "license": "GPL-3.0-or-later AND LGPL-2.1-or-later", "context_tokens_est": 548, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2013-4288\n\nRace condition in PolicyKit (aka polkit) allows local users to bypass intended PolicyKit restrictions and gain privileges by starting a setuid or pkexec process before the authorization check is performed, related to (1) the polkit_unix_process_new API function, (2) the dbus API, or (3) the --process (unix-process) option for authorization to pkcheck.\n\n## Package\nsystemd-mini\n\n## Files to modify\n- src/cryptsetup/cryptsetup.c\n\n## Upstream Fix\n```diff\nFrom adc40dc2f670a6298cce918fb318ba6a4b80c306 Mon Sep 17 00:00:00 2001\nFrom: Tom Gundersen <teg@jklm.no>\nDate: Wed, 21 Nov 2012 12:30:47 +0100\nSubject: [PATCH] cryptsetup: fix nofail support\n\nThis was documented in the man page and supported in the generator,\nbut systemd-cryptestup itself would fail with this option.\n\nsystemd-cryptsetup should ignore 'nofail', as it does with 'noauto'.\n---\n src/cryptsetup/cryptsetup.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c\nindex 56a3b50974671..f33284370c0d7 100644\n--- a/src/cryptsetup/cryptsetup.c\n+++ b/src/cryptsetup/cryptsetup.c\n@@ -62,7 +62,7 @@ static int parse_one_option(const char *option) {\n assert(option);\n \n /* Handled outside of this tool */\n- if (streq(option, \"noauto\"))\n+ if (streq(option, \"noauto\") || streq(option, \"nofail\"))\n return 0;\n \n if (startswith(option, \"cipher=\")) {\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From adc40dc2f670a6298cce918fb318ba6a4b80c306 Mon Sep 17 00:00:00 2001\nFrom: Tom Gundersen <teg@jklm.no>\nDate: Wed, 21 Nov 2012 12:30:47 +0100\nSubject: [PATCH] cryptsetup: fix nofail support\n\nThis was documented in the man page and supported in the generator,\nbut systemd-cryptestup itself would fail with this option.\n\nsystemd-cryptsetup should ignore 'nofail', as it does with 'noauto'.\n---\n src/cryptsetup/cryptsetup.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c\nindex 56a3b50..f332843 100644\n--- a/src/cryptsetup/cryptsetup.c\n+++ b/src/cryptsetup/cryptsetup.c\n@@ -62,7 +62,7 @@ static int parse_one_option(const char *option) {\n assert(option);\n \n /* Handled outside of this tool */\n- if (streq(option, \"noauto\"))\n+ if (streq(option, \"noauto\") || streq(option, \"nofail\"))\n return 0;\n \n if (startswith(option, \"cipher=\")) {\n-- \n1.7.10.4" } ]
{ "id": "systemd-mini-2025-crypsetup-handle-nofail.patch", "cve_id": "CVE-2013-4288", "package": "systemd-mini", "upstream_enriched": true, "upstream_commit": "adc40dc2f670a6298cce918fb318ba6a4b80c306", "upstream_repo": "systemd/systemd", "tier": "adapted", "has_source_context": false, "license": "LGPL-2.1-or-later", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-2698\n\nThe iakerb_gss_export_sec_context function in lib/gssapi/krb5/iakerb.c in MIT Kerberos 5 (aka krb5) 1.14 pre-release 2015-09-14 improperly accesses a certain pointer, which allows remote authenticated users to cause a denial of service (memory corruption) or possibly have unspecified other impact by interacting with an application that calls the gss_export_sec_context function. NOTE: this vulnerability exists because of an incorrect fix for CVE-2015-2696.\n\n## Package\nkrb5-mini\n\n## Files to modify\n- src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c\n\n## Upstream Fix\n```diff\nFrom d1f707024f1d0af6e54a18885322d70fa15ec4d3 Mon Sep 17 00:00:00 2001\nFrom: Greg Hudson <ghudson@mit.edu>\nDate: Fri, 5 Dec 2014 14:01:39 -0500\nSubject: [PATCH] Fix LDAP misused policy name crash [CVE-2014-5353]\n\nIn krb5_ldap_get_password_policy_from_dn, if LDAP_SEARCH returns\nsuccessfully with no results, return KRB5_KDB_NOENTRY instead of\nreturning success with a zeroed-out policy object. This fixes a null\ndereference when an admin attempts to use an LDAP ticket policy name\nas a password policy name.\n\nCVE-2014-5353:\n\nIn MIT krb5, when kadmind is configured to use LDAP for the KDC\ndatabase, an authenticated remote attacker can cause a NULL dereference\nby attempting to use a named ticket policy object as a password policy\nfor a principal. The attacker needs to be authenticated as a user who\nhas the elevated privilege for setting password policy by adding or\nmodifying principals.\n\nQueries to LDAP scoped to the krbPwdPolicy object class will correctly\nnot return entries of other classes, such as ticket policy objects, but\nmay return success with no returned elements if an object with the\nrequested DN exists in a different object class. In this case, the\nroutine to retrieve a password policy returned success with a password\npolicy object that consisted entirely of zeroed memory. In particular,\naccesses to the policy name will dereference a NULL pointer. KDC\noperation does not access the policy name field, but most kadmin\noperations involving the principal with incorrect password policy\nwill trigger the crash.\n\nThanks to Patrik Kis for reporting this problem.\n\nCVSSv2 Vector: AV:N/AC:M/Au:S/C:N/I:N/A:C/E:H/RL:OF/RC:C\n\n[kaduk@mit.edu: CVE description and CVSS score]\n\nticket: 8051 (new)\ntarget_version: 1.13.1\ntags: pullup\n---\n src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c b/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c\nindex 522773e95b9..6779f51c7bf 100644\n--- a/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c\n+++ b/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c\n@@ -314,10 +314,11 @@ krb5_ldap_get_password_policy_from_dn(krb5_context context, char *pol_name,\n LDAP_SEARCH(pol_dn, LDAP_SCOPE_BASE, \"(objectclass=krbPwdPolicy)\", password_policy_attributes);\n \n ent=ldap_first_entry(ld, result);\n- if (ent != NULL) {\n- if ((st = populate_policy(context, ld, ent, pol_name, *policy)) != 0)\n- goto cleanup;\n+ if (ent == NULL) {\n+ st = KRB5_KDB_NOENTRY;\n+ goto cleanup;\n }\n+ st = populate_policy(context, ld, ent, pol_name, *policy);\n \n cleanup:\n ldap_msgfree(result);\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From d1f707024f1d0af6e54a18885322d70fa15ec4d3 Mon Sep 17 00:00:00 2001\nFrom: Greg Hudson <ghudson@mit.edu>\nDate: Fri, 5 Dec 2014 14:01:39 -0500\nSubject: [PATCH] Fix LDAP misused policy name crash [CVE-2014-5353]\n\nIn krb5_ldap_get_password_policy_from_dn, if LDAP_SEARCH returns\nsuccessfully with no results, return KRB5_KDB_NOENTRY instead of\nreturning success with a zeroed-out policy object. This fixes a null\ndereference when an admin attempts to use an LDAP ticket policy name\nas a password policy name.\n\nCVE-2014-5353:\n\nIn MIT krb5, when kadmind is configured to use LDAP for the KDC\ndatabase, an authenticated remote attacker can cause a NULL dereference\nby attempting to use a named ticket policy object as a password policy\nfor a principal. The attacker needs to be authenticated as a user who\nhas the elevated privilege for setting password policy by adding or\nmodifying principals.\n\nQueries to LDAP scoped to the krbPwdPolicy object class will correctly\nnot return entries of other classes, such as ticket policy objects, but\nmay return success with no returned elements if an object with the\nrequested DN exists in a different object class. In this case, the\nroutine to retrieve a password policy returned success with a password\npolicy object that consisted entirely of zeroed memory. In particular,\naccesses to the policy name will dereference a NULL pointer. KDC\noperation does not access the policy name field, but most kadmin\noperations involving the principal with incorrect password policy\nwill trigger the crash.\n\nThanks to Patrik Kis for reporting this problem.\n\nCVSSv2 Vector: AV:N/AC:M/Au:S/C:N/I:N/A:C/E:H/RL:OF/RC:C\n\n[kaduk@mit.edu: CVE description and CVSS score]\n\nticket: 8051 (new)\ntarget_version: 1.13.1\ntags: pullup\n---\n src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c b/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c\nindex 522773e..6779f51 100644\n--- a/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c\n+++ b/src/plugins/kdb/ldap/libkdb_ldap/ldap_pwd_policy.c\n@@ -314,10 +314,11 @@ krb5_ldap_get_password_policy_from_dn(krb5_context context, char *pol_name,\n LDAP_SEARCH(pol_dn, LDAP_SCOPE_BASE, \"(objectclass=krbPwdPolicy)\", password_policy_attributes);\n \n ent=ldap_first_entry(ld, result);\n- if (ent != NULL) {\n- if ((st = populate_policy(context, ld, ent, pol_name, *policy)) != 0)\n- goto cleanup;\n+ if (ent == NULL) {\n+ st = KRB5_KDB_NOENTRY;\n+ goto cleanup;\n }\n+ st = populate_policy(context, ld, ent, pol_name, *policy);\n \n cleanup:\n ldap_msgfree(result);" } ]
{ "id": "krb5-mini-4431-krb5-1.12.2-CVE-2014-5353.patc", "cve_id": "CVE-2015-2698", "package": "krb5-mini", "upstream_enriched": true, "upstream_commit": "d1f707024f1d0af6e54a18885322d70fa15ec4d3", "upstream_repo": "krb5/krb5", "tier": "adapted", "has_source_context": false, "license": "MIT", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-3190\n\nThe fill_xrgb32_lerp_opaque_spans function in cairo-image-compositor.c in cairo before 1.14.2 allows remote attackers to cause a denial of service (out-of-bounds read and application crash) via a negative span length.\n\n## Package\ncairo\n\n## Files to modify\n- src/cairo-pen.c\n\n## Upstream Fix\n```diff\ndiff --git a/src/cairo-pen.c b/src/cairo-pen.c\nindex 61be0e8..8eed775 100644\n--- a/src/cairo-pen.c\n+++ b/src/cairo-pen.c\n@@ -284,7 +284,20 @@ _cairo_pen_vertices_needed (double\t tolerance,\n \t\t\t\t\t\t\t\t radius);\n int num_vertices;\n \n- if (tolerance >= 4*major_axis) { /* XXX relaxed from 2*major for inkscape */\n+ if (tolerance >= 100*major_axis) { /* XXX relaxed from 2*major for inkscape */\n+\t/*\n+ * When we decide for num_vertices = 1, the object is not drawn.\n+\t * To avoid https://bugs.freedesktop.org/show_bug.cgi?id=77298\n+\t * we use 100*major -- this just helps us to the 0.001mm line width.\n+\t *\n+\t * The author of the 'XXX relaxed' comment above, originally used 4*major,\n+\t * which is not sufficient for my inkscape lasercutter usecase.\n+\t *\n+\t * Please double check if num_vertices == 1 should never be done (for PDF).\n+\t *\n+\t * jnweiger@gmail.com\n+\t */\n+\t// fprintf(stderr, \"tolerance=%g major_axis=%g -> num_vertices = 1\\n\", tolerance, major_axis);\n \tnum_vertices = 1;\n } else if (tolerance >= major_axis) {\n \tnum_vertices = 4;\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "diff --git a/src/cairo-pen.c b/src/cairo-pen.c\nindex 61be0e8..8eed775 100644\n--- a/src/cairo-pen.c\n+++ b/src/cairo-pen.c\n@@ -284,7 +284,20 @@ _cairo_pen_vertices_needed (double\t tolerance,\n \t\t\t\t\t\t\t\t radius);\n int num_vertices;\n \n- if (tolerance >= 4*major_axis) { /* XXX relaxed from 2*major for inkscape */\n+ if (tolerance >= 100*major_axis) { /* XXX relaxed from 2*major for inkscape */\n+\t/*\n+ * When we decide for num_vertices = 1, the object is not drawn.\n+\t * To avoid https://bugs.freedesktop.org/show_bug.cgi?id=77298\n+\t * we use 100*major -- this just helps us to the 0.001mm line width.\n+\t *\n+\t * The author of the 'XXX relaxed' comment above, originally used 4*major,\n+\t * which is not sufficient for my inkscape lasercutter usecase.\n+\t *\n+\t * Please double check if num_vertices == 1 should never be done (for PDF).\n+\t *\n+\t * jnweiger@gmail.com\n+\t */\n+\t// fprintf(stderr, \"tolerance=%g major_axis=%g -> num_vertices = 1\\n\", tolerance, major_axis);\n \tnum_vertices = 1;\n } else if (tolerance >= major_axis) {\n \tnum_vertices = 4;" } ]
{ "id": "cairo-4912-cairo-render-thin-lines.patch", "cve_id": "CVE-2016-3190", "package": "cairo", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": false, "license": "LGPL-2.1-or-later OR MPL-1.1", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-0777\n\nThe resend_bytes function in roaming_common.c in the client in OpenSSH 5.x, 6.x, and 7.x before 7.1p2 allows remote servers to obtain sensitive information from process memory by requesting transmission of an entire buffer, as demonstrated by reading a private key.\n\n## Package\nopenssh-askpass-gnome\n\n## Files to modify\n- openssh-6.6p1/monitor_wrap.c\n- openssh-6.6p1/sshd.c\n- openssh-6.6p1/audit.c\n- openssh-6.6p1/audit.h\n- openssh-6.6p1/audit-bsm.c\n\n## Upstream Fix\n```diff\n# HG changeset patch\n# Parent 78384019c3a49ad8d87367715674539c3f58798a\n# server key destruction and auditing\n# based on:\n# https://bugzilla.mindrot.org/show_bug.cgi?id=1402\n# https://bugzilla.mindrot.org/attachment.cgi?id=2015\n# by jchadima@redhat.com\n\ndiff --git a/openssh-6.6p1/audit-bsm.c b/openssh-6.6p1/audit-bsm.c\n--- a/openssh-6.6p1/audit-bsm.c\n+++ b/openssh-6.6p1/audit-bsm.c\n@@ -486,9 +486,27 @@ audit_kex_body(int ctos, char *enc, char\n \t/* not implemented */\n }\n \n void\n audit_session_key_free_body(int ctos, pid_t pid, uid_t uid)\n {\n \t/* not implemented */\n }\n+\n+void\n+audit_destroy_sensitive_data(const char *fp)\n+{\n+\t/* not implemented */\n+}\n+\n+void\n+audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)\n+{\n+\t/* not implemented */\n+}\n+\n+void\n+audit_generate_ephemeral_server_key(const char *fp)\n+{\n+\t/* not implemented */\n+}\n #endif /* BSM */\ndiff --git a/openssh-6.6p1/audit-linux.c b/openssh-6.6p1/audit-linux.c\n--- a/openssh-6.6p1/audit-linux.c\n+++ b/openssh-6.6p1/audit-linux.c\n@@ -351,9 +351,53 @@ audit_session_key_free_body(int ctos, pi\n \taudit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,\n \t\t\tbuf, NULL, get_remote_ipaddr(), NULL, 1);\n \taudit_close(audit_fd);\n \t/* do not abort if the error is EPERM and sshd is run as non root user */\n \tif ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))\n \t\terror(\"cannot write into audit\");\n }\n \n+void\n+audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)\n+{\n+\tchar buf[AUDIT_LOG_SIZE];\n+\tint audit_fd, audit_ok;\n+\n+\tsnprintf(buf, sizeof(buf), \"op=destroy kind=server fp=%s direction=? spid=%jd suid=%jd \",\n+\t\tfp, (intmax_t)pid, (intmax_t)uid);\n+\taudit_fd = audit_open();\n+\tif (audit_fd < 0) {\n+\t\tif (errno != EINVAL && errno != EPROTONOSUPPORT &&\n+\t\t\t\t\t errno != EAFNOSUPPORT)\n+\t\t\terror(\"cannot open audit\");\n+\t\treturn;\n+\t}\n+\taudit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,\n+\t\t\tbuf, NULL, get_remote_ipaddr(), NULL, 1);\n+\taudit_close(audit_fd);\n+\t/* do not abort if the error is EPERM and sshd is run as non root user */\n+\tif ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))\n+\t\terror(\"cannot write into audit\");\n+}\n+\n+void\n+audit_generate_ephemeral_server_key(const char *fp)\n+{\n+\tchar buf[AUDIT_LOG_SIZE];\n+\tint audit_fd, audit_ok;\n+\n+\tsnprintf(buf, sizeof(buf), \"op=create kind=server fp=%s direction=? \", fp);\n+\taudit_fd = audit_open();\n+\tif (audit_fd < 0) {\n+\t\tif (errno != EINVAL && errno != EPROTONOSUPPORT &&\n+\t\t\t\t\t errno != EAFNOSUPPORT)\n+\t\t\terror(\"cannot open audit\");\n+\t\treturn;\n+\t}\n+\taudit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,\n+\t\t\tbuf, NULL, 0, NULL, 1);\n+\taudit_close(audit_fd);\n+\t/* do not abort if the error is EPERM and sshd is run as non root user */\n+\tif ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))\n+\t\terror(\"cannot write into audit\");\n+}\n #endif /* USE_LINUX_AUDIT */\ndiff --git a/openssh-6.6p1/audit.c b/openssh-6.6p1/audit.c\n--- a/openssh-6.6p1/audit.c\n+++ b/openssh-6.6p1/audit.c\n@@ -285,10 +285,29 @@ audit_kex_body(int ctos, char *enc, char\n * This will be called on succesfull session key discard\n */\n void\n audit_session_key_free_body(int ctos, pid_t pid, uid_t uid)\n {\n \tdebug(\"audit session key discard euid %u direction %d from pid %ld uid %u\",\n \t\t(unsigned)geteuid(), ctos, (long)pid, (unsigned)uid);\n }\n+\n+/*\n+ * This will be called on destroy private part of the server key\n+ */\n+void\n+audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)\n+{\n+\tdebug(\"audit destroy sensitive data euid %d fingerprint %s from pid %ld uid %u\",\n+\t\tgeteuid(), fp, (long)pid, (unsigned)uid);\n+}\n+\n+/*\n+ * This will be called on generation of the ephemeral server key\n+ */\n+void\n+audit_generate_ephemeral_server_key(const char *)\n+{\n+\tdebug(\"audit create ephemeral server key euid %d fingerprint %s\", geteuid(), fp);\n+}\n # endif /* !defined CUSTOM_SSH_AUDIT_EVENTS */\n #endif /* SSH_AUDIT_EVENTS */\ndiff --git a/openssh-6.6p1/audit.h b/openssh-6.6p1/audit.h\n--- a/openssh-6.6p1/audit.h\n+++ b/openssh-6.6p1/audit.h\n@@ -59,10 +59,12 @@ ssh_audit_event_t audit_classify_auth(co\n int\taudit_keyusage(int, const char *, unsigned, char *, int);\n void\taudit_key(int, int *, const Key *);\n void\taudit_unsupported(int);\n void\taudit_kex(int, char *, char *, char *);\n void\taudit_unsupported_body(int);\n void\taudit_kex_body(int, char *, char *, char *, pid_t, uid_t);\n void\taudit_session_key_free(int ctos);\n void\taudit_session_key_free_body(int ctos, pid_t, uid_t);\n+void\taudit_destroy_sensitive_data(const char *, pid_t, uid_t);\n+void\taudit_generate_ephemeral_server_key(const char *);\n \n #endif /* _SSH_AUDIT_H */\ndiff --git a/openssh-6.6p1/key.c b/openssh-6.6p1/key.c\n--- a/openssh-6.6p1/key.c\n+++ b/openssh-6.6p1/key.c\n@@ -1964,16 +1964,43 @@ key_demote(const Key *k)\n \t\tfatal(\"key_demote: bad key type %d\", k->type);\n \t\tbreak;\n \t}\n \n \treturn (pk);\n }\n \n int\n+key_is_private(const Key *k)\n+{\n+\tswitch (k->type) {\n+\tcase KEY_RSA_CERT_V00:\n+\tcase KEY_RSA_CERT:\n+\tcase KEY_RSA1:\n+\tcase KEY_RSA:\n+\t\treturn k->rsa->d != NULL;\n+\tcase KEY_DSA_CERT_V00:\n+\tcase KEY_DSA_CERT:\n+\tcase KEY_DSA:\n+\t\treturn k->dsa->priv_key != NULL;\n+#ifdef OPENSSL_HAS_ECC\n+\tcase KEY_ECDSA_CERT:\n+\tcase KEY_ECDSA:\n+\t\treturn EC_KEY_get0_private_key(k->ecdsa) != NULL;\n+#endif\n+\tcase KEY_ED25519_CERT:\n+\tcase KEY_ED25519:\n+\t\treturn k->ed25519_sk != NULL;\n+\tdefault:\n+\t\tfatal(\"key_is_private: bad key type %d\", k->type);\n+\t\treturn 1;\n+\t}\n+}\n+\n+int\n key_is_cert(const Key *k)\n {\n \tif (k == NULL)\n \t\treturn 0;\n \treturn key_type_is_cert(k->type);\n }\n \n /* Return the cert-less equivalent to a certified key type */\ndiff --git a/openssh-6.6p1/key.h b/openssh-6.6p1/key.h\n--- a/openssh-6.6p1/key.h\n+++ b/openssh-6.6p1/key.h\n@@ -113,16 +113,17 @@ int\t\t key_read(Key *, char **);\n u_int\t\t key_size(const Key *);\n enum fp_type\t key_fp_type_select(void);\n char\t\t*key_fp_type_str(enum fp_type);\n \n Key\t*key_generate(int, u_int);\n Key\t*key_from_private(const Key *);\n int\t key_type_from_name(char *);\n int\t key_is_cert(const Key *);\n+int\t key_is_private(const Key *k);\n int\t key_type_is_cert(int);\n int\t key_type_plain(int);\n int\t key_to_certified(Key *, int);\n int\t key_drop_cert(Key *);\n int\t key_certify(Key *, Key *);\n void\t key_cert_copy(const Key *, struct Key *);\n int\t key_cert_check_authority(const Key *, int, int, const char *,\n \t const char **);\ndiff --git a/openssh-6.6p1/monitor.c b/openssh-6.6p1/monitor.c\n--- a/openssh-6.6p1/monitor.c\n+++ b/openssh-6.6p1/monitor.c\n@@ -109,16 +109,18 @@ extern u_int utmp_len;\n extern Newkeys *current_keys[];\n extern z_stream incoming_stream;\n extern z_stream outgoing_stream;\n extern u_char session_id[];\n extern Buffer auth_debug;\n extern int auth_debug_init;\n extern Buffer loginmsg;\n \n+extern void destroy_sensitive_data(int);\n+\n /* State exported from the child */\n \n struct {\n \tz_stream incoming;\n \tz_stream outgoing;\n \tu_char *keyin;\n \tu_int keyinlen;\n \tu_char *keyout;\n@@ -180,16 +182,17 @@ int mm_answer_gss_checkmic(int, Buffer *\n \n #ifdef SSH_AUDIT_EVENTS\n int mm_answer_audit_event(int, Buffer *);\n int mm_answer_audit_command(int, Buffer *);\n int mm_answer_audit_end_command(int, Buffer *);\n int mm_answer_audit_unsupported_body(int, Buffer *);\n int mm_answer_audit_kex_body(int, Buffer *);\n int mm_answer_audit_session_key_free_body(int, Buffer *);\n+int mm_answer_audit_server_key_free(int, Buffer *);\n #endif\n \n static int monitor_read_log(struct monitor *);\n \n static Authctxt *authctxt;\n static BIGNUM *ssh1_challenge = NULL;\t/* used for ssh1 rsa auth */\n \n /* local state for key verify */\n@@ -234,16 +237,17 @@ struct mon_table mon_dispatch_proto20[] \n {MONITOR_REQ_PAM_RESPOND, MON_ISAUTH, mm_answer_pam_respond},\n {MONITOR_REQ_PAM_FREE_CTX, MON_ONCE|MON_AUTHDECIDE, mm_answer_pam_free_ctx},\n #endif\n #ifdef SSH_AUDIT_EVENTS\n {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},\n {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},\n {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},\n {MONITOR_RE\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "# HG changeset patch\n# Parent 78384019c3a49ad8d87367715674539c3f58798a\n# server key destruction and auditing\n# based on:\n# https://bugzilla.mindrot.org/show_bug.cgi?id=1402\n# https://bugzilla.mindrot.org/attachment.cgi?id=2015\n# by jchadima@redhat.com\n\ndiff --git a/openssh-6.6p1/audit-bsm.c b/openssh-6.6p1/audit-bsm.c\n--- a/openssh-6.6p1/audit-bsm.c\n+++ b/openssh-6.6p1/audit-bsm.c\n@@ -486,9 +486,27 @@ audit_kex_body(int ctos, char *enc, char\n \t/* not implemented */\n }\n \n void\n audit_session_key_free_body(int ctos, pid_t pid, uid_t uid)\n {\n \t/* not implemented */\n }\n+\n+void\n+audit_destroy_sensitive_data(const char *fp)\n+{\n+\t/* not implemented */\n+}\n+\n+void\n+audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)\n+{\n+\t/* not implemented */\n+}\n+\n+void\n+audit_generate_ephemeral_server_key(const char *fp)\n+{\n+\t/* not implemented */\n+}\n #endif /* BSM */\ndiff --git a/openssh-6.6p1/audit-linux.c b/openssh-6.6p1/audit-linux.c\n--- a/openssh-6.6p1/audit-linux.c\n+++ b/openssh-6.6p1/audit-linux.c\n@@ -351,9 +351,53 @@ audit_session_key_free_body(int ctos, pi\n \taudit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,\n \t\t\tbuf, NULL, get_remote_ipaddr(), NULL, 1);\n \taudit_close(audit_fd);\n \t/* do not abort if the error is EPERM and sshd is run as non root user */\n \tif ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))\n \t\terror(\"cannot write into audit\");\n }\n \n+void\n+audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)\n+{\n+\tchar buf[AUDIT_LOG_SIZE];\n+\tint audit_fd, audit_ok;\n+\n+\tsnprintf(buf, sizeof(buf), \"op=destroy kind=server fp=%s direction=? spid=%jd suid=%jd \",\n+\t\tfp, (intmax_t)pid, (intmax_t)uid);\n+\taudit_fd = audit_open();\n+\tif (audit_fd < 0) {\n+\t\tif (errno != EINVAL && errno != EPROTONOSUPPORT &&\n+\t\t\t\t\t errno != EAFNOSUPPORT)\n+\t\t\terror(\"cannot open audit\");\n+\t\treturn;\n+\t}\n+\taudit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,\n+\t\t\tbuf, NULL, get_remote_ipaddr(), NULL, 1);\n+\taudit_close(audit_fd);\n+\t/* do not abort if the error is EPERM and sshd is run as non root user */\n+\tif ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))\n+\t\terror(\"cannot write into audit\");\n+}\n+\n+void\n+audit_generate_ephemeral_server_key(const char *fp)\n+{\n+\tchar buf[AUDIT_LOG_SIZE];\n+\tint audit_fd, audit_ok;\n+\n+\tsnprintf(buf, sizeof(buf), \"op=create kind=server fp=%s direction=? \", fp);\n+\taudit_fd = audit_open();\n+\tif (audit_fd < 0) {\n+\t\tif (errno != EINVAL && errno != EPROTONOSUPPORT &&\n+\t\t\t\t\t errno != EAFNOSUPPORT)\n+\t\t\terror(\"cannot open audit\");\n+\t\treturn;\n+\t}\n+\taudit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,\n+\t\t\tbuf, NULL, 0, NULL, 1);\n+\taudit_close(audit_fd);\n+\t/* do not abort if the error is EPERM and sshd is run as non root user */\n+\tif ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))\n+\t\terror(\"cannot write into audit\");\n+}\n #endif /* USE_LINUX_AUDIT */\ndiff --git a/openssh-6.6p1/audit.c b/openssh-6.6p1/audit.c\n--- a/openssh-6.6p1/audit.c\n+++ b/openssh-6.6p1/audit.c\n@@ -285,10 +285,29 @@ audit_kex_body(int ctos, char *enc, char\n * This will be called on succesfull session key discard\n */\n void\n audit_session_key_free_body(int ctos, pid_t pid, uid_t uid)\n {\n \tdebug(\"audit session key discard euid %u direction %d from pid %ld uid %u\",\n \t\t(unsigned)geteuid(), ctos, (long)pid, (unsigned)uid);\n }\n+\n+/*\n+ * This will be called on destroy private part of the server key\n+ */\n+void\n+audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)\n+{\n+\tdebug(\"audit destroy sensitive data euid %d fingerprint %s from pid %ld uid %u\",\n+\t\tgeteuid(), fp, (long)pid, (unsigned)uid);\n+}\n+\n+/*\n+ * This will be called on generation of the ephemeral server key\n+ */\n+void\n+audit_generate_ephemeral_server_key(const char *)\n+{\n+\tdebug(\"audit create ephemeral server key euid %d fingerprint %s\", geteuid(), fp);\n+}\n # endif /* !defined CUSTOM_SSH_AUDIT_EVENTS */\n #endif /* SSH_AUDIT_EVENTS */\ndiff --git a/openssh-6.6p1/audit.h b/openssh-6.6p1/audit.h\n--- a/openssh-6.6p1/audit.h\n+++ b/openssh-6.6p1/audit.h\n@@ -59,10 +59,12 @@ ssh_audit_event_t audit_classify_auth(co\n int\taudit_keyusage(int, const char *, unsigned, char *, int);\n void\taudit_key(int, int *, const Key *);\n void\taudit_unsupported(int);\n void\taudit_kex(int, char *, char *, char *);\n void\taudit_unsupported_body(int);\n void\taudit_kex_body(int, char *, char *, char *, pid_t, uid_t);\n void\taudit_session_key_free(int ctos);\n void\taudit_session_key_free_body(int ctos, pid_t, uid_t);\n+void\taudit_destroy_sensitive_data(const char *, pid_t, uid_t);\n+void\taudit_generate_ephemeral_server_key(const char *);\n \n #endif /* _SSH_AUDIT_H */\ndiff --git a/openssh-6.6p1/key.c b/openssh-6.6p1/key.c\n--- a/openssh-6.6p1/key.c\n+++ b/openssh-6.6p1/key.c\n@@ -1964,16 +1964,43 @@ key_demote(const Key *k)\n \t\tfatal(\"key_demote: bad key type %d\", k->type);\n \t\tbreak;\n \t}\n \n \treturn (pk);\n }\n \n int\n+key_is_private(const Key *k)\n+{\n+\tswitch (k->type) {\n+\tcase KEY_RSA_CERT_V00:\n+\tcase KEY_RSA_CERT:\n+\tcase KEY_RSA1:\n+\tcase KEY_RSA:\n+\t\treturn k->rsa->d != NULL;\n+\tcase KEY_DSA_CERT_V00:\n+\tcase KEY_DSA_CERT:\n+\tcase KEY_DSA:\n+\t\treturn k->dsa->priv_key != NULL;\n+#ifdef OPENSSL_HAS_ECC\n+\tcase KEY_ECDSA_CERT:\n+\tcase KEY_ECDSA:\n+\t\treturn EC_KEY_get0_private_key(k->ecdsa) != NULL;\n+#endif\n+\tcase KEY_ED25519_CERT:\n+\tcase KEY_ED25519:\n+\t\treturn k->ed25519_sk != NULL;\n+\tdefault:\n+\t\tfatal(\"key_is_private: bad key type %d\", k->type);\n+\t\treturn 1;\n+\t}\n+}\n+\n+int\n key_is_cert(const Key *k)\n {\n \tif (k == NULL)\n \t\treturn 0;\n \treturn key_type_is_cert(k->type);\n }\n \n /* Return the cert-less equivalent to a certified key type */\ndiff --git a/openssh-6.6p1/key.h b/openssh-6.6p1/key.h\n--- a/openssh-6.6p1/key.h\n+++ b/openssh-6.6p1/key.h\n@@ -113,16 +113,17 @@ int\t\t key_read(Key *, char **);\n u_int\t\t key_size(const Key *);\n enum fp_type\t key_fp_type_select(void);\n char\t\t*key_fp_type_str(enum fp_type);\n \n Key\t*key_generate(int, u_int);\n Key\t*key_from_private(const Key *);\n int\t key_type_from_name(char *);\n int\t key_is_cert(const Key *);\n+int\t key_is_private(const Key *k);\n int\t key_type_is_cert(int);\n int\t key_type_plain(int);\n int\t key_to_certified(Key *, int);\n int\t key_drop_cert(Key *);\n int\t key_certify(Key *, Key *);\n void\t key_cert_copy(const Key *, struct Key *);\n int\t key_cert_check_authority(const Key *, int, int, const char *,\n \t const char **);\ndiff --git a/openssh-6.6p1/monitor.c b/openssh-6.6p1/monitor.c\n--- a/openssh-6.6p1/monitor.c\n+++ b/openssh-6.6p1/monitor.c\n@@ -109,16 +109,18 @@ extern u_int utmp_len;\n extern Newkeys *current_keys[];\n extern z_stream incoming_stream;\n extern z_stream outgoing_stream;\n extern u_char session_id[];\n extern Buffer auth_debug;\n extern int auth_debug_init;\n extern Buffer loginmsg;\n \n+extern void destroy_sensitive_data(int);\n+\n /* State exported from the child */\n \n struct {\n \tz_stream incoming;\n \tz_stream outgoing;\n \tu_char *keyin;\n \tu_int keyinlen;\n \tu_char *keyout;\n@@ -180,16 +182,17 @@ int mm_answer_gss_checkmic(int, Buffer *\n \n #ifdef SSH_AUDIT_EVENTS\n int mm_answer_audit_event(int, Buffer *);\n int mm_answer_audit_command(int, Buffer *);\n int mm_answer_audit_end_command(int, Buffer *);\n int mm_answer_audit_unsupported_body(int, Buffer *);\n int mm_answer_audit_kex_body(int, Buffer *);\n int mm_answer_audit_session_key_free_body(int, Buffer *);\n+int mm_answer_audit_server_key_free(int, Buffer *);\n #endif\n \n static int monitor_read_log(struct monitor *);\n \n static Authctxt *authctxt;\n static BIGNUM *ssh1_challenge = NULL;\t/* used for ssh1 rsa auth */\n \n /* local state for key verify */\n@@ -234,16 +237,17 @@ struct mon_table mon_dispatch_proto20[] \n {MONITOR_REQ_PAM_RESPOND, MON_ISAUTH, mm_answer_pam_respond},\n {MONITOR_REQ_PAM_FREE_CTX, MON_ONCE|MON_AUTHDECIDE, mm_answer_pam_free_ctx},\n #endif\n #ifdef SSH_AUDIT_EVENTS\n {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},\n {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},\n {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},\n {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},\n+ {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},\n #endif\n #ifdef BSD_AUTH\n {MONITOR_REQ_BSDAUTHQUERY, MON_ISAUTH, mm_answer_bsdauthquery},\n {MONITOR_REQ_BSDAUTHRESPOND, MON_AUTH, mm_answer_bsdauthrespond},\n #endif\n #ifdef SKEY\n {MONITOR_REQ_SKEYQUERY, MON_ISAUTH, mm_answer_skeyquery},\n {MONITOR_REQ_SKEYRESPOND, MON_AUTH, mm_answer_skeyrespond},\n@@ -267,16 +271,17 @@ struct mon_table mon_dispatch_postauth20\n {MONITOR_REQ_TERM, 0, mm_answer_term},\n #ifdef SSH_AUDIT_EVENTS\n {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},\n {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT, mm_answer_audit_command},\n {MONITOR_REQ_AUDIT_END_COMMAND, MON_PERMIT, mm_answer_audit_end_command},\n {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},\n {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},\n {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},\n+ {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},\n #endif\n {0, 0, NULL}\n };\n \n struct mon_table mon_dispatch_proto15[] = {\n {MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow},\n {MONITOR_REQ_SESSKEY, MON_ONCE, mm_answer_sesskey},\n {MONITOR_REQ_SESSID, MON_ONCE, mm_answer_sessid},\n@@ -301,31 +306,33 @@ struct mon_table mon_dispatch_proto15[] \n {MONITOR_REQ_PAM_RESPOND, MON_ISAUTH, mm_answer_pam_respond},\n {MONITOR_REQ_PAM_FREE_CTX, MON_ONCE|MON_AUTHDECIDE, mm_answer_pam_free_ctx},\n #endif\n #ifdef SSH_AUDIT_EVENTS\n {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},\n {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},\n {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},\n {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},\n+ {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},\n #endif\n {0, 0, NULL}\n };\n \n struct mon_table mon_dispatch_postauth15[] = {\n {MONITOR_REQ_PTY, MON_ONCE, mm_answer_pty},\n {MONITOR_REQ_PTYCLEANUP, MON_ONCE, mm_answer_pty_cleanup},\n {MONITOR_REQ_TERM, 0, mm_answer_term},\n #ifdef SSH_AUDIT_EVENTS\n {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},\n {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT|MON_ONCE, mm_answer_audit_command},\n {MONITOR_REQ_AUDIT_END_COMMAND, MON_PERMIT, mm_answer_audit_end_command},\n {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},\n {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},\n {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},\n+ {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},\n #endif\n {0, 0, NULL}\n };\n \n struct mon_table *mon_dispatch;\n \n /* Specifies if a certain message is allowed at the moment */\n \n@@ -1739,16 +1746,18 @@ mm_answer_term(int sock, Buffer *req)\n \t/* The child is terminating */\n \tsession_destroy_all(&mm_session_close);\n \n #ifdef USE_PAM\n \tif (options.use_pam)\n \t\tsshpam_cleanup();\n #endif\n \n+\tdestroy_sensitive_data(0);\n+\n \twhile (waitpid(pmonitor->m_pid, &status, 0) == -1)\n \t\tif (errno != EINTR)\n \t\t\texit(1);\n \n \tres = WIFEXITED(status) ? WEXITSTATUS(status) : 1;\n \n \t/* Terminate process */\n \texit(res);\n@@ -2280,10 +2289,31 @@ mm_answer_audit_session_key_free_body(in\n \n \taudit_session_key_free_body(ctos, pid, uid);\n \n \tbuffer_clear(m);\n \n \tmm_request_send(sock, MONITOR_ANS_AUDIT_SESSION_KEY_FREE, m);\n \treturn 0;\n }\n+\n+int\n+mm_answer_audit_server_key_free(int sock, Buffer *m)\n+{\n+\tint len;\n+\tchar *fp;\n+\tpid_t pid;\n+\tuid_t uid;\n+\n+\tfp = buffer_get_string(m, &len);\n+\tpid = buffer_get_int64(m);\n+\tuid = buffer_get_int64(m);\n+\n+\taudit_destroy_sensitive_data(fp, pid, uid);\n+\n+\tfree(fp);\n+\tbuffer_clear(m);\n+\n+\tmm_request_send(sock, MONITOR_ANS_AUDIT_SERVER_KEY_FREE, m);\n+\treturn 0;\n+}\n #endif /* SSH_AUDIT_EVENTS */\n \ndiff --git a/openssh-6.6p1/monitor.h b/openssh-6.6p1/monitor.h\n--- a/openssh-6.6p1/monitor.h\n+++ b/openssh-6.6p1/monitor.h\n@@ -63,16 +63,17 @@ enum monitor_reqtype {\n \tMONITOR_REQ_PAM_QUERY = 106, MONITOR_ANS_PAM_QUERY = 107,\n \tMONITOR_REQ_PAM_RESPOND = 108, MONITOR_ANS_PAM_RESPOND = 109,\n \tMONITOR_REQ_PAM_FREE_CTX = 110, MONITOR_ANS_PAM_FREE_CTX = 111,\n \tMONITOR_REQ_AUDIT_EVENT = 112, MONITOR_REQ_AUDIT_COMMAND = 113,\n \tMONITOR_ANS_AUDIT_COMMAND = 114, MONITOR_REQ_AUDIT_END_COMMAND = 115,\n \tMONITOR_REQ_AUDIT_UNSUPPORTED = 116, MONITOR_ANS_AUDIT_UNSUPPORTED = 117,\n \tMONITOR_REQ_AUDIT_KEX = 118, MONITOR_ANS_AUDIT_KEX = 119,\n \tMONITOR_REQ_AUDIT_SESSION_KEY_FREE = 120, MONITOR_ANS_AUDIT_SESSION_KEY_FREE = 121,\n+\tMONITOR_REQ_AUDIT_SERVER_KEY_FREE = 122, MONITOR_ANS_AUDIT_SERVER_KEY_FREE = 123,\n \n };\n \n struct mm_master;\n struct monitor {\n \tint\t\t\t m_recvfd;\n \tint\t\t\t m_sendfd;\n \tint\t\t\t m_log_recvfd;\ndiff --git a/openssh-6.6p1/monitor_wrap.c b/openssh-6.6p1/monitor_wrap.c\n--- a/openssh-6.6p1/monitor_wrap.c\n+++ b/openssh-6.6p1/monitor_wrap.c\n@@ -1373,10 +1373,26 @@ mm_audit_session_key_free_body(int ctos,\n \tbuffer_put_int(&m, ctos);\n \tbuffer_put_int64(&m, pid);\n \tbuffer_put_int64(&m, uid);\n \tmm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_SESSION_KEY_FREE, &m);\n \tmm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUDIT_SESSION_KEY_FREE,\n \t\t\t\t &m);\n \tbuffer_free(&m);\n }\n+\n+void\n+mm_audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)\n+{\n+\tBuffer m;\n+\n+\tbuffer_init(&m);\n+\tbuffer_put_cstring(&m, fp);\n+\tbuffer_put_int64(&m, pid);\n+\tbuffer_put_int64(&m, uid);\n+\n+\tmm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_SERVER_KEY_FREE, &m);\n+\tmm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUDIT_SERVER_KEY_FREE,\n+\t\t\t\t &m);\n+\tbuffer_free(&m);\n+}\n #endif /* SSH_AUDIT_EVENTS */\n \ndiff --git a/openssh-6.6p1/monitor_wrap.h b/openssh-6.6p1/monitor_wrap.h\n--- a/openssh-6.6p1/monitor_wrap.h\n+++ b/openssh-6.6p1/monitor_wrap.h\n@@ -75,16 +75,17 @@ void mm_sshpam_free_ctx(void *);\n #ifdef SSH_AUDIT_EVENTS\n #include \"audit.h\"\n void mm_audit_event(ssh_audit_event_t);\n int mm_audit_run_command(const char *);\n void mm_audit_end_command(int, const char *);\n void mm_audit_unsupported_body(int);\n void mm_audit_kex_body(int, char *, char *, char *, pid_t, uid_t);\n void mm_audit_session_key_free_body(int, pid_t, uid_t);\n+void mm_audit_destroy_sensitive_data(const char *, pid_t, uid_t);\n #endif\n \n struct Session;\n void mm_terminate(void);\n int mm_pty_allocate(int *, int *, char *, size_t);\n void mm_session_pty_cleanup2(struct Session *);\n \n /* SSHv1 interfaces */\ndiff --git a/openssh-6.6p1/session.c b/openssh-6.6p1/session.c\n--- a/openssh-6.6p1/session.c\n+++ b/openssh-6.6p1/session.c\n@@ -132,17 +132,17 @@ static int session_pty_req(Session *);\n \n /* import */\n extern ServerOptions options;\n extern char *__progname;\n extern int log_stderr;\n extern int debug_flag;\n extern u_int utmp_len;\n extern int startup_pipe;\n-extern void destroy_sensitive_data(void);\n+extern void destroy_sensitive_data(int);\n extern Buffer loginmsg;\n \n /* original command from peer. */\n const char *original_command = NULL;\n \n /* data */\n static int sessions_first_unused = -1;\n static int sessions_nalloc = 0;\n@@ -1695,17 +1695,17 @@ do_child(Session *s, const char *command\n \tchar **env;\n \tint env_size;\n \tchar *argv[ARGV_MAX];\n \tconst char *shell, *shell0, *hostname = NULL;\n \tstruct passwd *pw = s->pw;\n \tint r = 0;\n \n \t/* remove hostkey from the child's memory */\n-\tdestroy_sensitive_data();\n+\tdestroy_sensitive_data(1);\n \t/* Don't audit this - both us and the parent would be talking to the\n \t monitor over a single socket, with no synchronization. */\n \tpacket_destroy_all(0, 1);\n \n \t/* Force a password change */\n \tif (s->authctxt->force_pwchange) {\n \t\tdo_setusercontext(pw);\n \t\tchild_close_fds();\ndiff --git a/openssh-6.6p1/sshd.c b/openssh-6.6p1/sshd.c\n--- a/openssh-6.6p1/sshd.c\n+++ b/openssh-6.6p1/sshd.c\n@@ -257,17 +257,17 @@ Buffer cfg;\n \n /* message to be displayed after login */\n Buffer loginmsg;\n \n /* Unprivileged user */\n struct passwd *privsep_pw = NULL;\n \n /* Prototypes for various functions defined later in this file. */\n-void destroy_sensitive_data(void);\n+void destroy_sensitive_data(int);\n void demote_sensitive_data(void);\n \n static void do_ssh1_kex(void);\n static void do_ssh2_kex(void);\n \n /*\n * Close all listening sockets\n */\n@@ -555,60 +555,107 @@ sshd_exchange_identification(int sock_in\n \t\tclose(sock_out);\n \t\tlogit(\"Protocol major versions differ for %s: %.200s vs. %.200s\",\n \t\t get_remote_ipaddr(),\n \t\t server_version_string, client_version_string);\n \t\tcleanup_exit(255);\n \t}\n }\n \n-/* Destroy the host and server keys. They will no longer be needed. */\n+/*\n+ * Destroy the host and server keys. They will no longer be needed. Careful,\n+ * this can be called from cleanup_exit() - i.e. from just about anywhere.\n+ */\n void\n-destroy_sensitive_data(void)\n+destroy_sensitive_data(int privsep)\n {\n \tint i;\n+\tpid_t pid;\n+\tuid_t uid;\n \n \tif (sensitive_data.server_key) {\n \t\tkey_free(sensitive_data.server_key);\n \t\tsensitive_data.server_key = NULL;\n \t}\n+\tpid = getpid();\n+\tuid = getuid();\n \tfor (i = 0; i < options.num_host_key_files; i++) {\n \t\tif (sensitive_data.host_keys[i]) {\n+#ifdef SSH_AUDIT_EVENTS\n+\t\t\tchar *fp;\n+\n+\t\t\tif (key_is_private(sensitive_data.host_keys[i]))\n+\t\t\t\tfp = key_fingerprint(sensitive_data.host_keys[i],\n+\t\t\t\t\tkey_fp_type_select(), SSH_FP_HEX);\n+\t\t\telse\n+\t\t\t\tfp = NULL;\n+#endif\n \t\t\tkey_free(sensitive_data.host_keys[i]);\n \t\t\tsensitive_data.host_keys[i] = NULL;\n+#ifdef SSH_AUDIT_EVENTS\n+\t\t\tif (fp != NULL) {\n+\t\t\t\tif (privsep)\n+\t\t\t\t\tPRIVSEP(audit_destroy_sensitive_data(fp,\n+\t\t\t\t\t\tpid, uid));\n+\t\t\t\telse\n+\t\t\t\t\taudit_destroy_sensitive_data(fp,\n+\t\t\t\t\t\tpid, uid);\n+\t\t\t\tfree(fp);\n+\t\t\t}\n+#endif\n \t\t}\n-\t\tif (sensitive_data.host_certificates[i]) {\n+\t\tif (sensitive_data.host_certificates\n+\t\t && sensitive_data.host_certificates[i]) {\n \t\t\tkey_free(sensitive_data.host_certificates[i]);\n \t\t\tsensitive_data.host_certificates[i] = NULL;\n \t\t}\n \t}\n \tsensitive_data.ssh1_host_key = NULL;\n \texplicit_bzero(sensitive_data.ssh1_cookie, SSH_SESSION_KEY_LENGTH);\n }\n \n /* Demote private to public keys for network child */\n void\n demote_sensitive_data(void)\n {\n \tKey *tmp;\n+\tpid_t pid;\n+\tuid_t uid;\n \tint i;\n \n+\tpid = getpid();\n+\tuid = getuid();\n \tif (sensitive_data.server_key) {\n \t\ttmp = key_demote(sensitive_data.server_key);\n \t\tkey_free(sensitive_data.server_key);\n \t\tsensitive_data.server_key = tmp;\n \t}\n \n \tfor (i = 0; i < options.num_host_key_files; i++) {\n \t\tif (sensitive_data.host_keys[i]) {\n+#ifdef SSH_AUDIT_EVENTS\n+\t\t\tchar *fp;\n+\n+\t\t\tif (key_is_private(sensitive_data.host_keys[i]))\n+\t\t\t\tfp = key_fingerprint(sensitive_data.host_keys[i],\n+\t\t\t\t\tkey_fp_type_select(), SSH_FP_HEX);\n+\t\t\telse\n+\t\t\t\tfp = NULL;\n+#endif\n \t\t\ttmp = key_demote(sensitive_data.host_keys[i]);\n \t\t\tkey_free(sensitive_data.host_keys[i]);\n \t\t\tsensitive_data.host_keys[i] = tmp;\n \t\t\tif (tmp->type == KEY_RSA1)\n \t\t\t\tsensitive_data.ssh1_host_key = tmp;\n+#ifdef SSH_AUDIT_EVENTS\n+\t\t\tif (fp != NULL) {\n+\t\t\t\taudit_destroy_sensitive_data(fp, pid, uid);\n+\t\t\t\tfree(fp);\n+\t\t\t}\n+#endif\n \t\t}\n \t\t/* Certs do not need demotion */\n \t}\n \n \t/* We do not clear ssh1_host key and cookie. XXX - Okay Niels? */\n }\n \n static void\n@@ -1199,16 +1246,17 @@ server_accept_loop(int *sock_in, int *so\n \n \t\t/* Wait in select until there is a connection. */\n \t\tret = select(maxfd+1, fdset, NULL, NULL, NULL);\n \t\tif (ret < 0 && errno != EINTR)\n \t\t\terror(\"select: %.100s\", strerror(errno));\n \t\tif (received_sigterm) {\n \t\t\tlogit(\"Received signal %d; terminating.\",\n \t\t\t (int) received_sigterm);\n+\t\t\tdestroy_sensitive_data(0);\n \t\t\tclose_listen_socks();\n \t\t\tunlink(options.pid_file);\n \t\t\texit(received_sigterm == SIGTERM ? 0 : 255);\n \t\t}\n \t\tif (key_used && key_do_regen) {\n \t\t\tgenerate_ephemeral_server_key();\n \t\t\tkey_used = 0;\n \t\t\tkey_do_regen = 0;\n@@ -2168,27 +2216,28 @@ main(int ac, char **av)\n \t/*\n \t * In privilege separation, we fork another child and prepare\n \t * file descriptor passing.\n \t */\n \tif (use_privsep) {\n \t\tprivsep_postauth(authctxt);\n \t\t/* the monitor process [priv] will not return */\n \t\tif (!compat20)\n-\t\t\tdestroy_sensitive_data();\n+\t\t\tdestroy_sensitive_data(0);\n \t}\n \n \tpacket_set_timeout(options.client_alive_interval,\n \t options.client_alive_count_max);\n \n \t/* Start session. */\n \tdo_authenticated(authctxt);\n \n \t/* The connection has been terminated. */\n \tpacket_destroy_all(1, 1);\n+\tdestroy_sensitive_data(1);\n \n \tpacket_get_state(MODE_IN, NULL, NULL, NULL, &ibytes);\n \tpacket_get_state(MODE_OUT, NULL, NULL, NULL, &obytes);\n \tverbose(\"Transferred: sent %llu, received %llu bytes\",\n \t (unsigned long long)obytes, (unsigned long long)ibytes);\n \n \tverbose(\"Closing connection to %.500s port %d\", remote_ip, remote_port);\n \n@@ -2413,17 +2462,17 @@ do_ssh1_kex(void)\n \t\t\tfatal(\"%s: hash failed\", __func__);\n \t\tssh_digest_free(md);\n \t\texplicit_bzero(buf, bytes);\n \t\tfree(buf);\n \t\tfor (i = 0; i < 16; i++)\n \t\t\tsession_id[i] = session_key[i] ^ session_key[i + 16];\n \t}\n \t/* Destroy the private and public keys. No longer. */\n-\tdestroy_sensitive_data();\n+\tdestroy_sensitive_data(0);\n \n \tif (use_privsep)\n \t\tmm_ssh1_session_id(session_id);\n \n \t/* Destroy the decrypted integer. It is no longer needed. */\n \tBN_clear_free(session_key_int);\n \n \t/* Set the session key. From this on all communications will be encrypted. */\n@@ -2559,16 +2608,18 @@ cleanup_exit(int i)\n \t\t\tdebug(\"Killing privsep child %d\", pmonitor->m_pid);\n \t\t\tif (kill(pmonitor->m_pid, SIGKILL) != 0 &&\n \t\t\t errno != ESRCH)\n \t\t\t\terror(\"%s: kill(%d): %s\", __func__,\n \t\t\t\t pmonitor->m_pid, strerror(errno));\n \t\t}\n \t}\n \tis_privsep_child = use_privsep && (pmonitor != NULL) && !mm_is_monitor();\n+\tif (sensitive_data.host_keys != NULL)\n+\t\tdestroy_sensitive_data(is_privsep_child);\n \tpacket_destroy_all(1, is_privsep_child);\n #ifdef SSH_AUDIT_EVENTS\n \t/* done after do_cleanup so it can cancel the PAM auth 'thread' */\n \tif ((the_authctxt == NULL || !the_authctxt->authenticated) &&\n \t (!use_privsep || mm_is_monitor()))\n \t\taudit_event(SSH_CONNECTION_ABANDON);\n #endif\n \t_exit(i);" } ]
{ "id": "openssh-askpass-gnome-4526-openssh-6.6p1-audit6-server_ke", "cve_id": "CVE-2016-0777", "package": "openssh-askpass-gnome", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": false, "license": "BSD-2-Clause", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2012-0864\n\nInteger overflow in the vfprintf function in stdio-common/vfprintf.c in glibc 2.14 and other versions allows context-dependent attackers to bypass the FORTIFY_SOURCE protection mechanism, conduct format string attacks, and write to arbitrary memory via a large number of arguments.\n\n## Package\nglibc\n\n## Files to modify\n- nscd/nscd.h\n\n## Target Source Code\n\n### nscd.h\n\n#### region() [lines 66-156]\n```c\nstruct traced_file\n{\n time_t mtime;\n struct traced_file *next;\n int call_res_init;\n int inotify_descr;\n char fname[];\n};\n\n\n/* Structure describing dynamic part of one database. */\nstruct database_dyn\n{\n pthread_rwlock_t lock;\n pthread_cond_t prune_cond;\n pthread_mutex_t prune_lock;\n pthread_mutex_t prune_run_lock;\n time_t wakeup_time;\n\n int enabled;\n int check_file;\n int clear_cache;\n int persistent;\n int shared;\n int propagate;\n struct traced_file *traced_files;\n const char *db_filename;\n time_t file_mtime;\n size_t suggested_module;\n size_t max_db_size;\n\n unsigned long int postimeout;\t/* In seconds. */\n unsigned long int negtimeout;\t/* In seconds. */\n\n int wr_fd;\t\t\t/* Writable file descriptor. */\n int ro_fd;\t\t\t/* Unwritable file descriptor. */\n\n const struct iovec *disabled_iov;\n\n struct database_pers_head *head;\n char *data;\n size_t memsize;\n pthread_mutex_t memlock;\n bool mmap_used;\n bool last_alloc_failed;\n};\n\n\n/* Paths of the file for the persistent storage. */\n#define _PATH_NSCD_PASSWD_DB\t\"/var/db/nscd/passwd\"\n#define _PATH_NSCD_GROUP_DB\t\"/var/db/nscd/group\"\n#define _PATH_NSCD_HOSTS_DB\t\"/var/db/nscd/hosts\"\n#define _PATH_NSCD_SERVICES_DB\t\"/var/db/nscd/services\"\n#define _PATH_NSCD_NETGROUP_DB\t\"/var/db/nscd/netgroup\"\n\n/* Path used when not using persistent storage. */\n#define _PATH_NSCD_XYZ_DB_TMP\t\"/var/run/nscd/dbXXXXXX\"\n\n/* Maximum alignment requirement we will encounter. */\n#define BLOCK_ALIGN_LOG 3\n#define BLOCK_ALIGN (1 << BLOCK_ALIGN_LOG)\n#define BLOCK_ALIGN_M1 (BLOCK_ALIGN - 1)\n\n/* Default value for the maximum size of the database files. */\n#define DEFAULT_MAX_DB_SIZE\t(32 * 1024 * 1024)\n\n/* Number of bytes of data we initially reserve for each hash table bucket. */\n#define DEFAULT_DATASIZE_PER_BUCKET 1024\n\n/* Default module of hash table. */\n#define DEFAULT_SUGGESTED_MODULE 211\n\n\n/* Number of seconds between two cache pruning runs if we do not have\n better information when it is really needed. */\n#define CACHE_PRUNE_INTERVAL\t15\n\n\n/* Global variables. */\nextern struct database_dyn dbs[lastdb] attribute_hidden;\nextern const char *const dbnames[lastdb];\nextern const char *const serv2str[LASTREQ];\n\nextern const struct iovec pwd_iov_disabled;\nextern const struct iovec grp_iov_disabled;\nextern const struct iovec hst_iov_disabled;\nextern const struct iovec serv_iov_disabled;\nextern const struct iovec netgroup_iov_disabled;\n\n\n/* Initial number of threads to run. */\n```\n\n\n## Upstream Fix\n```diff\n2004-12-09 Thorsten Kukuk <kukuk@suse.de>\n\n\t* nscd/nscd.h: Move persistent storage back to /var/run/nscd\n\nIndex: nscd/nscd.h\n===================================================================\n--- nscd/nscd.h.orig\n+++ nscd/nscd.h\n@@ -105,10 +105,10 @@ struct database_dyn\n \n \n /* Paths of the file for the persistent storage. */\n-#define _PATH_NSCD_PASSWD_DB\t\"/var/db/nscd/passwd\"\n-#define _PATH_NSCD_GROUP_DB\t\"/var/db/nscd/group\"\n-#define _PATH_NSCD_HOSTS_DB\t\"/var/db/nscd/hosts\"\n-#define _PATH_NSCD_SERVICES_DB\t\"/var/db/nscd/services\"\n+#define _PATH_NSCD_PASSWD_DB\t\"/var/run/nscd/passwd\"\n+#define _PATH_NSCD_GROUP_DB\t\"/var/run/nscd/group\"\n+#define _PATH_NSCD_HOSTS_DB\t\"/var/run/nscd/hosts\"\n+#define _PATH_NSCD_SERVICES_DB\t\"/var/run/nscd/services\"\n \n /* Path used when not using persistent storage. */\n #define _PATH_NSCD_XYZ_DB_TMP\t\"/var/run/nscd/dbXXXXXX\"\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "2004-12-09 Thorsten Kukuk <kukuk@suse.de>\n\n\t* nscd/nscd.h: Move persistent storage back to /var/run/nscd\n\nIndex: nscd/nscd.h\n===================================================================\n--- nscd/nscd.h.orig\n+++ nscd/nscd.h\n@@ -105,10 +105,10 @@ struct database_dyn\n \n \n /* Paths of the file for the persistent storage. */\n-#define _PATH_NSCD_PASSWD_DB\t\"/var/db/nscd/passwd\"\n-#define _PATH_NSCD_GROUP_DB\t\"/var/db/nscd/group\"\n-#define _PATH_NSCD_HOSTS_DB\t\"/var/db/nscd/hosts\"\n-#define _PATH_NSCD_SERVICES_DB\t\"/var/db/nscd/services\"\n+#define _PATH_NSCD_PASSWD_DB\t\"/var/run/nscd/passwd\"\n+#define _PATH_NSCD_GROUP_DB\t\"/var/run/nscd/group\"\n+#define _PATH_NSCD_HOSTS_DB\t\"/var/run/nscd/hosts\"\n+#define _PATH_NSCD_SERVICES_DB\t\"/var/run/nscd/services\"\n \n /* Path used when not using persistent storage. */\n #define _PATH_NSCD_XYZ_DB_TMP\t\"/var/run/nscd/dbXXXXXX\"" } ]
{ "id": "glibc-342-glibc-2.3.3-nscd-db-path.diff", "cve_id": "CVE-2012-0864", "package": "glibc", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 627, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-5423\n\nPostgreSQL before 9.1.23, 9.2.x before 9.2.18, 9.3.x before 9.3.14, 9.4.x before 9.4.9, and 9.5.x before 9.5.4 allow remote authenticated users to cause a denial of service (NULL pointer dereference and server crash), obtain sensitive memory information, or possibly execute arbitrary code via (1) a CASE expression within the test value subexpression of another CASE or (2) inlining of an SQL function that implements the equality operator used for a CASE expression involving values of different types.\n\n## Package\npostgresql93\n\n## Files to modify\n- postgresql-9.3.5.orig/src/include/pg_config_manual.h\n- postgresql-9.3.5.orig/src/backend/utils/misc/guc.c\n- postgresql-9.3.5.orig/src/bin/initdb/initdb.c\n- src/backend/utils/misc/guc.c\n- src/bin/initdb/initdb.c\n\n## Target Source Code\n\n### contrib/pg_upgrade/test.sh\n\n#### region() [lines 99-185]\n```c\nrm -rf \"$BASE_PGDATA\" \"$PGDATA\"\n\nlogdir=$PWD/log\nrm -rf \"$logdir\"\nmkdir \"$logdir\"\n\n# Clear out any environment vars that might cause libpq to connect to\n# the wrong postmaster (cf pg_regress.c)\n#\n# Some shells, such as NetBSD's, return non-zero from unset if the variable\n# is already unset. Since we are operating under 'set -e', this causes the\n# script to fail. To guard against this, set them all to an empty string first.\nPGDATABASE=\"\"; unset PGDATABASE\nPGUSER=\"\"; unset PGUSER\nPGSERVICE=\"\"; unset PGSERVICE\nPGSSLMODE=\"\"; unset PGSSLMODE\nPGREQUIRESSL=\"\"; unset PGREQUIRESSL\nPGCONNECT_TIMEOUT=\"\"; unset PGCONNECT_TIMEOUT\nPGHOSTADDR=\"\"; unset PGHOSTADDR\n\n# Select a non-conflicting port number, similarly to pg_regress.c\nPG_VERSION_NUM=`grep '#define PG_VERSION_NUM' $newsrc/src/include/pg_config.h | awk '{print $3}'`\nPGPORT=`expr $PG_VERSION_NUM % 16384 + 49152`\nexport PGPORT\n\ni=0\nwhile psql -X postgres </dev/null 2>/dev/null\ndo\n\ti=`expr $i + 1`\n\tif [ $i -eq 16 ]\n\tthen\n\t\techo port $PGPORT apparently in use\n\t\texit 1\n\tfi\n\tPGPORT=`expr $PGPORT + 1`\n\texport PGPORT\ndone\n\n# buildfarm may try to override port via EXTRA_REGRESS_OPTS ...\nEXTRA_REGRESS_OPTS=\"$EXTRA_REGRESS_OPTS --port=$PGPORT\"\nexport EXTRA_REGRESS_OPTS\n\n# enable echo so the user can see what is being executed\nset -x\n\n$oldbindir/initdb -N\n$oldbindir/pg_ctl start -l \"$logdir/postmaster1.log\" -o \"$POSTMASTER_OPTS\" -w\nif \"$MAKE\" -C \"$oldsrc\" installcheck; then\n\tpg_dumpall -f \"$temp_root\"/dump1.sql || pg_dumpall1_status=$?\n\tif [ \"$newsrc\" != \"$oldsrc\" ]; then\n\t\toldpgversion=`psql -A -t -d regression -c \"SHOW server_version_num\"`\n\t\tfix_sql=\"\"\n\t\tcase $oldpgversion in\n\t\t\t804??)\n\t\t\t\tfix_sql=\"UPDATE pg_proc SET probin = replace(probin::text, '$oldsrc', '$newsrc')::bytea WHERE probin LIKE '$oldsrc%'; DROP FUNCTION public.myfunc(integer);\"\n\t\t\t\t;;\n\t\t\t900??)\n\t\t\t\tfix_sql=\"SET bytea_output TO escape; UPDATE pg_proc SET probin = replace(probin::text, '$oldsrc', '$newsrc')::bytea WHERE probin LIKE '$oldsrc%';\"\n\t\t\t\t;;\n\t\t\t901??)\n\t\t\t\tfix_sql=\"UPDATE pg_proc SET probin = replace(probin, '$oldsrc', '$newsrc') WHERE probin LIKE '$oldsrc%';\"\n\t\t\t\t;;\n\t\tesac\n\t\tpsql -d regression -c \"$fix_sql;\" || psql_fix_sql_status=$?\n\n\t\tmv \"$temp_root\"/dump1.sql \"$temp_root\"/dump1.sql.orig\n\t\tsed \"s;$oldsrc;$newsrc;g\" \"$temp_root\"/dump1.sql.orig >\"$temp_root\"/dump1.sql\n\tfi\nelse\n\tmake_installcheck_status=$?\nfi\n$oldbindir/pg_ctl -m fast stop\nif [ -n \"$make_installcheck_status\" ]; then\n\texit 1\nfi\nif [ -n \"$psql_fix_sql_status\" ]; then\n\texit 1\nfi\nif [ -n \"$pg_dumpall1_status\" ]; then\n\techo \"pg_dumpall of pre-upgrade database cluster failed\"\n\texit 1\nfi\n\nPGDATA=$BASE_PGDATA\n\ninitdb -N\n\n```\n\n### src/backend/utils/misc/guc.c\n\n#### region() [lines 2932-3019]\n```c\n\t\tcheck_timezone, assign_timezone, show_timezone\n\t},\n\t{\n\t\t{\"timezone_abbreviations\", PGC_USERSET, CLIENT_CONN_LOCALE,\n\t\t\tgettext_noop(\"Selects a file of time zone abbreviations.\"),\n\t\t\tNULL\n\t\t},\n\t\t&timezone_abbreviations_string,\n\t\tNULL,\n\t\tcheck_timezone_abbreviations, assign_timezone_abbreviations, NULL\n\t},\n\n\t{\n\t\t{\"transaction_isolation\", PGC_USERSET, CLIENT_CONN_STATEMENT,\n\t\t\tgettext_noop(\"Sets the current transaction's isolation level.\"),\n\t\t\tNULL,\n\t\t\tGUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE\n\t\t},\n\t\t&XactIsoLevel_string,\n\t\t\"default\",\n\t\tcheck_XactIsoLevel, assign_XactIsoLevel, show_XactIsoLevel\n\t},\n\n\t{\n\t\t{\"unix_socket_group\", PGC_POSTMASTER, CONN_AUTH_SETTINGS,\n\t\t\tgettext_noop(\"Sets the owning group of the Unix-domain socket.\"),\n\t\t\tgettext_noop(\"The owning user of the socket is always the user \"\n\t\t\t\t\t\t \"that starts the server.\")\n\t\t},\n\t\t&Unix_socket_group,\n\t\t\"\",\n\t\tNULL, NULL, NULL\n\t},\n\n\t{\n\t\t{\"unix_socket_directories\", PGC_POSTMASTER, CONN_AUTH_SETTINGS,\n\t\t\tgettext_noop(\"Sets the directories where Unix-domain sockets will be created.\"),\n\t\t\tNULL,\n\t\t\tGUC_SUPERUSER_ONLY\n\t\t},\n\t\t&Unix_socket_directories,\n#ifdef HAVE_UNIX_SOCKETS\n\t\tDEFAULT_PGSOCKET_DIR,\n#else\n\t\t\"\",\n#endif\n\t\tNULL, NULL, NULL\n\t},\n\n\t{\n\t\t{\"listen_addresses\", PGC_POSTMASTER, CONN_AUTH_SETTINGS,\n\t\t\tgettext_noop(\"Sets the host name or IP address(es) to listen to.\"),\n\t\t\tNULL,\n\t\t\tGUC_LIST_INPUT\n\t\t},\n\t\t&ListenAddresses,\n\t\t\"localhost\",\n\t\tNULL, NULL, NULL\n\t},\n\n\t{\n\t\t{\"data_directory\", PGC_POSTMASTER, FILE_LOCATIONS,\n\t\t\tgettext_noop(\"Sets the server's data directory.\"),\n\t\t\tNULL,\n\t\t\tGUC_SUPERUSER_ONLY\n\t\t},\n\t\t&data_directory,\n\t\tNULL,\n\t\tNULL, NULL, NULL\n\t},\n\n\t{\n\t\t{\"config_file\", PGC_POSTMASTER, FILE_LOCATIONS,\n\t\t\tgettext_noop(\"Sets the server's main configuration file.\"),\n\t\t\tNULL,\n\t\t\tGUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY\n\t\t},\n\t\t&ConfigFileName,\n\t\tNULL,\n\t\tNULL, NULL, NULL\n\t},\n\n\t{\n\t\t{\"hba_file\", PGC_POSTMASTER, FILE_LOCATIONS,\n\t\t\tgettext_noop(\"Sets the server's \\\"hba\\\" configuration file.\"),\n\t\t\tNULL,\n\t\t\tGUC_SUPERUSER_ONLY\n\t\t},\n```\n\n### src/bin/initdb/initdb.c\n\n#### region() [lines 1165-1252]\n```c\n\t\tif (status == 0)\n\t\t\tbreak;\n\t}\n\tn_buffers = test_buffs;\n\n\tif ((n_buffers * (BLCKSZ / 1024)) % 1024 == 0)\n\t\tprintf(\"%dMB\\n\", (n_buffers * (BLCKSZ / 1024)) / 1024);\n\telse\n\t\tprintf(\"%dkB\\n\", n_buffers * (BLCKSZ / 1024));\n}\n\n/*\n * set up all the config files\n */\nstatic void\nsetup_config(void)\n{\n\tchar\t **conflines;\n\tchar\t\trepltok[MAXPGPATH];\n\tchar\t\tpath[MAXPGPATH];\n\tconst char *default_timezone;\n\n\tfputs(_(\"creating configuration files ... \"), stdout);\n\tfflush(stdout);\n\n\t/* postgresql.conf */\n\n\tconflines = readfile(conf_file);\n\n\tsnprintf(repltok, sizeof(repltok), \"max_connections = %d\", n_connections);\n\tconflines = replace_token(conflines, \"#max_connections = 100\", repltok);\n\n\tif ((n_buffers * (BLCKSZ / 1024)) % 1024 == 0)\n\t\tsnprintf(repltok, sizeof(repltok), \"shared_buffers = %dMB\",\n\t\t\t\t (n_buffers * (BLCKSZ / 1024)) / 1024);\n\telse\n\t\tsnprintf(repltok, sizeof(repltok), \"shared_buffers = %dkB\",\n\t\t\t\t n_buffers * (BLCKSZ / 1024));\n\tconflines = replace_token(conflines, \"#shared_buffers = 32MB\", repltok);\n\n#ifdef HAVE_UNIX_SOCKETS\n\tsnprintf(repltok, sizeof(repltok), \"#unix_socket_directories = '%s'\",\n\t\t\t DEFAULT_PGSOCKET_DIR);\n#else\n\tsnprintf(repltok, sizeof(repltok), \"#unix_socket_directories = ''\");\n#endif\n\tconflines = replace_token(conflines, \"#unix_socket_directories = '/tmp'\",\n\t\t\t\t\t\t\t repltok);\n\n#if DEF_PGPORT != 5432\n\tsnprintf(repltok, sizeof(repltok), \"#port = %d\", DEF_PGPORT);\n\tconflines = replace_token(conflines, \"#port = 5432\", repltok);\n#endif\n\n\tsnprintf(repltok, sizeof(repltok), \"lc_messages = '%s'\",\n\t\t\t escape_quotes(lc_messages));\n\tconflines = replace_token(conflines, \"#lc_messages = 'C'\", repltok);\n\n\tsnprintf(repltok, sizeof(repltok), \"lc_monetary = '%s'\",\n\t\t\t escape_quotes(lc_monetary));\n\tconflines = replace_token(conflines, \"#lc_monetary = 'C'\", repltok);\n\n\tsnprintf(repltok, sizeof(repltok), \"lc_numeric = '%s'\",\n\t\t\t escape_quotes(lc_numeric));\n\tconflines = replace_token(conflines, \"#lc_numeric = 'C'\", repltok);\n\n\tsnprintf(repltok, sizeof(repltok), \"lc_time = '%s'\",\n\t\t\t escape_quotes(lc_time));\n\tconflines = replace_token(conflines, \"#lc_time = 'C'\", repltok);\n\n\tswitch (locale_date_order(lc_time))\n\t{\n\t\tcase DATEORDER_YMD:\n\t\t\tstrcpy(repltok, \"datestyle = 'iso, ymd'\");\n\t\t\tbreak;\n\t\tcase DATEORDER_DMY:\n\t\t\tstrcpy(repltok, \"datestyle = 'iso, dmy'\");\n\t\t\tbreak;\n\t\tcase DATEORDER_MDY:\n\t\tdefault:\n\t\t\tstrcpy(repltok, \"datestyle = 'iso, mdy'\");\n\t\t\tbreak;\n\t}\n\tconflines = replace_token(conflines, \"#datestyle = 'iso, mdy'\", repltok);\n\n\tsnprintf(repltok, sizeof(repltok),\n\t\t\t \"default_text_search_config = 'pg_catalog.%s'\",\n\t\t\t escape_quotes(default_text_search_config));\n```\n\n### src/include/pg_config_manual.h\n\n#### region() [lines 105-192]\n```c\n\n/*\n * Disable UNIX sockets for certain operating systems.\n */\n#if defined(WIN32)\n#undef HAVE_UNIX_SOCKETS\n#endif\n\n/*\n * Define this if your operating system supports link()\n */\n#if !defined(WIN32) && !defined(__CYGWIN__)\n#define HAVE_WORKING_LINK 1\n#endif\n\n/*\n * USE_POSIX_FADVISE controls whether Postgres will attempt to use the\n * posix_fadvise() kernel call. Usually the automatic configure tests are\n * sufficient, but some older Linux distributions had broken versions of\n * posix_fadvise(). If necessary you can remove the #define here.\n */\n#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)\n#define USE_POSIX_FADVISE\n#endif\n\n/*\n * USE_PREFETCH code should be compiled only if we have a way to implement\n * prefetching. (This is decoupled from USE_POSIX_FADVISE because there\n * might in future be support for alternative low-level prefetch APIs.)\n */\n#ifdef USE_POSIX_FADVISE\n#define USE_PREFETCH\n#endif\n\n/*\n * This is the default directory in which AF_UNIX socket files are\n * placed. Caution: changing this risks breaking your existing client\n * applications, which are likely to continue to look in the old\n * directory. But if you just hate the idea of sockets in /tmp,\n * here's where to twiddle it. You can also override this at runtime\n * with the postmaster's -k switch.\n */\n#define DEFAULT_PGSOCKET_DIR \"/tmp\"\n\n/*\n * The random() function is expected to yield values between 0 and\n * MAX_RANDOM_VALUE. Currently, all known implementations yield\n * 0..2^31-1, so we just hardwire this constant. We could do a\n * configure test if it proves to be necessary. CAUTION: Think not to\n * replace this with RAND_MAX. RAND_MAX defines the maximum value of\n * the older rand() function, which is often different from --- and\n * considerably inferior to --- random().\n */\n#define MAX_RANDOM_VALUE (0x7FFFFFFF)\n\n/*\n * Set the format style used by gcc to check printf type functions. We really\n * want the \"gnu_printf\" style set, which includes what glibc uses, such\n * as %m for error strings and %lld for 64 bit long longs. But not all gcc\n * compilers are known to support it, so we just use \"printf\" which all\n * gcc versions alive are known to support, except on Windows where\n * using \"gnu_printf\" style makes a dramatic difference. Maybe someday\n * we'll have a configure test for this, if we ever discover use of more\n * variants to be necessary.\n */\n#ifdef WIN32\n#define PG_PRINTF_ATTRIBUTE gnu_printf\n#else\n#define PG_PRINTF_ATTRIBUTE printf\n#endif\n\n/*\n * On PPC machines, decide whether to use the mutex hint bit in LWARX\n * instructions. Setting the hint bit will slightly improve spinlock\n * performance on POWER6 and later machines, but does nothing before that,\n * and will result in illegal-instruction failures on some pre-POWER4\n * machines. By default we use the hint bit when building for 64-bit PPC,\n * which should be safe in nearly all cases. You might want to override\n * this if you are building 32-bit code for a known-recent PPC machine.\n */\n#ifdef HAVE_PPC_LWARX_MUTEX_HINT\t/* must have assembler support in any case */\n#if defined(__ppc64__) || defined(__powerpc64__)\n#define USE_PPC_LWARX_MUTEX_HINT\n#endif\n#endif\n\n/*\n * On PPC machines, decide whether to use LWSYNC instructions in place of\n```\n\n\n## Upstream Fix\n```diff\nChange the built-in default socket directory to be /var/run/postgresql.\nFor backwards compatibility with (probably non-libpq-based) clients that\nmight still expect to find the socket in /tmp, also create a socket in\n/tmp. This is to resolve communication problems with clients operating\nunder systemd's PrivateTmp environment, which won't be using the same\nglobal /tmp directory as the server; see bug #825448.\n\nNote that we apply the socket directory change at the level of the\nhard-wired defaults in the C code, not by just twiddling the setting in\npostgresql.conf.sample; this is so that the change will take effect on\nserver package update, without requiring any existing postgresql.conf\nto be updated. (Of course, a user who dislikes this behavior can still\noverride it via postgresql.conf.)\n\n\nIndex: postgresql-9.3.5/contrib/pg_upgrade/test.sh\n===================================================================\n--- postgresql-9.3.5.orig/contrib/pg_upgrade/test.sh\t2014-07-25 12:48:53.890020586 +0200\n+++ postgresql-9.3.5/contrib/pg_upgrade/test.sh\t2014-07-25 12:54:10.221108886 +0200\n@@ -138,6 +138,12 @@\n EXTRA_REGRESS_OPTS=\"$EXTRA_REGRESS_OPTS --port=$PGPORT\"\n export EXTRA_REGRESS_OPTS\n \n+# we want the Unix sockets in $temp_root\n+PGHOST=$temp_root\n+export PGHOST\n+\n+POSTMASTER_OPTS=\"$POSTMASTER_OPTS -c unix_socket_directories='$PGHOST'\"\n+\n # enable echo so the user can see what is being executed\n set -x\n \nIndex: postgresql-9.3.5/src/backend/utils/misc/guc.c\n===================================================================\n--- postgresql-9.3.5.orig/src/backend/utils/misc/guc.c\t2014-07-25 12:48:53.893020625 +0200\n+++ postgresql-9.3.5/src/backend/utils/misc/guc.c\t2014-07-25 12:54:10.223108912 +0200\n@@ -2971,7 +2971,7 @@\n \t\t},\n \t\t&Unix_socket_directories,\n #ifdef HAVE_UNIX_SOCKETS\n-\t\tDEFAULT_PGSOCKET_DIR,\n+\t\tDEFAULT_PGSOCKET_DIR \", /tmp\",\n #else\n \t\t\"\",\n #endif\nIndex: postgresql-9.3.5/src/bin/initdb/initdb.c\n===================================================================\n--- postgresql-9.3.5.orig/src/bin/initdb/initdb.c\t2014-07-25 12:48:53.894020638 +0200\n+++ postgresql-9.3.5/src/bin/initdb/initdb.c\t2014-07-25 12:54:10.223108912 +0200\n@@ -1204,7 +1204,7 @@\n \n #ifdef HAVE_UNIX_SOCKETS\n \tsnprintf(repltok, sizeof(repltok), \"#unix_socket_directories = '%s'\",\n-\t\t\t DEFAULT_PGSOCKET_DIR);\n+\t\t\t DEFAULT_PGSOCKET_DIR \", /tmp\");\n #else\n \tsnprintf(repltok, sizeof(repltok), \"#unix_socket_directories = ''\");\n #endif\nIndex: postgresql-9.3.5/src/include/pg_config_manual.h\n===================================================================\n--- postgresql-9.3.5.orig/src/include/pg_config_manual.h\t2014-07-25 12:48:53.894020638 +0200\n+++ postgresql-9.3.5/src/include/pg_config_manual.h\t2014-07-25 12:54:10.224108925 +0200\n@@ -144,7 +144,7 @@\n * here's where to twiddle it. You can also override this at runtime\n * with the postmaster's -k switch.\n */\n-#define DEFAULT_PGSOCKET_DIR \"/tmp\"\n+#define DEFAULT_PGSOCKET_DIR \"/var/run/postgresql\"\n \n /*\n * The random() function is expected to yield values between 0 and\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "Change the built-in default socket directory to be /var/run/postgresql.\nFor backwards compatibility with (probably non-libpq-based) clients that\nmight still expect to find the socket in /tmp, also create a socket in\n/tmp. This is to resolve communication problems with clients operating\nunder systemd's PrivateTmp environment, which won't be using the same\nglobal /tmp directory as the server; see bug #825448.\n\nNote that we apply the socket directory change at the level of the\nhard-wired defaults in the C code, not by just twiddling the setting in\npostgresql.conf.sample; this is so that the change will take effect on\nserver package update, without requiring any existing postgresql.conf\nto be updated. (Of course, a user who dislikes this behavior can still\noverride it via postgresql.conf.)\n\n\nIndex: postgresql-9.3.5/contrib/pg_upgrade/test.sh\n===================================================================\n--- postgresql-9.3.5.orig/contrib/pg_upgrade/test.sh\t2014-07-25 12:48:53.890020586 +0200\n+++ postgresql-9.3.5/contrib/pg_upgrade/test.sh\t2014-07-25 12:54:10.221108886 +0200\n@@ -138,6 +138,12 @@\n EXTRA_REGRESS_OPTS=\"$EXTRA_REGRESS_OPTS --port=$PGPORT\"\n export EXTRA_REGRESS_OPTS\n \n+# we want the Unix sockets in $temp_root\n+PGHOST=$temp_root\n+export PGHOST\n+\n+POSTMASTER_OPTS=\"$POSTMASTER_OPTS -c unix_socket_directories='$PGHOST'\"\n+\n # enable echo so the user can see what is being executed\n set -x\n \nIndex: postgresql-9.3.5/src/backend/utils/misc/guc.c\n===================================================================\n--- postgresql-9.3.5.orig/src/backend/utils/misc/guc.c\t2014-07-25 12:48:53.893020625 +0200\n+++ postgresql-9.3.5/src/backend/utils/misc/guc.c\t2014-07-25 12:54:10.223108912 +0200\n@@ -2971,7 +2971,7 @@\n \t\t},\n \t\t&Unix_socket_directories,\n #ifdef HAVE_UNIX_SOCKETS\n-\t\tDEFAULT_PGSOCKET_DIR,\n+\t\tDEFAULT_PGSOCKET_DIR \", /tmp\",\n #else\n \t\t\"\",\n #endif\nIndex: postgresql-9.3.5/src/bin/initdb/initdb.c\n===================================================================\n--- postgresql-9.3.5.orig/src/bin/initdb/initdb.c\t2014-07-25 12:48:53.894020638 +0200\n+++ postgresql-9.3.5/src/bin/initdb/initdb.c\t2014-07-25 12:54:10.223108912 +0200\n@@ -1204,7 +1204,7 @@\n \n #ifdef HAVE_UNIX_SOCKETS\n \tsnprintf(repltok, sizeof(repltok), \"#unix_socket_directories = '%s'\",\n-\t\t\t DEFAULT_PGSOCKET_DIR);\n+\t\t\t DEFAULT_PGSOCKET_DIR \", /tmp\");\n #else\n \tsnprintf(repltok, sizeof(repltok), \"#unix_socket_directories = ''\");\n #endif\nIndex: postgresql-9.3.5/src/include/pg_config_manual.h\n===================================================================\n--- postgresql-9.3.5.orig/src/include/pg_config_manual.h\t2014-07-25 12:48:53.894020638 +0200\n+++ postgresql-9.3.5/src/include/pg_config_manual.h\t2014-07-25 12:54:10.224108925 +0200\n@@ -144,7 +144,7 @@\n * here's where to twiddle it. You can also override this at runtime\n * with the postmaster's -k switch.\n */\n-#define DEFAULT_PGSOCKET_DIR \"/tmp\"\n+#define DEFAULT_PGSOCKET_DIR \"/var/run/postgresql\"\n \n /*\n * The random() function is expected to yield values between 0 and" } ]
{ "id": "postgresql93-5637-postgresql-var-run-socket.patc", "cve_id": "CVE-2016-5423", "package": "postgresql93", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": true, "license": "PostgreSQL", "context_tokens_est": 2712, "context_files": 4 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-3627\n\nThe xmlStringGetNodeList function in tree.c in libxml2 2.9.3 and earlier, when used in recovery mode, allows context-dependent attackers to cause a denial of service (infinite recursion, stack consumption, and application crash) via a crafted XML document.\n\n## Package\nlibxml2\n\n## Files to modify\n- parser.c\n\n## Target Source Code\n\n### parser.c\n\n#### xmlParseReference() [lines 7196-7078]\n```c\n\n```\n\n\n## Upstream Fix\n```diff\nFrom 72a46a519ce7326d9a00f0b6a7f2a8e958cd1675 Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard <veillard@redhat.com>\nDate: Thu, 23 Oct 2014 11:35:36 +0800\nSubject: [PATCH] Fix missing entities after CVE-2014-3660 fix\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=738805\n\nThe fix for CVE-2014-3660 introduced a regression in some case\nwhere entity substitution is required and the entity is used\nfirst in anotther entity referenced from an attribute value\n---\n parser.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/parser.c b/parser.c\nindex 67c9dfd9ad..a8d1b67316 100644\n--- a/parser.c\n+++ b/parser.c\n@@ -7235,7 +7235,8 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {\n * far more secure as the parser will only process data coming from\n * the document entity by default.\n */\n- if ((ent->checked == 0) &&\n+ if (((ent->checked == 0) ||\n+ ((ent->children == NULL) && (ctxt->options & XML_PARSE_NOENT))) &&\n ((ent->etype != XML_EXTERNAL_GENERAL_PARSED_ENTITY) ||\n (ctxt->options & (XML_PARSE_NOENT | XML_PARSE_DTDVALID)))) {\n \tunsigned long oldnbent = ctxt->nbentities;\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 72a46a519ce7326d9a00f0b6a7f2a8e958cd1675 Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard <veillard@redhat.com>\nDate: Thu, 23 Oct 2014 11:35:36 +0800\nSubject: [PATCH 1/2] Fix missing entities after CVE-2014-3660 fix\n\nFor https://bugzilla.gnome.org/show_bug.cgi?id=738805\n\nThe fix for CVE-2014-3660 introduced a regression in some case\nwhere entity substitution is required and the entity is used\nfirst in anotther entity referenced from an attribute value\n---\n parser.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/parser.c b/parser.c\nindex 67c9dfd..a8d1b67 100644\n--- a/parser.c\n+++ b/parser.c\n@@ -7235,7 +7235,8 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {\n * far more secure as the parser will only process data coming from\n * the document entity by default.\n */\n- if ((ent->checked == 0) &&\n+ if (((ent->checked == 0) ||\n+ ((ent->children == NULL) && (ctxt->options & XML_PARSE_NOENT))) &&\n ((ent->etype != XML_EXTERNAL_GENERAL_PARSED_ENTITY) ||\n (ctxt->options & (XML_PARSE_NOENT | XML_PARSE_DTDVALID)))) {\n \tunsigned long oldnbent = ctxt->nbentities;\n-- \n2.1.2" } ]
{ "id": "libxml2-5040-0001-Fix-missing-entities-afte", "cve_id": "CVE-2016-3627", "package": "libxml2", "upstream_enriched": true, "upstream_commit": "72a46a519ce7326d9a00f0b6a7f2a8e958cd1675", "upstream_repo": "GNOME/libxml2", "tier": "adapted", "has_source_context": true, "license": "MIT", "context_tokens_est": 16, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2013-4288\n\nRace condition in PolicyKit (aka polkit) allows local users to bypass intended PolicyKit restrictions and gain privileges by starting a setuid or pkexec process before the authorization check is performed, related to (1) the polkit_unix_process_new API function, (2) the dbus API, or (3) the --process (unix-process) option for authorization to pkcheck.\n\n## Package\nsystemd-mini\n\n## Files to modify\n- src/libudev/libudev-device.c\n- src/udev/udevd.c\n- systemd-195.orig/src/libudev/libudev-device.c\n- systemd-195.orig/src/udev/udevd.c\n- src/libudev/libudev-private.h\n\n## Target Source Code\n\n### src/libudev/libudev-device.c\n\n#### region() [lines 29-115]\n```c\n#include \"libudev-private.h\"\n\n/**\n * SECTION:libudev-device\n * @short_description: kernel sys devices\n *\n * Representation of kernel sys devices. Devices are uniquely identified\n * by their syspath, every device has exactly one path in the kernel sys\n * filesystem. Devices usually belong to a kernel subsystem, and and have\n * a unique name inside that subsystem.\n */\n\n/**\n * udev_device:\n *\n * Opaque object representing one kernel sys device.\n */\nstruct udev_device {\n struct udev *udev;\n struct udev_device *parent_device;\n char *syspath;\n const char *devpath;\n char *sysname;\n const char *sysnum;\n char *devnode;\n mode_t devnode_mode;\n char *subsystem;\n char *devtype;\n char *driver;\n char *action;\n char *devpath_old;\n char *id_filename;\n char **envp;\n char *monitor_buf;\n size_t monitor_buf_len;\n struct udev_list devlinks_list;\n struct udev_list properties_list;\n struct udev_list sysattr_value_list;\n struct udev_list sysattr_list;\n struct udev_list tags_list;\n unsigned long long int seqnum;\n unsigned long long int usec_initialized;\n int devlink_priority;\n int refcount;\n dev_t devnum;\n int ifindex;\n int watch_handle;\n int maj, min;\n bool parent_set;\n bool subsystem_set;\n bool devtype_set;\n bool devlinks_uptodate;\n bool envp_uptodate;\n bool tags_uptodate;\n bool driver_set;\n bool info_loaded;\n bool db_loaded;\n bool uevent_loaded;\n bool is_initialized;\n bool sysattr_list_read;\n bool db_persist;\n};\n\n/**\n * udev_device_get_seqnum:\n * @udev_device: udev device\n *\n * This is only valid if the device was received through a monitor. Devices read from\n * sys do not have a sequence number.\n *\n * Returns: the kernel event sequence number, or 0 if there is no sequence number available.\n **/\n_public_ unsigned long long int udev_device_get_seqnum(struct udev_device *udev_device)\n{\n if (udev_device == NULL)\n return 0;\n return udev_device->seqnum;\n}\n\nstatic int udev_device_set_seqnum(struct udev_device *udev_device, unsigned long long int seqnum)\n{\n char num[32];\n\n udev_device->seqnum = seqnum;\n snprintf(num, sizeof(num), \"%llu\", seqnum);\n udev_device_add_property(udev_device, \"SEQNUM\", num);\n return 0;\n```\n\n#### udev_device_set_devnum() [lines 149-165]\n```c\n return udev_device->devnum;\n}\n\nstatic int udev_device_set_devnum(struct udev_device *udev_device, dev_t devnum)\n{\n char num[32];\n\n udev_device->devnum = devnum;\n\n snprintf(num, sizeof(num), \"%u\", major(devnum));\n udev_device_add_property(udev_device, \"MAJOR\", num);\n snprintf(num, sizeof(num), \"%u\", minor(devnum));\n udev_device_add_property(udev_device, \"MINOR\", num);\n return 0;\n}\n\nconst char *udev_device_get_devpath_old(struct udev_device *udev_device)\n```\n\n#### region() [lines 357-429]\n```c\n */\nvoid udev_device_add_property_from_string_parse(struct udev_device *udev_device, const char *property)\n{\n if (startswith(property, \"DEVPATH=\")) {\n char path[UTIL_PATH_SIZE];\n\n util_strscpyl(path, sizeof(path), \"/sys\", &property[8], NULL);\n udev_device_set_syspath(udev_device, path);\n } else if (startswith(property, \"SUBSYSTEM=\")) {\n udev_device_set_subsystem(udev_device, &property[10]);\n } else if (startswith(property, \"DEVTYPE=\")) {\n udev_device_set_devtype(udev_device, &property[8]);\n } else if (startswith(property, \"DEVNAME=\")) {\n udev_device_set_devnode(udev_device, &property[8]);\n } else if (startswith(property, \"DEVLINKS=\")) {\n char devlinks[UTIL_PATH_SIZE];\n char *slink;\n char *next;\n\n util_strscpy(devlinks, sizeof(devlinks), &property[9]);\n slink = devlinks;\n next = strchr(slink, ' ');\n while (next != NULL) {\n next[0] = '\\0';\n \n/* ... truncated ... */\n```\n\n### src/libudev/libudev-private.h\n\n#### region() [lines 26-112]\n```c\n#define WRITE_END 1\n\n/* avoid (sometimes expensive) calculations of parameters for debug output */\n#define udev_log_cond(udev, prio, arg...) \\\n do { \\\n if (udev_get_log_priority(udev) >= prio) \\\n udev_log(udev, prio, __FILE__, __LINE__, __FUNCTION__, ## arg); \\\n } while (0)\n\n#define udev_dbg(udev, arg...) udev_log_cond(udev, LOG_DEBUG, ## arg)\n#define udev_info(udev, arg...) udev_log_cond(udev, LOG_INFO, ## arg)\n#define udev_err(udev, arg...) udev_log_cond(udev, LOG_ERR, ## arg)\n\n/* libudev.c */\nvoid udev_log(struct udev *udev,\n int priority, const char *file, int line, const char *fn,\n const char *format, ...)\n __attribute__((format(printf, 6, 7)));\nint udev_get_rules_path(struct udev *udev, char **path[], unsigned long long *ts_usec[]);\nstruct udev_list_entry *udev_add_property(struct udev *udev, const char *key, const char *value);\nstruct udev_list_entry *udev_get_properties_list_entry(struct udev *udev);\n\n/* libudev-device.c */\nstruct udev_device *udev_device_new(struct udev *udev);\nmode_t udev_device_get_devnode_mode(struct udev_device *udev_device);\nint udev_device_set_syspath(struct udev_device *udev_device, const char *syspath);\nint udev_device_set_devnode(struct udev_device *udev_device, const char *devnode);\nint udev_device_add_devlink(struct udev_device *udev_device, const char *devlink);\nvoid udev_device_cleanup_devlinks_list(struct udev_device *udev_device);\nstruct udev_list_entry *udev_device_add_property(struct udev_device *udev_device, const char *key, const char *value);\nvoid udev_device_add_property_from_string_parse(struct udev_device *udev_device, const char *property);\nint udev_device_add_property_from_string_parse_finish(struct udev_device *udev_device);\nchar **udev_device_get_properties_envp(struct udev_device *udev_device);\nssize_t udev_device_get_properties_monitor_buf(struct udev_device *udev_device, const char **buf);\nint udev_device_read_db(struct udev_device *udev_device, const char *dbfile);\nint udev_device_read_uevent_file(struct udev_device *udev_device);\nint udev_device_set_action(struct udev_device *udev_device, const char *action);\nconst char *udev_device_get_devpath_old(struct udev_device *udev_device);\nconst char *udev_device_get_id_filename(struct udev_device *udev_device);\nvoid udev_device_set_is_initialized(struct udev_device *udev_device);\nint udev_device_add_tag(struct udev_device *udev_device, const char *tag);\nvoid udev_device_cleanup_tags_list(struct udev_device *udev_device);\nunsigned long long udev_device_get_usec_initialized(struct udev_device *udev_device);\nvoid udev_device_set_usec_initialized(struct udev_device *udev_device, unsigned long long usec_initialized);\nint udev_device_get_devlink_priority(struct udev_device *udev_device);\nint udev_device_set_devlink_priority(struct udev_device *udev_device, int prio);\nint udev_device_get_watch_handle(struct udev_device *udev_device);\nint udev_device_set_watch_handle(struct udev_device *udev_device, int handle);\nint udev_device_get_ifindex(struct udev_device *udev_device);\nvoid udev_device_set_info_loaded(struct udev_device *device);\nbool udev_device_get_db_persist(struct udev_device *udev_device);\nvoid udev_device_set_db_persist(struct udev_device *udev_device);\n\n/* libudev-device-private.c */\nint udev_device_update_db(struct udev_device *udev_device);\nint udev_device_delete_db(struct udev_device *udev_device);\nint udev_device_tag_index(struct udev_device *dev, struct udev_device *dev_old, bool add);\n\n/* libudev-monitor.c - netlink/unix socket communication */\nint udev_monitor_disconnect(struct udev_monitor *udev_monitor);\nint udev_monitor_allow_unicast_sender(struct udev_monitor *udev_monitor, struct udev_monitor *sender);\nint udev_monitor_send_device(struct udev_monitor *udev_monitor,\n struct udev_monitor *destination, struct udev_device *udev_device);\nstruct udev_monitor *udev_monitor_new_from_netlink_fd(struct udev *udev, const char *name, int fd);\n\n/* libudev-list.c */\nstruct udev_list_node {\n struct udev_list_node *next, *prev;\n};\nstruct udev_list {\n struct udev *udev;\n struct udev_list_node node;\n struct udev_list_entry **entries;\n \n/* ... truncated ... */\n```\n\n### src/udev/udevd.c\n\n#### region() [lines 207-390]\n```c\n worker->udev = udev;\n\n pid = fork();\n switch (pid) {\n case 0: {\n struct udev_device *dev = NULL;\n int fd_monitor;\n struct epoll_event ep_signal, ep_monitor;\n sigset_t mask;\n int rc = EXIT_SUCCESS;\n\n /* take initial device from queue */\n dev = event->dev;\n event->dev = NULL;\n\n free(worker);\n worker_list_cleanup(udev);\n event_queue_cleanup(udev, EVENT_UNDEF);\n udev_queue_export_unref(udev_queue_export);\n udev_monitor_unref(monitor);\n udev_ctrl_unref(udev_ctrl);\n close(fd_signal);\n close(fd_ep);\n close(worker_watch[READ_END]);\n\n sigfillset(&mask);\n fd_signal = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC);\n if (fd_signal < 0) {\n log_error(\"error creating signalfd %m\\n\");\n rc = 2;\n goto out;\n }\n\n fd_ep = epoll_create1(EPOLL_CLOEXEC);\n if (fd_ep < 0) {\n log_error(\"error creating epoll fd: %m\\n\");\n rc = 3;\n goto out;\n }\n\n/* ... 132 lines omitted ... */\n worker->pid = pid;\n worker->state = WORKER_RUNNING;\n worker->event_start_usec = now_usec();\n worker->event = event;\n event->state = EVENT_RUNNING;\n udev_list_node_append(&worker->node, &worker_list);\n children++;\n log_debug(\"seq %llu forked new worker [%u]\\n\", udev_device_get_seqnum(event->dev), pid);\n break;\n }\n}\n\n```\n\n#### event_run() [lines 388-427]\n```c\n }\n}\n\nstatic void event_run(struct event *event)\n{\n struct udev_list_node *loop;\n\n udev_list_node_foreach(loop, &worker_list) {\n struct worker *worker = node_to_worker(loop);\n ssize_t count;\n\n if (worker->state != WORKER_IDLE)\n continue;\n\n count = udev_monitor_send_device(monitor, worker->monitor, event->dev);\n if (count < 0) {\n log_error(\"worker [%u] did not accept message %zi (%m), kill it\\n\", worker->pid, count);\n kill(worker->pid, SIGKILL);\n worker->state = WORKER_KILLED;\n continue;\n }\n worker_ref(worker);\n worker->event = event;\n worker->state = WORKER_RUNNING;\n worker->event_start_usec = now_usec();\n event->state = EVENT_RUNNING;\n return;\n }\n\n if (children >= children_max) {\n if (children_max > 1)\n log_debug(\"maximum number (%i) of children reached\\n\", children);\n return;\n }\n\n /* start new worker and pass initial device */\n worker_new(event);\n}\n\nstatic int event_queue_insert(struct udev_device *dev)\n```\n\n#### event_queue_insert() [lines 424-456]\n```c\n worker_new(event);\n}\n\nstatic int event_queue_insert(struct udev_device *dev)\n{\n struct event *event;\n\n event = calloc(1, sizeof(struct event));\n if (event == NULL)\n return -1;\n\n event->udev = udev_device_get_udev(dev);\n event->dev = dev;\n event->seqnum = udev_device_get_seqnum(dev);\n event->devpath = udev_device_get_devpath(dev);\n event->devpath_len = strlen(event->devpath);\n event->devpath_old = udev_device_get_devpath_old(dev);\n event->devnum = udev_device_get_devnum(dev);\n event->is_block = streq(\"block\", udev_device_get_subsystem(dev));\n event->ifindex = udev_device_get_ifindex(dev);\n if (streq(udev_device_get_subsystem(dev), \"firmware\"))\n event->nodelay = true;\n\n udev_queue_export_device_queued(udev_queue_export, dev);\n log_debug(\"seq %llu queued, '%s' '%s'\\n\", udev_device_get_seqnum(dev),\n \n/* ... truncated ... */\n```\n\n\n### Type definitions\n\n```c\n/* from libudev-private.h */\nstruct udev_list_node {\n struct udev_list_node *next, *prev;\n};\n\n/* from libudev-private.h */\nstruct udev_list {\n struct udev *udev;\n struct udev_list_node node;\n struct udev_list_entry **entries;\n unsigned int entries_cur;\n unsigned int entries_max;\n bool unique;\n};\n```\n\n\n## Upstream Fix\n```diff\nWithout treating events with timeouts specially some drivers would\ncause a 30 seconds stall on boot: .\n\nI also received reports of some drivers not working at all, even\nafter the timeout.\n\nWe will remove this patch when more drivers have been fixed in\nthe kernel (3.4?).\n\nThis reverts 43d5c5f03645c4b842659f9b5bd0ae465e885e92 and\n57c6f8ae5f52a6e8ffc66a54966346f733dded39.\n---\n\nNote: this is mostly a FYI, and whether or not it makes sense\nto apply this upstream depends on how big problems other report\nregarding this issue.\n\n src/libudev-device.c | 19 +++++++++++++++++++\n src/libudev-private.h | 1 +\n src/udevd.c | 13 ++++++++++---\n 4 files changed, 32 insertions(+), 3 deletions(-)\n\nIndex: systemd-195/src/libudev/libudev-device.c\n===================================================================\n--- systemd-195.orig/src/libudev/libudev-device.c\n+++ systemd-195/src/libudev/libudev-device.c\n@@ -68,6 +68,7 @@ struct udev_device {\n struct udev_list tags_list;\n unsigned long long int seqnum;\n unsigned long long int usec_initialized;\n+ int timeout;\n int devlink_priority;\n int refcount;\n dev_t devnum;\n@@ -162,6 +163,21 @@ static int udev_device_set_devnum(struct\n return 0;\n }\n \n+int udev_device_get_timeout(struct udev_device *udev_device)\n+{\n+ return udev_device->timeout;\n+}\n+\n+static int udev_device_set_timeout(struct udev_device *udev_device, int timeout)\n+{\n+ char num[32];\n+\n+ udev_device->timeout = timeout;\n+ snprintf(num, sizeof(num), \"%u\", timeout);\n+ udev_device_add_property(udev_device, \"TIMEOUT\", num);\n+ return 0;\n+}\n+\n const char *udev_device_get_devpath_old(struct udev_device *udev_device)\n {\n return udev_device->devpath_old;\n@@ -418,6 +434,8 @@ void udev_device_add_property_from_strin\n udev_device_set_devpath_old(udev_device, &property[12]);\n } else if (startswith(property, \"SEQNUM=\")) {\n udev_device_set_seqnum(udev_device, strtoull(&property[7], NULL, 10));\n+ } else if (startswith(property, \"TIMEOUT=\")) {\n+ udev_device_set_timeout(udev_device, strtoull(&property[8], NULL, 10));\n } else if (startswith(property, \"IFINDEX=\")) {\n udev_device_set_ifindex(udev_device, strtoull(&property[8], NULL, 10));\n } else if (startswith(property, \"DEVMODE=\")) {\n@@ -605,6 +623,7 @@ struct udev_device *udev_device_new(stru\n udev_list_init(udev, &udev_device->sysattr_value_list, true);\n udev_list_init(udev, &udev_device->sysattr_list, false);\n udev_list_init(udev, &udev_device->tags_list, true);\n+ udev_device->timeout = -1;\n udev_device->watch_handle = -1;\n /* copy global properties */\n udev_list_entry_foreach(list_entry, udev_get_properties_list_entry(udev))\nIndex: systemd-195/src/libudev/libudev-private.h\n===================================================================\n--- systemd-195.orig/src/libudev/libudev-private.h\n+++ systemd-195/src/libudev/libudev-private.h\n@@ -65,6 +65,7 @@ const char *udev_device_get_id_filename(\n void udev_device_set_is_initialized(struct udev_device *udev_device);\n int udev_device_add_tag(struct udev_device *udev_device, const char *tag);\n void udev_device_cleanup_tags_list(struct udev_device *udev_device);\n+int udev_device_get_timeout(struct udev_device *udev_device);\n unsigned long long udev_device_get_usec_initialized(struct udev_device *udev_device);\n void udev_device_set_usec_initialized(struct udev_device *udev_device, unsigned long long usec_initialized);\n int udev_device_get_devlink_priority(struct udev_device *udev_device);\nIndex: systemd-195/src/udev/udevd.c\n===================================================================\n--- systemd-195.orig/src/udev/udevd.c\n+++ systemd-195/src/udev/udevd.c\n@@ -388,7 +388,7 @@ out:\n }\n }\n \n-static void event_run(struct event *event)\n+static void event_run(struct event *event, bool force)\n {\n struct udev_list_node *loop;\n \n@@ -414,7 +414,7 @@ static void event_run(struct event *even\n return;\n }\n \n- if (children >= children_max) {\n+ if (!force && children >= children_max) {\n if (children_max > 1)\n log_debug(\"maximum number (%i) of children reached\\n\", children);\n return;\n@@ -450,6 +450,13 @@ static int event_queue_insert(struct ude\n \n event->state = EVENT_QUEUED;\n udev_list_node_append(&event->node, &event_list);\n+\n+ /* run all events with a timeout set immediately */\n+ if (udev_device_get_timeout(dev) > 0) {\n+ event_run(event, true);\n+ return 0;\n+ }\n+\n return 0;\n }\n \n@@ -559,7 +566,7 @@ static void event_queue_start(struct ude\n if (is_devpath_busy(event))\n continue;\n \n- event_run(event);\n+ event_run(event, false);\n }\n }\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "Without treating events with timeouts specially some drivers would\ncause a 30 seconds stall on boot: .\n\nI also received reports of some drivers not working at all, even\nafter the timeout.\n\nWe will remove this patch when more drivers have been fixed in\nthe kernel (3.4?).\n\nThis reverts 43d5c5f03645c4b842659f9b5bd0ae465e885e92 and\n57c6f8ae5f52a6e8ffc66a54966346f733dded39.\n---\n\nNote: this is mostly a FYI, and whether or not it makes sense\nto apply this upstream depends on how big problems other report\nregarding this issue.\n\n src/libudev-device.c | 19 +++++++++++++++++++\n src/libudev-private.h | 1 +\n src/udevd.c | 13 ++++++++++---\n 4 files changed, 32 insertions(+), 3 deletions(-)\n\nIndex: systemd-195/src/libudev/libudev-device.c\n===================================================================\n--- systemd-195.orig/src/libudev/libudev-device.c\n+++ systemd-195/src/libudev/libudev-device.c\n@@ -68,6 +68,7 @@ struct udev_device {\n struct udev_list tags_list;\n unsigned long long int seqnum;\n unsigned long long int usec_initialized;\n+ int timeout;\n int devlink_priority;\n int refcount;\n dev_t devnum;\n@@ -162,6 +163,21 @@ static int udev_device_set_devnum(struct\n return 0;\n }\n \n+int udev_device_get_timeout(struct udev_device *udev_device)\n+{\n+ return udev_device->timeout;\n+}\n+\n+static int udev_device_set_timeout(struct udev_device *udev_device, int timeout)\n+{\n+ char num[32];\n+\n+ udev_device->timeout = timeout;\n+ snprintf(num, sizeof(num), \"%u\", timeout);\n+ udev_device_add_property(udev_device, \"TIMEOUT\", num);\n+ return 0;\n+}\n+\n const char *udev_device_get_devpath_old(struct udev_device *udev_device)\n {\n return udev_device->devpath_old;\n@@ -418,6 +434,8 @@ void udev_device_add_property_from_strin\n udev_device_set_devpath_old(udev_device, &property[12]);\n } else if (startswith(property, \"SEQNUM=\")) {\n udev_device_set_seqnum(udev_device, strtoull(&property[7], NULL, 10));\n+ } else if (startswith(property, \"TIMEOUT=\")) {\n+ udev_device_set_timeout(udev_device, strtoull(&property[8], NULL, 10));\n } else if (startswith(property, \"IFINDEX=\")) {\n udev_device_set_ifindex(udev_device, strtoull(&property[8], NULL, 10));\n } else if (startswith(property, \"DEVMODE=\")) {\n@@ -605,6 +623,7 @@ struct udev_device *udev_device_new(stru\n udev_list_init(udev, &udev_device->sysattr_value_list, true);\n udev_list_init(udev, &udev_device->sysattr_list, false);\n udev_list_init(udev, &udev_device->tags_list, true);\n+ udev_device->timeout = -1;\n udev_device->watch_handle = -1;\n /* copy global properties */\n udev_list_entry_foreach(list_entry, udev_get_properties_list_entry(udev))\nIndex: systemd-195/src/libudev/libudev-private.h\n===================================================================\n--- systemd-195.orig/src/libudev/libudev-private.h\n+++ systemd-195/src/libudev/libudev-private.h\n@@ -65,6 +65,7 @@ const char *udev_device_get_id_filename(\n void udev_device_set_is_initialized(struct udev_device *udev_device);\n int udev_device_add_tag(struct udev_device *udev_device, const char *tag);\n void udev_device_cleanup_tags_list(struct udev_device *udev_device);\n+int udev_device_get_timeout(struct udev_device *udev_device);\n unsigned long long udev_device_get_usec_initialized(struct udev_device *udev_device);\n void udev_device_set_usec_initialized(struct udev_device *udev_device, unsigned long long usec_initialized);\n int udev_device_get_devlink_priority(struct udev_device *udev_device);\nIndex: systemd-195/src/udev/udevd.c\n===================================================================\n--- systemd-195.orig/src/udev/udevd.c\n+++ systemd-195/src/udev/udevd.c\n@@ -388,7 +388,7 @@ out:\n }\n }\n \n-static void event_run(struct event *event)\n+static void event_run(struct event *event, bool force)\n {\n struct udev_list_node *loop;\n \n@@ -414,7 +414,7 @@ static void event_run(struct event *even\n return;\n }\n \n- if (children >= children_max) {\n+ if (!force && children >= children_max) {\n if (children_max > 1)\n log_debug(\"maximum number (%i) of children reached\\n\", children);\n return;\n@@ -450,6 +450,13 @@ static int event_queue_insert(struct ude\n \n event->state = EVENT_QUEUED;\n udev_list_node_append(&event->node, &event_list);\n+\n+ /* run all events with a timeout set immediately */\n+ if (udev_device_get_timeout(dev) > 0) {\n+ event_run(event, true);\n+ return 0;\n+ }\n+\n return 0;\n }\n \n@@ -559,7 +566,7 @@ static void event_queue_start(struct ude\n if (is_devpath_busy(event))\n continue;\n \n- event_run(event);\n+ event_run(event, false);\n }\n }" } ]
{ "id": "systemd-mini-2025-1001-Reinstate-TIMEOUT-handlin", "cve_id": "CVE-2013-4288", "package": "systemd-mini", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 3329, "context_files": 3 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2013-4288\n\nRace condition in PolicyKit (aka polkit) allows local users to bypass intended PolicyKit restrictions and gain privileges by starting a setuid or pkexec process before the authorization check is performed, related to (1) the polkit_unix_process_new API function, (2) the dbus API, or (3) the --process (unix-process) option for authorization to pkcheck.\n\n## Package\nsystemd\n\n## Files to modify\n- src/core/switch-root.c\n\n## Upstream Fix\n```diff\nFrom 891a4918ef75fa81e22691156c050d061bd53dd3 Mon Sep 17 00:00:00 2001\nFrom: Lennart Poettering <lennart@poettering.net>\nDate: Fri, 16 Nov 2012 18:15:30 +0100\nSubject: [PATCH] switch-root: try pivot_root() before overmounting /\n\nWe should always try to umount the old root dir if possible, instead of\novermounting it -- if that's possible.\n\nThe initial (\"first\") kernel rootfs can never be umounted, hence\nfor the usual nitrd case we never bothered using pivot_root() and\nhence with fully unmounting it. However, fedup now tranisitions twice\nduring boot, and in that case it is highly desirable that the \"second\"\nroot dir is entirely unmounted when we switch to the \"third\". This patch\nmakes that possible.\n\nThe pivot_root() needs a directory in the \"third\" root dir, to move the\n\"second\" root dir to. We use /mnt for that, under the assumption that\nthis directory is likely to exist, and is not itself a mount point.\n---\n src/core/switch-root.c | 27 ++++++++++++++++++++++++++-\n 1 file changed, 26 insertions(+), 1 deletion(-)\n\ndiff --git a/src/core/switch-root.c b/src/core/switch-root.c\nindex 150332a8587b8..ce0e41d510caf 100644\n--- a/src/core/switch-root.c\n+++ b/src/core/switch-root.c\n@@ -30,6 +30,7 @@\n #include \"util.h\"\n #include \"path-util.h\"\n #include \"switch-root.h\"\n+#include \"missing.h\"\n \n int switch_root(const char *new_root) {\n \n@@ -44,10 +45,21 @@ int switch_root(const char *new_root) {\n struct stat new_root_stat;\n bool old_root_remove;\n const char *i;\n+ _cleanup_free_ char *temporary_old_root = NULL;\n \n if (path_equal(new_root, \"/\"))\n return 0;\n \n+ /* When using pivot_root() we assume that /mnt exists as place\n+ * we can temporarily move the old root to. As we immediately\n+ * unmount it from there it doesn't matter much which\n+ * directory we choose for this, but it should be more likely\n+ * than not that /mnt exists and is suitable as mount point\n+ * and is on the same fs as the old root dir */\n+ temporary_old_root = strappend(new_root, \"/mnt\");\n+ if (!temporary_old_root)\n+ return -ENOMEM;\n+\n old_root_remove = in_initrd();\n \n if (stat(new_root, &new_root_stat) < 0) {\n@@ -103,7 +115,20 @@ int switch_root(const char *new_root) {\n log_warning(\"Failed to open root directory: %m\");\n }\n \n- if (mount(new_root, \"/\", NULL, MS_MOVE, NULL) < 0) {\n+ /* We first try a pivot_root() so that we can umount the old\n+ * root dir. In many cases (i.e. where rootfs is /), that's\n+ * not possible however, and hence we simply overmount root */\n+ if (pivot_root(new_root, temporary_old_root) >= 0) {\n+\n+ /* Immediately get rid of the old root. Since we are\n+ * running off it we need to do this lazily. */\n+ if (umount2(temporary_old_root, MNT_DETACH) < 0) {\n+ r = -errno;\n+ log_error(\"Failed to umount old root dir %s: %m\", temporary_old_root);\n+ goto fail;\n+ }\n+\n+ } else if (mount(new_root, \"/\", NULL, MS_MOVE, NULL) < 0) {\n r = -errno;\n log_error(\"Failed to mount moving %s to /: %m\", new_root);\n goto fail;\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 891a4918ef75fa81e22691156c050d061bd53dd3 Mon Sep 17 00:00:00 2001\nFrom: Lennart Poettering <lennart@poettering.net>\nDate: Fri, 16 Nov 2012 18:15:30 +0100\nSubject: [PATCH] switch-root: try pivot_root() before overmounting /\n\nWe should always try to umount the old root dir if possible, instead of\novermounting it -- if that's possible.\n\nThe initial (\"first\") kernel rootfs can never be umounted, hence\nfor the usual nitrd case we never bothered using pivot_root() and\nhence with fully unmounting it. However, fedup now tranisitions twice\nduring boot, and in that case it is highly desirable that the \"second\"\nroot dir is entirely unmounted when we switch to the \"third\". This patch\nmakes that possible.\n\nThe pivot_root() needs a directory in the \"third\" root dir, to move the\n\"second\" root dir to. We use /mnt for that, under the assumption that\nthis directory is likely to exist, and is not itself a mount point.\n---\n src/core/switch-root.c | 27 ++++++++++++++++++++++++++-\n 1 file changed, 26 insertions(+), 1 deletion(-)\n\ndiff --git a/src/core/switch-root.c b/src/core/switch-root.c\nindex 150332a..ce0e41d 100644\n--- a/src/core/switch-root.c\n+++ b/src/core/switch-root.c\n@@ -30,6 +30,7 @@\n #include \"util.h\"\n #include \"path-util.h\"\n #include \"switch-root.h\"\n+#include \"missing.h\"\n \n int switch_root(const char *new_root) {\n \n@@ -44,10 +45,21 @@ int switch_root(const char *new_root) {\n struct stat new_root_stat;\n bool old_root_remove;\n const char *i;\n+ _cleanup_free_ char *temporary_old_root = NULL;\n \n if (path_equal(new_root, \"/\"))\n return 0;\n \n+ /* When using pivot_root() we assume that /mnt exists as place\n+ * we can temporarily move the old root to. As we immediately\n+ * unmount it from there it doesn't matter much which\n+ * directory we choose for this, but it should be more likely\n+ * than not that /mnt exists and is suitable as mount point\n+ * and is on the same fs as the old root dir */\n+ temporary_old_root = strappend(new_root, \"/mnt\");\n+ if (!temporary_old_root)\n+ return -ENOMEM;\n+\n old_root_remove = in_initrd();\n \n if (stat(new_root, &new_root_stat) < 0) {\n@@ -103,7 +115,20 @@ int switch_root(const char *new_root) {\n log_warning(\"Failed to open root directory: %m\");\n }\n \n- if (mount(new_root, \"/\", NULL, MS_MOVE, NULL) < 0) {\n+ /* We first try a pivot_root() so that we can umount the old\n+ * root dir. In many cases (i.e. where rootfs is /), that's\n+ * not possible however, and hence we simply overmount root */\n+ if (pivot_root(new_root, temporary_old_root) >= 0) {\n+\n+ /* Immediately get rid of the old root. Since we are\n+ * running off it we need to do this lazily. */\n+ if (umount2(temporary_old_root, MNT_DETACH) < 0) {\n+ r = -errno;\n+ log_error(\"Failed to umount old root dir %s: %m\", temporary_old_root);\n+ goto fail;\n+ }\n+\n+ } else if (mount(new_root, \"/\", NULL, MS_MOVE, NULL) < 0) {\n r = -errno;\n log_error(\"Failed to mount moving %s to /: %m\", new_root);\n goto fail;\n-- \n1.7.10.4" } ]
{ "id": "systemd-2025-switch-root-try-pivot-root.pat", "cve_id": "CVE-2013-4288", "package": "systemd", "upstream_enriched": true, "upstream_commit": "891a4918ef75fa81e22691156c050d061bd53dd3", "upstream_repo": "systemd/systemd", "tier": "adapted", "has_source_context": false, "license": "LGPL-2.1-or-later", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-7981\n\nThe png_convert_to_rfc1123 function in png.c in libpng 1.0.x before 1.0.64, 1.2.x before 1.2.54, and 1.4.x before 1.4.17 allows remote attackers to obtain sensitive process memory information via crafted tIME chunk data in an image file, which triggers an out-of-bounds read.\n\n## Package\nlibpng12\n\n## Files to modify\n- pngrutil.c\n- pngwutil.c\n- pngset.c\n\n## Upstream Fix\n```diff\nFrom 81f44665cce4cb1373f049a76f3904e981b7a766 Mon Sep 17 00:00:00 2001\nFrom: Glenn Randers-Pehrson <glennrp at users.sourceforge.net>\nDate: Thu, 29 Oct 2015 09:26:41 -0500\nSubject: [PATCH] [libpng16] Reject attempt to write over-length PLTE chunk\n\n---\n libpng-manual.txt | 5 +++++\n libpng.3 | 5 +++++\n pngwrite.c | 4 ++--\n pngwutil.c | 7 +++++--\n 4 files changed, 17 insertions(+), 4 deletions(-)\n\ndiff --git a/libpng-manual.txt b/libpng-manual.txt\nindex afdf291f06..921463c09e 100644\n--- a/libpng-manual.txt\n+++ b/libpng-manual.txt\n@@ -5142,6 +5142,11 @@ It can be set for testing debug or beta builds to ensure that they will compile\n when the build type is switched to RC or STABLE. In essence this overrides the\n PNG_LIBPNG_BUILD_BASE_TYPE definition which is not directly user controllable.\n \n+Starting with libpng-1.6.19, attempting to write an over-length PLTE chunk\n+is an error. Previously this requirement of the PNG specification was not\n+enforced. Libpng continues to accept over-length PLTE chunks when reading,\n+but does not make any use of the extra entries.\n+\n XIII. Detecting libpng\n \n The png_get_io_ptr() function has been present since libpng-0.88, has never\ndiff --git a/libpng.3 b/libpng.3\nindex 7491f064a8..75f7b68b7b 100644\n--- a/libpng.3\n+++ b/libpng.3\n@@ -5650,6 +5650,11 @@ It can be set for testing debug or beta builds to ensure that they will compile\n when the build type is switched to RC or STABLE. In essence this overrides the\n PNG_LIBPNG_BUILD_BASE_TYPE definition which is not directly user controllable.\n \n+Starting with libpng-1.6.19, attempting to write an over-length PLTE chunk\n+is an error. Previously this requirement of the PNG specification was not\n+enforced. Libpng continues to accept over-length PLTE chunks when reading,\n+but does not make any use of the extra entries.\n+\n .SH XIII. Detecting libpng\n \n The png_get_io_ptr() function has been present since libpng-0.88, has never\ndiff --git a/pngwrite.c b/pngwrite.c\nindex 2da3f01f34..dd3f9b6c1a 100644\n--- a/pngwrite.c\n+++ b/pngwrite.c\n@@ -1,7 +1,7 @@\n \n /* pngwrite.c - general routines to write a PNG file\n *\n- * Last changed in libpng 1.6.18 [July 23, 2015]\n+ * Last changed in libpng 1.6.19 [(PENDING RELEASE)]\n * Copyright (c) 1998-2015 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n@@ -206,7 +206,7 @@ png_write_info(png_structrp png_ptr, png_const_inforp info_ptr)\n png_write_PLTE(png_ptr, info_ptr->palette,\n (png_uint_32)info_ptr->num_palette);\n \n- else if ((info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) !=0)\n+ else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n png_error(png_ptr, \"Valid palette required for paletted images\");\n \n #ifdef PNG_WRITE_tRNS_SUPPORTED\ndiff --git a/pngwutil.c b/pngwutil.c\nindex 957527584c..71923298f5 100644\n--- a/pngwutil.c\n+++ b/pngwutil.c\n@@ -922,17 +922,20 @@ void /* PRIVATE */\n png_write_PLTE(png_structrp png_ptr, png_const_colorp palette,\n png_uint_32 num_pal)\n {\n- png_uint_32 i;\n+ png_uint_32 max_num_pal, i;\n png_const_colorp pal_ptr;\n png_byte buf[3];\n \n png_debug(1, \"in png_write_PLTE\");\n \n+ max_num_pal = (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ?\n+ (1 << png_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH;\n+\n if ((\n #ifdef PNG_MNG_FEATURES_SUPPORTED\n (png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0 &&\n #endif\n- num_pal == 0) || num_pal > 256)\n+ num_pal == 0) || num_pal > max_num_pal)\n {\n if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n {\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 81f44665cce4cb1373f049a76f3904e981b7a766 Mon Sep 17 00:00:00 2001\nFrom: Glenn Randers-Pehrson <glennrp at users.sourceforge.net>\nDate: Thu, 29 Oct 2015 09:26:41 -0500\nSubject: [PATCH] [libpng16] Reject attempt to write over-length PLTE chunk\nIndex: pngwutil.c\n===================================================================\n--- pngwutil.c.orig\t2015-11-16 14:39:45.517740820 +0100\n+++ pngwutil.c\t2015-11-16 14:46:45.926414642 +0100\n@@ -575,17 +575,20 @@\n #ifdef PNG_USE_LOCAL_ARRAYS\n PNG_PLTE;\n #endif\n- png_uint_32 i;\n+ png_uint_32 max_palette_length, i;\n png_colorp pal_ptr;\n png_byte buf[3];\n \n png_debug(1, \"in png_write_PLTE\");\n \n+ max_palette_length = (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ?\n+ (1 << png_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH;\n+\n if ((\n #ifdef PNG_MNG_FEATURES_SUPPORTED\n !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&\n #endif\n- num_pal == 0) || num_pal > 256)\n+ num_pal == 0) || num_pal > max_palette_length)\n {\n if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n {\nIndex: pngrutil.c\n===================================================================\n--- pngrutil.c.orig\t2014-02-06 04:52:35.000000000 +0100\n+++ pngrutil.c\t2015-11-16 14:39:45.518740834 +0100\n@@ -503,7 +503,7 @@\n png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)\n {\n png_color palette[PNG_MAX_PALETTE_LENGTH];\n- int num, i;\n+ int max_palette_length, num, i;\n #ifdef PNG_POINTER_INDEXING_SUPPORTED\n png_colorp pal_ptr;\n #endif\n@@ -557,6 +557,19 @@\n \n num = (int)length / 3;\n \n+ /* If the palette has 256 or fewer entries but is too large for the bit\n+ * depth, we don't issue an error, to preserve the behavior of previous\n+ * libpng versions. We silently truncate the unused extra palette entries\n+ * here.\n+ */\n+ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n+ max_palette_length = (1 << png_ptr->bit_depth);\n+ else\n+ max_palette_length = PNG_MAX_PALETTE_LENGTH;\n+\n+ if (num > max_palette_length)\n+ num = max_palette_length;\n+\n #ifdef PNG_POINTER_INDEXING_SUPPORTED\n for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)\n {\nIndex: pngset.c\n===================================================================\n--- pngset.c.orig\t2015-11-16 14:39:45.509740712 +0100\n+++ pngset.c\t2015-11-16 14:39:45.518740834 +0100\n@@ -446,12 +446,17 @@\n png_colorp palette, int num_palette)\n {\n \n+ png_uint_32 max_palette_length;\n+\n png_debug1(1, \"in %s storage function\", \"PLTE\");\n \n if (png_ptr == NULL || info_ptr == NULL)\n return;\n \n- if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)\n+ max_palette_length = (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ?\n+ (1 << png_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH;\n+\n+ if (num_palette < 0 || num_palette > (int) max_palette_length)\n {\n if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n png_error(png_ptr, \"Invalid palette length\");" } ]
{ "id": "libpng12-4248-libpng12-CVE-2015-8126.patch", "cve_id": "CVE-2015-7981", "package": "libpng12", "upstream_enriched": true, "upstream_commit": "81f44665cce4cb1373f049a76f3904e981b7a766", "upstream_repo": "glennrp/libpng", "tier": "adapted", "has_source_context": false, "license": "Zlib", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2013-4288\n\nRace condition in PolicyKit (aka polkit) allows local users to bypass intended PolicyKit restrictions and gain privileges by starting a setuid or pkexec process before the authorization check is performed, related to (1) the polkit_unix_process_new API function, (2) the dbus API, or (3) the --process (unix-process) option for authorization to pkcheck.\n\n## Package\nsystemd\n\n## Files to modify\n- src/core/socket.c\n- systemd-195.orig/src/core/socket.c\n\n## Target Source Code\n\n### src/core/socket.c\n\n#### socket_add_device_link() [lines 287-308]\n```c\n return 0;\n}\n\nstatic int socket_add_device_link(Socket *s) {\n char *t;\n int r;\n\n assert(s);\n\n if (!s->bind_to_device)\n return 0;\n\n if (asprintf(&t, \"/sys/subsystem/net/devices/%s\", s->bind_to_device) < 0)\n return -ENOMEM;\n\n r = unit_add_node_link(UNIT(s), t, false);\n free(t);\n\n return r;\n}\n\nstatic int socket_add_default_dependencies(Socket *s) {\n```\n\n\n## Upstream Fix\n```diff\nFrom 7d0c710d72f8a6e5c6909c65700aa088c53aebc6 Mon Sep 17 00:00:00 2001\nFrom: =?UTF-8?q?Micha=C5=82=20Bartoszkiewicz?= <mbartoszkiewicz@gmail.com>\nDate: Sat, 12 Jan 2013 23:05:52 +0100\nSubject: [PATCH] core: do not make sockets dependent on lo\n\n/sys/subsystem/net/devices/lo is never considered active, so sockets\nwith BindToDevice=lo would never be activated.\n---\n src/core/socket.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/src/core/socket.c b/src/core/socket.c\nindex fcbcdbe192f30..d75504051b457 100644\n--- a/src/core/socket.c\n+++ b/src/core/socket.c\n@@ -308,7 +308,7 @@ static int socket_add_device_link(Socket *s) {\n \n assert(s);\n \n- if (!s->bind_to_device)\n+ if (!s->bind_to_device || streq(s->bind_to_device, \"lo\"))\n return 0;\n \n if (asprintf(&t, \"/sys/subsystem/net/devices/%s\", s->bind_to_device) < 0)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 7d0c710d72f8a6e5c6909c65700aa088c53aebc6 Mon Sep 17 00:00:00 2001\nFrom: =?UTF-8?q?Micha=C5=82=20Bartoszkiewicz?= <mbartoszkiewicz@gmail.com>\nDate: Sat, 12 Jan 2013 23:05:52 +0100\nSubject: [PATCH] core: do not make sockets dependent on lo\n\n/sys/subsystem/net/devices/lo is never considered active, so sockets\nwith BindToDevice=lo would never be activated.\n---\n src/core/socket.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\nIndex: systemd-195/src/core/socket.c\n===================================================================\n--- systemd-195.orig/src/core/socket.c\n+++ systemd-195/src/core/socket.c\n@@ -293,7 +293,7 @@ static int socket_add_device_link(Socket\n \n assert(s);\n \n- if (!s->bind_to_device)\n+ if (!s->bind_to_device || streq(s->bind_to_device, \"lo\"))\n return 0;\n \n if (asprintf(&t, \"/sys/subsystem/net/devices/%s\", s->bind_to_device) < 0)" } ]
{ "id": "systemd-2025-do-not-make-sockets-dependent-", "cve_id": "CVE-2013-4288", "package": "systemd", "upstream_enriched": true, "upstream_commit": "7d0c710d72f8a6e5c6909c65700aa088c53aebc6", "upstream_repo": "systemd/systemd", "tier": "adapted", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 129, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2013-1969\n\nMultiple use-after-free vulnerabilities in libxml2 2.9.0 and possibly other versions might allow context-dependent attackers to cause a denial of service (crash) and possibly execute arbitrary code via vectors related to the (1) htmlParseChunk and (2) xmldecl_done functions, as demonstrated by a buffer overflow in the xmlBufGetInputBase function.\n\n## Package\nlibxml2\n\n## Files to modify\n- dict.c\n- hash.c\n\n## Upstream Fix\n```diff\nFrom 8973d58b7498fa5100a876815476b81fd1a2412a Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard <veillard@redhat.com>\nDate: Sat, 04 Feb 2012 11:07:44 +0000\nSubject: Add hash randomization to hash and dict structures\n\nFollowing http://www.ocert.org/advisories/ocert-2011-003.html\nit seems that having hash randomization might be a good idea\nwhen using XML with untrusted data\n* configure.in: lookup for rand, srand and time\n* dict.c: add randomization to dictionaries hash tables\n* hash.c: add randomization to normal hash tables\n---\ndiff --git a/configure.in b/configure.in\nindex fa80375..828b66a 100644\n--- a/configure.in\n+++ b/configure.in\n@@ -512,6 +512,7 @@ AC_CHECK_FUNCS(strdup strndup strerror)\n AC_CHECK_FUNCS(finite isnand fp_class class fpclass)\n AC_CHECK_FUNCS(strftime localtime gettimeofday ftime)\n AC_CHECK_FUNCS(stat _stat signal)\n+AC_CHECK_FUNCS(rand srand time)\n \n dnl Checking the standard string functions availability\n AC_CHECK_FUNCS(printf sprintf fprintf snprintf vfprintf vsprintf vsnprintf sscanf,,\ndiff --git a/dict.c b/dict.c\nindex 3eff231..ae4966b 100644\n--- a/dict.c\n+++ b/dict.c\n@@ -2,7 +2,7 @@\n * dict.c: dictionary of reusable strings, just used to avoid allocation\n * and freeing operations.\n *\n- * Copyright (C) 2003 Daniel Veillard.\n+ * Copyright (C) 2003-2012 Daniel Veillard.\n *\n * Permission to use, copy, modify, and distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n@@ -19,6 +19,28 @@\n #define IN_LIBXML\n #include \"libxml.h\"\n \n+#ifdef HAVE_STDLIB_H\n+#include <stdlib.h>\n+#endif\n+#ifdef HAVE_TIME_H\n+#include <time.h>\n+#endif\n+\n+/*\n+ * Following http://www.ocert.org/advisories/ocert-2011-003.html\n+ * it seems that having hash randomization might be a good idea\n+ * when using XML with untrusted data\n+ * Note1: that it works correctly only if compiled with WITH_BIG_KEY\n+ * which is the default.\n+ * Note2: the fast function used for a small dict won't protect very\n+ * well but since the attack is based on growing a very big hash\n+ * list we will use the BigKey algo as soon as the hash size grows\n+ * over MIN_DICT_SIZE so this actually works\n+ */\n+#if defined(HAVE_RAND) && defined(HAVE_SRAND) && defined(HAVE_TIME)\n+#define DICT_RANDOMIZATION\n+#endif\n+\n #include <string.h>\n #ifdef HAVE_STDINT_H\n #include <stdint.h>\n@@ -44,23 +66,23 @@ typedef unsigned __int32 uint32_t;\n #define WITH_BIG_KEY\n \n #ifdef WITH_BIG_KEY\n-#define xmlDictComputeKey(dict, name, len)\t\t\t\\\n- (((dict)->size == MIN_DICT_SIZE) ?\t\t\t\t\\\n- xmlDictComputeFastKey(name, len) :\t\t\t\t\\\n- xmlDictComputeBigKey(name, len))\n-\n-#define xmlDictComputeQKey(dict, prefix, plen, name, len)\t\\\n- (((prefix) == NULL) ?\t\t\t\t\t\\\n- (xmlDictComputeKey(dict, name, len)) :\t\t\t\\\n- (((dict)->size == MIN_DICT_SIZE) ?\t\t\t\\\n- xmlDictComputeFastQKey(prefix, plen, name, len) :\t\\\n- xmlDictComputeBigQKey(prefix, plen, name, len)))\n+#define xmlDictComputeKey(dict, name, len) \\\n+ (((dict)->size == MIN_DICT_SIZE) ? \\\n+ xmlDictComputeFastKey(name, len, (dict)->seed) : \\\n+ xmlDictComputeBigKey(name, len, (dict)->seed))\n+\n+#define xmlDictComputeQKey(dict, prefix, plen, name, len) \\\n+ (((prefix) == NULL) ? \\\n+ (xmlDictComputeKey(dict, name, len)) : \\\n+ (((dict)->size == MIN_DICT_SIZE) ? \\\n+ xmlDictComputeFastQKey(prefix, plen, name, len, (dict)->seed) :\t\\\n+ xmlDictComputeBigQKey(prefix, plen, name, len, (dict)->seed)))\n \n #else /* !WITH_BIG_KEY */\n-#define xmlDictComputeKey(dict, name, len)\t\t\t\\\n- xmlDictComputeFastKey(name, len)\n-#define xmlDictComputeQKey(dict, prefix, plen, name, len)\t\\\n- xmlDictComputeFastQKey(prefix, plen, name, len)\n+#define xmlDictComputeKey(dict, name, len) \\\n+ xmlDictComputeFastKey(name, len, (dict)->seed)\n+#define xmlDictComputeQKey(dict, prefix, plen, name, len) \\\n+ xmlDictComputeFastQKey(prefix, plen, name, len, (dict)->seed)\n #endif /* WITH_BIG_KEY */\n \n /*\n@@ -98,6 +120,8 @@ struct _xmlDict {\n xmlDictStringsPtr strings;\n \n struct _xmlDict *subdict;\n+ /* used for randomization */\n+ int seed;\n };\n \n /*\n@@ -125,6 +149,9 @@ static int xmlInitializeDict(void) {\n if ((xmlDictMutex = xmlNewRMutex()) == NULL)\n return(0);\n \n+#ifdef DICT_RANDOMIZATION\n+ srand(time(NULL));\n+#endif\n xmlDictInitialized = 1;\n return(1);\n }\n@@ -277,13 +304,13 @@ found_pool:\n */\n \n static uint32_t\n-xmlDictComputeBigKey(const xmlChar* data, int namelen) {\n+xmlDictComputeBigKey(const xmlChar* data, int namelen, int seed) {\n uint32_t hash;\n int i;\n \n if (namelen <= 0 || data == NULL) return(0);\n \n- hash = 0;\n+ hash = seed;\n \n for (i = 0;i < namelen; i++) {\n hash += data[i];\n@@ -310,12 +337,12 @@ xmlDictComputeBigKey(const xmlChar* data, int namelen) {\n */\n static unsigned long\n xmlDictComputeBigQKey(const xmlChar *prefix, int plen,\n- const xmlChar *name, int len)\n+ const xmlChar *name, int len, int seed)\n {\n uint32_t hash;\n int i;\n \n- hash = 0;\n+ hash = seed;\n \n for (i = 0;i < plen; i++) {\n hash += prefix[i];\n@@ -346,8 +373,8 @@ xmlDictComputeBigQKey(const xmlChar *prefix, int plen,\n * for low hash table fill.\n */\n static unsigned long\n-xmlDictComputeFastKey(const xmlChar *name, int namelen) {\n- unsigned long value = 0L;\n+xmlDictComputeFastKey(const xmlChar *name, int namelen, int seed) {\n+ unsigned long value = seed;\n \n if (name == NULL) return(0);\n value = *name;\n@@ -381,9 +408,9 @@ xmlDictComputeFastKey(const xmlChar *name, int namelen) {\n */\n static unsigned long\n xmlDictComputeFastQKey(const xmlChar *prefix, int plen,\n- const xmlChar *name, int len)\n+ const xmlChar *name, int len, int seed)\n {\n- unsigned long value = 0L;\n+ unsigned long value = (unsigned long) seed;\n \n if (plen == 0)\n \tvalue += 30 * (unsigned long) ':';\n@@ -460,6 +487,11 @@ xmlDictCreate(void) {\n \tdict->subdict = NULL;\n if (dict->dict) {\n \t memset(dict->dict, 0, MIN_DICT_SIZE * sizeof(xmlDictEntry));\n+#ifdef DICT_RANDOMIZATION\n+ dict->seed = rand();\n+#else\n+ dict->seed = 0;\n+#endif\n \t return(dict);\n }\n xmlFree(dict);\n@@ -486,6 +518,7 @@ xmlDictCreateSub(xmlDictPtr sub) {\n #ifdef DICT_DEBUG_PATTERNS\n fprintf(stderr, \"R\");\n #endif\n+ dict->seed = sub->seed;\n dict->subdict = sub;\n \txmlDictReference(dict->subdict);\n }\ndiff --git a/hash.c b/hash.c\nindex b78bc2d..fe1424f 100644\n--- a/hash.c\n+++ b/hash.c\n@@ -3,7 +3,7 @@\n *\n * Reference: Your favorite introductory book on algorithms\n *\n- * Copyright (C) 2000 Bjorn Reese and Daniel Veillard.\n+ * Copyright (C) 2000,2012 Bjorn Reese and Daniel Veillard.\n *\n * Permission to use, copy, modify, and distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n@@ -21,6 +21,22 @@\n #include \"libxml.h\"\n \n #include <string.h>\n+#ifdef HAVE_STDLIB_H\n+#include <stdlib.h>\n+#endif\n+#ifdef HAVE_TIME_H\n+#include <time.h>\n+#endif\n+\n+/*\n+ * Following http://www.ocert.org/advisories/ocert-2011-003.html\n+ * it seems that having hash randomization might be a good idea\n+ * when using XML with untrusted data\n+ */\n+#if defined(HAVE_RAND) && defined(HAVE_SRAND) && defined(HAVE_TIME)\n+#define HASH_RANDOMIZATION\n+#endif\n+\n #include <libxml/parser.h>\n #include <libxml/hash.h>\n #include <libxml/xmlmemory.h>\n@@ -31,6 +47,10 @@\n \n /* #define DEBUG_GROW */\n \n+#ifdef HASH_RANDOMIZATION\n+static int hash_initialized = 0;\n+#endif\n+\n /*\n * A single entry in the hash table\n */\n@@ -53,6 +73,9 @@ struct _xmlHashTable {\n int size;\n int nbElems;\n xmlDictPtr dict;\n+#ifdef HASH_RANDOMIZATION\n+ int random_see\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 8973d58b7498fa5100a876815476b81fd1a2412a Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard <veillard@redhat.com>\nDate: Sat, 04 Feb 2012 11:07:44 +0000\nSubject: Add hash randomization to hash and dict structures\n\nFollowing http://www.ocert.org/advisories/ocert-2011-003.html\nit seems that having hash randomization might be a good idea\nwhen using XML with untrusted data\n* configure.in: lookup for rand, srand and time\n* dict.c: add randomization to dictionaries hash tables\n* hash.c: add randomization to normal hash tables\n---\ndiff --git a/configure.in b/configure.in\nindex fa80375..828b66a 100644\n--- a/configure.in\n+++ b/configure.in\n@@ -512,6 +512,7 @@ AC_CHECK_FUNCS(strdup strndup strerror)\n AC_CHECK_FUNCS(finite isnand fp_class class fpclass)\n AC_CHECK_FUNCS(strftime localtime gettimeofday ftime)\n AC_CHECK_FUNCS(stat _stat signal)\n+AC_CHECK_FUNCS(rand srand time)\n \n dnl Checking the standard string functions availability\n AC_CHECK_FUNCS(printf sprintf fprintf snprintf vfprintf vsprintf vsnprintf sscanf,,\ndiff --git a/dict.c b/dict.c\nindex 3eff231..ae4966b 100644\n--- a/dict.c\n+++ b/dict.c\n@@ -2,7 +2,7 @@\n * dict.c: dictionary of reusable strings, just used to avoid allocation\n * and freeing operations.\n *\n- * Copyright (C) 2003 Daniel Veillard.\n+ * Copyright (C) 2003-2012 Daniel Veillard.\n *\n * Permission to use, copy, modify, and distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n@@ -19,6 +19,28 @@\n #define IN_LIBXML\n #include \"libxml.h\"\n \n+#ifdef HAVE_STDLIB_H\n+#include <stdlib.h>\n+#endif\n+#ifdef HAVE_TIME_H\n+#include <time.h>\n+#endif\n+\n+/*\n+ * Following http://www.ocert.org/advisories/ocert-2011-003.html\n+ * it seems that having hash randomization might be a good idea\n+ * when using XML with untrusted data\n+ * Note1: that it works correctly only if compiled with WITH_BIG_KEY\n+ * which is the default.\n+ * Note2: the fast function used for a small dict won't protect very\n+ * well but since the attack is based on growing a very big hash\n+ * list we will use the BigKey algo as soon as the hash size grows\n+ * over MIN_DICT_SIZE so this actually works\n+ */\n+#if defined(HAVE_RAND) && defined(HAVE_SRAND) && defined(HAVE_TIME)\n+#define DICT_RANDOMIZATION\n+#endif\n+\n #include <string.h>\n #ifdef HAVE_STDINT_H\n #include <stdint.h>\n@@ -44,23 +66,23 @@ typedef unsigned __int32 uint32_t;\n #define WITH_BIG_KEY\n \n #ifdef WITH_BIG_KEY\n-#define xmlDictComputeKey(dict, name, len)\t\t\t\\\n- (((dict)->size == MIN_DICT_SIZE) ?\t\t\t\t\\\n- xmlDictComputeFastKey(name, len) :\t\t\t\t\\\n- xmlDictComputeBigKey(name, len))\n-\n-#define xmlDictComputeQKey(dict, prefix, plen, name, len)\t\\\n- (((prefix) == NULL) ?\t\t\t\t\t\\\n- (xmlDictComputeKey(dict, name, len)) :\t\t\t\\\n- (((dict)->size == MIN_DICT_SIZE) ?\t\t\t\\\n- xmlDictComputeFastQKey(prefix, plen, name, len) :\t\\\n- xmlDictComputeBigQKey(prefix, plen, name, len)))\n+#define xmlDictComputeKey(dict, name, len) \\\n+ (((dict)->size == MIN_DICT_SIZE) ? \\\n+ xmlDictComputeFastKey(name, len, (dict)->seed) : \\\n+ xmlDictComputeBigKey(name, len, (dict)->seed))\n+\n+#define xmlDictComputeQKey(dict, prefix, plen, name, len) \\\n+ (((prefix) == NULL) ? \\\n+ (xmlDictComputeKey(dict, name, len)) : \\\n+ (((dict)->size == MIN_DICT_SIZE) ? \\\n+ xmlDictComputeFastQKey(prefix, plen, name, len, (dict)->seed) :\t\\\n+ xmlDictComputeBigQKey(prefix, plen, name, len, (dict)->seed)))\n \n #else /* !WITH_BIG_KEY */\n-#define xmlDictComputeKey(dict, name, len)\t\t\t\\\n- xmlDictComputeFastKey(name, len)\n-#define xmlDictComputeQKey(dict, prefix, plen, name, len)\t\\\n- xmlDictComputeFastQKey(prefix, plen, name, len)\n+#define xmlDictComputeKey(dict, name, len) \\\n+ xmlDictComputeFastKey(name, len, (dict)->seed)\n+#define xmlDictComputeQKey(dict, prefix, plen, name, len) \\\n+ xmlDictComputeFastQKey(prefix, plen, name, len, (dict)->seed)\n #endif /* WITH_BIG_KEY */\n \n /*\n@@ -98,6 +120,8 @@ struct _xmlDict {\n xmlDictStringsPtr strings;\n \n struct _xmlDict *subdict;\n+ /* used for randomization */\n+ int seed;\n };\n \n /*\n@@ -125,6 +149,9 @@ static int xmlInitializeDict(void) {\n if ((xmlDictMutex = xmlNewRMutex()) == NULL)\n return(0);\n \n+#ifdef DICT_RANDOMIZATION\n+ srand(time(NULL));\n+#endif\n xmlDictInitialized = 1;\n return(1);\n }\n@@ -277,13 +304,13 @@ found_pool:\n */\n \n static uint32_t\n-xmlDictComputeBigKey(const xmlChar* data, int namelen) {\n+xmlDictComputeBigKey(const xmlChar* data, int namelen, int seed) {\n uint32_t hash;\n int i;\n \n if (namelen <= 0 || data == NULL) return(0);\n \n- hash = 0;\n+ hash = seed;\n \n for (i = 0;i < namelen; i++) {\n hash += data[i];\n@@ -310,12 +337,12 @@ xmlDictComputeBigKey(const xmlChar* data, int namelen) {\n */\n static unsigned long\n xmlDictComputeBigQKey(const xmlChar *prefix, int plen,\n- const xmlChar *name, int len)\n+ const xmlChar *name, int len, int seed)\n {\n uint32_t hash;\n int i;\n \n- hash = 0;\n+ hash = seed;\n \n for (i = 0;i < plen; i++) {\n hash += prefix[i];\n@@ -346,8 +373,8 @@ xmlDictComputeBigQKey(const xmlChar *prefix, int plen,\n * for low hash table fill.\n */\n static unsigned long\n-xmlDictComputeFastKey(const xmlChar *name, int namelen) {\n- unsigned long value = 0L;\n+xmlDictComputeFastKey(const xmlChar *name, int namelen, int seed) {\n+ unsigned long value = seed;\n \n if (name == NULL) return(0);\n value = *name;\n@@ -381,9 +408,9 @@ xmlDictComputeFastKey(const xmlChar *name, int namelen) {\n */\n static unsigned long\n xmlDictComputeFastQKey(const xmlChar *prefix, int plen,\n- const xmlChar *name, int len)\n+ const xmlChar *name, int len, int seed)\n {\n- unsigned long value = 0L;\n+ unsigned long value = (unsigned long) seed;\n \n if (plen == 0)\n \tvalue += 30 * (unsigned long) ':';\n@@ -460,6 +487,11 @@ xmlDictCreate(void) {\n \tdict->subdict = NULL;\n if (dict->dict) {\n \t memset(dict->dict, 0, MIN_DICT_SIZE * sizeof(xmlDictEntry));\n+#ifdef DICT_RANDOMIZATION\n+ dict->seed = rand();\n+#else\n+ dict->seed = 0;\n+#endif\n \t return(dict);\n }\n xmlFree(dict);\n@@ -486,6 +518,7 @@ xmlDictCreateSub(xmlDictPtr sub) {\n #ifdef DICT_DEBUG_PATTERNS\n fprintf(stderr, \"R\");\n #endif\n+ dict->seed = sub->seed;\n dict->subdict = sub;\n \txmlDictReference(dict->subdict);\n }\ndiff --git a/hash.c b/hash.c\nindex b78bc2d..fe1424f 100644\n--- a/hash.c\n+++ b/hash.c\n@@ -3,7 +3,7 @@\n *\n * Reference: Your favorite introductory book on algorithms\n *\n- * Copyright (C) 2000 Bjorn Reese and Daniel Veillard.\n+ * Copyright (C) 2000,2012 Bjorn Reese and Daniel Veillard.\n *\n * Permission to use, copy, modify, and distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n@@ -21,6 +21,22 @@\n #include \"libxml.h\"\n \n #include <string.h>\n+#ifdef HAVE_STDLIB_H\n+#include <stdlib.h>\n+#endif\n+#ifdef HAVE_TIME_H\n+#include <time.h>\n+#endif\n+\n+/*\n+ * Following http://www.ocert.org/advisories/ocert-2011-003.html\n+ * it seems that having hash randomization might be a good idea\n+ * when using XML with untrusted data\n+ */\n+#if defined(HAVE_RAND) && defined(HAVE_SRAND) && defined(HAVE_TIME)\n+#define HASH_RANDOMIZATION\n+#endif\n+\n #include <libxml/parser.h>\n #include <libxml/hash.h>\n #include <libxml/xmlmemory.h>\n@@ -31,6 +47,10 @@\n \n /* #define DEBUG_GROW */\n \n+#ifdef HASH_RANDOMIZATION\n+static int hash_initialized = 0;\n+#endif\n+\n /*\n * A single entry in the hash table\n */\n@@ -53,6 +73,9 @@ struct _xmlHashTable {\n int size;\n int nbElems;\n xmlDictPtr dict;\n+#ifdef HASH_RANDOMIZATION\n+ int random_seed;\n+#endif\n };\n \n /*\n@@ -65,6 +88,9 @@ xmlHashComputeKey(xmlHashTablePtr table, const xmlChar *name,\n unsigned long value = 0L;\n char ch;\n \n+#ifdef HASH_RANDOMIZATION\n+ value = table->random_seed;\n+#endif\n if (name != NULL) {\n \tvalue += 30 * (*name);\n \twhile ((ch = *name++) != 0) {\n@@ -92,6 +118,9 @@ xmlHashComputeQKey(xmlHashTablePtr table,\n unsigned long value = 0L;\n char ch;\n \n+#ifdef HASH_RANDOMIZATION\n+ value = table->random_seed;\n+#endif\n if (prefix != NULL)\n \tvalue += 30 * (*prefix);\n else\n@@ -156,6 +185,13 @@ xmlHashCreate(int size) {\n table->table = xmlMalloc(size * sizeof(xmlHashEntry));\n if (table->table) {\n \t memset(table->table, 0, size * sizeof(xmlHashEntry));\n+#ifdef HASH_RANDOMIZATION\n+ if (!hash_initialized) {\n+ srand(time(NULL));\n+ hash_initialized = 1;\n+ }\n+ table->random_seed = rand();\n+#endif\n \t return(table);\n }\n xmlFree(table);\n--\ncgit v0.9.0.2" } ]
{ "id": "libxml2-1604-libxml2-CVE-2012-0841.patch", "cve_id": "CVE-2013-1969", "package": "libxml2", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": false, "license": "MIT", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2013-4288\n\nRace condition in PolicyKit (aka polkit) allows local users to bypass intended PolicyKit restrictions and gain privileges by starting a setuid or pkexec process before the authorization check is performed, related to (1) the polkit_unix_process_new API function, (2) the dbus API, or (3) the --process (unix-process) option for authorization to pkcheck.\n\n## Package\nsystemd\n\n## Files to modify\n- src/core/shutdown.c\n- src/core/umount.c\n\n## Target Source Code\n\n### src/core/shutdown.c\n\n#### main() [lines 129-317]\n```c\n return 0;\n}\n\nint main(int argc, char *argv[]) {\n int cmd, r;\n unsigned retries;\n bool need_umount = true, need_swapoff = true, need_loop_detach = true, need_dm_detach = true;\n bool in_container, use_watchdog = false;\n char *arguments[3];\n\n log_parse_environment();\n log_set_target(LOG_TARGET_CONSOLE); /* syslog will die if not gone yet */\n log_open();\n\n umask(0022);\n\n if (getpid() != 1) {\n log_error(\"Not executed by init (pid 1).\");\n r = -EPERM;\n goto error;\n }\n\n if (argc != 2) {\n log_error(\"Invalid number of arguments.\");\n r = -EINVAL;\n goto error;\n }\n\n in_container = detect_container(NULL) > 0;\n\n if (streq(argv[1], \"reboot\"))\n cmd = RB_AUTOBOOT;\n else if (streq(argv[1], \"poweroff\"))\n cmd = RB_POWER_OFF;\n else if (streq(argv[1], \"halt\"))\n cmd = RB_HALT_SYSTEM;\n else if (streq(argv[1], \"kexec\"))\n cmd = LINUX_REBOOT_CMD_KEXEC;\n else {\n log_error(\"Unknown action '%s'.\", argv[1]);\n/* ... 55 lines omitted ... */\n else if (r > 0)\n log_info(\"Not all loop devices detached, %d left.\", r);\n else\n log_error(\"Failed to detach loop devices: %s\", strerror(-r));\n }\n\n if (need_dm_detach) {\n log_info(\"Detaching DM devices.\");\n r = dm_detach_all(&changed);\n if (r == 0)\n need_dm_detach = false;\n else if (r > 0)\n log_warning(\"Not all DM devices detached, %d left.\", r);\n else\n log_error(\"Failed to detach DM devices: %s\", strerror(-r));\n }\n\n if (!need_umount && !need_swapoff && !need_loop_detach && !need_dm_detach) {\n if (retries > 0)\n log_info(\"All filesystems, swaps, loop devices, DM devices detached.\");\n /* Yay, done */\n break;\n }\n\n /* If in this iteration we didn't manage to\n * unmount/deactivate anything, we simply give up */\n if (!changed) {\n/* ... 47 lines omitted ... */\n reboot(cmd);\n\n if (errno == EPERM && in_container) {\n /* If we are in a container, and we lacked\n * CAP_SYS_BOOT just exit, this will kill our\n * container for good. */\n log_error(\"Exiting container.\");\n exit(0);\n }\n\n log_error(\"Failed to invoke reboot(): %m\");\n r = -errno;\n\n error:\n log_error(\"Critical error while doing system shutdown: %s\", strerror(-r));\n\n freeze();\n return EXIT_FAILURE;\n}\n\n```\n\n\n## Upstream Fix\n```diff\nFrom 2569a5ce16638d99f1ebaaa7774d183496d8b8e8 Mon Sep 17 00:00:00 2001\nFrom: Michal Schmidt <mschmidt@redhat.com>\nDate: Fri, 7 Dec 2012 17:28:30 +0100\nSubject: [PATCH] shutdown: downgrade a warning\n\nAll messages of the kind \"not all done, %d left\" are log_info, except\nthe one for DM devices. Make it info too.\n---\n src/core/shutdown.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/src/core/shutdown.c b/src/core/shutdown.c\nindex 4bb4b4d..192746a 100644\n--- a/src/core/shutdown.c\n+++ b/src/core/shutdown.c\n@@ -233,7 +233,7 @@ int main(int argc, char *argv[]) {\n if (r == 0)\n need_dm_detach = false;\n else if (r > 0)\n- log_warning(\"Not all DM devices detached, %d left.\", r);\n+ log_info(\"Not all DM devices detached, %d left.\", r);\n else\n log_error(\"Failed to detach DM devices: %s\", strerror(-r));\n }\n-- \n1.7.10.4\n\nFrom c678406681d32d56730b9e9c002d5500d7aa7f8b Mon Sep 17 00:00:00 2001\nFrom: Michal Schmidt <mschmidt@redhat.com>\nDate: Fri, 7 Dec 2012 17:34:21 +0100\nSubject: [PATCH] umount: fix check for DM changed\n\ndelete_dm() returns 0 on success. The check for \"r > 0\" was likely\na copy&paste error from the loopback code where \"r > 0\" makes sense.\n---\n src/core/umount.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/src/core/umount.c b/src/core/umount.c\nindex f6c520e..8776807 100644\n--- a/src/core/umount.c\n+++ b/src/core/umount.c\n@@ -536,7 +536,7 @@ static int dm_points_list_detach(MountPoint **head, bool *changed) {\n \n if ((r = delete_dm(m->devnum)) >= 0) {\n \n- if (r > 0 && changed)\n+ if (changed)\n *changed = true;\n \n mount_point_free(head, m);\n-- \n1.7.10.4\n\nFrom bce93b7ac7642426039863493694d8c12812e2a7 Mon Sep 17 00:00:00 2001\nFrom: Michal Schmidt <mschmidt@redhat.com>\nDate: Fri, 7 Dec 2012 17:44:50 +0100\nSubject: [PATCH] shutdown, umount: logging improvements\n\nIn bugreports about hangs during the late shutdown we are often missing\nimportant information - what were we trying to unmount/detach when it hung.\n\nInstead of printing what we successfully unmounted, print what we are\ngoing to unmount/detach. And add messages to mark the completion of\ncategories (mount/swap/loop/DM).\n---\n src/core/shutdown.c | 20 ++++++++++++--------\n src/core/umount.c | 15 +++++++++------\n 2 files changed, 21 insertions(+), 14 deletions(-)\n\ndiff --git a/src/core/shutdown.c b/src/core/shutdown.c\nindex 192746a..6783008 100644\n--- a/src/core/shutdown.c\n+++ b/src/core/shutdown.c\n@@ -197,9 +197,10 @@ int main(int argc, char *argv[]) {\n if (need_umount) {\n log_info(\"Unmounting file systems.\");\n r = umount_all(&changed);\n- if (r == 0)\n+ if (r == 0) {\n need_umount = false;\n- else if (r > 0)\n+ log_info(\"All filesystems unmounted.\");\n+ } else if (r > 0)\n log_info(\"Not all file systems unmounted, %d left.\", r);\n else\n log_error(\"Failed to unmount file systems: %s\", strerror(-r));\n@@ -208,9 +209,10 @@ int main(int argc, char *argv[]) {\n if (need_swapoff) {\n log_info(\"Disabling swaps.\");\n r = swapoff_all(&changed);\n- if (r == 0)\n+ if (r == 0) {\n need_swapoff = false;\n- else if (r > 0)\n+ log_info(\"All swaps disabled.\");\n+ } else if (r > 0)\n log_info(\"Not all swaps are turned off, %d left.\", r);\n else\n log_error(\"Failed to turn off swaps: %s\", strerror(-r));\n@@ -219,9 +221,10 @@ int main(int argc, char *argv[]) {\n if (need_loop_detach) {\n log_info(\"Detaching loop devices.\");\n r = loopback_detach_all(&changed);\n- if (r == 0)\n+ if (r == 0) {\n need_loop_detach = false;\n- else if (r > 0)\n+ log_info(\"All loop devices detached.\");\n+ } else if (r > 0)\n log_info(\"Not all loop devices detached, %d left.\", r);\n else\n log_error(\"Failed to detach loop devices: %s\", strerror(-r));\n@@ -230,9 +233,10 @@ int main(int argc, char *argv[]) {\n if (need_dm_detach) {\n log_info(\"Detaching DM devices.\");\n r = dm_detach_all(&changed);\n- if (r == 0)\n+ if (r == 0) {\n need_dm_detach = false;\n- else if (r > 0)\n+ log_info(\"All DM devices detached.\");\n+ } else if (r > 0)\n log_info(\"Not all DM devices detached, %d left.\", r);\n else\n log_error(\"Failed to detach DM devices: %s\", strerror(-r));\ndiff --git a/src/core/umount.c b/src/core/umount.c\nindex 8776807..fd90d9f 100644\n--- a/src/core/umount.c\n+++ b/src/core/umount.c\n@@ -443,8 +443,8 @@ static int mount_points_list_umount(MountPoint **head, bool *changed, bool log_e\n continue;\n \n /* Trying to umount. Forcing to umount if busy (only for NFS mounts) */\n+ log_info(\"Unmounting %s.\", m->path);\n if (umount2(m->path, MNT_FORCE) == 0) {\n- log_info(\"Unmounted %s.\", m->path);\n if (changed)\n *changed = true;\n \n@@ -465,6 +465,7 @@ static int swap_points_list_off(MountPoint **head, bool *changed) {\n assert(head);\n \n LIST_FOREACH_SAFE(mount_point, m, n, *head) {\n+ log_info(\"Disabling swap %s.\", m->path);\n if (swapoff(m->path) == 0) {\n if (changed)\n *changed = true;\n@@ -500,8 +501,9 @@ static int loopback_points_list_detach(MountPoint **head, bool *changed) {\n continue;\n }\n \n- if ((r = delete_loopback(m->path)) >= 0) {\n-\n+ log_info(\"Deleting loopback %s.\", m->path);\n+ r = delete_loopback(m->path);\n+ if (r >= 0) {\n if (r > 0 && changed)\n *changed = true;\n \n@@ -534,14 +536,15 @@ static int dm_points_list_detach(MountPoint **head, bool *changed) {\n continue;\n }\n \n- if ((r = delete_dm(m->devnum)) >= 0) {\n-\n+ log_info(\"Deleting DM %u:%u.\", major(m->devnum), minor(m->devnum));\n+ r = delete_dm(m->devnum);\n+ if (r >= 0) {\n if (changed)\n *changed = true;\n \n mount_point_free(head, m);\n } else {\n- log_warning(\"Could not delete dm %s: %m\", m->path);\n+ log_warning(\"Could not delete DM %s: %m\", m->path);\n n_failed++;\n }\n }\n-- \n1.7.10.4\n\nFrom 735e0712710a1dc26da0febafb91b242b2687f3f Mon Sep 17 00:00:00 2001\nFrom: Michal Schmidt <mschmidt@redhat.com>\nDate: Fri, 7 Dec 2012 18:02:43 +0100\nSubject: [PATCH] shutdown, umount: use verbs consisten\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 2569a5ce16638d99f1ebaaa7774d183496d8b8e8 Mon Sep 17 00:00:00 2001\nFrom: Michal Schmidt <mschmidt@redhat.com>\nDate: Fri, 7 Dec 2012 17:28:30 +0100\nSubject: [PATCH] shutdown: downgrade a warning\n\nAll messages of the kind \"not all done, %d left\" are log_info, except\nthe one for DM devices. Make it info too.\n---\n src/core/shutdown.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/src/core/shutdown.c b/src/core/shutdown.c\nindex 4bb4b4d..192746a 100644\n--- a/src/core/shutdown.c\n+++ b/src/core/shutdown.c\n@@ -233,7 +233,7 @@ int main(int argc, char *argv[]) {\n if (r == 0)\n need_dm_detach = false;\n else if (r > 0)\n- log_warning(\"Not all DM devices detached, %d left.\", r);\n+ log_info(\"Not all DM devices detached, %d left.\", r);\n else\n log_error(\"Failed to detach DM devices: %s\", strerror(-r));\n }\n-- \n1.7.10.4\n\nFrom c678406681d32d56730b9e9c002d5500d7aa7f8b Mon Sep 17 00:00:00 2001\nFrom: Michal Schmidt <mschmidt@redhat.com>\nDate: Fri, 7 Dec 2012 17:34:21 +0100\nSubject: [PATCH] umount: fix check for DM changed\n\ndelete_dm() returns 0 on success. The check for \"r > 0\" was likely\na copy&paste error from the loopback code where \"r > 0\" makes sense.\n---\n src/core/umount.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/src/core/umount.c b/src/core/umount.c\nindex f6c520e..8776807 100644\n--- a/src/core/umount.c\n+++ b/src/core/umount.c\n@@ -536,7 +536,7 @@ static int dm_points_list_detach(MountPoint **head, bool *changed) {\n \n if ((r = delete_dm(m->devnum)) >= 0) {\n \n- if (r > 0 && changed)\n+ if (changed)\n *changed = true;\n \n mount_point_free(head, m);\n-- \n1.7.10.4\n\nFrom bce93b7ac7642426039863493694d8c12812e2a7 Mon Sep 17 00:00:00 2001\nFrom: Michal Schmidt <mschmidt@redhat.com>\nDate: Fri, 7 Dec 2012 17:44:50 +0100\nSubject: [PATCH] shutdown, umount: logging improvements\n\nIn bugreports about hangs during the late shutdown we are often missing\nimportant information - what were we trying to unmount/detach when it hung.\n\nInstead of printing what we successfully unmounted, print what we are\ngoing to unmount/detach. And add messages to mark the completion of\ncategories (mount/swap/loop/DM).\n---\n src/core/shutdown.c | 20 ++++++++++++--------\n src/core/umount.c | 15 +++++++++------\n 2 files changed, 21 insertions(+), 14 deletions(-)\n\ndiff --git a/src/core/shutdown.c b/src/core/shutdown.c\nindex 192746a..6783008 100644\n--- a/src/core/shutdown.c\n+++ b/src/core/shutdown.c\n@@ -197,9 +197,10 @@ int main(int argc, char *argv[]) {\n if (need_umount) {\n log_info(\"Unmounting file systems.\");\n r = umount_all(&changed);\n- if (r == 0)\n+ if (r == 0) {\n need_umount = false;\n- else if (r > 0)\n+ log_info(\"All filesystems unmounted.\");\n+ } else if (r > 0)\n log_info(\"Not all file systems unmounted, %d left.\", r);\n else\n log_error(\"Failed to unmount file systems: %s\", strerror(-r));\n@@ -208,9 +209,10 @@ int main(int argc, char *argv[]) {\n if (need_swapoff) {\n log_info(\"Disabling swaps.\");\n r = swapoff_all(&changed);\n- if (r == 0)\n+ if (r == 0) {\n need_swapoff = false;\n- else if (r > 0)\n+ log_info(\"All swaps disabled.\");\n+ } else if (r > 0)\n log_info(\"Not all swaps are turned off, %d left.\", r);\n else\n log_error(\"Failed to turn off swaps: %s\", strerror(-r));\n@@ -219,9 +221,10 @@ int main(int argc, char *argv[]) {\n if (need_loop_detach) {\n log_info(\"Detaching loop devices.\");\n r = loopback_detach_all(&changed);\n- if (r == 0)\n+ if (r == 0) {\n need_loop_detach = false;\n- else if (r > 0)\n+ log_info(\"All loop devices detached.\");\n+ } else if (r > 0)\n log_info(\"Not all loop devices detached, %d left.\", r);\n else\n log_error(\"Failed to detach loop devices: %s\", strerror(-r));\n@@ -230,9 +233,10 @@ int main(int argc, char *argv[]) {\n if (need_dm_detach) {\n log_info(\"Detaching DM devices.\");\n r = dm_detach_all(&changed);\n- if (r == 0)\n+ if (r == 0) {\n need_dm_detach = false;\n- else if (r > 0)\n+ log_info(\"All DM devices detached.\");\n+ } else if (r > 0)\n log_info(\"Not all DM devices detached, %d left.\", r);\n else\n log_error(\"Failed to detach DM devices: %s\", strerror(-r));\ndiff --git a/src/core/umount.c b/src/core/umount.c\nindex 8776807..fd90d9f 100644\n--- a/src/core/umount.c\n+++ b/src/core/umount.c\n@@ -443,8 +443,8 @@ static int mount_points_list_umount(MountPoint **head, bool *changed, bool log_e\n continue;\n \n /* Trying to umount. Forcing to umount if busy (only for NFS mounts) */\n+ log_info(\"Unmounting %s.\", m->path);\n if (umount2(m->path, MNT_FORCE) == 0) {\n- log_info(\"Unmounted %s.\", m->path);\n if (changed)\n *changed = true;\n \n@@ -465,6 +465,7 @@ static int swap_points_list_off(MountPoint **head, bool *changed) {\n assert(head);\n \n LIST_FOREACH_SAFE(mount_point, m, n, *head) {\n+ log_info(\"Disabling swap %s.\", m->path);\n if (swapoff(m->path) == 0) {\n if (changed)\n *changed = true;\n@@ -500,8 +501,9 @@ static int loopback_points_list_detach(MountPoint **head, bool *changed) {\n continue;\n }\n \n- if ((r = delete_loopback(m->path)) >= 0) {\n-\n+ log_info(\"Deleting loopback %s.\", m->path);\n+ r = delete_loopback(m->path);\n+ if (r >= 0) {\n if (r > 0 && changed)\n *changed = true;\n \n@@ -534,14 +536,15 @@ static int dm_points_list_detach(MountPoint **head, bool *changed) {\n continue;\n }\n \n- if ((r = delete_dm(m->devnum)) >= 0) {\n-\n+ log_info(\"Deleting DM %u:%u.\", major(m->devnum), minor(m->devnum));\n+ r = delete_dm(m->devnum);\n+ if (r >= 0) {\n if (changed)\n *changed = true;\n \n mount_point_free(head, m);\n } else {\n- log_warning(\"Could not delete dm %s: %m\", m->path);\n+ log_warning(\"Could not delete DM %s: %m\", m->path);\n n_failed++;\n }\n }\n-- \n1.7.10.4\n\nFrom 735e0712710a1dc26da0febafb91b242b2687f3f Mon Sep 17 00:00:00 2001\nFrom: Michal Schmidt <mschmidt@redhat.com>\nDate: Fri, 7 Dec 2012 18:02:43 +0100\nSubject: [PATCH] shutdown, umount: use verbs consistently\n\nMounts are \"unmounted\".\nSwaps are \"deactivated\", not \"turned off\" nor \"disabled\".\nLoop and DM devices are \"detached\", not \"deleted\".\n\nEspecially the deleting sounded a bit scary.\n---\n src/core/shutdown.c | 8 ++++----\n src/core/umount.c | 10 +++++-----\n 2 files changed, 9 insertions(+), 9 deletions(-)\n\ndiff --git a/src/core/shutdown.c b/src/core/shutdown.c\nindex 6783008..0b0e0c3 100644\n--- a/src/core/shutdown.c\n+++ b/src/core/shutdown.c\n@@ -207,15 +207,15 @@ int main(int argc, char *argv[]) {\n }\n \n if (need_swapoff) {\n- log_info(\"Disabling swaps.\");\n+ log_info(\"Deactivating swaps.\");\n r = swapoff_all(&changed);\n if (r == 0) {\n need_swapoff = false;\n- log_info(\"All swaps disabled.\");\n+ log_info(\"All swaps deactivated.\");\n } else if (r > 0)\n- log_info(\"Not all swaps are turned off, %d left.\", r);\n+ log_info(\"Not all swaps deactivated, %d left.\", r);\n else\n- log_error(\"Failed to turn off swaps: %s\", strerror(-r));\n+ log_error(\"Failed to deactivate swaps: %s\", strerror(-r));\n }\n \n if (need_loop_detach) {\ndiff --git a/src/core/umount.c b/src/core/umount.c\nindex fd90d9f..96232d3 100644\n--- a/src/core/umount.c\n+++ b/src/core/umount.c\n@@ -465,7 +465,7 @@ static int swap_points_list_off(MountPoint **head, bool *changed) {\n assert(head);\n \n LIST_FOREACH_SAFE(mount_point, m, n, *head) {\n- log_info(\"Disabling swap %s.\", m->path);\n+ log_info(\"Deactivating swap %s.\", m->path);\n if (swapoff(m->path) == 0) {\n if (changed)\n *changed = true;\n@@ -501,7 +501,7 @@ static int loopback_points_list_detach(MountPoint **head, bool *changed) {\n continue;\n }\n \n- log_info(\"Deleting loopback %s.\", m->path);\n+ log_info(\"Detaching loopback %s.\", m->path);\n r = delete_loopback(m->path);\n if (r >= 0) {\n if (r > 0 && changed)\n@@ -509,7 +509,7 @@ static int loopback_points_list_detach(MountPoint **head, bool *changed) {\n \n mount_point_free(head, m);\n } else {\n- log_warning(\"Could not delete loopback %s: %m\", m->path);\n+ log_warning(\"Could not detach loopback %s: %m\", m->path);\n n_failed++;\n }\n }\n@@ -536,7 +536,7 @@ static int dm_points_list_detach(MountPoint **head, bool *changed) {\n continue;\n }\n \n- log_info(\"Deleting DM %u:%u.\", major(m->devnum), minor(m->devnum));\n+ log_info(\"Detaching DM %u:%u.\", major(m->devnum), minor(m->devnum));\n r = delete_dm(m->devnum);\n if (r >= 0) {\n if (changed)\n@@ -544,7 +544,7 @@ static int dm_points_list_detach(MountPoint **head, bool *changed) {\n \n mount_point_free(head, m);\n } else {\n- log_warning(\"Could not delete DM %s: %m\", m->path);\n+ log_warning(\"Could not detach DM %s: %m\", m->path);\n n_failed++;\n }\n }\n-- \n1.7.10.4" } ]
{ "id": "systemd-2025-shutdown-improvements.patch", "cve_id": "CVE-2013-4288", "package": "systemd", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 780, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2012-1138\n\nFreeType before 2.4.9, as used in Mozilla Firefox Mobile before 10.0.4 and other products, allows remote attackers to cause a denial of service (invalid heap read operation and memory corruption) or possibly execute arbitrary code via vectors involving the MIRP instruction in a TrueType font.\n\n## Package\nfreetype2\n\n## Files to modify\n- freetype-2.4.4.orig/src/bdf/bdflib.c\n- src/bdf/bdflib.c\n\n## Target Source Code\n\n### src/bdf/bdflib.c\n\n#### region() [lines 1677-1727]\n```c\n glyph = font->glyphs + ( font->glyphs_used - 1 );\n\n /* Check to see whether a bitmap is being constructed. */\n if ( p->flags & _BDF_BITMAP )\n {\n /* If there are more rows than are specified in the glyph metrics, */\n /* ignore the remaining lines. */\n if ( p->row >= (unsigned long)glyph->bbx.height )\n {\n if ( !( p->flags & _BDF_GLYPH_HEIGHT_CHECK ) )\n {\n FT_TRACE2(( \"_bdf_parse_glyphs: \" ACMSG13, glyph->encoding ));\n p->flags |= _BDF_GLYPH_HEIGHT_CHECK;\n font->modified = 1;\n }\n\n goto Exit;\n }\n\n /* Only collect the number of nibbles indicated by the glyph */\n /* metrics. If there are more columns, they are simply ignored. */\n nibbles = glyph->bpr << 1;\n bp = glyph->bitmap + p->row * glyph->bpr;\n\n for ( i = 0; i < nibbles; i++ )\n {\n c = line[i];\n *bp = (FT_Byte)( ( *bp << 4 ) + a2i[c] );\n if ( i + 1 < nibbles && ( i & 1 ) )\n *++bp = 0;\n }\n\n /* Remove possible garbage at the right. */\n mask_index = ( glyph->bbx.width * p->font->bpp ) & 7;\n if ( glyph->bbx.width )\n *bp &= nibble_mask[mask_index];\n\n /* If any line has extra columns, indicate they have been removed. */\n if ( ( line[nibbles] == '0' || a2i[(int)line[nibbles]] != 0 ) &&\n !( p->flags & _BDF_GLYPH_WIDTH_CHECK ) )\n {\n FT_TRACE2(( \"_bdf_parse_glyphs: \" ACMSG14, glyph->encoding ));\n p->flags |= _BDF_GLYPH_WIDTH_CHECK;\n font->modified = 1;\n }\n\n p->row++;\n goto Exit;\n }\n\n /* Expect the SWIDTH (scalable width) field next. */\n```\n\n#### region() [lines 1727-1738]\n```c\n /* Expect the SWIDTH (scalable width) field next. */\n if ( ft_memcmp( line, \"SWIDTH\", 6 ) == 0 )\n {\n if ( !( p->flags & _BDF_ENCODING ) )\n {\n /* Missing ENCODING field. */\n FT_ERROR(( \"_bdf_parse_glyphs: \" ERRMSG1, lineno, \"ENCODING\" ));\n error = BDF_Err_Missing_Encoding_Field;\n goto Exit;\n }\n\n error = _bdf_list_split( &p->list, (char *)\" +\", line, linelen );\n```\n\n\n## Upstream Fix\n```diff\nFrom 6ac022dc750d95296a6f731b9594f2e751d997fa Mon Sep 17 00:00:00 2001\nFrom: Werner Lemberg <wl@gnu.org>\nDate: Thu, 1 Mar 2012 16:43:20 +0100\nSubject: [PATCH] [bdf] Fix Savannah bug #35656.\n\n* src/bdf/bdflib.c (_bdf_parse_glyphs) <_BDF_BITMAP>: Check validity\nof nibble characters instead of accessing `a2i' array.\n---\n ChangeLog | 7 +++++++\n src/bdf/bdflib.c | 8 ++++----\n 2 files changed, 11 insertions(+), 4 deletions(-)\n\ndiff --git a/ChangeLog b/ChangeLog\nindex 51c129e15..2dc9673d1 100644\n--- a/ChangeLog\n+++ b/ChangeLog\n@@ -1,3 +1,10 @@\n+2012-03-01 Werner Lemberg <wl@gnu.org>\n+\n+\t[bdf] Fix Savannah bug #35656.\n+\n+\t* src/bdf/bdflib.c (_bdf_parse_glyphs) <_BDF_BITMAP>: Check validity\n+\tof nibble characters instead of accessing `a2i' array.\n+\n 2012-03-01 Werner Lemberg <wl@gnu.org>\n \n \t[winfonts] Fix Savannah bug #35659.\ndiff --git a/src/bdf/bdflib.c b/src/bdf/bdflib.c\nindex fc635c9b4..6a66d1d1f 100644\n--- a/src/bdf/bdflib.c\n+++ b/src/bdf/bdflib.c\n@@ -1746,7 +1746,7 @@\n for ( i = 0; i < nibbles; i++ )\n {\n c = line[i];\n- if ( !c )\n+ if ( !isdigok( hdigits, c ) )\n break;\n *bp = (FT_Byte)( ( *bp << 4 ) + a2i[c] );\n if ( i + 1 < nibbles && ( i & 1 ) )\n@@ -1769,9 +1769,9 @@\n *bp &= nibble_mask[mask_index];\n \n /* If any line has extra columns, indicate they have been removed. */\n- if ( i == nibbles &&\n- ( line[nibbles] == '0' || a2i[(int)line[nibbles]] != 0 ) &&\n- !( p->flags & _BDF_GLYPH_WIDTH_CHECK ) )\n+ if ( i == nibbles &&\n+ isdigok( hdigits, line[nibbles] ) &&\n+ !( p->flags & _BDF_GLYPH_WIDTH_CHECK ) )\n {\n FT_TRACE2(( \"_bdf_parse_glyphs: \" ACMSG14, glyph->encoding ));\n p->flags |= _BDF_GLYPH_WIDTH_CHECK;\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 6ac022dc750d95296a6f731b9594f2e751d997fa Mon Sep 17 00:00:00 2001\nFrom: Werner Lemberg <wl@gnu.org>\nDate: Thu, 01 Mar 2012 15:43:20 +0000\nSubject: [bdf] Fix Savannah bug #35656.\n\n* src/bdf/bdflib.c (_bdf_parse_glyphs) <_BDF_BITMAP>: Check validity\nof nibble characters instead of accessing `a2i' array.\n---\n---\n src/bdf/bdflib.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\nIndex: freetype-2.4.4/src/bdf/bdflib.c\n===================================================================\n--- freetype-2.4.4.orig/src/bdf/bdflib.c\n+++ freetype-2.4.4/src/bdf/bdflib.c\n@@ -1707,7 +1707,7 @@\n for ( i = 0; i < nibbles; i++ )\n {\n c = line[i];\n- if ( !c )\n+ if ( !isdigok( hdigits, c ) )\n break;\n *bp = (FT_Byte)( ( *bp << 4 ) + a2i[c] );\n if ( i + 1 < nibbles && ( i & 1 ) )\n@@ -1730,9 +1730,9 @@\n *bp &= nibble_mask[mask_index];\n \n /* If any line has extra columns, indicate they have been removed. */\n- if ( i == nibbles &&\n- ( line[nibbles] == '0' || a2i[(int)line[nibbles]] != 0 ) &&\n- !( p->flags & _BDF_GLYPH_WIDTH_CHECK ) )\n+ if ( i == nibbles &&\n+ isdigok( hdigits, line[nibbles] ) &&\n+ !( p->flags & _BDF_GLYPH_WIDTH_CHECK ) )\n {\n FT_TRACE2(( \"_bdf_parse_glyphs: \" ACMSG14, glyph->encoding ));\n p->flags |= _BDF_GLYPH_WIDTH_CHECK;" } ]
{ "id": "freetype2-418-CVE-2012-1139.patch", "cve_id": "CVE-2012-1138", "package": "freetype2", "upstream_enriched": true, "upstream_commit": "6ac022dc750d95296a6f731b9594f2e751d997fa", "upstream_repo": "freetype/freetype", "tier": "adapted", "has_source_context": true, "license": "FTL AND GPL-2.0-only", "context_tokens_est": 560, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2012-3955\n\nISC DHCP 4.1.x before 4.1-ESV-R7 and 4.2.x before 4.2.4-P2 allows remote attackers to cause a denial of service (daemon crash) in opportunistic circumstances by establishing an IPv6 lease in an environment where the lease expiration time is later reduced.\n\n## Package\ndhcp\n\n## Files to modify\n- server/ldap.c\n\n## Upstream Fix\n```diff\nFrom 98c770187f29389e94873712e13108cc5d44cf89 Mon Sep 17 00:00:00 2001\nFrom: Marius Tomaschewski <mt@suse.de>\nDate: Mon, 10 Dec 2012 09:56:00 +0100\nReferences: bnc#788787\nUpstream: sent [ISC-Bugs #32217]\nSubject: [PATCH] Fixed memory leaks in ldap read config error handling\n\nFixed to free ldap results before bailing out when the\ndhcpServer object or it's dhcpService references can't\nbe parsed / resolved.\n---\n server/ldap.c | 15 +++++++++++----\n 1 Datei geändert, 11 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)\n\ndiff --git a/server/ldap.c b/server/ldap.c\nindex fb7b504..2f6e1c6 100644\n--- a/server/ldap.c\n+++ b/server/ldap.c\n@@ -475,11 +475,14 @@ ldap_parse_host (struct ldap_config_stack *item, struct parse *cfile)\n x_parser_strcat (cfile, tempbv[0]->bv_val);\n x_parser_strcat (cfile, \" {\\n\");\n \n- if (hwaddr != NULL && hwaddr[0] != NULL)\n+ if (hwaddr != NULL)\n {\n- x_parser_strcat (cfile, \"hardware \");\n- x_parser_strcat (cfile, hwaddr[0]->bv_val);\n- x_parser_strcat (cfile, \";\\n\");\n+ if (hwaddr[0] != NULL)\n+ {\n+ x_parser_strcat (cfile, \"hardware \");\n+ x_parser_strcat (cfile, hwaddr[0]->bv_val);\n+ x_parser_strcat (cfile, \";\\n\");\n+ }\n ldap_value_free_len (hwaddr);\n }\n \n@@ -2090,6 +2093,8 @@ ldap_read_config (void)\n res = ldap_parse_entry_options(hostent, cfile, NULL);\n if (res != ISC_R_SUCCESS)\n {\n+ ldap_value_free_len (tempbv);\n+ ldap_msgfree (hostres);\n ldap_memfree (hostdn);\n ldap_stop();\n x_parser_free(&cfile);\n@@ -2102,6 +2107,8 @@ ldap_read_config (void)\n if (res != ISC_R_SUCCESS)\n {\n log_error (\"LDAP: cannot parse dhcpServer entry '%s'\", hostdn);\n+ ldap_value_free_len (tempbv);\n+ ldap_msgfree (hostres);\n ldap_memfree (hostdn);\n ldap_stop();\n x_parser_free(&cfile);\n-- \n1.7.10.4\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 98c770187f29389e94873712e13108cc5d44cf89 Mon Sep 17 00:00:00 2001\nFrom: Marius Tomaschewski <mt@suse.de>\nDate: Mon, 10 Dec 2012 09:56:00 +0100\nReferences: bnc#788787\nUpstream: sent [ISC-Bugs #32217]\nSubject: [PATCH] Fixed memory leaks in ldap read config error handling\n\nFixed to free ldap results before bailing out when the\ndhcpServer object or it's dhcpService references can't\nbe parsed / resolved.\n---\n server/ldap.c | 15 +++++++++++----\n 1 Datei geändert, 11 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)\n\ndiff --git a/server/ldap.c b/server/ldap.c\nindex fb7b504..2f6e1c6 100644\n--- a/server/ldap.c\n+++ b/server/ldap.c\n@@ -475,11 +475,14 @@ ldap_parse_host (struct ldap_config_stack *item, struct parse *cfile)\n x_parser_strcat (cfile, tempbv[0]->bv_val);\n x_parser_strcat (cfile, \" {\\n\");\n \n- if (hwaddr != NULL && hwaddr[0] != NULL)\n+ if (hwaddr != NULL)\n {\n- x_parser_strcat (cfile, \"hardware \");\n- x_parser_strcat (cfile, hwaddr[0]->bv_val);\n- x_parser_strcat (cfile, \";\\n\");\n+ if (hwaddr[0] != NULL)\n+ {\n+ x_parser_strcat (cfile, \"hardware \");\n+ x_parser_strcat (cfile, hwaddr[0]->bv_val);\n+ x_parser_strcat (cfile, \";\\n\");\n+ }\n ldap_value_free_len (hwaddr);\n }\n \n@@ -2090,6 +2093,8 @@ ldap_read_config (void)\n res = ldap_parse_entry_options(hostent, cfile, NULL);\n if (res != ISC_R_SUCCESS)\n {\n+ ldap_value_free_len (tempbv);\n+ ldap_msgfree (hostres);\n ldap_memfree (hostdn);\n ldap_stop();\n x_parser_free(&cfile);\n@@ -2102,6 +2107,8 @@ ldap_read_config (void)\n if (res != ISC_R_SUCCESS)\n {\n log_error (\"LDAP: cannot parse dhcpServer entry '%s'\", hostdn);\n+ ldap_value_free_len (tempbv);\n+ ldap_msgfree (hostres);\n ldap_memfree (hostdn);\n ldap_stop();\n x_parser_free(&cfile);\n-- \n1.7.10.4" } ]
{ "id": "dhcp-902-dhcp-4.2.4-ldap-0005-memleak-f", "cve_id": "CVE-2012-3955", "package": "dhcp", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": false, "license": "MPL-2.0", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2013-4288\n\nRace condition in PolicyKit (aka polkit) allows local users to bypass intended PolicyKit restrictions and gain privileges by starting a setuid or pkexec process before the authorization check is performed, related to (1) the polkit_unix_process_new API function, (2) the dbus API, or (3) the --process (unix-process) option for authorization to pkcheck.\n\n## Package\nsystemd\n\n## Files to modify\n- src/journal/journalctl.c\n\n## Target Source Code\n\n### src/journal/journalctl.c\n\n#### add_priorities() [lines 534-562]\n```c\n return 0;\n}\n\nstatic int add_priorities(sd_journal *j) {\n char match[] = \"PRIORITY=0\";\n int i, r;\n\n assert(j);\n\n if (arg_priorities == 0xFF)\n return 0;\n\n for (i = LOG_EMERG; i <= LOG_DEBUG; i++)\n if (arg_priorities & (1 << i)) {\n match[sizeof(match)-2] = '0' + i;\n\n log_info(\"adding match %s\", match);\n\n r = sd_journal_add_match(j, match, strlen(match));\n if (r < 0) {\n log_error(\"Failed to add match: %s\", strerror(-r));\n return r;\n }\n }\n\n return 0;\n}\n\nstatic int setup_keys(void) {\n```\n\n\n## Upstream Fix\n```diff\nFrom db87a36e74ff26d1046a451ee086c9a2c4113d12 Mon Sep 17 00:00:00 2001\nFrom: Lennart Poettering <lennart@poettering.net>\nDate: Wed, 24 Oct 2012 01:05:55 +0200\nSubject: [PATCH] journalctl: remove left-over log message\n\n---\n src/journal/journalctl.c | 2 --\n 1 file changed, 2 deletions(-)\n\ndiff --git a/src/journal/journalctl.c b/src/journal/journalctl.c\nindex d1338d2b7c5fd..0f20448bf0870 100644\n--- a/src/journal/journalctl.c\n+++ b/src/journal/journalctl.c\n@@ -547,8 +547,6 @@ static int add_priorities(sd_journal *j) {\n if (arg_priorities & (1 << i)) {\n match[sizeof(match)-2] = '0' + i;\n \n- log_info(\"adding match %s\", match);\n-\n r = sd_journal_add_match(j, match, strlen(match));\n if (r < 0) {\n log_error(\"Failed to add match: %s\", strerror(-r));\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From db87a36e74ff26d1046a451ee086c9a2c4113d12 Mon Sep 17 00:00:00 2001\nFrom: Lennart Poettering <lennart@poettering.net>\nDate: Wed, 24 Oct 2012 01:05:55 +0200\nSubject: [PATCH] journalctl: remove left-over log message\n\n---\n src/journal/journalctl.c | 2 --\n 1 file changed, 2 deletions(-)\n\ndiff --git a/src/journal/journalctl.c b/src/journal/journalctl.c\nindex d1338d2..0f20448 100644\n--- a/src/journal/journalctl.c\n+++ b/src/journal/journalctl.c\n@@ -547,8 +547,6 @@ static int add_priorities(sd_journal *j) {\n if (arg_priorities & (1 << i)) {\n match[sizeof(match)-2] = '0' + i;\n \n- log_info(\"adding match %s\", match);\n-\n r = sd_journal_add_match(j, match, strlen(match));\n if (r < 0) {\n log_error(\"Failed to add match: %s\", strerror(-r));\n-- \n1.7.10.4" } ]
{ "id": "systemd-2025-journalctl-remove-leftover-mes", "cve_id": "CVE-2013-4288", "package": "systemd", "upstream_enriched": true, "upstream_commit": "db87a36e74ff26d1046a451ee086c9a2c4113d12", "upstream_repo": "systemd/systemd", "tier": "adapted", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 208, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-0777\n\nThe resend_bytes function in roaming_common.c in the client in OpenSSH 5.x, 6.x, and 7.x before 7.1p2 allows remote servers to obtain sensitive information from process memory by requesting transmission of an entire buffer, as demonstrated by reading a private key.\n\n## Package\nopenssh-askpass-gnome\n\n## Files to modify\n- openssh-6.6p1/monitor_wrap.c\n- openssh-6.6p1/sshd.c\n- openssh-6.6p1/audit.c\n- openssh-6.6p1/audit.h\n- openssh-6.6p1/audit-bsm.c\n\n## Upstream Fix\n```diff\n# server key destruction and auditing\n# based on:\n# https://bugzilla.mindrot.org/show_bug.cgi?id=1402\n# https://bugzilla.mindrot.org/attachment.cgi?id=2015\n# by jchadima@redhat.com\n\ndiff --git a/openssh-6.6p1/audit-bsm.c b/openssh-6.6p1/audit-bsm.c\n--- a/openssh-6.6p1/audit-bsm.c\n+++ b/openssh-6.6p1/audit-bsm.c\n@@ -486,9 +486,27 @@ audit_kex_body(int ctos, char *enc, char\n \t/* not implemented */\n }\n \n void\n audit_session_key_free_body(int ctos, pid_t pid, uid_t uid)\n {\n \t/* not implemented */\n }\n+\n+void\n+audit_destroy_sensitive_data(const char *fp)\n+{\n+\t/* not implemented */\n+}\n+\n+void\n+audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)\n+{\n+\t/* not implemented */\n+}\n+\n+void\n+audit_generate_ephemeral_server_key(const char *fp)\n+{\n+\t/* not implemented */\n+}\n #endif /* BSM */\ndiff --git a/openssh-6.6p1/audit-linux.c b/openssh-6.6p1/audit-linux.c\n--- a/openssh-6.6p1/audit-linux.c\n+++ b/openssh-6.6p1/audit-linux.c\n@@ -351,9 +351,55 @@ audit_session_key_free_body(int ctos, pi\n \taudit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,\n \t\t\tbuf, NULL, get_remote_ipaddr(), NULL, 1);\n \taudit_close(audit_fd);\n \t/* do not abort if the error is EPERM and sshd is run as non root user */\n \tif ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))\n \t\terror(\"cannot write into audit\");\n }\n \n+void\n+audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)\n+{\n+\tchar buf[AUDIT_LOG_SIZE];\n+\tint audit_fd, audit_ok;\n+\n+\tsnprintf(buf, sizeof(buf), \"op=destroy kind=server fp=%s direction=? spid=%jd suid=%jd \",\n+\t\tfp, (intmax_t)pid, (intmax_t)uid);\n+\taudit_fd = audit_open();\n+\tif (audit_fd < 0) {\n+\t\tif (errno != EINVAL && errno != EPROTONOSUPPORT &&\n+\t\t\t\t\t errno != EAFNOSUPPORT)\n+\t\t\terror(\"cannot open audit\");\n+\t\treturn;\n+\t}\n+\taudit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,\n+\t\t\tbuf, NULL,\n+\t\t\tlistening_for_clients() ? NULL : get_remote_ipaddr(),\n+\t\t\tNULL, 1);\n+\taudit_close(audit_fd);\n+\t/* do not abort if the error is EPERM and sshd is run as non root user */\n+\tif ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))\n+\t\terror(\"cannot write into audit\");\n+}\n+\n+void\n+audit_generate_ephemeral_server_key(const char *fp)\n+{\n+\tchar buf[AUDIT_LOG_SIZE];\n+\tint audit_fd, audit_ok;\n+\n+\tsnprintf(buf, sizeof(buf), \"op=create kind=server fp=%s direction=? \", fp);\n+\taudit_fd = audit_open();\n+\tif (audit_fd < 0) {\n+\t\tif (errno != EINVAL && errno != EPROTONOSUPPORT &&\n+\t\t\t\t\t errno != EAFNOSUPPORT)\n+\t\t\terror(\"cannot open audit\");\n+\t\treturn;\n+\t}\n+\taudit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,\n+\t\t\tbuf, NULL, 0, NULL, 1);\n+\taudit_close(audit_fd);\n+\t/* do not abort if the error is EPERM and sshd is run as non root user */\n+\tif ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))\n+\t\terror(\"cannot write into audit\");\n+}\n #endif /* USE_LINUX_AUDIT */\ndiff --git a/openssh-6.6p1/audit.c b/openssh-6.6p1/audit.c\n--- a/openssh-6.6p1/audit.c\n+++ b/openssh-6.6p1/audit.c\n@@ -285,10 +285,29 @@ audit_kex_body(int ctos, char *enc, char\n * This will be called on succesfull session key discard\n */\n void\n audit_session_key_free_body(int ctos, pid_t pid, uid_t uid)\n {\n \tdebug(\"audit session key discard euid %u direction %d from pid %ld uid %u\",\n \t\t(unsigned)geteuid(), ctos, (long)pid, (unsigned)uid);\n }\n+\n+/*\n+ * This will be called on destroy private part of the server key\n+ */\n+void\n+audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)\n+{\n+\tdebug(\"audit destroy sensitive data euid %d fingerprint %s from pid %ld uid %u\",\n+\t\tgeteuid(), fp, (long)pid, (unsigned)uid);\n+}\n+\n+/*\n+ * This will be called on generation of the ephemeral server key\n+ */\n+void\n+audit_generate_ephemeral_server_key(const char *)\n+{\n+\tdebug(\"audit create ephemeral server key euid %d fingerprint %s\", geteuid(), fp);\n+}\n # endif /* !defined CUSTOM_SSH_AUDIT_EVENTS */\n #endif /* SSH_AUDIT_EVENTS */\ndiff --git a/openssh-6.6p1/audit.h b/openssh-6.6p1/audit.h\n--- a/openssh-6.6p1/audit.h\n+++ b/openssh-6.6p1/audit.h\n@@ -43,26 +43,30 @@ enum ssh_audit_event_type {\n \tSSH_INVALID_USER,\n \tSSH_NOLOGIN,\t\t/* denied by /etc/nologin, not implemented */\n \tSSH_CONNECTION_CLOSE,\t/* closed after attempting auth or session */\n \tSSH_CONNECTION_ABANDON,\t/* closed without completing auth */\n \tSSH_AUDIT_UNKNOWN\n };\n typedef enum ssh_audit_event_type ssh_audit_event_t;\n \n+int\tlistening_for_clients(void);\n+\n void\taudit_connection_from(const char *, int);\n void\taudit_event(ssh_audit_event_t);\n void\taudit_count_session_open(void);\n void\taudit_session_open(struct logininfo *);\n void\taudit_session_close(struct logininfo *);\n int\taudit_run_command(const char *);\n void \taudit_end_command(int, const char *);\n ssh_audit_event_t audit_classify_auth(const char *);\n int\taudit_keyusage(int, const char *, unsigned, char *, int);\n void\taudit_key(int, int *, const Key *);\n void\taudit_unsupported(int);\n void\taudit_kex(int, char *, char *, char *);\n void\taudit_unsupported_body(int);\n void\taudit_kex_body(int, char *, char *, char *, pid_t, uid_t);\n void\taudit_session_key_free(int ctos);\n void\taudit_session_key_free_body(int ctos, pid_t, uid_t);\n+void\taudit_destroy_sensitive_data(const char *, pid_t, uid_t);\n+void\taudit_generate_ephemeral_server_key(const char *);\n \n #endif /* _SSH_AUDIT_H */\ndiff --git a/openssh-6.6p1/key.c b/openssh-6.6p1/key.c\n--- a/openssh-6.6p1/key.c\n+++ b/openssh-6.6p1/key.c\n@@ -1964,16 +1964,43 @@ key_demote(const Key *k)\n \t\tfatal(\"key_demote: bad key type %d\", k->type);\n \t\tbreak;\n \t}\n \n \treturn (pk);\n }\n \n int\n+key_is_private(const Key *k)\n+{\n+\tswitch (k->type) {\n+\tcase KEY_RSA_CERT_V00:\n+\tcase KEY_RSA_CERT:\n+\tcase KEY_RSA1:\n+\tcase KEY_RSA:\n+\t\treturn k->rsa->d != NULL;\n+\tcase KEY_DSA_CERT_V00:\n+\tcase KEY_DSA_CERT:\n+\tcase KEY_DSA:\n+\t\treturn k->dsa->priv_key != NULL;\n+#ifdef OPENSSL_HAS_ECC\n+\tcase KEY_ECDSA_CERT:\n+\tcase KEY_ECDSA:\n+\t\treturn EC_KEY_get0_private_key(k->ecdsa) != NULL;\n+#endif\n+\tcase KEY_ED25519_CERT:\n+\tcase KEY_ED25519:\n+\t\treturn k->ed25519_sk != NULL;\n+\tdefault:\n+\t\tfatal(\"key_is_private: bad key type %d\", k->type);\n+\t\treturn 1;\n+\t}\n+}\n+\n+int\n key_is_cert(const Key *k)\n {\n \tif (k == NULL)\n \t\treturn 0;\n \treturn key_type_is_cert(k->type);\n }\n \n /* Return the cert-less equivalent to a certified key type */\ndiff --git a/openssh-6.6p1/key.h b/openssh-6.6p1/key.h\n--- a/openssh-6.6p1/key.h\n+++ b/openssh-6.6p1/key.h\n@@ -113,16 +113,17 @@ int\t\t key_read(Key *, char **);\n u_int\t\t key_size(const Key *);\n enum fp_type\t key_fp_type_select(void);\n char\t\t*key_fp_type_str(enum fp_type);\n \n Key\t*key_generate(int, u_int);\n Key\t*key_from_private(const Key *);\n int\t key_type_from_name(char *);\n int\t key_is_cert(const Key *);\n+int\t key_is_private(const Key *k);\n int\t key_type_is_cert(int);\n int\t key_type_plain(int);\n int\t key_to_certified(Key *, int);\n int\t key_drop_cert(Key *);\n int\t key_certify(Key *, Key *);\n void\t key_cert_copy(const Key *, struct Key *);\n int\t key_cert_check_authority(const Key *, int, int, const char *,\n \t const char **);\ndiff --git a/openssh-6.6p1/monitor.c b/openssh-6.6p1/monitor.c\n--- a/openssh-6.6p1/monitor.c\n+++ b/openssh-6.6p1/monitor.c\n@@ -109,16 +109,18 @@ extern u_int utmp_len;\n extern Newkeys *current_keys[];\n extern z_stream incoming_stream;\n extern z_stream outgoing_stream;\n extern u_char session_id[];\n extern Buffer auth_debug;\n extern int auth_debug_init;\n extern Buffer loginmsg;\n \n+extern void destroy_sensitive_data(int);\n+\n /* State exported from the child */\n \n struct {\n \tz_stream incoming;\n \tz_stream outgoing;\n \tu_char *keyin;\n \tu_int keyinlen;\n \tu_char *keyout;\n@@ -180,16 +182,17 @@ int mm_answer_gss_checkmic(int, Buffer *\n \n #ifdef SSH_AUDIT_EVENTS\n int mm_answer_audit_event(int, Buffer *);\n int mm_answer_audit_command(int, Buffer *);\n int mm_answer_audit_end_command(int, Buffer *);\n int mm_answer_audit_unsupported_body(int, Buffer *);\n int mm_answer_audit_kex_body(int, Buffer *);\n int mm_answer_audit_session_key_free_body(int, Buffer *);\n+int mm_answer_audit_server_key_free(int, Buffer *);\n #endif\n \n static int monitor_r\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "# server key destruction and auditing\n# based on:\n# https://bugzilla.mindrot.org/show_bug.cgi?id=1402\n# https://bugzilla.mindrot.org/attachment.cgi?id=2015\n# by jchadima@redhat.com\n\ndiff --git a/openssh-6.6p1/audit-bsm.c b/openssh-6.6p1/audit-bsm.c\n--- a/openssh-6.6p1/audit-bsm.c\n+++ b/openssh-6.6p1/audit-bsm.c\n@@ -486,9 +486,27 @@ audit_kex_body(int ctos, char *enc, char\n \t/* not implemented */\n }\n \n void\n audit_session_key_free_body(int ctos, pid_t pid, uid_t uid)\n {\n \t/* not implemented */\n }\n+\n+void\n+audit_destroy_sensitive_data(const char *fp)\n+{\n+\t/* not implemented */\n+}\n+\n+void\n+audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)\n+{\n+\t/* not implemented */\n+}\n+\n+void\n+audit_generate_ephemeral_server_key(const char *fp)\n+{\n+\t/* not implemented */\n+}\n #endif /* BSM */\ndiff --git a/openssh-6.6p1/audit-linux.c b/openssh-6.6p1/audit-linux.c\n--- a/openssh-6.6p1/audit-linux.c\n+++ b/openssh-6.6p1/audit-linux.c\n@@ -351,9 +351,55 @@ audit_session_key_free_body(int ctos, pi\n \taudit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,\n \t\t\tbuf, NULL, get_remote_ipaddr(), NULL, 1);\n \taudit_close(audit_fd);\n \t/* do not abort if the error is EPERM and sshd is run as non root user */\n \tif ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))\n \t\terror(\"cannot write into audit\");\n }\n \n+void\n+audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)\n+{\n+\tchar buf[AUDIT_LOG_SIZE];\n+\tint audit_fd, audit_ok;\n+\n+\tsnprintf(buf, sizeof(buf), \"op=destroy kind=server fp=%s direction=? spid=%jd suid=%jd \",\n+\t\tfp, (intmax_t)pid, (intmax_t)uid);\n+\taudit_fd = audit_open();\n+\tif (audit_fd < 0) {\n+\t\tif (errno != EINVAL && errno != EPROTONOSUPPORT &&\n+\t\t\t\t\t errno != EAFNOSUPPORT)\n+\t\t\terror(\"cannot open audit\");\n+\t\treturn;\n+\t}\n+\taudit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,\n+\t\t\tbuf, NULL,\n+\t\t\tlistening_for_clients() ? NULL : get_remote_ipaddr(),\n+\t\t\tNULL, 1);\n+\taudit_close(audit_fd);\n+\t/* do not abort if the error is EPERM and sshd is run as non root user */\n+\tif ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))\n+\t\terror(\"cannot write into audit\");\n+}\n+\n+void\n+audit_generate_ephemeral_server_key(const char *fp)\n+{\n+\tchar buf[AUDIT_LOG_SIZE];\n+\tint audit_fd, audit_ok;\n+\n+\tsnprintf(buf, sizeof(buf), \"op=create kind=server fp=%s direction=? \", fp);\n+\taudit_fd = audit_open();\n+\tif (audit_fd < 0) {\n+\t\tif (errno != EINVAL && errno != EPROTONOSUPPORT &&\n+\t\t\t\t\t errno != EAFNOSUPPORT)\n+\t\t\terror(\"cannot open audit\");\n+\t\treturn;\n+\t}\n+\taudit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,\n+\t\t\tbuf, NULL, 0, NULL, 1);\n+\taudit_close(audit_fd);\n+\t/* do not abort if the error is EPERM and sshd is run as non root user */\n+\tif ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))\n+\t\terror(\"cannot write into audit\");\n+}\n #endif /* USE_LINUX_AUDIT */\ndiff --git a/openssh-6.6p1/audit.c b/openssh-6.6p1/audit.c\n--- a/openssh-6.6p1/audit.c\n+++ b/openssh-6.6p1/audit.c\n@@ -285,10 +285,29 @@ audit_kex_body(int ctos, char *enc, char\n * This will be called on succesfull session key discard\n */\n void\n audit_session_key_free_body(int ctos, pid_t pid, uid_t uid)\n {\n \tdebug(\"audit session key discard euid %u direction %d from pid %ld uid %u\",\n \t\t(unsigned)geteuid(), ctos, (long)pid, (unsigned)uid);\n }\n+\n+/*\n+ * This will be called on destroy private part of the server key\n+ */\n+void\n+audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)\n+{\n+\tdebug(\"audit destroy sensitive data euid %d fingerprint %s from pid %ld uid %u\",\n+\t\tgeteuid(), fp, (long)pid, (unsigned)uid);\n+}\n+\n+/*\n+ * This will be called on generation of the ephemeral server key\n+ */\n+void\n+audit_generate_ephemeral_server_key(const char *)\n+{\n+\tdebug(\"audit create ephemeral server key euid %d fingerprint %s\", geteuid(), fp);\n+}\n # endif /* !defined CUSTOM_SSH_AUDIT_EVENTS */\n #endif /* SSH_AUDIT_EVENTS */\ndiff --git a/openssh-6.6p1/audit.h b/openssh-6.6p1/audit.h\n--- a/openssh-6.6p1/audit.h\n+++ b/openssh-6.6p1/audit.h\n@@ -43,26 +43,30 @@ enum ssh_audit_event_type {\n \tSSH_INVALID_USER,\n \tSSH_NOLOGIN,\t\t/* denied by /etc/nologin, not implemented */\n \tSSH_CONNECTION_CLOSE,\t/* closed after attempting auth or session */\n \tSSH_CONNECTION_ABANDON,\t/* closed without completing auth */\n \tSSH_AUDIT_UNKNOWN\n };\n typedef enum ssh_audit_event_type ssh_audit_event_t;\n \n+int\tlistening_for_clients(void);\n+\n void\taudit_connection_from(const char *, int);\n void\taudit_event(ssh_audit_event_t);\n void\taudit_count_session_open(void);\n void\taudit_session_open(struct logininfo *);\n void\taudit_session_close(struct logininfo *);\n int\taudit_run_command(const char *);\n void \taudit_end_command(int, const char *);\n ssh_audit_event_t audit_classify_auth(const char *);\n int\taudit_keyusage(int, const char *, unsigned, char *, int);\n void\taudit_key(int, int *, const Key *);\n void\taudit_unsupported(int);\n void\taudit_kex(int, char *, char *, char *);\n void\taudit_unsupported_body(int);\n void\taudit_kex_body(int, char *, char *, char *, pid_t, uid_t);\n void\taudit_session_key_free(int ctos);\n void\taudit_session_key_free_body(int ctos, pid_t, uid_t);\n+void\taudit_destroy_sensitive_data(const char *, pid_t, uid_t);\n+void\taudit_generate_ephemeral_server_key(const char *);\n \n #endif /* _SSH_AUDIT_H */\ndiff --git a/openssh-6.6p1/key.c b/openssh-6.6p1/key.c\n--- a/openssh-6.6p1/key.c\n+++ b/openssh-6.6p1/key.c\n@@ -1964,16 +1964,43 @@ key_demote(const Key *k)\n \t\tfatal(\"key_demote: bad key type %d\", k->type);\n \t\tbreak;\n \t}\n \n \treturn (pk);\n }\n \n int\n+key_is_private(const Key *k)\n+{\n+\tswitch (k->type) {\n+\tcase KEY_RSA_CERT_V00:\n+\tcase KEY_RSA_CERT:\n+\tcase KEY_RSA1:\n+\tcase KEY_RSA:\n+\t\treturn k->rsa->d != NULL;\n+\tcase KEY_DSA_CERT_V00:\n+\tcase KEY_DSA_CERT:\n+\tcase KEY_DSA:\n+\t\treturn k->dsa->priv_key != NULL;\n+#ifdef OPENSSL_HAS_ECC\n+\tcase KEY_ECDSA_CERT:\n+\tcase KEY_ECDSA:\n+\t\treturn EC_KEY_get0_private_key(k->ecdsa) != NULL;\n+#endif\n+\tcase KEY_ED25519_CERT:\n+\tcase KEY_ED25519:\n+\t\treturn k->ed25519_sk != NULL;\n+\tdefault:\n+\t\tfatal(\"key_is_private: bad key type %d\", k->type);\n+\t\treturn 1;\n+\t}\n+}\n+\n+int\n key_is_cert(const Key *k)\n {\n \tif (k == NULL)\n \t\treturn 0;\n \treturn key_type_is_cert(k->type);\n }\n \n /* Return the cert-less equivalent to a certified key type */\ndiff --git a/openssh-6.6p1/key.h b/openssh-6.6p1/key.h\n--- a/openssh-6.6p1/key.h\n+++ b/openssh-6.6p1/key.h\n@@ -113,16 +113,17 @@ int\t\t key_read(Key *, char **);\n u_int\t\t key_size(const Key *);\n enum fp_type\t key_fp_type_select(void);\n char\t\t*key_fp_type_str(enum fp_type);\n \n Key\t*key_generate(int, u_int);\n Key\t*key_from_private(const Key *);\n int\t key_type_from_name(char *);\n int\t key_is_cert(const Key *);\n+int\t key_is_private(const Key *k);\n int\t key_type_is_cert(int);\n int\t key_type_plain(int);\n int\t key_to_certified(Key *, int);\n int\t key_drop_cert(Key *);\n int\t key_certify(Key *, Key *);\n void\t key_cert_copy(const Key *, struct Key *);\n int\t key_cert_check_authority(const Key *, int, int, const char *,\n \t const char **);\ndiff --git a/openssh-6.6p1/monitor.c b/openssh-6.6p1/monitor.c\n--- a/openssh-6.6p1/monitor.c\n+++ b/openssh-6.6p1/monitor.c\n@@ -109,16 +109,18 @@ extern u_int utmp_len;\n extern Newkeys *current_keys[];\n extern z_stream incoming_stream;\n extern z_stream outgoing_stream;\n extern u_char session_id[];\n extern Buffer auth_debug;\n extern int auth_debug_init;\n extern Buffer loginmsg;\n \n+extern void destroy_sensitive_data(int);\n+\n /* State exported from the child */\n \n struct {\n \tz_stream incoming;\n \tz_stream outgoing;\n \tu_char *keyin;\n \tu_int keyinlen;\n \tu_char *keyout;\n@@ -180,16 +182,17 @@ int mm_answer_gss_checkmic(int, Buffer *\n \n #ifdef SSH_AUDIT_EVENTS\n int mm_answer_audit_event(int, Buffer *);\n int mm_answer_audit_command(int, Buffer *);\n int mm_answer_audit_end_command(int, Buffer *);\n int mm_answer_audit_unsupported_body(int, Buffer *);\n int mm_answer_audit_kex_body(int, Buffer *);\n int mm_answer_audit_session_key_free_body(int, Buffer *);\n+int mm_answer_audit_server_key_free(int, Buffer *);\n #endif\n \n static int monitor_read_log(struct monitor *);\n \n static Authctxt *authctxt;\n static BIGNUM *ssh1_challenge = NULL;\t/* used for ssh1 rsa auth */\n \n /* local state for key verify */\n@@ -234,16 +237,17 @@ struct mon_table mon_dispatch_proto20[] \n {MONITOR_REQ_PAM_RESPOND, MON_ISAUTH, mm_answer_pam_respond},\n {MONITOR_REQ_PAM_FREE_CTX, MON_ONCE|MON_AUTHDECIDE, mm_answer_pam_free_ctx},\n #endif\n #ifdef SSH_AUDIT_EVENTS\n {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},\n {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},\n {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},\n {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},\n+ {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},\n #endif\n #ifdef BSD_AUTH\n {MONITOR_REQ_BSDAUTHQUERY, MON_ISAUTH, mm_answer_bsdauthquery},\n {MONITOR_REQ_BSDAUTHRESPOND, MON_AUTH, mm_answer_bsdauthrespond},\n #endif\n #ifdef SKEY\n {MONITOR_REQ_SKEYQUERY, MON_ISAUTH, mm_answer_skeyquery},\n {MONITOR_REQ_SKEYRESPOND, MON_AUTH, mm_answer_skeyrespond},\n@@ -267,16 +271,17 @@ struct mon_table mon_dispatch_postauth20\n {MONITOR_REQ_TERM, 0, mm_answer_term},\n #ifdef SSH_AUDIT_EVENTS\n {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},\n {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT, mm_answer_audit_command},\n {MONITOR_REQ_AUDIT_END_COMMAND, MON_PERMIT, mm_answer_audit_end_command},\n {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},\n {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},\n {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},\n+ {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},\n #endif\n {0, 0, NULL}\n };\n \n struct mon_table mon_dispatch_proto15[] = {\n {MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow},\n {MONITOR_REQ_SESSKEY, MON_ONCE, mm_answer_sesskey},\n {MONITOR_REQ_SESSID, MON_ONCE, mm_answer_sessid},\n@@ -301,31 +306,33 @@ struct mon_table mon_dispatch_proto15[] \n {MONITOR_REQ_PAM_RESPOND, MON_ISAUTH, mm_answer_pam_respond},\n {MONITOR_REQ_PAM_FREE_CTX, MON_ONCE|MON_AUTHDECIDE, mm_answer_pam_free_ctx},\n #endif\n #ifdef SSH_AUDIT_EVENTS\n {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},\n {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},\n {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},\n {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},\n+ {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},\n #endif\n {0, 0, NULL}\n };\n \n struct mon_table mon_dispatch_postauth15[] = {\n {MONITOR_REQ_PTY, MON_ONCE, mm_answer_pty},\n {MONITOR_REQ_PTYCLEANUP, MON_ONCE, mm_answer_pty_cleanup},\n {MONITOR_REQ_TERM, 0, mm_answer_term},\n #ifdef SSH_AUDIT_EVENTS\n {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},\n {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT|MON_ONCE, mm_answer_audit_command},\n {MONITOR_REQ_AUDIT_END_COMMAND, MON_PERMIT, mm_answer_audit_end_command},\n {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},\n {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},\n {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},\n+ {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},\n #endif\n {0, 0, NULL}\n };\n \n struct mon_table *mon_dispatch;\n \n /* Specifies if a certain message is allowed at the moment */\n \n@@ -1739,16 +1746,18 @@ mm_answer_term(int sock, Buffer *req)\n \t/* The child is terminating */\n \tsession_destroy_all(&mm_session_close);\n \n #ifdef USE_PAM\n \tif (options.use_pam)\n \t\tsshpam_cleanup();\n #endif\n \n+\tdestroy_sensitive_data(0);\n+\n \twhile (waitpid(pmonitor->m_pid, &status, 0) == -1)\n \t\tif (errno != EINTR)\n \t\t\texit(1);\n \n \tres = WIFEXITED(status) ? WEXITSTATUS(status) : 1;\n \n \t/* Terminate process */\n \texit(res);\n@@ -2280,10 +2289,31 @@ mm_answer_audit_session_key_free_body(in\n \n \taudit_session_key_free_body(ctos, pid, uid);\n \n \tbuffer_clear(m);\n \n \tmm_request_send(sock, MONITOR_ANS_AUDIT_SESSION_KEY_FREE, m);\n \treturn 0;\n }\n+\n+int\n+mm_answer_audit_server_key_free(int sock, Buffer *m)\n+{\n+\tint len;\n+\tchar *fp;\n+\tpid_t pid;\n+\tuid_t uid;\n+\n+\tfp = buffer_get_string(m, &len);\n+\tpid = buffer_get_int64(m);\n+\tuid = buffer_get_int64(m);\n+\n+\taudit_destroy_sensitive_data(fp, pid, uid);\n+\n+\tfree(fp);\n+\tbuffer_clear(m);\n+\n+\tmm_request_send(sock, MONITOR_ANS_AUDIT_SERVER_KEY_FREE, m);\n+\treturn 0;\n+}\n #endif /* SSH_AUDIT_EVENTS */\n \ndiff --git a/openssh-6.6p1/monitor.h b/openssh-6.6p1/monitor.h\n--- a/openssh-6.6p1/monitor.h\n+++ b/openssh-6.6p1/monitor.h\n@@ -63,16 +63,17 @@ enum monitor_reqtype {\n \tMONITOR_REQ_PAM_QUERY = 106, MONITOR_ANS_PAM_QUERY = 107,\n \tMONITOR_REQ_PAM_RESPOND = 108, MONITOR_ANS_PAM_RESPOND = 109,\n \tMONITOR_REQ_PAM_FREE_CTX = 110, MONITOR_ANS_PAM_FREE_CTX = 111,\n \tMONITOR_REQ_AUDIT_EVENT = 112, MONITOR_REQ_AUDIT_COMMAND = 113,\n \tMONITOR_ANS_AUDIT_COMMAND = 114, MONITOR_REQ_AUDIT_END_COMMAND = 115,\n \tMONITOR_REQ_AUDIT_UNSUPPORTED = 116, MONITOR_ANS_AUDIT_UNSUPPORTED = 117,\n \tMONITOR_REQ_AUDIT_KEX = 118, MONITOR_ANS_AUDIT_KEX = 119,\n \tMONITOR_REQ_AUDIT_SESSION_KEY_FREE = 120, MONITOR_ANS_AUDIT_SESSION_KEY_FREE = 121,\n+\tMONITOR_REQ_AUDIT_SERVER_KEY_FREE = 122, MONITOR_ANS_AUDIT_SERVER_KEY_FREE = 123,\n \n };\n \n struct mm_master;\n struct monitor {\n \tint\t\t\t m_recvfd;\n \tint\t\t\t m_sendfd;\n \tint\t\t\t m_log_recvfd;\ndiff --git a/openssh-6.6p1/monitor_wrap.c b/openssh-6.6p1/monitor_wrap.c\n--- a/openssh-6.6p1/monitor_wrap.c\n+++ b/openssh-6.6p1/monitor_wrap.c\n@@ -1373,10 +1373,26 @@ mm_audit_session_key_free_body(int ctos,\n \tbuffer_put_int(&m, ctos);\n \tbuffer_put_int64(&m, pid);\n \tbuffer_put_int64(&m, uid);\n \tmm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_SESSION_KEY_FREE, &m);\n \tmm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUDIT_SESSION_KEY_FREE,\n \t\t\t\t &m);\n \tbuffer_free(&m);\n }\n+\n+void\n+mm_audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)\n+{\n+\tBuffer m;\n+\n+\tbuffer_init(&m);\n+\tbuffer_put_cstring(&m, fp);\n+\tbuffer_put_int64(&m, pid);\n+\tbuffer_put_int64(&m, uid);\n+\n+\tmm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_SERVER_KEY_FREE, &m);\n+\tmm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUDIT_SERVER_KEY_FREE,\n+\t\t\t\t &m);\n+\tbuffer_free(&m);\n+}\n #endif /* SSH_AUDIT_EVENTS */\n \ndiff --git a/openssh-6.6p1/monitor_wrap.h b/openssh-6.6p1/monitor_wrap.h\n--- a/openssh-6.6p1/monitor_wrap.h\n+++ b/openssh-6.6p1/monitor_wrap.h\n@@ -75,16 +75,17 @@ void mm_sshpam_free_ctx(void *);\n #ifdef SSH_AUDIT_EVENTS\n #include \"audit.h\"\n void mm_audit_event(ssh_audit_event_t);\n int mm_audit_run_command(const char *);\n void mm_audit_end_command(int, const char *);\n void mm_audit_unsupported_body(int);\n void mm_audit_kex_body(int, char *, char *, char *, pid_t, uid_t);\n void mm_audit_session_key_free_body(int, pid_t, uid_t);\n+void mm_audit_destroy_sensitive_data(const char *, pid_t, uid_t);\n #endif\n \n struct Session;\n void mm_terminate(void);\n int mm_pty_allocate(int *, int *, char *, size_t);\n void mm_session_pty_cleanup2(struct Session *);\n \n /* SSHv1 interfaces */\ndiff --git a/openssh-6.6p1/session.c b/openssh-6.6p1/session.c\n--- a/openssh-6.6p1/session.c\n+++ b/openssh-6.6p1/session.c\n@@ -132,17 +132,17 @@ static int session_pty_req(Session *);\n \n /* import */\n extern ServerOptions options;\n extern char *__progname;\n extern int log_stderr;\n extern int debug_flag;\n extern u_int utmp_len;\n extern int startup_pipe;\n-extern void destroy_sensitive_data(void);\n+extern void destroy_sensitive_data(int);\n extern Buffer loginmsg;\n \n /* original command from peer. */\n const char *original_command = NULL;\n \n /* data */\n static int sessions_first_unused = -1;\n static int sessions_nalloc = 0;\n@@ -1693,17 +1693,17 @@ do_child(Session *s, const char *command\n \tchar **env;\n \tint env_size;\n \tchar *argv[ARGV_MAX];\n \tconst char *shell, *shell0, *hostname = NULL;\n \tstruct passwd *pw = s->pw;\n \tint r = 0;\n \n \t/* remove hostkey from the child's memory */\n-\tdestroy_sensitive_data();\n+\tdestroy_sensitive_data(1);\n \t/* Don't audit this - both us and the parent would be talking to the\n \t monitor over a single socket, with no synchronization. */\n \tpacket_destroy_all(0, 1);\n \n \t/* Force a password change */\n \tif (s->authctxt->force_pwchange) {\n \t\tdo_setusercontext(pw);\n \t\tchild_close_fds();\ndiff --git a/openssh-6.6p1/sshd.c b/openssh-6.6p1/sshd.c\n--- a/openssh-6.6p1/sshd.c\n+++ b/openssh-6.6p1/sshd.c\n@@ -259,17 +259,17 @@ Buffer cfg;\n \n /* message to be displayed after login */\n Buffer loginmsg;\n \n /* Unprivileged user */\n struct passwd *privsep_pw = NULL;\n \n /* Prototypes for various functions defined later in this file. */\n-void destroy_sensitive_data(void);\n+void destroy_sensitive_data(int);\n void demote_sensitive_data(void);\n \n static void do_ssh1_kex(void);\n static void do_ssh2_kex(void);\n \n /*\n * Close all listening sockets\n */\n@@ -278,16 +278,25 @@ close_listen_socks(void)\n {\n \tint i;\n \n \tfor (i = 0; i < num_listen_socks; i++)\n \t\tclose(listen_socks[i]);\n \tnum_listen_socks = -1;\n }\n \n+/*\n+ * Is this process listening for clients (i.e. not specific to any specific\n+ * client connection?)\n+ */\n+int listening_for_clients(void)\n+{\n+\treturn num_listen_socks > 0;\n+}\n+\n static void\n close_startup_pipes(void)\n {\n \tint i;\n \n \tif (startup_pipes)\n \t\tfor (i = 0; i < options.max_startups; i++)\n \t\t\tif (startup_pipes[i] != -1)\n@@ -557,60 +566,99 @@ sshd_exchange_identification(int sock_in\n \t\tclose(sock_out);\n \t\tlogit(\"Protocol major versions differ for %s: %.200s vs. %.200s\",\n \t\t get_remote_ipaddr(),\n \t\t server_version_string, client_version_string);\n \t\tcleanup_exit(255);\n \t}\n }\n \n-/* Destroy the host and server keys. They will no longer be needed. */\n+/*\n+ * Destroy the host and server keys. They will no longer be needed. Careful,\n+ * this can be called from cleanup_exit() - i.e. from just about anywhere.\n+ */\n void\n-destroy_sensitive_data(void)\n+destroy_sensitive_data(int privsep)\n {\n \tint i;\n+\tpid_t pid;\n+\tuid_t uid;\n \n \tif (sensitive_data.server_key) {\n \t\tkey_free(sensitive_data.server_key);\n \t\tsensitive_data.server_key = NULL;\n \t}\n+\tpid = getpid();\n+\tuid = getuid();\n \tfor (i = 0; i < options.num_host_key_files; i++) {\n \t\tif (sensitive_data.host_keys[i]) {\n+\t\t\tchar *fp;\n+\n+\t\t\tif (key_is_private(sensitive_data.host_keys[i]))\n+\t\t\t\tfp = key_fingerprint(sensitive_data.host_keys[i],\n+\t\t\t\t\tkey_fp_type_select(), SSH_FP_HEX);\n+\t\t\telse\n+\t\t\t\tfp = NULL;\n \t\t\tkey_free(sensitive_data.host_keys[i]);\n \t\t\tsensitive_data.host_keys[i] = NULL;\n+\t\t\tif (fp != NULL) {\n+\t\t\t\tif (privsep)\n+\t\t\t\t\tPRIVSEP(audit_destroy_sensitive_data(fp,\n+\t\t\t\t\t\tpid, uid));\n+\t\t\t\telse\n+\t\t\t\t\taudit_destroy_sensitive_data(fp,\n+\t\t\t\t\t\tpid, uid);\n+\t\t\t\tfree(fp);\n+\t\t\t}\n \t\t}\n-\t\tif (sensitive_data.host_certificates[i]) {\n+\t\tif (sensitive_data.host_certificates\n+\t\t && sensitive_data.host_certificates[i]) {\n \t\t\tkey_free(sensitive_data.host_certificates[i]);\n \t\t\tsensitive_data.host_certificates[i] = NULL;\n \t\t}\n \t}\n \tsensitive_data.ssh1_host_key = NULL;\n \texplicit_bzero(sensitive_data.ssh1_cookie, SSH_SESSION_KEY_LENGTH);\n }\n \n /* Demote private to public keys for network child */\n void\n demote_sensitive_data(void)\n {\n \tKey *tmp;\n+\tpid_t pid;\n+\tuid_t uid;\n \tint i;\n \n+\tpid = getpid();\n+\tuid = getuid();\n \tif (sensitive_data.server_key) {\n \t\ttmp = key_demote(sensitive_data.server_key);\n \t\tkey_free(sensitive_data.server_key);\n \t\tsensitive_data.server_key = tmp;\n \t}\n \n \tfor (i = 0; i < options.num_host_key_files; i++) {\n \t\tif (sensitive_data.host_keys[i]) {\n+\t\t\tchar *fp;\n+\n+\t\t\tif (key_is_private(sensitive_data.host_keys[i]))\n+\t\t\t\tfp = key_fingerprint(sensitive_data.host_keys[i],\n+\t\t\t\t\tkey_fp_type_select(), SSH_FP_HEX);\n+\t\t\telse\n+\t\t\t\tfp = NULL;\n \t\t\ttmp = key_demote(sensitive_data.host_keys[i]);\n \t\t\tkey_free(sensitive_data.host_keys[i]);\n \t\t\tsensitive_data.host_keys[i] = tmp;\n \t\t\tif (tmp->type == KEY_RSA1)\n \t\t\t\tsensitive_data.ssh1_host_key = tmp;\n+\t\t\tif (fp != NULL) {\n+\t\t\t\taudit_destroy_sensitive_data(fp, pid, uid);\n+\t\t\t\tfree(fp);\n+\t\t\t}\n \t\t}\n \t\t/* Certs do not need demotion */\n \t}\n \n \t/* We do not clear ssh1_host key and cookie. XXX - Okay Niels? */\n }\n \n static void\n@@ -1201,16 +1249,17 @@ server_accept_loop(int *sock_in, int *so\n \n \t\t/* Wait in select until there is a connection. */\n \t\tret = select(maxfd+1, fdset, NULL, NULL, NULL);\n \t\tif (ret < 0 && errno != EINTR)\n \t\t\terror(\"select: %.100s\", strerror(errno));\n \t\tif (received_sigterm) {\n \t\t\tlogit(\"Received signal %d; terminating.\",\n \t\t\t (int) received_sigterm);\n+\t\t\tdestroy_sensitive_data(0);\n \t\t\tclose_listen_socks();\n \t\t\tunlink(options.pid_file);\n \t\t\texit(received_sigterm == SIGTERM ? 0 : 255);\n \t\t}\n \t\tif (key_used && key_do_regen) {\n \t\t\tgenerate_ephemeral_server_key();\n \t\t\tkey_used = 0;\n \t\t\tkey_do_regen = 0;\n@@ -2167,27 +2216,28 @@ main(int ac, char **av)\n \t/*\n \t * In privilege separation, we fork another child and prepare\n \t * file descriptor passing.\n \t */\n \tif (use_privsep) {\n \t\tprivsep_postauth(authctxt);\n \t\t/* the monitor process [priv] will not return */\n \t\tif (!compat20)\n-\t\t\tdestroy_sensitive_data();\n+\t\t\tdestroy_sensitive_data(0);\n \t}\n \n \tpacket_set_timeout(options.client_alive_interval,\n \t options.client_alive_count_max);\n \n \t/* Start session. */\n \tdo_authenticated(authctxt);\n \n \t/* The connection has been terminated. */\n \tpacket_destroy_all(1, 1);\n+\tdestroy_sensitive_data(1);\n \n \tpacket_get_state(MODE_IN, NULL, NULL, NULL, &ibytes);\n \tpacket_get_state(MODE_OUT, NULL, NULL, NULL, &obytes);\n \tverbose(\"Transferred: sent %llu, received %llu bytes\",\n \t (unsigned long long)obytes, (unsigned long long)ibytes);\n \n \tverbose(\"Closing connection to %.500s port %d\", remote_ip, remote_port);\n \n@@ -2412,17 +2462,17 @@ do_ssh1_kex(void)\n \t\t\tfatal(\"%s: hash failed\", __func__);\n \t\tssh_digest_free(md);\n \t\texplicit_bzero(buf, bytes);\n \t\tfree(buf);\n \t\tfor (i = 0; i < 16; i++)\n \t\t\tsession_id[i] = session_key[i] ^ session_key[i + 16];\n \t}\n \t/* Destroy the private and public keys. No longer. */\n-\tdestroy_sensitive_data();\n+\tdestroy_sensitive_data(0);\n \n \tif (use_privsep)\n \t\tmm_ssh1_session_id(session_id);\n \n \t/* Destroy the decrypted integer. It is no longer needed. */\n \tBN_clear_free(session_key_int);\n \n \t/* Set the session key. From this on all communications will be encrypted. */\n@@ -2556,16 +2606,18 @@ cleanup_exit(int i)\n \t\t\tdebug(\"Killing privsep child %d\", pmonitor->m_pid);\n \t\t\tif (kill(pmonitor->m_pid, SIGKILL) != 0 &&\n \t\t\t errno != ESRCH)\n \t\t\t\terror(\"%s: kill(%d): %s\", __func__,\n \t\t\t\t pmonitor->m_pid, strerror(errno));\n \t\t}\n \t}\n \tis_privsep_child = use_privsep && (pmonitor != NULL) && !mm_is_monitor();\n+\tif (sensitive_data.host_keys != NULL)\n+\t\tdestroy_sensitive_data(is_privsep_child);\n \tpacket_destroy_all(1, is_privsep_child);\n #ifdef SSH_AUDIT_EVENTS\n \t/* done after do_cleanup so it can cancel the PAM auth 'thread' */\n \tif ((the_authctxt == NULL || !the_authctxt->authenticated) &&\n \t (!use_privsep || mm_is_monitor()))\n \t\taudit_event(SSH_CONNECTION_ABANDON);\n #endif\n \t_exit(i);" } ]
{ "id": "openssh-askpass-gnome-4527-openssh-6.6p1-audit6-server_ke", "cve_id": "CVE-2016-0777", "package": "openssh-askpass-gnome", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": false, "license": "BSD-2-Clause", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-2105\n\nInteger overflow in the EVP_EncodeUpdate function in crypto/evp/encode.c in OpenSSL before 1.0.1t and 1.0.2 before 1.0.2h allows remote attackers to cause a denial of service (heap memory corruption) via a large amount of binary data.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i/crypto/asn1/asn1_lib.c\n- openssl-1.0.1i.orig/crypto/asn1/asn1_par.c\n- crypto/asn1/asn1_lib.c\n- openssl-1.0.1i.orig/crypto/asn1/asn1_lib.c\n- openssl-1.0.1i/crypto/asn1/asn1_par.c\n\n## Target Source Code\n\n### crypto/asn1/asn1_lib.c\n\n#### region() [lines 23-110]\n```c\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions\n * are met:\n * 1. Redistributions of source code must retain the copyright\n * notice, this list of conditions and the following disclaimer.\n * 2. Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in the\n * documentation and/or other materials provided with the distribution.\n * 3. All advertising materials mentioning features or use of this software\n * must display the following acknowledgement:\n * \"This product includes cryptographic software written by\n * Eric Young (eay@cryptsoft.com)\"\n * The word 'cryptographic' can be left out if the rouines from the library\n * being used are not cryptographic related :-).\n * 4. If you include any Windows specific code (or a derivative thereof) from \n * the apps directory (application code) you must include an acknowledgement:\n * \"This product includes software written by Tim Hudson (tjh@cryptsoft.com)\"\n * \n * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n * SUCH DAMAGE.\n * \n * The licence and distribution terms for any publically available version or\n * derivative of this code cannot be changed. i.e. this code cannot simply be\n * copied and put under another distribution licence\n * [including the GNU Public Licence.]\n */\n\n#include <stdio.h>\n#include <limits.h>\n#include \"cryptlib.h\"\n#include <openssl/asn1.h>\n#include <openssl/asn1_mac.h>\n\nstatic int asn1_get_length(const unsigned char **pp,int *inf,long *rl,int max);\nstatic void asn1_put_length(unsigned char **pp, int length);\nconst char ASN1_version[]=\"ASN.1\" OPENSSL_VERSION_PTEXT;\n\nstatic int _asn1_check_infinite_end(const unsigned char **p, long len)\n\t{\n\t/* If there is 0 or 1 byte left, the length check should pick\n\t * things up */\n\tif (len <= 0)\n\t\treturn(1);\n\telse if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0))\n\t\t{\n\t\t(*p)+=2;\n\t\treturn(1);\n\t\t}\n\treturn(0);\n\t}\n\nint ASN1_check_infinite_end(unsigned char **p, long len)\n\t{\n\treturn _asn1_check_infinite_end((const unsigned char **)p, len);\n\t}\n\nint ASN1_const_check_infinite_end(const unsigned char **p, long len)\n\t{\n\treturn _asn1_check_infinite_end(p, len);\n\t}\n\n\nint ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,\n\tint *pclass, long omax)\n\t{\n\tint i,ret;\n\tlong l;\n\tconst unsigned char *p= *pp;\n\tint tag,xclass,inf;\n\tlong max=omax;\n\n\tif (!max) goto err;\n\tret=(*p&V_ASN1_CONSTRUCTED);\n\txclass=(*p&V_ASN1_PRIVATE);\n\ti= *p&V_ASN1_PRIMITIVE_TAG;\n\tif (i == V_ASN1_PRIMITIVE_TAG)\n\t\t{\t\t/* high-tag */\n\t\tp++;\n\t\tif (--max == 0) goto err;\n```\n\n#### ASN1_get_object() [lines 91-157]\n```c\n\t}\n\n\nint ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,\n\tint *pclass, long omax)\n\t{\n\tint i,ret;\n\tlong l;\n\tconst unsigned char *p= *pp;\n\tint tag,xclass,inf;\n\tlong max=omax;\n\n\tif (!max) goto err;\n\tret=(*p&V_ASN1_CONSTRUCTED);\n\txclass=(*p&V_ASN1_PRIVATE);\n\ti= *p&V_ASN1_PRIMITIVE_TAG;\n\tif (i == V_ASN1_PRIMITIVE_TAG)\n\t\t{\t\t/* high-tag */\n\t\tp++;\n\t\tif (--max == 0) goto err;\n\t\tl=0;\n\t\twhile (*p&0x80)\n\t\t\t{\n\t\t\tl<<=7L;\n\t\t\tl|= *(p++)&0x7f;\n\t\t\tif (--max == 0) goto err;\n\t\t\tif (l > (INT_MAX >> 7L)) goto err;\n\t\t\t}\n\t\tl<<=7L;\n\t\tl|= *(p++)&0x7f;\n\t\ttag=(int)l;\n\t\tif (--max == 0) goto err;\n\t\t}\n\telse\n\t\t{ \n\t\ttag=i;\n\t\tp++;\n\t\tif (--max == 0) goto err;\n\t\t}\n\t*ptag=tag;\n\t*pclass=xclass;\n\tif (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;\n\n\tif (inf && !(ret & V_ASN1_CONSTRUCTED))\n\t\tgoto err;\n\n#if 0\n\tfprintf(stderr,\"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\\n\", \n\t\t(int)p,*plength,omax,(int)*pp,(int)(p+ *plength),\n\t\t(int)(omax+ *pp));\n\n#endif\n\tif (*plength > (omax - (p - *pp)))\n\t\t{\n\t\tASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);\n\t\t/* Set this so that even if things are not long enough\n\t\t * the values are set correctly */\n\t\tret|=0x80;\n\t\t}\n\t*pp=p;\n\treturn(ret|inf);\nerr:\n\tASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG);\n\treturn(0x80);\n\t}\n\nstatic int asn1_get_length(const unsigned char **pp, int *inf, long *rl, int max)\n```\n\n#### asn1_get_length() [lines 154-196]\n```c\n\treturn(0x80);\n\t}\n\nstatic int asn1_get_length(const unsigned char **pp, int *inf, long *rl, int max)\n\t{\n\tconst unsigned char *p= *pp;\n\tunsigned long ret=0;\n\tunsigned int i;\n\n\tif (max-- < 1) return(0);\n\tif (*p == 0x80)\n\t\t{\n\t\t*inf=1;\n\t\tret=0;\n\t\tp++;\n\t\t}\n\telse\n\t\t{\n\t\t*inf=0;\n\t\ti= *p&0x7f;\n\t\tif (*(p++) & 0x80)\n\t\t\t{\n\t\t\tif (i > sizeof(long))\n\t\t\t\treturn 0;\n\t\t\tif (max-- == 0) return(0);\n\t\t\twhile (i-- > 0)\n\t\t\t\t{\n\t\t\t\tret<<=8L;\n\t\t\t\tret|= *(p++);\n\t\t\t\tif (max-- == 0) return(0);\n\t\t\t\t}\n\t\t\t}\n\t\telse\n\t\t\tret=i;\n\t\t}\n\tif (ret > LONG_MAX)\n\t\treturn 0;\n\t*pp=p;\n\t*rl=(long)ret;\n\treturn(1);\n\t}\n\n/* class 0 is constructed\n```\n\n### crypto/asn1/asn1_par.c\n\n#### asn1_parse2() [lines 64-102]\n```c\n\nstatic int asn1_print_info(BIO *bp, int tag, int xclass,int constructed,\n\tint indent);\nstatic int asn1_parse2(BIO *bp, const unsigned char **pp, long length,\n\tint offset, int depth, int indent, int dump);\nstatic int asn1_print_info(BIO *bp, int tag, int xclass, int constructed,\n\t int indent)\n\t{\n\tstatic const char fmt[]=\"%-18s\";\n\tchar str[128];\n\tconst char *p;\n\n\tif (constructed & V_ASN1_CONSTRUCTED)\n\t\tp=\"cons: \";\n\telse\n\t\tp=\"prim: \";\n\tif (BIO_write(bp,p,6) < 6) goto err;\n\tBIO_indent(bp,indent,128);\n\n\tp=str;\n\tif ((xclass & V_ASN1_PRIVATE) == V_ASN1_PRIVATE)\n\t\tBIO_snprintf(str,sizeof str,\"priv [ %d ] \",tag);\n\telse if ((xclass & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC)\n\t\tBIO_snprintf(str,sizeof str,\"cont [ %d ]\",tag);\n\telse if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION)\n\t\tBIO_snprintf(str,sizeof str,\"appl [ %d ]\",tag);\n\telse if (tag > 30)\n\t\tBIO_snprintf(str,sizeof str,\"<ASN1 %d>\",tag);\n\telse\n\t\tp = ASN1_tag2str(tag);\n\n\tif (BIO_printf(bp,fmt,p) <= 0)\n\t\tgoto err;\n\treturn(1);\nerr:\n\treturn(0);\n\t}\n\nint ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent)\n```\n\n\n## Upstream Fix\n```diff\nFrom 697283ba418b21c4c0682d7050264b492e2ea4e2 Mon Sep 17 00:00:00 2001\nFrom: Viktor Dukhovni <openssl-users@dukhovni.org>\nDate: Tue, 19 Apr 2016 22:23:24 -0400\nSubject: [PATCH] Fix buffer overrun in ASN1_parse().\n\nBackport of commits:\n\n 79c7f74d6cefd5d32fa20e69195ad3de834ce065\n\tbdcd660e33710079b495cf5cc6a1aaa5d2dcd317\n\nfrom master.\n\nReviewed-by: Matt Caswell <matt@openssl.org>\n---\n crypto/asn1/asn1_lib.c | 18 +++++++-----------\n crypto/asn1/asn1_par.c | 17 +++++++++++++----\n 2 files changed, 20 insertions(+), 15 deletions(-)\n\ndiff --git a/crypto/asn1/asn1_lib.c b/crypto/asn1/asn1_lib.c\nindex 0b61fc930967c..54b683c15152d 100644\n--- a/crypto/asn1/asn1_lib.c\n+++ b/crypto/asn1/asn1_lib.c\n@@ -63,7 +63,7 @@\n #include <openssl/asn1_mac.h>\n \n static int asn1_get_length(const unsigned char **pp, int *inf, long *rl,\n- int max);\n+ long max);\n static void asn1_put_length(unsigned char **pp, int length);\n const char ASN1_version[] = \"ASN.1\" OPENSSL_VERSION_PTEXT;\n \n@@ -131,7 +131,7 @@ int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,\n }\n *ptag = tag;\n *pclass = xclass;\n- if (!asn1_get_length(&p, &inf, plength, (int)max))\n+ if (!asn1_get_length(&p, &inf, plength, max))\n goto err;\n \n if (inf && !(ret & V_ASN1_CONSTRUCTED))\n@@ -159,14 +159,14 @@ int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,\n }\n \n static int asn1_get_length(const unsigned char **pp, int *inf, long *rl,\n- int max)\n+ long max)\n {\n const unsigned char *p = *pp;\n unsigned long ret = 0;\n- unsigned int i;\n+ unsigned long i;\n \n if (max-- < 1)\n- return (0);\n+ return 0;\n if (*p == 0x80) {\n *inf = 1;\n ret = 0;\n@@ -175,15 +175,11 @@ static int asn1_get_length(const unsigned char **pp, int *inf, long *rl,\n *inf = 0;\n i = *p & 0x7f;\n if (*(p++) & 0x80) {\n- if (i > sizeof(long))\n+ if (i > sizeof(ret) || max < i)\n return 0;\n- if (max-- == 0)\n- return (0);\n while (i-- > 0) {\n ret <<= 8L;\n ret |= *(p++);\n- if (max-- == 0)\n- return (0);\n }\n } else\n ret = i;\n@@ -192,7 +188,7 @@ static int asn1_get_length(const unsigned char **pp, int *inf, long *rl,\n return 0;\n *pp = p;\n *rl = (long)ret;\n- return (1);\n+ return 1;\n }\n \n /*\ndiff --git a/crypto/asn1/asn1_par.c b/crypto/asn1/asn1_par.c\nindex 0ca985a2be1e7..e85e3398b6bb8 100644\n--- a/crypto/asn1/asn1_par.c\n+++ b/crypto/asn1/asn1_par.c\n@@ -173,6 +173,8 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,\n if (!asn1_print_info(bp, tag, xclass, j, (indent) ? depth : 0))\n goto end;\n if (j & V_ASN1_CONSTRUCTED) {\n+ const unsigned char *sp;\n+\n ep = p + len;\n if (BIO_write(bp, \"\\n\", 1) <= 0)\n goto end;\n@@ -182,6 +184,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,\n goto end;\n }\n if ((j == 0x21) && (len == 0)) {\n+ sp = p;\n for (;;) {\n r = asn1_parse2(bp, &p, (long)(tot - p),\n offset + (p - *pp), depth + 1,\n@@ -190,19 +193,25 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,\n ret = 0;\n goto end;\n }\n- if ((r == 2) || (p >= tot))\n+ if ((r == 2) || (p >= tot)) {\n+ len = p - sp;\n break;\n+ }\n }\n- } else\n+ } else {\n+ long tmp = len;\n+\n while (p < ep) {\n- r = asn1_parse2(bp, &p, (long)len,\n- offset + (p - *pp), depth + 1,\n+ sp = p;\n+ r = asn1_parse2(bp, &p, tmp, offset + (p - *pp), depth + 1,\n indent, dump);\n if (r == 0) {\n ret = 0;\n goto end;\n }\n+ tmp -= p - sp;\n }\n+ }\n } else if (xclass != 0) {\n p += len;\n if (BIO_write(bp, \"\\n\", 1) <= 0)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 697283ba418b21c4c0682d7050264b492e2ea4e2 Mon Sep 17 00:00:00 2001\nFrom: Viktor Dukhovni <openssl-users@dukhovni.org>\nDate: Tue, 19 Apr 2016 22:23:24 -0400\nSubject: [PATCH] Fix buffer overrun in ASN1_parse().\n\nBackport of commits:\n\n 79c7f74d6cefd5d32fa20e69195ad3de834ce065\n\tbdcd660e33710079b495cf5cc6a1aaa5d2dcd317\n\nfrom master.\n\nReviewed-by: Matt Caswell <matt@openssl.org>\n---\n crypto/asn1/asn1_lib.c | 18 +++++++-----------\n crypto/asn1/asn1_par.c | 17 +++++++++++++----\n 2 files changed, 20 insertions(+), 15 deletions(-)\n\nIndex: openssl-1.0.1i/crypto/asn1/asn1_lib.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/asn1/asn1_lib.c\t2016-04-28 17:19:12.524562985 +0200\n+++ openssl-1.0.1i/crypto/asn1/asn1_lib.c\t2016-04-28 17:22:25.536752503 +0200\n@@ -62,7 +62,7 @@\n #include <openssl/asn1.h>\n #include <openssl/asn1_mac.h>\n \n-static int asn1_get_length(const unsigned char **pp,int *inf,long *rl,int max);\n+static int asn1_get_length(const unsigned char **pp,int *inf,long *rl,long max);\n static void asn1_put_length(unsigned char **pp, int length);\n const char ASN1_version[]=\"ASN.1\" OPENSSL_VERSION_PTEXT;\n \n@@ -129,7 +129,7 @@ int ASN1_get_object(const unsigned char\n \t\t}\n \t*ptag=tag;\n \t*pclass=xclass;\n-\tif (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;\n+\tif (!asn1_get_length(&p,&inf,plength,max)) goto err;\n \n \tif (inf && !(ret & V_ASN1_CONSTRUCTED))\n \t\tgoto err;\n@@ -154,11 +154,11 @@ err:\n \treturn(0x80);\n \t}\n \n-static int asn1_get_length(const unsigned char **pp, int *inf, long *rl, int max)\n+static int asn1_get_length(const unsigned char **pp, int *inf, long *rl, long max)\n \t{\n \tconst unsigned char *p= *pp;\n \tunsigned long ret=0;\n-\tunsigned int i;\n+\tunsigned long i;\n \n \tif (max-- < 1) return(0);\n \tif (*p == 0x80)\n@@ -173,14 +173,12 @@ static int asn1_get_length(const unsigne\n \t\ti= *p&0x7f;\n \t\tif (*(p++) & 0x80)\n \t\t\t{\n-\t\t\tif (i > sizeof(long))\n+\t\t\tif (i > sizeof(ret) || max < i)\n \t\t\t\treturn 0;\n-\t\t\tif (max-- == 0) return(0);\n \t\t\twhile (i-- > 0)\n \t\t\t\t{\n \t\t\t\tret<<=8L;\n \t\t\t\tret|= *(p++);\n-\t\t\t\tif (max-- == 0) return(0);\n \t\t\t\t}\n \t\t\t}\n \t\telse\nIndex: openssl-1.0.1i/crypto/asn1/asn1_par.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/asn1/asn1_par.c\t2016-04-28 17:19:12.524562985 +0200\n+++ openssl-1.0.1i/crypto/asn1/asn1_par.c\t2016-04-28 17:27:44.140999764 +0200\n@@ -165,6 +165,7 @@ static int asn1_parse2(BIO *bp, const un\n \t\t\tgoto end;\n \t\tif (j & V_ASN1_CONSTRUCTED)\n \t\t\t{\n+\t\t\tconst unsigned char *sp;\n \t\t\tep=p+len;\n \t\t\tif (BIO_write(bp,\"\\n\",1) <= 0) goto end;\n \t\t\tif (len > length)\n@@ -176,23 +177,33 @@ static int asn1_parse2(BIO *bp, const un\n \t\t\t\t}\n \t\t\tif ((j == 0x21) && (len == 0))\n \t\t\t\t{\n+\t\t\t\tsp = p;\n \t\t\t\tfor (;;)\n \t\t\t\t\t{\n \t\t\t\t\tr=asn1_parse2(bp,&p,(long)(tot-p),\n \t\t\t\t\t\toffset+(p - *pp),depth+1,\n \t\t\t\t\t\tindent,dump);\n \t\t\t\t\tif (r == 0) { ret=0; goto end; }\n-\t\t\t\t\tif ((r == 2) || (p >= tot)) break;\n+\t\t\t\t\tif ((r == 2) || (p >= tot))\n+\t\t\t\t\t\t{\n+\t\t\t\t\t\tlen = p - sp;\n+\t\t\t\t\t\tbreak;\n+\t\t\t\t\t\t}\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\telse\n+\t\t\t\t{\n+\t\t\t\tlong tmp = len;\n \t\t\t\twhile (p < ep)\n \t\t\t\t\t{\n-\t\t\t\t\tr=asn1_parse2(bp,&p,(long)len,\n+\t\t\t\t\tsp = p;\n+\t\t\t\t\tr=asn1_parse2(bp,&p,tmp,\n \t\t\t\t\t\toffset+(p - *pp),depth+1,\n \t\t\t\t\t\tindent,dump);\n \t\t\t\t\tif (r == 0) { ret=0; goto end; }\n+\t\t\t\t\ttmp -= p - sp;\n \t\t\t\t\t}\n+\t\t\t\t}\n \t\t\t}\n \t\telse if (xclass != 0)\n \t\t\t{" } ]
{ "id": "openssl-5042-0001-Fix-buffer-overrun-in-ASN", "cve_id": "CVE-2016-2105", "package": "openssl", "upstream_enriched": true, "upstream_commit": "697283ba418b21c4c0682d7050264b492e2ea4e2", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "license": "OpenSSL", "context_tokens_est": 1661, "context_files": 2 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-3706\n\nStack-based buffer overflow in the getaddrinfo function in sysdeps/posix/getaddrinfo.c in the GNU C Library (aka glibc or libc6) allows remote attackers to cause a denial of service (crash) via vectors involving hostent conversion. NOTE: this vulnerability exists because of an incomplete fix for CVE-2013-4458.\n\n## Package\nglibc-testsuite\n\n## Files to modify\n- glibc-2.19.orig/malloc/arena.c\n- glibc-2.19.orig/malloc/malloc.c\n- malloc/arena.c\n- malloc/tst-malloc-backtrace.c\n- malloc/hooks.c\n\n## Target Source Code\n\n### malloc/Makefile\n\n#### region() [lines 1-75]\n```c\n# Copyright (C) 1991-2014 Free Software Foundation, Inc.\n# This file is part of the GNU C Library.\n\n# The GNU C Library is free software; you can redistribute it and/or\n# modify it under the terms of the GNU Lesser General Public\n# License as published by the Free Software Foundation; either\n# version 2.1 of the License, or (at your option) any later version.\n\n# The GNU C Library is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n# Lesser General Public License for more details.\n\n# You should have received a copy of the GNU Lesser General Public\n# License along with the GNU C Library; if not, see\n# <http://www.gnu.org/licenses/>.\n\n#\n#\tMakefile for malloc routines\n#\nsubdir\t:= malloc\n\nall:\n\ndist-headers := malloc.h\nheaders := $(dist-headers) obstack.h mcheck.h\ntests := mallocbug tst-malloc tst-valloc tst-calloc tst-obstack \\\n\t tst-mallocstate tst-mcheck tst-mallocfork tst-trim1 \\\n\t tst-malloc-usable tst-realloc tst-posix_memalign \\\n\t tst-pvalloc tst-memalign\ntest-srcs = tst-mtrace\n\nroutines = malloc morecore mcheck mtrace obstack\n\ninstall-lib := libmcheck.a\nnon-lib.a := libmcheck.a\n\n# Additional library.\nextra-libs = libmemusage\nextra-libs-others = $(extra-libs)\n\nlibmemusage-routines = memusage\nlibmemusage-inhibit-o = $(filter-out .os,$(object-suffixes))\n\n# These should be removed by `make clean'.\nextra-objs = mcheck-init.o libmcheck.a\n\n# Include the cleanup handler.\naux := set-freeres thread-freeres\n\ninclude ../Makeconfig\n\nCPPFLAGS-memusagestat = -DNOT_IN_libc\n\n# The Perl script to analyze the output of the mtrace functions.\nifneq ($(PERL),no)\ninstall-bin-script = mtrace\ngenerated = mtrace\n\n# The Perl script will print addresses and to do this nicely we must know\n# whether we are on a 32 or 64 bit machine.\nifneq ($(findstring wordsize-32,$(config-sysdirs)),)\naddress-width=10\nelse\naddress-width=18\nendif\nendif\n\n# Unless we get a test for the availability of libgd which also works\n# for cross-compiling we disable the memusagestat generation in this\n# situation.\nifneq ($(cross-compiling),yes)\n# If the gd library is available we build the `memusagestat' program.\nifneq ($(LIBGD),no)\nothers: $(objpfx)memusage\n```\n\n#### region() [lines 3-89]\n```c\n\n# The GNU C Library is free software; you can redistribute it and/or\n# modify it under the terms of the GNU Lesser General Public\n# License as published by the Free Software Foundation; either\n# version 2.\n/* ... truncated ... */\n```\n\n### malloc/arena.c\n\n#### region() [lines 75-162]\n```c\n/* Thread specific data */\n\nstatic tsd_key_t arena_key;\nstatic mutex_t list_lock = MUTEX_INITIALIZER;\nstatic size_t narenas = 1;\nstatic mstate free_list;\n\n#if THREAD_STATS\nstatic int stat_n_heaps;\n# define THREAD_STAT(x) x\n#else\n# define THREAD_STAT(x) do ; while (0)\n#endif\n\n/* Mapped memory in non-main arenas (reliable only for NO_THREADS). */\nstatic unsigned long arena_mem;\n\n/* Already initialized? */\nint __malloc_initialized = -1;\n\n/**************************************************************************/\n\n\n/* arena_get() acquires an arena and locks the corresponding mutex.\n First, try the one last locked successfully by this thread. (This\n is the common case and handled with a macro for speed.) Then, loop\n once over the circularly linked list of arenas. If no arena is\n readily available, create a new one. In this latter case, `size'\n is just a hint as to how much memory will be required immediately\n in the new arena. */\n\n#define arena_get(ptr, size) do { \\\n arena_lookup (ptr);\t\t\t\t\t\t \\\n arena_lock (ptr, size);\t\t\t\t\t\t \\\n } while (0)\n\n#define arena_lookup(ptr) do { \\\n void *vptr = NULL;\t\t\t\t\t\t \\\n ptr = (mstate) tsd_getspecific (arena_key, vptr);\t\t\t \\\n } while (0)\n\n#define arena_lock(ptr, size) do {\t\t\t\t\t \\\n if (ptr)\t\t\t\t\t\t\t\t \\\n (void) mutex_lock (&ptr->mutex);\t\t\t\t \\\n else\t\t\t\t\t\t\t\t \\\n ptr = arena_get2 (ptr, (size), NULL);\t\t\t\t \\\n } while (0)\n\n/* find the heap and corresponding arena for a given ptr */\n\n#define heap_for_ptr(ptr) \\\n ((heap_info *) ((unsigned long) (ptr) & ~(HEAP_MAX_SIZE - 1)))\n#define arena_for_chunk(ptr) \\\n (chunk_non_main_arena (ptr) ? heap_for_ptr (ptr)->ar_ptr : &main_arena)\n\n\n/**************************************************************************/\n\n#ifndef NO_THREADS\n\n/* atfork support. */\n\nstatic void *(*save_malloc_hook)(size_t __size, const void *);\nstatic void (*save_free_hook) (void *__ptr, const void *);\nstatic void *save_arena;\n\n# ifdef ATFORK_MEM\nATFORK_MEM;\n# endif\n\n/* Magic value for the thread-specific arena pointer when\n malloc_atfork() is in use. */\n\n# define ATFORK_ARENA_PTR ((void *) -1)\n\n/* The following hooks are used while the `atfork' handling mechanism\n is active. */\n\nstatic void *\nmalloc_atfork (size_t sz, const void *caller)\n{\n void *vptr = NULL;\n void *victim;\n\n tsd_getspecific (arena_key, vptr);\n if (vptr == ATFORK_ARENA_PTR)\n {\n /* We are the only thread that may allocate at all. */\n```\n\n### malloc/hooks.c\n\n#### malloc_check_get_size() [lines 97-124]\n```c\n must reach it with this iteration, otherwise we have witnessed a memory\n corruption. */\nstatic size_t\nmalloc_check_get_size (mchunkptr p)\n{\n size_t size;\n unsigned char c;\n unsigned char magic = MAGICBYTE (p);\n\n assert (using_malloc_checking == 1);\n\n for (size = chunksize (p) - 1 + (chunk_is_mmapped (p) ? 0 : SIZE_SZ);\n (c = ((unsigned char *) p)[size]) != magic;\n size -= c)\n {\n if (c <= 0 || size < (c + 2 * SIZE_SZ))\n {\n malloc_printerr (check_action, \"malloc_check_get_size: memory corruption\",\n chunk2mem (p));\n return 0;\n }\n }\n\n /* chunk2mem size. */\n return size - 2 * SIZE_SZ;\n}\n\n/* Instrument a chunk with overrun detector byte(s) and convert it\n```\n\n#### top_check() [lines 222-267]\n```c\n\nstatic int\ninternal_function\ntop_check (void)\n{\n mchunkptr t = top (&main_arena);\n char *brk, *new_brk;\n INTERNAL_SIZE_T front_misalign, sbrk_size;\n unsigned long pagesz = GLRO (dl_pagesize);\n\n if (t == initial_top (&main_arena) ||\n (!chunk_is_mmapped (t) &&\n chunksize (t) >= MINSIZE &&\n prev_inuse (t) &&\n (!contiguous (&main_arena) ||\n (char *) t + chunksize (t) == mp_.sbrk_base + main_arena.system_mem)))\n return 0;\n\n malloc_printerr (check_action, \"malloc: top chunk is corrupt\", t);\n\n /* Try to set up a new top chunk. */\n brk = MORECORE (0);\n front_misalign = (unsigned long) chunk2mem (brk) & MALLOC_ALIGN_MASK;\n if (front_misalign > 0)\n front_misalign = MALLOC_ALIGNMENT - front_misalign;\n sbrk_size = front_misalign + mp_.top_pad + MINSIZE;\n sbrk_size += pagesz - ((unsigned long) (brk + sbrk_size) & (pagesz - 1));\n new_brk = (char *) (MORECORE (sbrk_size));\n if (new_brk == (char *) (MORECORE_FAILURE))\n {\n __set_errno (ENOMEM);\n return -1;\n }\n /* Call the `morecore' hook if necessary. */\n void (*hook) (void) = atomic_forced_read (__after_morecore_hook);\n if (hook)\n (*hook)();\n main_arena.system_mem = (new_brk - mp_.sbrk_base) + sbrk_size;\n\n top (&main_arena) = (mchunkptr) (brk + front_misalign);\n set_head (top (&main_arena), (sbrk_size - front_misalign) | PREV_INUSE);\n\n return 0;\n}\n\nstatic void *\n```\n\n#### free_check() [lines 282-311]\n```c\n}\n\nstatic void\nfree_check (void *mem, const void *caller)\n{\n mchunkptr p;\n\n if (!mem)\n return;\n\n (void) mutex_lock (&main_arena.mutex);\n p = mem2chunk_check (mem, NULL);\n if (!p)\n {\n (void) mutex_unlock (&main_arena.mutex);\n\n malloc_printerr (\n/* ... truncated ... */\n```\n\n### malloc/malloc.c\n\n#### _int_realloc() [lines 4200-4370]\n```c\n*/\n\nvoid*\n_int_realloc(mstate av, mchunkptr oldp, INTERNAL_SIZE_T oldsize,\n\t INTERNAL_SIZE_T nb)\n{\n mchunkptr newp; /* chunk to return */\n INTERNAL_SIZE_T newsize; /* its size */\n void* newmem; /* corresponding user mem */\n\n mchunkptr next; /* next contiguous chunk after oldp */\n\n mchunkptr remainder; /* extra space at end of newp */\n unsigned long remainder_size; /* its size */\n\n mchunkptr bck; /* misc temp for linking */\n mchunkptr fwd; /* misc temp for linking */\n\n unsigned long copysize; /* bytes to copy */\n unsigned int ncopies; /* INTERNAL_SIZE_T words to copy */\n INTERNAL_SIZE_T* s; /* copy source */\n INTERNAL_SIZE_T* d; /* copy destination */\n\n const char *errstr = NULL;\n\n /* oldmem size */\n if (__builtin_expect (oldp->size <= 2 * SIZE_SZ, 0)\n || __builtin_expect (oldsize >= av->system_mem, 0))\n {\n errstr = \"realloc(): invalid old size\";\n errout:\n malloc_printerr (check_action, errstr, chunk2mem (oldp));\n return NULL;\n }\n\n check_inuse_chunk (av, oldp);\n\n /* All callers already filter out mmap'ed chunks. */\n assert (!chunk_is_mmapped (oldp));\n\n/* ... 124 lines omitted ... */\n {\n set_head_size (newp, newsize | (av != &main_arena ? NON_MAIN_ARENA : 0));\n set_inuse_bit_at_offset (newp, newsize);\n }\n else /* split remainder */\n {\n remainder = chunk_at_offset (newp, nb);\n set_head_size (newp, nb | (av != &main_arena ? NON_MAIN_ARENA : 0));\n set_head (remainder, remainder_size | PREV_INUSE |\n (av != &main_arena ? NON_MAIN_ARENA : 0));\n /* Mark remainder as inuse so free() won't complain */\n set_inuse_bit_at_offset (remainder, remainder_size);\n _int_free (av, remainder, 1);\n }\n\n check_inuse_chunk (av, newp);\n return chunk2mem (newp);\n}\n\n/*\n```\n\n#### region() [lines 1367-1458]\n```c\n chunk in a list is known to be preceeded and followed by either\n inuse chunks or the ends of memory.\n\n Chunks in bins are kept in size order, with ties going to the\n approximately least recently used chunk. Ordering isn't needed\n for the small bins, which all contain the same-sized chunks, but\n facilitates best-fit allocation for larger chunks. These lists\n are just sequential. Keeping them in order almost never requires\n enough traversal to warrant using fancier ordered d\n/* ... truncated ... */\n```\n\n\n## Upstream Fix\n```diff\n2015-05-19 Siddhesh Poyarekar <siddhesh@redhat.com>\n\n\t[BZ #16159]\n\t* malloc/Makefile (tests): New test case tst-malloc-backtrace.\n\t* malloc/arena.c (arena_lock): Check if arena is corrupt.\n\t(reused_arena): Find a non-corrupt arena.\n\t(heap_trim): Pass arena to unlink.\n\t* malloc/hooks.c (malloc_check_get_size): Pass arena to\n\tmalloc_printerr.\n\t(top_check): Likewise.\n\t(free_check): Likewise.\n\t(realloc_check): Likewise.\n\t* malloc/malloc.c (malloc_printerr): Add arena argument.\n\t(unlink): Likewise.\n\t(munmap_chunk): Adjust.\n\t(ARENA_CORRUPTION_BIT): New macro.\n\t(arena_is_corrupt): Likewise.\n\t(set_arena_corrupt): Likewise.\n\t(sysmalloc): Use mmap if there are no usable arenas.\n\t(_int_malloc): Likewise.\n\t(__libc_malloc): Don't fail if arena_get returns NULL.\n\t(_mid_memalign): Likewise.\n\t(__libc_calloc): Likewise.\n\t(__libc_realloc): Adjust for additional argument to\n\tmalloc_printerr.\n\t(_int_free): Likewise.\n\t(malloc_consolidate): Likewise.\n\t(_int_realloc): Likewise.\n\t(_int_memalign): Don't touch corrupt arenas.\n\t* malloc/tst-malloc-backtrace.c: New test case.\n\nIndex: glibc-2.19/malloc/Makefile\n===================================================================\n--- glibc-2.19.orig/malloc/Makefile\n+++ glibc-2.19/malloc/Makefile\n@@ -27,7 +27,8 @@ headers := $(dist-headers) obstack.h mch\n tests := mallocbug tst-malloc tst-valloc tst-calloc tst-obstack \\\n \t tst-mallocstate tst-mcheck tst-mallocfork tst-trim1 \\\n \t tst-malloc-usable tst-realloc tst-posix_memalign \\\n-\t tst-pvalloc tst-memalign\n+\t tst-pvalloc tst-memalign \\\n+\t tst-malloc-backtrace\n test-srcs = tst-mtrace\n \n routines = malloc morecore mcheck mtrace obstack\n@@ -42,6 +43,9 @@ extra-libs-others = $(extra-libs)\n libmemusage-routines = memusage\n libmemusage-inhibit-o = $(filter-out .os,$(object-suffixes))\n \n+$(objpfx)tst-malloc-backtrace: $(common-objpfx)nptl/libpthread.so \\\n+\t\t\t $(common-objpfx)nptl/libpthread_nonshared.a\n+\n # These should be removed by `make clean'.\n extra-objs = mcheck-init.o libmcheck.a\n \nIndex: glibc-2.19/malloc/arena.c\n===================================================================\n--- glibc-2.19.orig/malloc/arena.c\n+++ glibc-2.19/malloc/arena.c\n@@ -114,7 +114,7 @@ int __malloc_initialized = -1;\n } while (0)\n \n #define arena_lock(ptr, size) do {\t\t\t\t\t \\\n- if (ptr)\t\t\t\t\t\t\t\t \\\n+ if (ptr && !arena_is_corrupt (ptr))\t\t\t\t \\\n (void) mutex_lock (&ptr->mutex);\t\t\t\t \\\n else\t\t\t\t\t\t\t\t \\\n ptr = arena_get2 (ptr, (size), NULL);\t\t\t\t \\\n@@ -702,7 +702,7 @@ heap_trim (heap_info *heap, size_t pad)\n if (!prev_inuse (p)) /* consolidate backward */\n {\n p = prev_chunk (p);\n- unlink (p, bck, fwd);\n+ unlink (ar_ptr, p, bck, fwd);\n }\n assert (((unsigned long) ((char *) p + new_size) & (pagesz - 1)) == 0);\n assert (((char *) p + new_size) == ((char *) heap + heap->size));\n@@ -828,7 +828,7 @@ reused_arena (mstate avoid_arena)\n result = next_to_use;\n do\n {\n- if (!mutex_trylock (&result->mutex))\n+ if (!arena_is_corrupt (result) && !mutex_trylock (&result->mutex))\n goto out;\n \n result = result->next;\n@@ -840,7 +840,21 @@ reused_arena (mstate avoid_arena)\n if (result == avoid_arena)\n result = result->next;\n \n- /* No arena available. Wait for the next in line. */\n+ /* Make sure that the arena we get is not corrupted. */\n+ mstate begin = result;\n+ while (arena_is_corrupt (result) || result == avoid_arena)\n+ {\n+ result = result->next;\n+ if (result == begin)\n+\tbreak;\n+ }\n+\n+ /* We could not find any arena that was either not corrupted or not the one\n+ we wanted to avoid. */\n+ if (result == begin || result == avoid_arena)\n+ return NULL;\n+\n+ /* No arena available without contention. Wait for the next in line. */\n LIBC_PROBE (memory_arena_reuse_wait, 3, &result->mutex, result, avoid_arena);\n (void) mutex_lock (&result->mutex);\n \nIndex: glibc-2.19/malloc/hooks.c\n===================================================================\n--- glibc-2.19.orig/malloc/hooks.c\n+++ glibc-2.19/malloc/hooks.c\n@@ -112,7 +112,8 @@ malloc_check_get_size (mchunkptr p)\n if (c <= 0 || size < (c + 2 * SIZE_SZ))\n {\n malloc_printerr (check_action, \"malloc_check_get_size: memory corruption\",\n- chunk2mem (p));\n+ chunk2mem (p),\n+\t\t\t chunk_is_mmapped (p) ? NULL : arena_for_chunk (p));\n return 0;\n }\n }\n@@ -237,7 +238,8 @@ top_check (void)\n (char *) t + chunksize (t) == mp_.sbrk_base + main_arena.system_mem)))\n return 0;\n \n- malloc_printerr (check_action, \"malloc: top chunk is corrupt\", t);\n+ malloc_printerr (check_action, \"malloc: top chunk is corrupt\", t,\n+\t\t &main_arena);\n \n /* Try to set up a new top chunk. */\n brk = MORECORE (0);\n@@ -295,7 +297,8 @@ free_check (void *mem, const void *calle\n {\n (void) mutex_unlock (&main_arena.mutex);\n \n- malloc_printerr (check_action, \"free(): invalid pointer\", mem);\n+ malloc_printerr (check_action, \"free(): invalid pointer\", mem,\n+\t\t &main_arena);\n return;\n }\n if (chunk_is_mmapped (p))\n@@ -333,7 +336,8 @@ realloc_check (void *oldmem, size_t byte\n (void) mutex_unlock (&main_arena.mutex);\n if (!oldp)\n {\n- malloc_printerr (check_action, \"realloc(): invalid pointer\", oldmem);\n+ malloc_printerr (check_action, \"realloc(): invalid pointer\", oldmem,\n+\t\t &main_arena);\n return malloc_check (bytes, NULL);\n }\n const INTERNAL_SIZE_T oldsize = chunksize (oldp);\nIndex: glibc-2.19/malloc/malloc.c\n===================================================================\n--- glibc-2.19.orig/malloc/malloc.c\n+++ glibc-2.19/malloc/malloc.c\n@@ -1054,7 +1054,7 @@ static void* _int_realloc(mstate, mchun\n static void* _int_memalign(mstate, size_t, size_t);\n static void* _mid_memalign(size_t, size_t, void *);\n \n-static void malloc_printerr(int action, const char *str, void *ptr);\n+static void malloc_printerr(int action, const char *str, void *ptr, mstate av);\n \n static void* internal_function mem2mem_check(void *p, size_t sz);\n static int internal_function top_check(void);\n@@ -1406,11 +1406,11 @@ typedef struct malloc_chunk *mbinptr;\n #define last(b) ((b)->bk)\n \n /* Take a chunk off a bin list */\n-#define unlink(P, BK, FD) { \\\n+#define unlink(AV, P, BK, FD) { \\\n FD = P->fd;\t\t\t\t\t\t\t\t \\\n BK = P->bk;\t\t\t\t\t\t\t\t \\\n if (__builtin_expect (FD->bk != P || BK->fd != P, 0))\t\t \\\n- malloc_printerr (check_action, \"corrupted double-linked list\", P); \\\n+ malloc_printerr (check_action, \"corrupted double-linked list\", P, AV); \\\n else {\t\t\t\t\t\t\t\t \\\n FD->bk = BK;\t\t\t\t\t\t\t \\\n BK->fd = FD;\t\t\t\t\t\t\t \\\n@@ -1649,6 +1649,15 @@ typedef struct malloc_chunk *mfastbinptr\n #define set_noncontiguous(M) ((M)->flags |= NONCONTIGUOUS_BIT)\n #define set_contiguous(M) ((M)->flags &= ~NONCONTIGUOUS_BIT)\n \n+/* ARENA_CORRUPTION_BIT is set if a memory corruption was detected on the\n+ arena. Such an arena is no longer used to allocate chunks. Chunks\n+ allocated in that arena before detecting corruption are not freed. */\n+\n+#define ARENA_CORRUPTION_BIT (4U)\n+\n+#define arena_is_corrupt(A)\t(((A)->flags & ARENA_CORRUPTION_BIT))\n+#define set_arena_corrupt(A)\t((A)->flags |= ARENA_CORRUPTION_BIT)\n+\n /*\n Set value of max_fast.\n Use impossibly small value if 0.\n@@ -2278,8 +2287,9 @@ sysmalloc (INTERNAL_SIZE_T nb, mstate av\n rather than expanding top.\n */\n \n- if ((unsigned long) (nb) >= (unsigned long) (mp_.mmap_threshold) &&\n- (mp_.n_mmaps < mp_.n_mmaps_max))\n+ if (av == NULL\n+ || ((unsigned long) (nb) >= (unsigned long) (mp_.mmap_threshold)\n+\t && (mp_.n_mmaps < mp_.n_mmaps_max)))\n {\n char *mm; /* return value from mmap call*/\n \n@@ -2352,6 +2362,10 @@ sysmalloc (INTERNAL_SIZE_T nb,\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "2015-05-19 Siddhesh Poyarekar <siddhesh@redhat.com>\n\n\t[BZ #16159]\n\t* malloc/Makefile (tests): New test case tst-malloc-backtrace.\n\t* malloc/arena.c (arena_lock): Check if arena is corrupt.\n\t(reused_arena): Find a non-corrupt arena.\n\t(heap_trim): Pass arena to unlink.\n\t* malloc/hooks.c (malloc_check_get_size): Pass arena to\n\tmalloc_printerr.\n\t(top_check): Likewise.\n\t(free_check): Likewise.\n\t(realloc_check): Likewise.\n\t* malloc/malloc.c (malloc_printerr): Add arena argument.\n\t(unlink): Likewise.\n\t(munmap_chunk): Adjust.\n\t(ARENA_CORRUPTION_BIT): New macro.\n\t(arena_is_corrupt): Likewise.\n\t(set_arena_corrupt): Likewise.\n\t(sysmalloc): Use mmap if there are no usable arenas.\n\t(_int_malloc): Likewise.\n\t(__libc_malloc): Don't fail if arena_get returns NULL.\n\t(_mid_memalign): Likewise.\n\t(__libc_calloc): Likewise.\n\t(__libc_realloc): Adjust for additional argument to\n\tmalloc_printerr.\n\t(_int_free): Likewise.\n\t(malloc_consolidate): Likewise.\n\t(_int_realloc): Likewise.\n\t(_int_memalign): Don't touch corrupt arenas.\n\t* malloc/tst-malloc-backtrace.c: New test case.\n\nIndex: glibc-2.19/malloc/Makefile\n===================================================================\n--- glibc-2.19.orig/malloc/Makefile\n+++ glibc-2.19/malloc/Makefile\n@@ -27,7 +27,8 @@ headers := $(dist-headers) obstack.h mch\n tests := mallocbug tst-malloc tst-valloc tst-calloc tst-obstack \\\n \t tst-mallocstate tst-mcheck tst-mallocfork tst-trim1 \\\n \t tst-malloc-usable tst-realloc tst-posix_memalign \\\n-\t tst-pvalloc tst-memalign\n+\t tst-pvalloc tst-memalign \\\n+\t tst-malloc-backtrace\n test-srcs = tst-mtrace\n \n routines = malloc morecore mcheck mtrace obstack\n@@ -42,6 +43,9 @@ extra-libs-others = $(extra-libs)\n libmemusage-routines = memusage\n libmemusage-inhibit-o = $(filter-out .os,$(object-suffixes))\n \n+$(objpfx)tst-malloc-backtrace: $(common-objpfx)nptl/libpthread.so \\\n+\t\t\t $(common-objpfx)nptl/libpthread_nonshared.a\n+\n # These should be removed by `make clean'.\n extra-objs = mcheck-init.o libmcheck.a\n \nIndex: glibc-2.19/malloc/arena.c\n===================================================================\n--- glibc-2.19.orig/malloc/arena.c\n+++ glibc-2.19/malloc/arena.c\n@@ -114,7 +114,7 @@ int __malloc_initialized = -1;\n } while (0)\n \n #define arena_lock(ptr, size) do {\t\t\t\t\t \\\n- if (ptr)\t\t\t\t\t\t\t\t \\\n+ if (ptr && !arena_is_corrupt (ptr))\t\t\t\t \\\n (void) mutex_lock (&ptr->mutex);\t\t\t\t \\\n else\t\t\t\t\t\t\t\t \\\n ptr = arena_get2 (ptr, (size), NULL);\t\t\t\t \\\n@@ -702,7 +702,7 @@ heap_trim (heap_info *heap, size_t pad)\n if (!prev_inuse (p)) /* consolidate backward */\n {\n p = prev_chunk (p);\n- unlink (p, bck, fwd);\n+ unlink (ar_ptr, p, bck, fwd);\n }\n assert (((unsigned long) ((char *) p + new_size) & (pagesz - 1)) == 0);\n assert (((char *) p + new_size) == ((char *) heap + heap->size));\n@@ -828,7 +828,7 @@ reused_arena (mstate avoid_arena)\n result = next_to_use;\n do\n {\n- if (!mutex_trylock (&result->mutex))\n+ if (!arena_is_corrupt (result) && !mutex_trylock (&result->mutex))\n goto out;\n \n result = result->next;\n@@ -840,7 +840,21 @@ reused_arena (mstate avoid_arena)\n if (result == avoid_arena)\n result = result->next;\n \n- /* No arena available. Wait for the next in line. */\n+ /* Make sure that the arena we get is not corrupted. */\n+ mstate begin = result;\n+ while (arena_is_corrupt (result) || result == avoid_arena)\n+ {\n+ result = result->next;\n+ if (result == begin)\n+\tbreak;\n+ }\n+\n+ /* We could not find any arena that was either not corrupted or not the one\n+ we wanted to avoid. */\n+ if (result == begin || result == avoid_arena)\n+ return NULL;\n+\n+ /* No arena available without contention. Wait for the next in line. */\n LIBC_PROBE (memory_arena_reuse_wait, 3, &result->mutex, result, avoid_arena);\n (void) mutex_lock (&result->mutex);\n \nIndex: glibc-2.19/malloc/hooks.c\n===================================================================\n--- glibc-2.19.orig/malloc/hooks.c\n+++ glibc-2.19/malloc/hooks.c\n@@ -112,7 +112,8 @@ malloc_check_get_size (mchunkptr p)\n if (c <= 0 || size < (c + 2 * SIZE_SZ))\n {\n malloc_printerr (check_action, \"malloc_check_get_size: memory corruption\",\n- chunk2mem (p));\n+ chunk2mem (p),\n+\t\t\t chunk_is_mmapped (p) ? NULL : arena_for_chunk (p));\n return 0;\n }\n }\n@@ -237,7 +238,8 @@ top_check (void)\n (char *) t + chunksize (t) == mp_.sbrk_base + main_arena.system_mem)))\n return 0;\n \n- malloc_printerr (check_action, \"malloc: top chunk is corrupt\", t);\n+ malloc_printerr (check_action, \"malloc: top chunk is corrupt\", t,\n+\t\t &main_arena);\n \n /* Try to set up a new top chunk. */\n brk = MORECORE (0);\n@@ -295,7 +297,8 @@ free_check (void *mem, const void *calle\n {\n (void) mutex_unlock (&main_arena.mutex);\n \n- malloc_printerr (check_action, \"free(): invalid pointer\", mem);\n+ malloc_printerr (check_action, \"free(): invalid pointer\", mem,\n+\t\t &main_arena);\n return;\n }\n if (chunk_is_mmapped (p))\n@@ -333,7 +336,8 @@ realloc_check (void *oldmem, size_t byte\n (void) mutex_unlock (&main_arena.mutex);\n if (!oldp)\n {\n- malloc_printerr (check_action, \"realloc(): invalid pointer\", oldmem);\n+ malloc_printerr (check_action, \"realloc(): invalid pointer\", oldmem,\n+\t\t &main_arena);\n return malloc_check (bytes, NULL);\n }\n const INTERNAL_SIZE_T oldsize = chunksize (oldp);\nIndex: glibc-2.19/malloc/malloc.c\n===================================================================\n--- glibc-2.19.orig/malloc/malloc.c\n+++ glibc-2.19/malloc/malloc.c\n@@ -1054,7 +1054,7 @@ static void* _int_realloc(mstate, mchun\n static void* _int_memalign(mstate, size_t, size_t);\n static void* _mid_memalign(size_t, size_t, void *);\n \n-static void malloc_printerr(int action, const char *str, void *ptr);\n+static void malloc_printerr(int action, const char *str, void *ptr, mstate av);\n \n static void* internal_function mem2mem_check(void *p, size_t sz);\n static int internal_function top_check(void);\n@@ -1406,11 +1406,11 @@ typedef struct malloc_chunk *mbinptr;\n #define last(b) ((b)->bk)\n \n /* Take a chunk off a bin list */\n-#define unlink(P, BK, FD) { \\\n+#define unlink(AV, P, BK, FD) { \\\n FD = P->fd;\t\t\t\t\t\t\t\t \\\n BK = P->bk;\t\t\t\t\t\t\t\t \\\n if (__builtin_expect (FD->bk != P || BK->fd != P, 0))\t\t \\\n- malloc_printerr (check_action, \"corrupted double-linked list\", P); \\\n+ malloc_printerr (check_action, \"corrupted double-linked list\", P, AV); \\\n else {\t\t\t\t\t\t\t\t \\\n FD->bk = BK;\t\t\t\t\t\t\t \\\n BK->fd = FD;\t\t\t\t\t\t\t \\\n@@ -1649,6 +1649,15 @@ typedef struct malloc_chunk *mfastbinptr\n #define set_noncontiguous(M) ((M)->flags |= NONCONTIGUOUS_BIT)\n #define set_contiguous(M) ((M)->flags &= ~NONCONTIGUOUS_BIT)\n \n+/* ARENA_CORRUPTION_BIT is set if a memory corruption was detected on the\n+ arena. Such an arena is no longer used to allocate chunks. Chunks\n+ allocated in that arena before detecting corruption are not freed. */\n+\n+#define ARENA_CORRUPTION_BIT (4U)\n+\n+#define arena_is_corrupt(A)\t(((A)->flags & ARENA_CORRUPTION_BIT))\n+#define set_arena_corrupt(A)\t((A)->flags |= ARENA_CORRUPTION_BIT)\n+\n /*\n Set value of max_fast.\n Use impossibly small value if 0.\n@@ -2278,8 +2287,9 @@ sysmalloc (INTERNAL_SIZE_T nb, mstate av\n rather than expanding top.\n */\n \n- if ((unsigned long) (nb) >= (unsigned long) (mp_.mmap_threshold) &&\n- (mp_.n_mmaps < mp_.n_mmaps_max))\n+ if (av == NULL\n+ || ((unsigned long) (nb) >= (unsigned long) (mp_.mmap_threshold)\n+\t && (mp_.n_mmaps < mp_.n_mmaps_max)))\n {\n char *mm; /* return value from mmap call*/\n \n@@ -2352,6 +2362,10 @@ sysmalloc (INTERNAL_SIZE_T nb, mstate av\n }\n }\n \n+ /* There are no usable arenas and mmap also failed. */\n+ if (av == NULL)\n+ return 0;\n+\n /* Record incoming configuration of top */\n \n old_top = av->top;\n@@ -2526,7 +2540,8 @@ sysmalloc (INTERNAL_SIZE_T nb, mstate av\n else if (contiguous (av) && old_size && brk < old_end)\n {\n /* Oops! Someone else killed our space.. Can't touch anything. */\n- malloc_printerr (3, \"break adjusted to free malloc space\", brk);\n+ malloc_printerr (3, \"break adjusted to free malloc space\", brk,\n+\t\t\t av);\n }\n \n /*\n@@ -2813,7 +2828,7 @@ munmap_chunk (mchunkptr p)\n if (__builtin_expect (((block | total_size) & (GLRO (dl_pagesize) - 1)) != 0, 0))\n {\n malloc_printerr (check_action, \"munmap_chunk(): invalid pointer\",\n- chunk2mem (p));\n+ chunk2mem (p), NULL);\n return;\n }\n \n@@ -2883,22 +2898,19 @@ __libc_malloc (size_t bytes)\n \n arena_get (ar_ptr, bytes);\n \n- if (!ar_ptr)\n- return 0;\n-\n victim = _int_malloc (ar_ptr, bytes);\n- if (!victim)\n+ /* Retry with another arena only if we were able to find a usable arena\n+ before. */\n+ if (!victim && ar_ptr != NULL)\n {\n LIBC_PROBE (memory_malloc_retry, 1, bytes);\n ar_ptr = arena_get_retry (ar_ptr, bytes);\n- if (__builtin_expect (ar_ptr != NULL, 1))\n- {\n- victim = _int_malloc (ar_ptr, bytes);\n- (void) mutex_unlock (&ar_ptr->mutex);\n- }\n+ victim = _int_malloc (ar_ptr, bytes);\n }\n- else\n+\n+ if (ar_ptr != NULL)\n (void) mutex_unlock (&ar_ptr->mutex);\n+\n assert (!victim || chunk_is_mmapped (mem2chunk (victim)) ||\n ar_ptr == arena_for_chunk (mem2chunk (victim)));\n return victim;\n@@ -2974,6 +2986,11 @@ __libc_realloc (void *oldmem, size_t byt\n /* its size */\n const INTERNAL_SIZE_T oldsize = chunksize (oldp);\n \n+ if (chunk_is_mmapped (oldp))\n+ ar_ptr = NULL;\n+ else\n+ ar_ptr = arena_for_chunk (oldp);\n+\n /* Little security check which won't hurt performance: the\n allocator never wrapps around at the end of the address space.\n Therefore we can exclude some size values which might appear\n@@ -2981,7 +2998,8 @@ __libc_realloc (void *oldmem, size_t byt\n if (__builtin_expect ((uintptr_t) oldp > (uintptr_t) -oldsize, 0)\n || __builtin_expect (misaligned_chunk (oldp), 0))\n {\n- malloc_printerr (check_action, \"realloc(): invalid pointer\", oldmem);\n+ malloc_printerr (check_action, \"realloc(): invalid pointer\", oldmem,\n+\t\t ar_ptr);\n return NULL;\n }\n \n@@ -3010,7 +3028,6 @@ __libc_realloc (void *oldmem, size_t byt\n return newmem;\n }\n \n- ar_ptr = arena_for_chunk (oldp);\n #if THREAD_STATS\n if (!mutex_trylock (&ar_ptr->mutex))\n ++(ar_ptr->stat_lock_direct);\n@@ -3023,7 +3040,6 @@ __libc_realloc (void *oldmem, size_t byt\n (void) mutex_lock (&ar_ptr->mutex);\n #endif\n \n-\n newp = _int_realloc (ar_ptr, oldp, oldsize, nb);\n \n (void) mutex_unlock (&ar_ptr->mutex);\n@@ -3098,22 +3114,18 @@ _mid_memalign (size_t alignment, size_t\n }\n \n arena_get (ar_ptr, bytes + alignment + MINSIZE);\n- if (!ar_ptr)\n- return 0;\n \n p = _int_memalign (ar_ptr, alignment, bytes);\n- if (!p)\n+ if (!p && ar_ptr != NULL)\n {\n LIBC_PROBE (memory_memalign_retry, 2, bytes, alignment);\n ar_ptr = arena_get_retry (ar_ptr, bytes);\n- if (__builtin_expect (ar_ptr != NULL, 1))\n- {\n- p = _int_memalign (ar_ptr, alignment, bytes);\n- (void) mutex_unlock (&ar_ptr->mutex);\n- }\n+ p = _int_memalign (ar_ptr, alignment, bytes);\n }\n- else\n+\n+ if (ar_ptr != NULL)\n (void) mutex_unlock (&ar_ptr->mutex);\n+\n assert (!p || chunk_is_mmapped (mem2chunk (p)) ||\n ar_ptr == arena_for_chunk (mem2chunk (p)));\n return p;\n@@ -3193,47 +3205,53 @@ __libc_calloc (size_t n, size_t elem_siz\n sz = bytes;\n \n arena_get (av, sz);\n- if (!av)\n- return 0;\n-\n- /* Check if we hand out the top chunk, in which case there may be no\n- need to clear. */\n+ if (av)\n+ {\n+ /* Check if we hand out the top chunk, in which case there may be no\n+\t need to clear. */\n #if MORECORE_CLEARS\n- oldtop = top (av);\n- oldtopsize = chunksize (top (av));\n+ oldtop = top (av);\n+ oldtopsize = chunksize (top (av));\n # if MORECORE_CLEARS < 2\n- /* Only newly allocated memory is guaranteed to be cleared. */\n- if (av == &main_arena &&\n- oldtopsize < mp_.sbrk_base + av->max_system_mem - (char *) oldtop)\n- oldtopsize = (mp_.sbrk_base + av->max_system_mem - (char *) oldtop);\n+ /* Only newly allocated memory is guaranteed to be cleared. */\n+ if (av == &main_arena &&\n+\t oldtopsize < mp_.sbrk_base + av->max_system_mem - (char *) oldtop)\n+\toldtopsize = (mp_.sbrk_base + av->max_system_mem - (char *) oldtop);\n # endif\n- if (av != &main_arena)\n+ if (av != &main_arena)\n+\t{\n+\t heap_info *heap = heap_for_ptr (oldtop);\n+\t if (oldtopsize < (char *) heap + heap->mprotect_size - (char *) oldtop)\n+\t oldtopsize = (char *) heap + heap->mprotect_size - (char *) oldtop;\n+\t}\n+#endif\n+ }\n+ else\n {\n- heap_info *heap = heap_for_ptr (oldtop);\n- if (oldtopsize < (char *) heap + heap->mprotect_size - (char *) oldtop)\n- oldtopsize = (char *) heap + heap->mprotect_size - (char *) oldtop;\n+ /* No usable arenas. */\n+ oldtop = 0;\n+ oldtopsize = 0;\n }\n-#endif\n mem = _int_malloc (av, sz);\n \n \n assert (!mem || chunk_is_mmapped (mem2chunk (mem)) ||\n av == arena_for_chunk (mem2chunk (mem)));\n \n- if (mem == 0)\n+ if (mem == 0 && av != NULL)\n {\n LIBC_PROBE (memory_calloc_retry, 1, sz);\n av = arena_get_retry (av, sz);\n- if (__builtin_expect (av != NULL, 1))\n- {\n- mem = _int_malloc (av, sz);\n- (void) mutex_unlock (&av->mutex);\n- }\n- if (mem == 0)\n- return 0;\n+ mem = _int_malloc (av, sz);\n }\n- else\n+\n+ if (av != NULL)\n (void) mutex_unlock (&av->mutex);\n+\n+ /* Allocation failed even after a retry. */\n+ if (mem == 0)\n+ return 0;\n+\n p = mem2chunk (mem);\n \n /* Two optional cases in which clearing not necessary */\n@@ -3329,6 +3347,16 @@ _int_malloc (mstate av, size_t bytes)\n \n checked_request2size (bytes, nb);\n \n+ /* There are no usable arenas. Fall back to sysmalloc to get a chunk from\n+ mmap. */\n+ if (__glibc_unlikely (av == NULL))\n+ {\n+ void *p = sysmalloc (nb, av);\n+ if (p != NULL)\n+\talloc_perturb (p, bytes);\n+ return p;\n+ }\n+\n /*\n If the size qualifies as a fastbin, first check corresponding bin.\n This code is safe to execute even if av is not yet initialized, so we\n@@ -3354,7 +3382,7 @@ _int_malloc (mstate av, size_t bytes)\n {\n errstr = \"malloc(): memory corruption (fast)\";\n errout:\n- malloc_printerr (check_action, errstr, chunk2mem (victim));\n+ malloc_printerr (check_action, errstr, chunk2mem (victim), av);\n return NULL;\n }\n check_remalloced_chunk (av, victim, nb);\n@@ -3443,7 +3471,7 @@ _int_malloc (mstate av, size_t bytes)\n if (__builtin_expect (victim->size <= 2 * SIZE_SZ, 0)\n || __builtin_expect (victim->size > av->system_mem, 0))\n malloc_printerr (check_action, \"malloc(): memory corruption\",\n- chunk2mem (victim));\n+ chunk2mem (victim), av);\n size = chunksize (victim);\n \n /*\n@@ -3590,7 +3618,7 @@ _int_malloc (mstate av, size_t bytes)\n victim = victim->fd;\n \n remainder_size = size - nb;\n- unlink (victim, bck, fwd);\n+ unlink (av, victim, bck, fwd);\n \n /* Exhaust */\n if (remainder_size < MINSIZE)\n@@ -3695,7 +3723,7 @@ _int_malloc (mstate av, size_t bytes)\n remainder_size = size - nb;\n \n /* unlink */\n- unlink (victim, bck, fwd);\n+ unlink (av, victim, bck, fwd);\n \n /* Exhaust */\n if (remainder_size < MINSIZE)\n@@ -3835,7 +3863,7 @@ _int_free (mstate av, mchunkptr p, int h\n errout:\n if (!have_lock && locked)\n (void) mutex_unlock (&av->mutex);\n- malloc_printerr (check_action, errstr, chunk2mem (p));\n+ malloc_printerr (check_action, errstr, chunk2mem (p), av);\n return;\n }\n /* We know that each chunk is at least MINSIZE bytes in size or a\n@@ -3982,7 +4010,7 @@ _int_free (mstate av, mchunkptr p, int h\n prevsize = p->prev_size;\n size += prevsize;\n p = chunk_at_offset(p, -((long) prevsize));\n- unlink(p, bck, fwd);\n+ unlink(av, p, bck, fwd);\n }\n \n if (nextchunk != av->top) {\n@@ -3991,7 +4019,7 @@ _int_free (mstate av, mchunkptr p, int h\n \n /* consolidate forward */\n if (!nextinuse) {\n-\tunlink(nextchunk, bck, fwd);\n+\tunlink(av, nextchunk, bck, fwd);\n \tsize += nextsize;\n } else\n \tclear_inuse_bit_at_offset(nextchunk, 0);\n@@ -4152,7 +4180,7 @@ static void malloc_consolidate(mstate av\n \t prevsize = p->prev_size;\n \t size += prevsize;\n \t p = chunk_at_offset(p, -((long) prevsize));\n-\t unlink(p, bck, fwd);\n+\t unlink(av, p, bck, fwd);\n \t }\n \n \t if (nextchunk != av->top) {\n@@ -4160,7 +4188,7 @@ static void malloc_consolidate(mstate av\n \n \t if (!nextinuse) {\n \t size += nextsize;\n-\t unlink(nextchunk, bck, fwd);\n+\t unlink(av, nextchunk, bck, fwd);\n \t } else\n \t clear_inuse_bit_at_offset(nextchunk, 0);\n \n@@ -4229,7 +4257,7 @@ _int_realloc(mstate av, mchunkptr oldp,\n {\n errstr = \"realloc(): invalid old size\";\n errout:\n- malloc_printerr (check_action, errstr, chunk2mem (oldp));\n+ malloc_printerr (check_action, errstr, chunk2mem (oldp), av);\n return NULL;\n }\n \n@@ -4275,7 +4303,7 @@ _int_realloc(mstate av, mchunkptr oldp,\n (unsigned long) (nb))\n {\n newp = oldp;\n- unlink (next, bck, fwd);\n+ unlink (av, next, bck, fwd);\n }\n \n /* allocate, copy, free */\n@@ -4470,6 +4498,10 @@ _int_memalign (mstate av, size_t alignme\n static int\n mtrim (mstate av, size_t pad)\n {\n+ /* Don't touch corrupt arenas. */\n+ if (arena_is_corrupt (av))\n+ return 0;\n+\n /* Ensure initialization/consolidation */\n malloc_consolidate (av);\n \n@@ -4976,8 +5008,14 @@ libc_hidden_def (__libc_mallopt)\n extern char **__libc_argv attribute_hidden;\n \n static void\n-malloc_printerr (int action, const char *str, void *ptr)\n+malloc_printerr (int action, const char *str, void *ptr, mstate ar_ptr)\n {\n+ /* Avoid using this arena in future. We do not attempt to synchronize this\n+ with anything else because we minimally want to ensure that __libc_message\n+ gets its resources safely without stumbling on the current corruption. */\n+ if (ar_ptr)\n+ set_arena_corrupt (ar_ptr);\n+\n if ((action & 5) == 5)\n __libc_message (action & 2, \"%s\\n\", str);\n else if (action & 1)\nIndex: glibc-2.19/malloc/tst-malloc-backtrace.c\n===================================================================\n--- /dev/null\n+++ glibc-2.19/malloc/tst-malloc-backtrace.c\n@@ -0,0 +1,50 @@\n+/* Verify that backtrace does not deadlock on itself on memory corruption.\n+ Copyright (C) 2015 Free Software Foundation, Inc.\n+ This file is part of the GNU C Library.\n+\n+ The GNU C Library is free software; you can redistribute it and/or\n+ modify it under the terms of the GNU Lesser General Public\n+ License as published by the Free Software Foundation; either\n+ version 2.1 of the License, or (at your option) any later version.\n+\n+ The GNU C Library is distributed in the hope that it will be useful,\n+ but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ Lesser General Public License for more details.\n+\n+ You should have received a copy of the GNU Lesser General Public\n+ License along with the GNU C Library; if not, see\n+ <http://www.gnu.org/licenses/>. */\n+\n+\n+#include <stdlib.h>\n+\n+#define SIZE 4096\n+\n+/* Wrap free with a function to prevent gcc from optimizing it out. */\n+static void\n+__attribute__((noinline))\n+call_free (void *ptr)\n+{\n+ free (ptr);\n+ *(size_t *)(ptr - sizeof (size_t)) = 1;\n+}\n+\n+int\n+do_test (void)\n+{\n+ void *ptr1 = malloc (SIZE);\n+ void *ptr2 = malloc (SIZE);\n+\n+ call_free (ptr1);\n+ ptr1 = malloc (SIZE);\n+\n+ /* Not reached. The return statement is to put ptr2 into use so that gcc\n+ doesn't optimize out that malloc call. */\n+ return (ptr1 == ptr2);\n+}\n+\n+#define TEST_FUNCTION do_test ()\n+#define EXPECTED_SIGNAL SIGABRT\n+\n+#include \"../test-skeleton.c\"" } ]
{ "id": "glibc-testsuite-5322-Avoid-deadlock-in-malloc-on-ba", "cve_id": "CVE-2016-3706", "package": "glibc-testsuite", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 2587, "context_files": 4 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-6313\n\nThe mixing functions in the random number generator in Libgcrypt before 1.5.6, 1.6.x before 1.6.6, and 1.7.x before 1.7.3 and GnuPG before 1.4.21 make it easier for attackers to obtain the values of 160 bits by leveraging knowledge of the previous 4640 bits.\n\n## Package\nlibgcrypt\n\n## Files to modify\n- libgcrypt-1.6.1.orig/cipher/rsa.c\n- cipher/rsa.c\n- cipher/primegen.c\n- libgcrypt-1.6.1.orig/cipher/primegen.c\n\n## Target Source Code\n\n### cipher/rsa.c\n\n#### gen_x931_parm_xi() [lines 365-380]\n```c\n\n/* Helper for generate_x931. */\nstatic gcry_mpi_t\ngen_x931_parm_xi (void)\n{\n gcry_mpi_t xi;\n\n xi = mpi_snew (101);\n _gcry_mpi_randomize (xi, 101, GCRY_VERY_STRONG_RANDOM);\n mpi_set_highbit (xi, 100);\n gcry_assert ( mpi_get_nbits (xi) == 101 );\n\n return xi;\n}\n\n\n```\n\n#### fips_186_4_prime_check() [lines 431-456]\n```c\n gcry_mpi_t xq = NULL;\n gcry_mpi_t tmpval;\n\n if (!deriveparms)\n {\n /* Not given: Generate them. */\n xp = gen_x931_parm_xp (nbits/2);\n /* Make sure that |xp - xq| > 2^{nbits - 100} holds. */\n tmpval = mpi_snew (nbits/2);\n do\n {\n _gcry_mpi_release (xq);\n xq = gen_x931_parm_xp (nbits/2);\n mpi_sub (tmpval, xp, xq);\n }\n while (mpi_get_nbits (tmpval) <= (nbits/2 - 100));\n _gcry_mpi_release (tmpval);\n\n xp1 = gen_x931_parm_xi ();\n xp2 = gen_x931_parm_xi ();\n xq1 = gen_x931_parm_xi ();\n xq2 = gen_x931_parm_xi ();\n\n }\n else\n {\n```\n\n#### rsa_generate() [lines 755-852]\n```c\n *********************************************/\n\nstatic gcry_err_code_t\nrsa_generate (const gcry_sexp_t genparms, gcry_sexp_t *r_skey)\n{\n gpg_err_code_t ec;\n unsigned int nbits;\n unsigned long evalue;\n RSA_secret_key sk;\n gcry_sexp_t deriveparms;\n int flags = 0;\n gcry_sexp_t l1;\n gcry_sexp_t swap_info = NULL;\n\n memset (&sk, 0, sizeof sk);\n\n ec = _gcry_pk_util_get_nbits (genparms, &nbits);\n if (ec)\n return ec;\n\n ec = _gcry_pk_util_get_rsa_use_e (genparms, &evalue);\n if (ec)\n return ec;\n\n /* Parse the optional flags list. */\n l1 = sexp_find_token (genparms, \"flags\", 0);\n if (l1)\n {\n ec = _gcry_pk_util_parse_flaglist (l1, &flags, NULL);\n sexp_release (l1);\n if (ec)\n return ec;\n }\n\n deriveparms = (genparms?\n sexp_find_token (genparms, \"derive-parms\", 0) : NULL);\n if (!deriveparms)\n {\n /* Parse the optional \"use-x931\" flag. */\n l1 = sexp_find_token (genparms, \"use-x931\", 0);\n if (l1)\n {\n flags |= PUBKEY_FLAG_USE_X931;\n sexp_release (l1);\n }\n }\n\n if (deriveparms || (flags & PUBKEY_FLAG_USE_X931) || fips_mode ())\n {\n int swapped;\n ec = generate_x931 (&sk, nbits, evalue, deriveparms, &swapped);\n sexp_release (deriveparms);\n if (!ec && swapped)\n ec = sexp_new (&swap_info, \"(misc-key-info(p-q-swapped))\", 0, 1);\n }\n else\n {\n /* Parse the optional \"transient-key\" flag. */\n if (!(flags & PUBKEY_FLAG_TRANSIENT_KEY))\n {\n l1 = sexp_find_token (genparms, \"transient-key\", 0);\n if (l1)\n {\n flags |= PUBKEY_FLAG_TRANSIENT_KEY;\n sexp_release (l1);\n }\n }\n /* Generate. */\n ec = generate_std (&sk, nbits, evalue,\n !!(flags & PUBKEY_FLAG_TRANSIENT_KEY));\n }\n\n if (!ec)\n {\n ec = sexp_build (r_skey, NULL,\n \"(key-data\"\n \" (public-key\"\n \" (rsa(n%m)(e%m)))\"\n \" (private-key\"\n \" (rsa(n%m)(e%m)(d%m)(p%m)(q%m)(u%m)))\"\n \" %S)\",\n sk.n, sk.e,\n sk.n, sk.e, sk.d, sk.p, sk.q, sk.u,\n swap_info);\n }\n\n mpi_free (sk.n);\n mpi_free (sk.e);\n mpi_free (sk.p);\n mpi_free (sk.q);\n mpi_free (sk.d);\n mpi_free (sk.u);\n sexp_release (swap_info);\n\n return ec;\n}\n\n\n```\n\n### cipher/primegen.c\n\n#### check_prime() [lines 580-604]\n```c\n\telse\n\t count2 = 0;\n }\n while (! ((nprime == pbits) && check_prime (prime, val_2, 5,\n cb_func, cb_arg)));\n\n if (DBG_CIPHER)\n {\n progress ('\\n');\n log_mpidump (\"prime \", prime);\n log_mpidump (\"factor q\", q);\n if (need_q_factor)\n log_mpidump (\"factor q0\", q_factor);\n for (i = 0; i < n; i++)\n log_mpidump (\"factor pi\", factors[i]);\n log_debug (\"bit sizes: prime=%u, q=%u\",\n mpi_get_nbits (prime), mpi_get_nbits (q));\n if (need_q_factor)\n log_printf (\", q0=%u\", mpi_get_nbits (q_factor));\n for (i = 0; i < n; i++)\n log_printf (\", p%d=%u\", i, mpi_get_nbits (factors[i]));\n log_printf (\"\\n\");\n }\n\n if (ret_factors)\n```\n\n\n## Upstream Fix\n```diff\nIndex: libgcrypt-1.6.1/cipher/rsa.c\n===================================================================\n--- libgcrypt-1.6.1.orig/cipher/rsa.c\t2015-02-16 17:17:27.281576283 +0100\n+++ libgcrypt-1.6.1/cipher/rsa.c\t2015-02-16 18:21:08.946056697 +0100\n@@ -421,6 +421,279 @@ gen_x931_parm_xi (void)\n }\n \n \n+/****************\n+ * Generate a key pair with a key of size NBITS.\n+ * USE_E = 0 let Libcgrypt decide what exponent to use.\n+ * = 1 request the use of a \"secure\" exponent; this is required by some\n+ * specification to be 65537.\n+ * > 2 Use this public exponent. If the given exponent\n+ * is not odd one is internally added to it.\n+ * TESTPARMS: If set, do not generate but test whether the p,q is probably prime\n+ * Returns key with zeroes to not break code calling this function.\n+ * TRANSIENT_KEY: If true, generate the primes using the standard RNG.\n+ * Returns: 2 structures filled with all needed values\n+ */\n+static gpg_err_code_t\n+generate_fips (RSA_secret_key *sk, unsigned int nbits, unsigned long use_e,\n+ gcry_sexp_t testparms, int *swapped)\n+{\n+ gcry_mpi_t p, q; /* the two primes */\n+ gcry_mpi_t d; /* the private key */\n+ gcry_mpi_t u;\n+ gcry_mpi_t p1, q1;\n+ gcry_mpi_t n; /* the public key */\n+ gcry_mpi_t e; /* the exponent */\n+ gcry_mpi_t g;\n+ gcry_mpi_t minp;\n+ gcry_mpi_t diff, mindiff;\n+ gcry_random_level_t random_level;\n+ unsigned int pbits = nbits/2;\n+ unsigned int i;\n+ int pqswitch;\n+ gpg_err_code_t ec = GPG_ERR_NO_PRIME;\n+\n+ if (nbits < 1024 || (nbits & 0x1FF))\n+ return GPG_ERR_INV_VALUE;\n+ if (fips_mode() && nbits != 2048 && nbits != 3072)\n+ return GPG_ERR_INV_VALUE;\n+\n+ random_level = GCRY_VERY_STRONG_RANDOM;\n+\n+ if (testparms)\n+ {\n+ /* Parameters to derive the key are given. */\n+ /* Note that we explicitly need to setup the values of tbl\n+ because some compilers (e.g. OpenWatcom, IRIX) don't allow\n+ to initialize a structure with automatic variables. */\n+ struct { const char *name; gcry_mpi_t *value; } tbl[] = {\n+ { \"e\" },\n+ { \"p\" },\n+ { \"q\" },\n+ { NULL }\n+ };\n+ int idx;\n+ gcry_sexp_t oneparm;\n+\n+ tbl[0].value = &e;\n+ tbl[1].value = &p;\n+ tbl[2].value = &q;\n+\n+ for (idx=0; tbl[idx].name; idx++)\n+ {\n+ oneparm = sexp_find_token (testparms, tbl[idx].name, 0);\n+ if (oneparm)\n+ {\n+ *tbl[idx].value = sexp_nth_mpi (oneparm, 1,\n+ GCRYMPI_FMT_USG);\n+ sexp_release (oneparm);\n+ }\n+ }\n+ for (idx=0; tbl[idx].name; idx++)\n+ if (!*tbl[idx].value)\n+ break;\n+ if (tbl[idx].name)\n+ {\n+ /* At least one parameter is missing. */\n+ for (idx=0; tbl[idx].name; idx++)\n+ _gcry_mpi_release (*tbl[idx].value);\n+ return GPG_ERR_MISSING_VALUE;\n+ }\n+ }\n+ else\n+ {\n+ if (use_e < 65537)\n+ use_e = 65537; /* This is the smallest value allowed by FIPS */\n+\n+ e = mpi_alloc( (32+BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB );\n+\n+ use_e |= 1; /* make sure this is odd */\n+ mpi_set_ui (e, use_e);\n+\n+ p = mpi_snew (pbits);\n+ q = mpi_snew (pbits);\n+ }\n+\n+ n = mpi_new (nbits);\n+ d = mpi_snew (nbits);\n+ u = mpi_snew (nbits);\n+\n+ /* prepare approximate minimum p and q */\n+ minp = mpi_new (pbits);\n+ mpi_set_ui (minp, 0xB504F334);\n+ mpi_lshift (minp, minp, pbits - 32);\n+\n+ /* prepare minimum p and q difference */\n+ diff = mpi_new (pbits);\n+ mindiff = mpi_new (pbits - 99);\n+ mpi_set_ui (mindiff, 1);\n+ mpi_lshift (mindiff, mindiff, pbits - 100);\n+\n+ p1 = mpi_snew (pbits);\n+ q1 = mpi_snew (pbits);\n+ g = mpi_snew (pbits);\n+\n+retry:\n+ /* generate p and q */\n+ for (i = 0; i < 5 * pbits; i++)\n+ {\n+ ploop:\n+ if (!testparms)\n+ {\n+ _gcry_mpi_randomize (p, pbits, random_level);\n+ }\n+ if (mpi_cmp (p, minp) < 0)\n+ {\n+ if (testparms) goto err;\n+ goto ploop;\n+ }\n+\n+ mpi_sub_ui (p1, p, 1);\n+ if (mpi_gcd (g, p1, e))\n+ {\n+ if (_gcry_fips186_4_prime_check (p, pbits) != GPG_ERR_NO_ERROR)\n+ {\n+ /* not a prime */\n+ if (testparms) goto err;\n+ }\n+ else\n+ break;\n+ }\n+ else if (testparms) goto err;\n+ }\n+ if (i >= 5 * pbits)\n+ goto err;\n+\n+ for (i = 0; i < 5 * pbits; i++)\n+ {\n+ qloop:\n+ if (!testparms)\n+ {\n+ _gcry_mpi_randomize (q, pbits, random_level);\n+ }\n+ if (mpi_cmp (q, minp) < 0)\n+ {\n+ if (testparms) goto err;\n+ goto qloop;\n+ }\n+ if (mpi_cmp (p, q) < 0)\n+ {\n+ pqswitch = 1;\n+ mpi_sub (diff, q, p);\n+ }\n+ else\n+ {\n+ pqswitch = 0;\n+ mpi_sub (diff, p, q);\n+ }\n+ if (mpi_cmp (diff, mindiff) < 0)\n+ {\n+ if (testparms) goto err;\n+ goto qloop;\n+ }\n+\n+ mpi_sub_ui (q1, q, 1);\n+ if (mpi_gcd (g, q1, e))\n+ {\n+ if (_gcry_fips186_4_prime_check (q, pbits) != GPG_ERR_NO_ERROR)\n+ {\n+ /* not a prime */\n+ if (testparms) goto err;\n+ }\n+ else\n+ break;\n+ }\n+ else if (testparms) goto err;\n+ }\n+ if (i >= 5 * pbits)\n+ goto err;\n+\n+ if (testparms)\n+ {\n+ mpi_clear (p);\n+ mpi_clear (q);\n+ }\n+ else\n+ {\n+ gcry_mpi_t f;\n+ gcry_mpi_t phi;\n+\n+ f = mpi_snew (nbits);\n+ phi = mpi_snew (nbits);\n+\n+ if (pqswitch)\n+ {\n+ mpi_swap(p, q);\n+ }\n+\n+ /* calculate the modulus */\n+ mpi_mul(n, p, q);\n+\n+ /* Compute the Euler totient: phi = (p-1)(q-1) */\n+ mpi_mul (phi, p1, q1);\n+\n+ /* Compute: f = lcm(p-1,q-1) = phi / gcd(p-1,q-1) */\n+ mpi_gcd (g, p1, q1);\n+ mpi_fdiv_q (f, phi, g);\n+ _gcry_mpi_release (phi); phi = NULL;\n+\n+ /* Compute the secret key: d = e^{-1} mod lcm(p-1,q-1) */\n+ mpi_invm (d, e, f);\n+ _gcry_mpi_release (f);\n+\n+ if (mpi_get_nbits (d) < pbits) goto retry;\n+\n+ /* calculate the inverse of p and q (used for chinese remainder theorem)*/\n+ mpi_invm(u, p, q );\n+ }\n+\n+ ec = 0;\n+\n+ if( DBG_CIPHER )\n+ {\n+ log_mpidump(\" p= \", p );\n+ log_mpidump(\" q= \", q );\n+ log_mpidump(\" n= \", n );\n+ log_mpidump(\" e= \", e );\n+ log_mpidump(\" d= \", d );\n+ log_mpidump(\" u= \", u );\n+ }\n+\n+err:\n+\n+ _gcry_mpi_release (p1);\n+ _gcry_mpi_release (q1);\n+ _gcry_mpi_release (g);\n+ _gcry_mpi_release (minp);\n+ _gcry_mpi_release (mindiff);\n+ _gcry_mpi_release (diff);\n+\n+ sk->n = n;\n+ sk->e = e;\n+ sk->p = p;\n+ sk->q = q;\n+ sk->d = d;\n+ sk->u = u;\n+\n+ /* Now we can test our keys. */\n+ if (ec || (!testparms && test_keys (sk, nbits - 64)))\n+ {\n+ _gcry_mpi_release (sk->n); sk->n = NULL;\n+ _gcry_mpi_release (sk->e); sk->e = NULL;\n+ _gcry_mpi_release (sk->p); sk->p = NULL;\n+ _gcry_mpi_release (sk->q); sk->q = NULL;\n+ _gcry_mpi_release (sk->d); sk->d = NULL;\n+ _gcry_mpi_release (sk->u); sk->u = NULL;\n+ if (!ec)\n+ {\n+ fips_signal_error (\"self-test after key generation failed\");\n+ return GPG_ERR_SELFTEST_FAILED;\n+ }\n+ }\n+\n+ return ec;\n+}\n+\n+\n static gpg_err_code_t\n fips_186_4_prime_check(gcry_mpi_t x, unsigned int nbits, gcry_mpi_t e)\n {\n@@ -441,6 +714,8 @@ fips_186_4_prime_check(gcry_mpi_t x, uns\n return rc;\n }\n \n+\n+\n /* Variant of the standard key generation code using the algorithm\n from X9.31. Using this algorithm has the advantage that the\n generation can be made deterministic which is required for CAVS\n@@ -913,7 +1188,7 @@ rsa_generate (const gcry_sexp_t genparms\n }\n }\n \n- if (\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "Index: libgcrypt-1.6.1/cipher/rsa.c\n===================================================================\n--- libgcrypt-1.6.1.orig/cipher/rsa.c\t2015-02-16 17:17:27.281576283 +0100\n+++ libgcrypt-1.6.1/cipher/rsa.c\t2015-02-16 18:21:08.946056697 +0100\n@@ -421,6 +421,279 @@ gen_x931_parm_xi (void)\n }\n \n \n+/****************\n+ * Generate a key pair with a key of size NBITS.\n+ * USE_E = 0 let Libcgrypt decide what exponent to use.\n+ * = 1 request the use of a \"secure\" exponent; this is required by some\n+ * specification to be 65537.\n+ * > 2 Use this public exponent. If the given exponent\n+ * is not odd one is internally added to it.\n+ * TESTPARMS: If set, do not generate but test whether the p,q is probably prime\n+ * Returns key with zeroes to not break code calling this function.\n+ * TRANSIENT_KEY: If true, generate the primes using the standard RNG.\n+ * Returns: 2 structures filled with all needed values\n+ */\n+static gpg_err_code_t\n+generate_fips (RSA_secret_key *sk, unsigned int nbits, unsigned long use_e,\n+ gcry_sexp_t testparms, int *swapped)\n+{\n+ gcry_mpi_t p, q; /* the two primes */\n+ gcry_mpi_t d; /* the private key */\n+ gcry_mpi_t u;\n+ gcry_mpi_t p1, q1;\n+ gcry_mpi_t n; /* the public key */\n+ gcry_mpi_t e; /* the exponent */\n+ gcry_mpi_t g;\n+ gcry_mpi_t minp;\n+ gcry_mpi_t diff, mindiff;\n+ gcry_random_level_t random_level;\n+ unsigned int pbits = nbits/2;\n+ unsigned int i;\n+ int pqswitch;\n+ gpg_err_code_t ec = GPG_ERR_NO_PRIME;\n+\n+ if (nbits < 1024 || (nbits & 0x1FF))\n+ return GPG_ERR_INV_VALUE;\n+ if (fips_mode() && nbits != 2048 && nbits != 3072)\n+ return GPG_ERR_INV_VALUE;\n+\n+ random_level = GCRY_VERY_STRONG_RANDOM;\n+\n+ if (testparms)\n+ {\n+ /* Parameters to derive the key are given. */\n+ /* Note that we explicitly need to setup the values of tbl\n+ because some compilers (e.g. OpenWatcom, IRIX) don't allow\n+ to initialize a structure with automatic variables. */\n+ struct { const char *name; gcry_mpi_t *value; } tbl[] = {\n+ { \"e\" },\n+ { \"p\" },\n+ { \"q\" },\n+ { NULL }\n+ };\n+ int idx;\n+ gcry_sexp_t oneparm;\n+\n+ tbl[0].value = &e;\n+ tbl[1].value = &p;\n+ tbl[2].value = &q;\n+\n+ for (idx=0; tbl[idx].name; idx++)\n+ {\n+ oneparm = sexp_find_token (testparms, tbl[idx].name, 0);\n+ if (oneparm)\n+ {\n+ *tbl[idx].value = sexp_nth_mpi (oneparm, 1,\n+ GCRYMPI_FMT_USG);\n+ sexp_release (oneparm);\n+ }\n+ }\n+ for (idx=0; tbl[idx].name; idx++)\n+ if (!*tbl[idx].value)\n+ break;\n+ if (tbl[idx].name)\n+ {\n+ /* At least one parameter is missing. */\n+ for (idx=0; tbl[idx].name; idx++)\n+ _gcry_mpi_release (*tbl[idx].value);\n+ return GPG_ERR_MISSING_VALUE;\n+ }\n+ }\n+ else\n+ {\n+ if (use_e < 65537)\n+ use_e = 65537; /* This is the smallest value allowed by FIPS */\n+\n+ e = mpi_alloc( (32+BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB );\n+\n+ use_e |= 1; /* make sure this is odd */\n+ mpi_set_ui (e, use_e);\n+\n+ p = mpi_snew (pbits);\n+ q = mpi_snew (pbits);\n+ }\n+\n+ n = mpi_new (nbits);\n+ d = mpi_snew (nbits);\n+ u = mpi_snew (nbits);\n+\n+ /* prepare approximate minimum p and q */\n+ minp = mpi_new (pbits);\n+ mpi_set_ui (minp, 0xB504F334);\n+ mpi_lshift (minp, minp, pbits - 32);\n+\n+ /* prepare minimum p and q difference */\n+ diff = mpi_new (pbits);\n+ mindiff = mpi_new (pbits - 99);\n+ mpi_set_ui (mindiff, 1);\n+ mpi_lshift (mindiff, mindiff, pbits - 100);\n+\n+ p1 = mpi_snew (pbits);\n+ q1 = mpi_snew (pbits);\n+ g = mpi_snew (pbits);\n+\n+retry:\n+ /* generate p and q */\n+ for (i = 0; i < 5 * pbits; i++)\n+ {\n+ ploop:\n+ if (!testparms)\n+ {\n+ _gcry_mpi_randomize (p, pbits, random_level);\n+ }\n+ if (mpi_cmp (p, minp) < 0)\n+ {\n+ if (testparms) goto err;\n+ goto ploop;\n+ }\n+\n+ mpi_sub_ui (p1, p, 1);\n+ if (mpi_gcd (g, p1, e))\n+ {\n+ if (_gcry_fips186_4_prime_check (p, pbits) != GPG_ERR_NO_ERROR)\n+ {\n+ /* not a prime */\n+ if (testparms) goto err;\n+ }\n+ else\n+ break;\n+ }\n+ else if (testparms) goto err;\n+ }\n+ if (i >= 5 * pbits)\n+ goto err;\n+\n+ for (i = 0; i < 5 * pbits; i++)\n+ {\n+ qloop:\n+ if (!testparms)\n+ {\n+ _gcry_mpi_randomize (q, pbits, random_level);\n+ }\n+ if (mpi_cmp (q, minp) < 0)\n+ {\n+ if (testparms) goto err;\n+ goto qloop;\n+ }\n+ if (mpi_cmp (p, q) < 0)\n+ {\n+ pqswitch = 1;\n+ mpi_sub (diff, q, p);\n+ }\n+ else\n+ {\n+ pqswitch = 0;\n+ mpi_sub (diff, p, q);\n+ }\n+ if (mpi_cmp (diff, mindiff) < 0)\n+ {\n+ if (testparms) goto err;\n+ goto qloop;\n+ }\n+\n+ mpi_sub_ui (q1, q, 1);\n+ if (mpi_gcd (g, q1, e))\n+ {\n+ if (_gcry_fips186_4_prime_check (q, pbits) != GPG_ERR_NO_ERROR)\n+ {\n+ /* not a prime */\n+ if (testparms) goto err;\n+ }\n+ else\n+ break;\n+ }\n+ else if (testparms) goto err;\n+ }\n+ if (i >= 5 * pbits)\n+ goto err;\n+\n+ if (testparms)\n+ {\n+ mpi_clear (p);\n+ mpi_clear (q);\n+ }\n+ else\n+ {\n+ gcry_mpi_t f;\n+ gcry_mpi_t phi;\n+\n+ f = mpi_snew (nbits);\n+ phi = mpi_snew (nbits);\n+\n+ if (pqswitch)\n+ {\n+ mpi_swap(p, q);\n+ }\n+\n+ /* calculate the modulus */\n+ mpi_mul(n, p, q);\n+\n+ /* Compute the Euler totient: phi = (p-1)(q-1) */\n+ mpi_mul (phi, p1, q1);\n+\n+ /* Compute: f = lcm(p-1,q-1) = phi / gcd(p-1,q-1) */\n+ mpi_gcd (g, p1, q1);\n+ mpi_fdiv_q (f, phi, g);\n+ _gcry_mpi_release (phi); phi = NULL;\n+\n+ /* Compute the secret key: d = e^{-1} mod lcm(p-1,q-1) */\n+ mpi_invm (d, e, f);\n+ _gcry_mpi_release (f);\n+\n+ if (mpi_get_nbits (d) < pbits) goto retry;\n+\n+ /* calculate the inverse of p and q (used for chinese remainder theorem)*/\n+ mpi_invm(u, p, q );\n+ }\n+\n+ ec = 0;\n+\n+ if( DBG_CIPHER )\n+ {\n+ log_mpidump(\" p= \", p );\n+ log_mpidump(\" q= \", q );\n+ log_mpidump(\" n= \", n );\n+ log_mpidump(\" e= \", e );\n+ log_mpidump(\" d= \", d );\n+ log_mpidump(\" u= \", u );\n+ }\n+\n+err:\n+\n+ _gcry_mpi_release (p1);\n+ _gcry_mpi_release (q1);\n+ _gcry_mpi_release (g);\n+ _gcry_mpi_release (minp);\n+ _gcry_mpi_release (mindiff);\n+ _gcry_mpi_release (diff);\n+\n+ sk->n = n;\n+ sk->e = e;\n+ sk->p = p;\n+ sk->q = q;\n+ sk->d = d;\n+ sk->u = u;\n+\n+ /* Now we can test our keys. */\n+ if (ec || (!testparms && test_keys (sk, nbits - 64)))\n+ {\n+ _gcry_mpi_release (sk->n); sk->n = NULL;\n+ _gcry_mpi_release (sk->e); sk->e = NULL;\n+ _gcry_mpi_release (sk->p); sk->p = NULL;\n+ _gcry_mpi_release (sk->q); sk->q = NULL;\n+ _gcry_mpi_release (sk->d); sk->d = NULL;\n+ _gcry_mpi_release (sk->u); sk->u = NULL;\n+ if (!ec)\n+ {\n+ fips_signal_error (\"self-test after key generation failed\");\n+ return GPG_ERR_SELFTEST_FAILED;\n+ }\n+ }\n+\n+ return ec;\n+}\n+\n+\n static gpg_err_code_t\n fips_186_4_prime_check(gcry_mpi_t x, unsigned int nbits, gcry_mpi_t e)\n {\n@@ -441,6 +714,8 @@ fips_186_4_prime_check(gcry_mpi_t x, uns\n return rc;\n }\n \n+\n+\n /* Variant of the standard key generation code using the algorithm\n from X9.31. Using this algorithm has the advantage that the\n generation can be made deterministic which is required for CAVS\n@@ -913,7 +1188,7 @@ rsa_generate (const gcry_sexp_t genparms\n }\n }\n \n- if (deriveparms || (flags & PUBKEY_FLAG_USE_X931) || fips_mode ())\n+ if (deriveparms || (flags & PUBKEY_FLAG_USE_X931))\n {\n int swapped;\n ec = generate_x931 (&sk, nbits, evalue, deriveparms, &swapped);\n@@ -933,9 +1208,16 @@ rsa_generate (const gcry_sexp_t genparms\n sexp_release (l1);\n }\n }\n+ deriveparms = (genparms?\n+ sexp_find_token (genparms, \"test-parms\", 0) : NULL);\n+\n /* Generate. */\n- ec = generate_std (&sk, nbits, evalue,\n- !!(flags & PUBKEY_FLAG_TRANSIENT_KEY));\n+ if (deriveparms || fips_mode())\n+ ec = generate_fips (&sk, nbits, evalue, deriveparms, 0);\n+ else\n+ ec = generate_std (&sk, nbits, evalue, !!(flags & PUBKEY_FLAG_TRANSIENT_KEY));\n+\n+ sexp_release (deriveparms);\n }\n \n if (!ec)\nIndex: libgcrypt-1.6.1/cipher/primegen.c\n===================================================================\n--- libgcrypt-1.6.1.orig/cipher/primegen.c\t2015-02-16 16:43:58.418615762 +0100\n+++ libgcrypt-1.6.1/cipher/primegen.c\t2015-02-16 17:54:47.425359088 +0100\n@@ -913,6 +913,22 @@ check_prime( gcry_mpi_t prime, gcry_mpi_\n return 0;\n }\n \n+/* Check whether the number X is prime according to FIPS 186-4 table C.2. */\n+gcry_err_code_t\n+_gcry_fips186_4_prime_check (gcry_mpi_t x, unsigned int bits)\n+{\n+ gcry_err_code_t ec = GPG_ERR_NO_ERROR;\n+ gcry_mpi_t val_2 = mpi_alloc_set_ui (2);\n+/* Used by the Fermat test. */\n+\n+ /* We use 5 or 4 rounds as specified in table C.2 */\n+ if (! check_prime (x, val_2, bits > 1024 ? 4 : 5, NULL, NULL))\n+ ec = GPG_ERR_NO_PRIME;\n+\n+ mpi_free (val_2);\n+\n+ return ec;\n+}\n \n /*\n * Return true if n is probably a prime" } ]
{ "id": "libgcrypt-5635-libgcrypt-fips_rsa_keygen.patc", "cve_id": "CVE-2016-6313", "package": "libgcrypt", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": true, "license": "GPL-2.0-or-later AND LGPL-2.1-or-later AND GPL-3.0-or-later", "context_tokens_est": 1098, "context_files": 2 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-8684\n\nThe MagickMalloc function in magick/memory.c in GraphicsMagick 1.3.25 allows remote attackers to have unspecified impact via a crafted image, which triggers a memory allocation failure and a \"file truncation error for corrupt file.\"\n\n## Package\nImageMagick\n\n## Files to modify\n- ImageMagick-6.8.8-1.orig/coders/psd.c\n- coders/psd.c\n\n## Upstream Fix\n```diff\nFrom 4b1fba0af7c54b9da3681b57087e370839e4ac7f Mon Sep 17 00:00:00 2001\nFrom: dirk <dirk@git.imagemagick.org>\nDate: Fri, 15 Jan 2016 01:13:30 +0100\nSubject: [PATCH] Fixed overflow.\n\n---\n coders/psd.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/coders/psd.c b/coders/psd.c\nindex b04aa8f4a21..f33233e8f82 100644\n--- a/coders/psd.c\n+++ b/coders/psd.c\n@@ -2337,8 +2337,8 @@ static MagickBooleanType WriteImageChannels(const PSDInfo *psd_info,\n compact_pixels=(unsigned char *) NULL;\n if (next_image->compression == RLECompression)\n {\n- compact_pixels=(unsigned char *) AcquireQuantumMemory(2*channels*\n- next_image->columns,packet_size*sizeof(*compact_pixels));\n+ compact_pixels=(unsigned char *) AcquireQuantumMemory((2*channels*\n+ next_image->columns)+1,packet_size*sizeof(*compact_pixels));\n if (compact_pixels == (unsigned char *) NULL)\n ThrowWriterException(ResourceLimitError,\"MemoryAllocationFailed\");\n }\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 4b1fba0af7c54b9da3681b57087e370839e4ac7f Mon Sep 17 00:00:00 2001\nFrom: dirk <dirk@git.imagemagick.org>\nDate: Fri, 15 Jan 2016 01:13:30 +0100\nSubject: [PATCH] Fixed overflow.\n\n---\n coders/psd.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\nIndex: ImageMagick-6.8.8-1/coders/psd.c\n===================================================================\n--- ImageMagick-6.8.8-1.orig/coders/psd.c\t2016-09-30 13:52:03.833761216 +0200\n+++ ImageMagick-6.8.8-1/coders/psd.c\t2016-09-30 13:56:38.342270544 +0200\n@@ -630,6 +630,75 @@ static CompositeOperator PSDBlendModeToC\n return(OverCompositeOp);\n }\n \n+static inline void SetPSDPixel(Image *image,const size_t channels,\n+ const ssize_t type,const size_t packet_size,const Quantum pixel,\n+ PixelPacket *q,IndexPacket *indexes,ssize_t x,ExceptionInfo *exception)\n+{\n+ if (image->storage_class == PseudoClass)\n+ {\n+ if (packet_size == 1)\n+ SetPixelIndex(indexes+x,ScaleQuantumToChar(pixel));\n+ else\n+ SetPixelIndex(indexes+x,ScaleQuantumToShort(pixel));\n+ SetPixelRGBO(q,image->colormap+(ssize_t)\n+ ConstrainColormapIndex(image,GetPixelIndex(indexes+x)));\n+ return;\n+ }\n+ switch (type)\n+ {\n+ case -1:\n+ {\n+ SetPixelAlpha(q,pixel);\n+ break;\n+ }\n+ case -2:\n+ case 0:\n+ {\n+ SetPixelRed(q,pixel);\n+ if (channels == 1 || type == -2)\n+ {\n+ SetPixelGreen(q,GetPixelRed(q));\n+ SetPixelBlue(q,GetPixelRed(q));\n+ }\n+ break;\n+ }\n+ case 1:\n+ {\n+ if (image->storage_class == PseudoClass)\n+ SetPixelAlpha(q,pixel);\n+ else\n+ SetPixelGreen(q,pixel);\n+ break;\n+ }\n+ case 2:\n+ {\n+ if (image->storage_class == PseudoClass)\n+ SetPixelAlpha(q,pixel);\n+ else\n+ SetPixelBlue(q,pixel);\n+ break;\n+ }\n+ case 3:\n+ {\n+ if (image->colorspace == CMYKColorspace)\n+ SetPixelIndex(indexes+x,pixel);\n+ else\n+ if (image->matte != MagickFalse)\n+ SetPixelAlpha(q,pixel);\n+ break;\n+ }\n+ case 4:\n+ {\n+ if ((IssRGBCompatibleColorspace(image->colorspace) != MagickFalse) &&\n+ (channels > 3))\n+ break;\n+ if (image->matte != MagickFalse)\n+ SetPixelAlpha(q,pixel);\n+ break;\n+ }\n+ }\n+}\n+\n static MagickStatusType ReadPSDChannelPixels(Image *image,\n const size_t channels,const size_t row,const ssize_t type,\n const unsigned char *pixels,ExceptionInfo *exception)\n@@ -670,89 +739,28 @@ static MagickStatusType ReadPSDChannelPi\n p=PushShortPixel(MSBEndian,p,&nibble);\n pixel=ScaleShortToQuantum(nibble);\n }\n- switch (type)\n- {\n- case -1:\n- {\n- SetPixelAlpha(q,pixel);\n- break;\n- }\n- case 0:\n- {\n- SetPixelRed(q,pixel);\n- if (channels == 1)\n- {\n- SetPixelGreen(q,GetPixelRed(q));\n- SetPixelBlue(q,GetPixelRed(q));\n- }\n- if (image->storage_class == PseudoClass)\n- {\n- if (packet_size == 1)\n- SetPixelIndex(indexes+x,ScaleQuantumToChar(pixel));\n- else\n- SetPixelIndex(indexes+x,ScaleQuantumToShort(pixel));\n- SetPixelRGBO(q,image->colormap+(ssize_t)\n- ConstrainColormapIndex(image,GetPixelIndex(indexes+x)));\n- if (image->depth == 1)\n- {\n- ssize_t\n- bit,\n- number_bits;\n- \n- number_bits=image->columns-x;\n- if (number_bits > 8)\n- number_bits=8;\n- for (bit=0; bit < number_bits; bit++)\n- {\n- SetPixelIndex(indexes+x,(((unsigned char) pixel) &\n- (0x01 << (7-bit))) != 0 ? 0 : 255);\n- SetPixelRGBO(q,image->colormap+(ssize_t)\n- GetPixelIndex(indexes+x));\n- q++;\n- x++;\n- }\n- }\n- }\n- break;\n- }\n- case 1:\n+ if (image->depth > 1)\n {\n- if (image->storage_class == PseudoClass)\n- SetPixelAlpha(q,pixel);\n- else\n- SetPixelGreen(q,pixel);\n- break;\n+ SetPSDPixel(image,channels,type,packet_size,pixel,q++,indexes,x,exception);\n }\n- case 2:\n- {\n- if (image->storage_class == PseudoClass)\n- SetPixelAlpha(q,pixel);\n- else\n- SetPixelBlue(q,pixel);\n- break;\n- }\n- case 3:\n- {\n- if (image->colorspace == CMYKColorspace)\n- SetPixelIndex(indexes+x,pixel);\n- else\n- if (image->matte != MagickFalse)\n- SetPixelAlpha(q,pixel);\n- break;\n- }\n- case 4:\n+ else\n {\n- if ((IssRGBCompatibleColorspace(image->colorspace) != MagickFalse) &&\n- (channels > 3))\n- break;\n- if (image->matte != MagickFalse)\n- SetPixelAlpha(q,pixel);\n- break;\n+ ssize_t\n+ bit,\n+ number_bits;\n+\n+ number_bits=image->columns-x;\n+ if (number_bits > 8)\n+ number_bits=8;\n+ for (bit=0; bit < number_bits; bit++)\n+ {\n+ SetPSDPixel(image,channels,type,packet_size,pixel,q++,indexes,x++,\n+ exception);\n+ }\n+ if (x != image->columns)\n+ x--;\n+ continue;\n }\n- default:\n- break;\n- }\n- q++;\n }\n return(SyncAuthenticPixels(image,exception));\n }\n@@ -1725,6 +1733,8 @@ static Image *ReadPSDImage(const ImageIn\n image->matte=MagickFalse;\n }\n }\n+ if ((image->depth == 1) && (image->storage_class != PseudoClass))\n+ ThrowReaderException(CorruptImageError, \"ImproperImageHeader\");\n length=ReadBlobMSBLong(image);\n if (length != 0)\n {\n@@ -2153,8 +2163,8 @@ static MagickBooleanType WriteImageChann\n compact_pixels=(unsigned char *) NULL;\n if (next_image->compression == RLECompression)\n {\n- compact_pixels=(unsigned char *) AcquireQuantumMemory(2*channels*\n- next_image->columns,packet_size*sizeof(*compact_pixels));\n+ compact_pixels=(unsigned char *) AcquireQuantumMemory((2*channels*\n+ next_image->columns)+1,packet_size*sizeof(*compact_pixels));\n if (compact_pixels == (unsigned char *) NULL)\n ThrowWriterException(ResourceLimitError,\"MemoryAllocationFailed\");\n }" } ]
{ "id": "ImageMagick-5774-ImageMagick-CVE-2016-7514.patc", "cve_id": "CVE-2016-8684", "package": "ImageMagick", "upstream_enriched": true, "upstream_commit": "4b1fba0af7c54b9da3681b57087e370839e4ac7f", "upstream_repo": "ImageMagick/ImageMagick", "tier": "adapted", "has_source_context": false, "license": "ImageMagick", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-2695\n\nlib/gssapi/spnego/spnego_mech.c in MIT Kerberos 5 (aka krb5) before 1.14 relies on an inappropriate context handle, which allows remote attackers to cause a denial of service (incorrect pointer read and process crash) via a crafted SPNEGO packet that is mishandled during a gss_inquire_context call.\n\n## Package\nkrb5\n\n## Files to modify\n- src/lib/gssapi/spnego/gssapiP_spnego.h\n- src/lib/gssapi/spnego/spnego_mech.c\n\n## Target Source Code\n\n### src/lib/gssapi/spnego/gssapiP_spnego.h\n\n#### region() [lines 64-150]\n```c\n\n/*\n * The Mech OID:\n * { iso(1) org(3) dod(6) internet(1) security(5)\n * mechanism(5) spnego(2) }\n */\n\n#define\tSPNEGO_OID_LENGTH 6\n#define\tSPNEGO_OID \"\\053\\006\\001\\005\\005\\002\"\n\ntypedef void *spnego_token_t;\n\n/* spnego name structure for internal representation. */\ntypedef struct {\n\tgss_OID type;\n\tgss_buffer_t buffer;\n\tgss_OID\tmech_type;\n\tgss_name_t\tmech_name;\n} spnego_name_desc, *spnego_name_t;\n\n/* Structure for credential */\ntypedef struct {\n\tgss_cred_id_t mcred;\t/* mechglue union of obtainable creds */\n\tgss_OID_set neg_mechs;\t/* app-specified list of allowable mechs */\n} spnego_gss_cred_id_rec, *spnego_gss_cred_id_t;\n\n/* Structure for context handle */\ntypedef struct {\n\tOM_uint32\tmagic_num;\n\tgss_buffer_desc DER_mechTypes;\n\tgss_OID internal_mech;\n\tgss_ctx_id_t ctx_handle;\n\tchar *optionStr;\n\tgss_cred_id_t default_cred;\n\tint mic_reqd;\n\tint mic_sent;\n\tint mic_rcvd;\n\tint firstpass;\n\tint mech_complete;\n\tint nego_done;\n\tOM_uint32 ctx_flags;\n\tgss_name_t internal_name;\n\tgss_OID actual_mech;\n} spnego_gss_ctx_id_rec, *spnego_gss_ctx_id_t;\n\n/*\n * The magic number must be less than a standard pagesize\n * to avoid a possible collision with a real address.\n */\n#define\tSPNEGO_MAGIC_ID 0x00000fed\n\n/* SPNEGO oid declarations */\nextern const gss_OID_desc * const gss_mech_spnego;\nextern const gss_OID_set_desc * const gss_mech_set_spnego;\n\n#ifdef DEBUG\n#define\tdsyslog(a) syslog(LOG_DEBUG, a)\n#else\n#define\tdsyslog(a)\n#define\tSPNEGO_STATIC\n#endif\t/* DEBUG */\n\n/*\n * declarations of internal name mechanism functions\n */\n\nOM_uint32 spnego_gss_acquire_cred\n(\n\tOM_uint32 *,\t\t/* minor_status */\n\tgss_name_t,\t\t/* desired_name */\n\tOM_uint32,\t\t/* time_req */\n\tgss_OID_set,\t\t/* desired_mechs */\n\tgss_cred_usage_t,\t/* cred_usage */\n\tgss_cred_id_t *,\t/* output_cred_handle */\n\tgss_OID_set *,\t\t/* actual_mechs */\n\tOM_uint32 *\t\t/* time_rec */\n);\n\nOM_uint32 spnego_gss_release_cred\n(\n\tOM_uint32 *,\t\t/* minor_status */\n\t/* CSTYLED */\n\tgss_cred_id_t\t*\t/* cred_handle */\n);\n\nOM_uint32 spnego_gss_init_sec_context\n(\n```\n\n\n## Upstream Fix\n```diff\nFrom b51b33f2bc5d1497ddf5bd107f791c101695000d Mon Sep 17 00:00:00 2001\nFrom: Nicolas Williams <nico@twosigma.com>\nDate: Mon, 14 Sep 2015 12:27:52 -0400\nSubject: [PATCH] Fix SPNEGO context aliasing bugs [CVE-2015-2695]\n\nThe SPNEGO mechanism currently replaces its context handle with the\nmechanism context handle upon establishment, under the assumption that\nmost GSS functions are only called after context establishment. This\nassumption is incorrect, and can lead to aliasing violations for some\nprograms. Maintain the SPNEGO context structure after context\nestablishment and refer to it in all GSS methods. Add initiate and\nopened flags to the SPNEGO context structure for use in\ngss_inquire_context() prior to context establishment.\n\nCVE-2015-2695:\n\nIn MIT krb5 1.5 and later, applications which call\ngss_inquire_context() on a partially-established SPNEGO context can\ncause the GSS-API library to read from a pointer using the wrong type,\ngenerally causing a process crash. This bug may go unnoticed, because\nthe most common SPNEGO authentication scenario establishes the context\nafter just one call to gss_accept_sec_context(). Java server\napplications using the native JGSS provider are vulnerable to this\nbug. A carefully crafted SPNEGO packet might allow the\ngss_inquire_context() call to succeed with attacker-determined\nresults, but applications should not make access control decisions\nbased on gss_inquire_context() results prior to context establishment.\n\n CVSSv2 Vector: AV:N/AC:M/Au:N/C:N/I:N/A:C/E:POC/RL:OF/RC:C\n\n[ghudson@mit.edu: several bugfixes, style changes, and edge-case\nbehavior changes; commit message and CVE description]\n\nticket: 8244\ntarget_version: 1.14\ntags: pullup\n\ndiff --git a/src/lib/gssapi/spnego/gssapiP_spnego.h b/src/lib/gssapi/spnego/gssapiP_spnego.h\nindex 57372de..5c82764 100644\n--- a/src/lib/gssapi/spnego/gssapiP_spnego.h\n+++ b/src/lib/gssapi/spnego/gssapiP_spnego.h\n@@ -103,6 +103,8 @@ typedef struct {\n \tint firstpass;\n \tint mech_complete;\n \tint nego_done;\n+\tint initiate;\n+\tint opened;\n \tOM_uint32 ctx_flags;\n \tgss_name_t internal_name;\n \tgss_OID actual_mech;\ndiff --git a/src/lib/gssapi/spnego/spnego_mech.c b/src/lib/gssapi/spnego/spnego_mech.c\nindex ef76e1f..7849c85 100644\n--- a/src/lib/gssapi/spnego/spnego_mech.c\n+++ b/src/lib/gssapi/spnego/spnego_mech.c\n@@ -102,7 +102,7 @@ static OM_uint32 get_negotiable_mechs(OM_uint32 *, spnego_gss_cred_id_t,\n \t\t\t\t gss_cred_usage_t, gss_OID_set *);\n static void release_spnego_ctx(spnego_gss_ctx_id_t *);\n static void check_spnego_options(spnego_gss_ctx_id_t);\n-static spnego_gss_ctx_id_t create_spnego_ctx(void);\n+static spnego_gss_ctx_id_t create_spnego_ctx(int);\n static int put_mech_set(gss_OID_set mechSet, gss_buffer_t buf);\n static int put_input_token(unsigned char **, gss_buffer_t, unsigned int);\n static int put_mech_oid(unsigned char **, gss_OID_const, unsigned int);\n@@ -454,7 +454,7 @@ check_spnego_options(spnego_gss_ctx_id_t spnego_ctx)\n }\n \n static spnego_gss_ctx_id_t\n-create_spnego_ctx(void)\n+create_spnego_ctx(int initiate)\n {\n \tspnego_gss_ctx_id_t spnego_ctx = NULL;\n \tspnego_ctx = (spnego_gss_ctx_id_t)\n@@ -477,6 +477,8 @@ create_spnego_ctx(void)\n \tspnego_ctx->mic_rcvd = 0;\n \tspnego_ctx->mech_complete = 0;\n \tspnego_ctx->nego_done = 0;\n+\tspnego_ctx->opened = 0;\n+\tspnego_ctx->initiate = initiate;\n \tspnego_ctx->internal_name = GSS_C_NO_NAME;\n \tspnego_ctx->actual_mech = GSS_C_NO_OID;\n \n@@ -642,7 +644,7 @@ init_ctx_new(OM_uint32 *minor_status,\n \tOM_uint32 ret;\n \tspnego_gss_ctx_id_t sc = NULL;\n \n-\tsc = create_spnego_ctx();\n+\tsc = create_spnego_ctx(1);\n \tif (sc == NULL)\n \t\treturn GSS_S_FAILURE;\n \n@@ -659,10 +661,7 @@ init_ctx_new(OM_uint32 *minor_status,\n \t\tret = GSS_S_FAILURE;\n \t\tgoto cleanup;\n \t}\n-\t/*\n-\t * The actual context is not yet determined, set the output\n-\t * context handle to refer to the spnego context itself.\n-\t */\n+\n \tsc->ctx_handle = GSS_C_NO_CONTEXT;\n \t*ctx = (gss_ctx_id_t)sc;\n \tsc = NULL;\n@@ -1108,16 +1107,11 @@ cleanup:\n \t}\n \tgss_release_buffer(&tmpmin, &mechtok_out);\n \tif (ret == GSS_S_COMPLETE) {\n-\t\t/*\n-\t\t * Now, switch the output context to refer to the\n-\t\t * negotiated mechanism's context.\n-\t\t */\n-\t\t*context_handle = (gss_ctx_id_t)spnego_ctx->ctx_handle;\n+\t\tspnego_ctx->opened = 1;\n \t\tif (actual_mech != NULL)\n \t\t\t*actual_mech = spnego_ctx->actual_mech;\n \t\tif (ret_flags != NULL)\n \t\t\t*ret_flags = spnego_ctx->ctx_flags;\n-\t\trelease_spnego_ctx(&spnego_ctx);\n \t} else if (ret != GSS_S_CONTINUE_NEEDED) {\n \t\tif (spnego_ctx != NULL) {\n \t\t\tgss_delete_sec_context(&tmpmin,\n@@ -1285,7 +1279,7 @@ acc_ctx_hints(OM_uint32 *minor_status,\n \tif (ret != GSS_S_COMPLETE)\n \t\tgoto cleanup;\n \n-\tsc = create_spnego_ctx();\n+\tsc = create_spnego_ctx(0);\n \tif (sc == NULL) {\n \t\tret = GSS_S_FAILURE;\n \t\tgoto cleanup;\n@@ -1367,7 +1361,7 @@ acc_ctx_new(OM_uint32 *minor_status,\n \t\tgss_release_buffer(&tmpmin, &sc->DER_mechTypes);\n \t\tassert(mech_wanted != GSS_C_NO_OID);\n \t} else\n-\t\tsc = create_spnego_ctx();\n+\t\tsc = create_spnego_ctx(0);\n \tif (sc == NULL) {\n \t\tret = GSS_S_FAILURE;\n \t\t*return_token = NO_TOKEN_SEND;\n@@ -1750,13 +1744,12 @@ cleanup:\n \t\t\tret = GSS_S_FAILURE;\n \t}\n \tif (ret == GSS_S_COMPLETE) {\n-\t\t*context_handle = (gss_ctx_id_t)sc->ctx_handle;\n+\t\tsc->opened = 1;\n \t\tif (sc->internal_name != GSS_C_NO_NAME &&\n \t\t src_name != NULL) {\n \t\t\t*src_name = sc->internal_name;\n \t\t\tsc->internal_name = GSS_C_NO_NAME;\n \t\t}\n-\t\trelease_spnego_ctx(&sc);\n \t} else if (ret != GSS_S_CONTINUE_NEEDED) {\n \t\tif (sc != NULL) {\n \t\t\tgss_delete_sec_context(&tmpmin, &sc->ctx_handle,\n@@ -2069,8 +2062,13 @@ spnego_gss_unwrap(\n \t\tgss_qop_t *qop_state)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+\tif (sc->ctx_handle == GSS_C_NO_CONTEXT)\n+\t\treturn (GSS_S_NO_CONTEXT);\n+\n \tret = gss_unwrap(minor_status,\n-\t\t\tcontext_handle,\n+\t\t\tsc->ctx_handle,\n \t\t\tinput_message_buffer,\n \t\t\toutput_message_buffer,\n \t\t\tconf_state,\n@@ -2090,8 +2088,13 @@ spnego_gss_wrap(\n \t\tgss_buffer_t output_message_buffer)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+\tif (sc->ctx_handle == GSS_C_NO_CONTEXT)\n+\t\treturn (GSS_S_NO_CONTEXT);\n+\n \tret = gss_wrap(minor_status,\n-\t\t context_handle,\n+\t\t sc->ctx_handle,\n \t\t conf_req_flag,\n \t\t qop_req,\n \t\t input_message_buffer,\n@@ -2108,8 +2111,14 @@ spnego_gss_process_context_token(\n \t\t\t\tconst gss_buffer_t token_buffer)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+\t/* SPNEGO doesn't have its own context tokens. */\n+\tif (!sc->opened)\n+\t\treturn (GSS_S_DEFECTIVE_TOKEN);\n+\n \tret = gss_process_context_token(minor_status,\n-\t\t\t\t\tcontext_handle,\n+\t\t\t\t\tsc->ctx_handle,\n \t\t\t\t\ttoken_buffer);\n \n \treturn (ret);\n@@ -2133,19 +2142,9 @@ spnego_gss_delete_sec_context(\n \tif (*ctx == NULL)\n \t\treturn (GSS_S_COMPLETE);\n \n-\t/*\n-\t * If this is still an SPNEGO mech, release it locally.\n-\t */\n-\tif ((*ctx)->magic_num == SPNEGO_MAGIC_ID) {\n-\t\t(void) gss_delete_sec_context(minor_status,\n-\t\t\t\t &(*ctx)->ctx_handle,\n-\t\t\t\t output_token);\n-\t\t(void) release_spnego_ctx(ctx);\n-\t} else {\n-\t\tret = gss_delete_sec_context(minor_status,\n-\t\t\t\t context_handle,\n-\t\t\t\t output_token);\n-\t}\n+\t(void) gss_delete_sec_context(minor_status, &(*ctx)->ctx_handle,\n+\t\t\t\t output_token);\n+\t(void) release_spnego_ctx(ctx);\n \n \treturn (ret);\n }\n@@ -2157,8 +2156,13 @@ spnego_gss_context_time(\n \t\t\tOM_uint32\t*time_rec)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+\tif (sc->ctx_handle == GSS_C_NO_CONTEXT)\n+\t\treturn (GSS_S_NO_CONTEXT);\n+\n \tret = gss_context_time(minor_status,\n-\t\t\t context_handle,\n+\t\t\t sc->ctx_handle,\n \t\t\t time_rec);\n \treturn (ret);\n }\n@@ -2170,9 +2174,20 @@ spnego_gss_export_sec_context(\n \t\t\t gss_buffer_t interprocess_token)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = *(spnego_gss_ctx_id_t *)context_handle;\n+\n+\t/* We don't currently support exporting partially established\n+\t * contexts. */\n+\tif (!sc->opened)\n+\t\treturn GSS_S_UNAVAILABLE;\n+\n \tret = gss_export_sec_conte\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From b51b33f2bc5d1497ddf5bd107f791c101695000d Mon Sep 17 00:00:00 2001\nFrom: Nicolas Williams <nico@twosigma.com>\nDate: Mon, 14 Sep 2015 12:27:52 -0400\nSubject: [PATCH] Fix SPNEGO context aliasing bugs [CVE-2015-2695]\n\nThe SPNEGO mechanism currently replaces its context handle with the\nmechanism context handle upon establishment, under the assumption that\nmost GSS functions are only called after context establishment. This\nassumption is incorrect, and can lead to aliasing violations for some\nprograms. Maintain the SPNEGO context structure after context\nestablishment and refer to it in all GSS methods. Add initiate and\nopened flags to the SPNEGO context structure for use in\ngss_inquire_context() prior to context establishment.\n\nCVE-2015-2695:\n\nIn MIT krb5 1.5 and later, applications which call\ngss_inquire_context() on a partially-established SPNEGO context can\ncause the GSS-API library to read from a pointer using the wrong type,\ngenerally causing a process crash. This bug may go unnoticed, because\nthe most common SPNEGO authentication scenario establishes the context\nafter just one call to gss_accept_sec_context(). Java server\napplications using the native JGSS provider are vulnerable to this\nbug. A carefully crafted SPNEGO packet might allow the\ngss_inquire_context() call to succeed with attacker-determined\nresults, but applications should not make access control decisions\nbased on gss_inquire_context() results prior to context establishment.\n\n CVSSv2 Vector: AV:N/AC:M/Au:N/C:N/I:N/A:C/E:POC/RL:OF/RC:C\n\n[ghudson@mit.edu: several bugfixes, style changes, and edge-case\nbehavior changes; commit message and CVE description]\n\nticket: 8244\ntarget_version: 1.14\ntags: pullup\n\ndiff --git a/src/lib/gssapi/spnego/gssapiP_spnego.h b/src/lib/gssapi/spnego/gssapiP_spnego.h\nindex 57372de..5c82764 100644\n--- a/src/lib/gssapi/spnego/gssapiP_spnego.h\n+++ b/src/lib/gssapi/spnego/gssapiP_spnego.h\n@@ -103,6 +103,8 @@ typedef struct {\n \tint firstpass;\n \tint mech_complete;\n \tint nego_done;\n+\tint initiate;\n+\tint opened;\n \tOM_uint32 ctx_flags;\n \tgss_name_t internal_name;\n \tgss_OID actual_mech;\ndiff --git a/src/lib/gssapi/spnego/spnego_mech.c b/src/lib/gssapi/spnego/spnego_mech.c\nindex ef76e1f..7849c85 100644\n--- a/src/lib/gssapi/spnego/spnego_mech.c\n+++ b/src/lib/gssapi/spnego/spnego_mech.c\n@@ -102,7 +102,7 @@ static OM_uint32 get_negotiable_mechs(OM_uint32 *, spnego_gss_cred_id_t,\n \t\t\t\t gss_cred_usage_t, gss_OID_set *);\n static void release_spnego_ctx(spnego_gss_ctx_id_t *);\n static void check_spnego_options(spnego_gss_ctx_id_t);\n-static spnego_gss_ctx_id_t create_spnego_ctx(void);\n+static spnego_gss_ctx_id_t create_spnego_ctx(int);\n static int put_mech_set(gss_OID_set mechSet, gss_buffer_t buf);\n static int put_input_token(unsigned char **, gss_buffer_t, unsigned int);\n static int put_mech_oid(unsigned char **, gss_OID_const, unsigned int);\n@@ -454,7 +454,7 @@ check_spnego_options(spnego_gss_ctx_id_t spnego_ctx)\n }\n \n static spnego_gss_ctx_id_t\n-create_spnego_ctx(void)\n+create_spnego_ctx(int initiate)\n {\n \tspnego_gss_ctx_id_t spnego_ctx = NULL;\n \tspnego_ctx = (spnego_gss_ctx_id_t)\n@@ -477,6 +477,8 @@ create_spnego_ctx(void)\n \tspnego_ctx->mic_rcvd = 0;\n \tspnego_ctx->mech_complete = 0;\n \tspnego_ctx->nego_done = 0;\n+\tspnego_ctx->opened = 0;\n+\tspnego_ctx->initiate = initiate;\n \tspnego_ctx->internal_name = GSS_C_NO_NAME;\n \tspnego_ctx->actual_mech = GSS_C_NO_OID;\n \n@@ -642,7 +644,7 @@ init_ctx_new(OM_uint32 *minor_status,\n \tOM_uint32 ret;\n \tspnego_gss_ctx_id_t sc = NULL;\n \n-\tsc = create_spnego_ctx();\n+\tsc = create_spnego_ctx(1);\n \tif (sc == NULL)\n \t\treturn GSS_S_FAILURE;\n \n@@ -659,10 +661,7 @@ init_ctx_new(OM_uint32 *minor_status,\n \t\tret = GSS_S_FAILURE;\n \t\tgoto cleanup;\n \t}\n-\t/*\n-\t * The actual context is not yet determined, set the output\n-\t * context handle to refer to the spnego context itself.\n-\t */\n+\n \tsc->ctx_handle = GSS_C_NO_CONTEXT;\n \t*ctx = (gss_ctx_id_t)sc;\n \tsc = NULL;\n@@ -1108,16 +1107,11 @@ cleanup:\n \t}\n \tgss_release_buffer(&tmpmin, &mechtok_out);\n \tif (ret == GSS_S_COMPLETE) {\n-\t\t/*\n-\t\t * Now, switch the output context to refer to the\n-\t\t * negotiated mechanism's context.\n-\t\t */\n-\t\t*context_handle = (gss_ctx_id_t)spnego_ctx->ctx_handle;\n+\t\tspnego_ctx->opened = 1;\n \t\tif (actual_mech != NULL)\n \t\t\t*actual_mech = spnego_ctx->actual_mech;\n \t\tif (ret_flags != NULL)\n \t\t\t*ret_flags = spnego_ctx->ctx_flags;\n-\t\trelease_spnego_ctx(&spnego_ctx);\n \t} else if (ret != GSS_S_CONTINUE_NEEDED) {\n \t\tif (spnego_ctx != NULL) {\n \t\t\tgss_delete_sec_context(&tmpmin,\n@@ -1285,7 +1279,7 @@ acc_ctx_hints(OM_uint32 *minor_status,\n \tif (ret != GSS_S_COMPLETE)\n \t\tgoto cleanup;\n \n-\tsc = create_spnego_ctx();\n+\tsc = create_spnego_ctx(0);\n \tif (sc == NULL) {\n \t\tret = GSS_S_FAILURE;\n \t\tgoto cleanup;\n@@ -1367,7 +1361,7 @@ acc_ctx_new(OM_uint32 *minor_status,\n \t\tgss_release_buffer(&tmpmin, &sc->DER_mechTypes);\n \t\tassert(mech_wanted != GSS_C_NO_OID);\n \t} else\n-\t\tsc = create_spnego_ctx();\n+\t\tsc = create_spnego_ctx(0);\n \tif (sc == NULL) {\n \t\tret = GSS_S_FAILURE;\n \t\t*return_token = NO_TOKEN_SEND;\n@@ -1750,13 +1744,12 @@ cleanup:\n \t\t\tret = GSS_S_FAILURE;\n \t}\n \tif (ret == GSS_S_COMPLETE) {\n-\t\t*context_handle = (gss_ctx_id_t)sc->ctx_handle;\n+\t\tsc->opened = 1;\n \t\tif (sc->internal_name != GSS_C_NO_NAME &&\n \t\t src_name != NULL) {\n \t\t\t*src_name = sc->internal_name;\n \t\t\tsc->internal_name = GSS_C_NO_NAME;\n \t\t}\n-\t\trelease_spnego_ctx(&sc);\n \t} else if (ret != GSS_S_CONTINUE_NEEDED) {\n \t\tif (sc != NULL) {\n \t\t\tgss_delete_sec_context(&tmpmin, &sc->ctx_handle,\n@@ -2069,8 +2062,13 @@ spnego_gss_unwrap(\n \t\tgss_qop_t *qop_state)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+\tif (sc->ctx_handle == GSS_C_NO_CONTEXT)\n+\t\treturn (GSS_S_NO_CONTEXT);\n+\n \tret = gss_unwrap(minor_status,\n-\t\t\tcontext_handle,\n+\t\t\tsc->ctx_handle,\n \t\t\tinput_message_buffer,\n \t\t\toutput_message_buffer,\n \t\t\tconf_state,\n@@ -2090,8 +2088,13 @@ spnego_gss_wrap(\n \t\tgss_buffer_t output_message_buffer)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+\tif (sc->ctx_handle == GSS_C_NO_CONTEXT)\n+\t\treturn (GSS_S_NO_CONTEXT);\n+\n \tret = gss_wrap(minor_status,\n-\t\t context_handle,\n+\t\t sc->ctx_handle,\n \t\t conf_req_flag,\n \t\t qop_req,\n \t\t input_message_buffer,\n@@ -2108,8 +2111,14 @@ spnego_gss_process_context_token(\n \t\t\t\tconst gss_buffer_t token_buffer)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+\t/* SPNEGO doesn't have its own context tokens. */\n+\tif (!sc->opened)\n+\t\treturn (GSS_S_DEFECTIVE_TOKEN);\n+\n \tret = gss_process_context_token(minor_status,\n-\t\t\t\t\tcontext_handle,\n+\t\t\t\t\tsc->ctx_handle,\n \t\t\t\t\ttoken_buffer);\n \n \treturn (ret);\n@@ -2133,19 +2142,9 @@ spnego_gss_delete_sec_context(\n \tif (*ctx == NULL)\n \t\treturn (GSS_S_COMPLETE);\n \n-\t/*\n-\t * If this is still an SPNEGO mech, release it locally.\n-\t */\n-\tif ((*ctx)->magic_num == SPNEGO_MAGIC_ID) {\n-\t\t(void) gss_delete_sec_context(minor_status,\n-\t\t\t\t &(*ctx)->ctx_handle,\n-\t\t\t\t output_token);\n-\t\t(void) release_spnego_ctx(ctx);\n-\t} else {\n-\t\tret = gss_delete_sec_context(minor_status,\n-\t\t\t\t context_handle,\n-\t\t\t\t output_token);\n-\t}\n+\t(void) gss_delete_sec_context(minor_status, &(*ctx)->ctx_handle,\n+\t\t\t\t output_token);\n+\t(void) release_spnego_ctx(ctx);\n \n \treturn (ret);\n }\n@@ -2157,8 +2156,13 @@ spnego_gss_context_time(\n \t\t\tOM_uint32\t*time_rec)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+\tif (sc->ctx_handle == GSS_C_NO_CONTEXT)\n+\t\treturn (GSS_S_NO_CONTEXT);\n+\n \tret = gss_context_time(minor_status,\n-\t\t\t context_handle,\n+\t\t\t sc->ctx_handle,\n \t\t\t time_rec);\n \treturn (ret);\n }\n@@ -2170,9 +2174,20 @@ spnego_gss_export_sec_context(\n \t\t\t gss_buffer_t interprocess_token)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = *(spnego_gss_ctx_id_t *)context_handle;\n+\n+\t/* We don't currently support exporting partially established\n+\t * contexts. */\n+\tif (!sc->opened)\n+\t\treturn GSS_S_UNAVAILABLE;\n+\n \tret = gss_export_sec_context(minor_status,\n-\t\t\t\t context_handle,\n+\t\t\t\t &sc->ctx_handle,\n \t\t\t\t interprocess_token);\n+\tif (sc->ctx_handle == GSS_C_NO_CONTEXT) {\n+\t\trelease_spnego_ctx(&sc);\n+\t\t*context_handle = GSS_C_NO_CONTEXT;\n+\t}\n \treturn (ret);\n }\n \n@@ -2182,11 +2197,12 @@ spnego_gss_import_sec_context(\n \tconst gss_buffer_t\tinterprocess_token,\n \tgss_ctx_id_t\t\t*context_handle)\n {\n-\tOM_uint32 ret;\n-\tret = gss_import_sec_context(minor_status,\n-\t\t\t\t interprocess_token,\n-\t\t\t\t context_handle);\n-\treturn (ret);\n+\t/*\n+\t * Until we implement partial context exports, there are no SPNEGO\n+\t * exported context tokens, only tokens for underlying mechs. So just\n+\t * return an error for now.\n+\t */\n+\treturn GSS_S_UNAVAILABLE;\n }\n #endif /* LEAN_CLIENT */\n \n@@ -2203,16 +2219,48 @@ spnego_gss_inquire_context(\n \t\t\tint\t\t*opened)\n {\n \tOM_uint32 ret = GSS_S_COMPLETE;\n+\tspnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+\tif (src_name != NULL)\n+\t\t*src_name = GSS_C_NO_NAME;\n+\tif (targ_name != NULL)\n+\t\t*targ_name = GSS_C_NO_NAME;\n+\tif (lifetime_rec != NULL)\n+\t\t*lifetime_rec = 0;\n+\tif (mech_type != NULL)\n+\t\t*mech_type = (gss_OID)gss_mech_spnego;\n+\tif (ctx_flags != NULL)\n+\t\t*ctx_flags = 0;\n+\tif (locally_initiated != NULL)\n+\t\t*locally_initiated = sc->initiate;\n+\tif (opened != NULL)\n+\t\t*opened = sc->opened;\n+\n+\tif (sc->ctx_handle != GSS_C_NO_CONTEXT) {\n+\t\tret = gss_inquire_context(minor_status, sc->ctx_handle,\n+\t\t\t\t\t src_name, targ_name, lifetime_rec,\n+\t\t\t\t\t mech_type, ctx_flags, NULL, NULL);\n+\t}\n \n-\tret = gss_inquire_context(minor_status,\n-\t\t\t\tcontext_handle,\n-\t\t\t\tsrc_name,\n-\t\t\t\ttarg_name,\n-\t\t\t\tlifetime_rec,\n-\t\t\t\tmech_type,\n-\t\t\t\tctx_flags,\n-\t\t\t\tlocally_initiated,\n-\t\t\t\topened);\n+\tif (!sc->opened) {\n+\t\t/*\n+\t\t * We are still doing SPNEGO negotiation, so report SPNEGO as\n+\t\t * the OID. After negotiation is complete we will report the\n+\t\t * underlying mechanism OID.\n+\t\t */\n+\t\tif (mech_type != NULL)\n+\t\t\t*mech_type = (gss_OID)gss_mech_spnego;\n+\n+\t\t/*\n+\t\t * Remove flags we don't support with partially-established\n+\t\t * contexts. (Change this to keep GSS_C_TRANS_FLAG if we add\n+\t\t * support for exporting partial SPNEGO contexts.)\n+\t\t */\n+\t\tif (ctx_flags != NULL) {\n+\t\t\t*ctx_flags &= ~GSS_C_PROT_READY_FLAG;\n+\t\t\t*ctx_flags &= ~GSS_C_TRANS_FLAG;\n+\t\t}\n+\t}\n \n \treturn (ret);\n }\n@@ -2227,8 +2275,13 @@ spnego_gss_wrap_size_limit(\n \tOM_uint32\t*max_input_size)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+\tif (sc->ctx_handle == GSS_C_NO_CONTEXT)\n+\t\treturn (GSS_S_NO_CONTEXT);\n+\n \tret = gss_wrap_size_limit(minor_status,\n-\t\t\t\tcontext_handle,\n+\t\t\t\tsc->ctx_handle,\n \t\t\t\tconf_req_flag,\n \t\t\t\tqop_req,\n \t\t\t\treq_output_size,\n@@ -2245,8 +2298,13 @@ spnego_gss_get_mic(\n \t\tgss_buffer_t message_token)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+\tif (sc->ctx_handle == GSS_C_NO_CONTEXT)\n+\t\treturn (GSS_S_NO_CONTEXT);\n+\n \tret = gss_get_mic(minor_status,\n-\t\t context_handle,\n+\t\t sc->ctx_handle,\n \t\t qop_req,\n \t\t message_buffer,\n \t\t message_token);\n@@ -2262,8 +2320,13 @@ spnego_gss_verify_mic(\n \t\tgss_qop_t *qop_state)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+\tif (sc->ctx_handle == GSS_C_NO_CONTEXT)\n+\t\treturn (GSS_S_NO_CONTEXT);\n+\n \tret = gss_verify_mic(minor_status,\n-\t\t\t context_handle,\n+\t\t\t sc->ctx_handle,\n \t\t\t msg_buffer,\n \t\t\t token_buffer,\n \t\t\t qop_state);\n@@ -2278,8 +2341,14 @@ spnego_gss_inquire_sec_context_by_oid(\n \t\tgss_buffer_set_t *data_set)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+\t/* There are no SPNEGO-specific OIDs for this function. */\n+\tif (sc->ctx_handle == GSS_C_NO_CONTEXT)\n+\t\treturn (GSS_S_UNAVAILABLE);\n+\n \tret = gss_inquire_sec_context_by_oid(minor_status,\n-\t\t\t context_handle,\n+\t\t\t sc->ctx_handle,\n \t\t\t desired_object,\n \t\t\t data_set);\n \treturn (ret);\n@@ -2359,8 +2428,15 @@ spnego_gss_set_sec_context_option(\n \t\tconst gss_buffer_t value)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)*context_handle;\n+\n+\t/* There are no SPNEGO-specific OIDs for this function, and we cannot\n+\t * construct an empty SPNEGO context with it. */\n+\tif (sc == NULL || sc->ctx_handle == GSS_C_NO_CONTEXT)\n+\t\treturn (GSS_S_UNAVAILABLE);\n+\n \tret = gss_set_sec_context_option(minor_status,\n-\t\t\t context_handle,\n+\t\t\t &sc->ctx_handle,\n \t\t\t desired_object,\n \t\t\t value);\n \treturn (ret);\n@@ -2377,8 +2453,13 @@ spnego_gss_wrap_aead(OM_uint32 *minor_status,\n \t\t gss_buffer_t output_message_buffer)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+\tif (sc->ctx_handle == GSS_C_NO_CONTEXT)\n+\t\treturn (GSS_S_NO_CONTEXT);\n+\n \tret = gss_wrap_aead(minor_status,\n-\t\t\t context_handle,\n+\t\t\t sc->ctx_handle,\n \t\t\t conf_req_flag,\n \t\t\t qop_req,\n \t\t\t input_assoc_buffer,\n@@ -2399,8 +2480,13 @@ spnego_gss_unwrap_aead(OM_uint32 *minor_status,\n \t\t gss_qop_t *qop_state)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+\tif (sc->ctx_handle == GSS_C_NO_CONTEXT)\n+\t\treturn (GSS_S_NO_CONTEXT);\n+\n \tret = gss_unwrap_aead(minor_status,\n-\t\t\t context_handle,\n+\t\t\t sc->ctx_handle,\n \t\t\t input_message_buffer,\n \t\t\t input_assoc_buffer,\n \t\t\t output_payload_buffer,\n@@ -2419,8 +2505,13 @@ spnego_gss_wrap_iov(OM_uint32 *minor_status,\n \t\t int iov_count)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+\tif (sc->ctx_handle == GSS_C_NO_CONTEXT)\n+\t\treturn (GSS_S_NO_CONTEXT);\n+\n \tret = gss_wrap_iov(minor_status,\n-\t\t\t context_handle,\n+\t\t\t sc->ctx_handle,\n \t\t\t conf_req_flag,\n \t\t\t qop_req,\n \t\t\t conf_state,\n@@ -2438,8 +2529,13 @@ spnego_gss_unwrap_iov(OM_uint32 *minor_status,\n \t\t int iov_count)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+\tif (sc->ctx_handle == GSS_C_NO_CONTEXT)\n+\t\treturn (GSS_S_NO_CONTEXT);\n+\n \tret = gss_unwrap_iov(minor_status,\n-\t\t\t context_handle,\n+\t\t\t sc->ctx_handle,\n \t\t\t conf_state,\n \t\t\t qop_state,\n \t\t\t iov,\n@@ -2457,8 +2553,13 @@ spnego_gss_wrap_iov_length(OM_uint32 *minor_status,\n \t\t\t int iov_count)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+\tif (sc->ctx_handle == GSS_C_NO_CONTEXT)\n+\t\treturn (GSS_S_NO_CONTEXT);\n+\n \tret = gss_wrap_iov_length(minor_status,\n-\t\t\t\t context_handle,\n+\t\t\t\t sc->ctx_handle,\n \t\t\t\t conf_req_flag,\n \t\t\t\t qop_req,\n \t\t\t\t conf_state,\n@@ -2475,8 +2576,13 @@ spnego_gss_complete_auth_token(\n \t\tgss_buffer_t input_message_buffer)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+\tif (sc->ctx_handle == GSS_C_NO_CONTEXT)\n+\t\treturn (GSS_S_UNAVAILABLE);\n+\n \tret = gss_complete_auth_token(minor_status,\n-\t\t\t\t context_handle,\n+\t\t\t\t sc->ctx_handle,\n \t\t\t\t input_message_buffer);\n \treturn (ret);\n }\n@@ -2721,8 +2827,13 @@ spnego_gss_pseudo_random(OM_uint32 *minor_status,\n \t\t\t gss_buffer_t prf_out)\n {\n \tOM_uint32 ret;\n+\tspnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context;\n+\n+\tif (sc->ctx_handle == GSS_C_NO_CONTEXT)\n+\t\treturn (GSS_S_NO_CONTEXT);\n+\n \tret = gss_pseudo_random(minor_status,\n-\t\t\t\tcontext,\n+\t\t\t\tsc->ctx_handle,\n \t\t\t\tprf_key,\n \t\t\t\tprf_in,\n \t\t\t\tdesired_output_len,\n@@ -2863,7 +2974,12 @@ spnego_gss_get_mic_iov(OM_uint32 *minor_status, gss_ctx_id_t context_handle,\n \t\t gss_qop_t qop_req, gss_iov_buffer_desc *iov,\n \t\t int iov_count)\n {\n- return gss_get_mic_iov(minor_status, context_handle, qop_req, iov,\n+ spnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+ if (sc->ctx_handle == GSS_C_NO_CONTEXT)\n+\t return (GSS_S_NO_CONTEXT);\n+\n+ return gss_get_mic_iov(minor_status, sc->ctx_handle, qop_req, iov,\n \t\t\t iov_count);\n }\n \n@@ -2872,7 +2988,12 @@ spnego_gss_verify_mic_iov(OM_uint32 *minor_status, gss_ctx_id_t context_handle,\n \t\t\t gss_qop_t *qop_state, gss_iov_buffer_desc *iov,\n \t\t\t int iov_count)\n {\n- return gss_verify_mic_iov(minor_status, context_handle, qop_state, iov,\n+ spnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+ if (sc->ctx_handle == GSS_C_NO_CONTEXT)\n+\t return (GSS_S_NO_CONTEXT);\n+\n+ return gss_verify_mic_iov(minor_status, sc->ctx_handle, qop_state, iov,\n \t\t\t iov_count);\n }\n \n@@ -2881,7 +3002,12 @@ spnego_gss_get_mic_iov_length(OM_uint32 *minor_status,\n \t\t\t gss_ctx_id_t context_handle, gss_qop_t qop_req,\n \t\t\t gss_iov_buffer_desc *iov, int iov_count)\n {\n- return gss_get_mic_iov_length(minor_status, context_handle, qop_req, iov,\n+ spnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;\n+\n+ if (sc->ctx_handle == GSS_C_NO_CONTEXT)\n+\t return (GSS_S_NO_CONTEXT);\n+\n+ return gss_get_mic_iov_length(minor_status, sc->ctx_handle, qop_req, iov,\n \t\t\t\t iov_count);\n }\n \n-- \n2.6.2" } ]
{ "id": "krb5-4168-0102-Fix-SPNEGO-context-aliasi", "cve_id": "CVE-2015-2695", "package": "krb5", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": true, "license": "MIT", "context_tokens_est": 522, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2014-8710\n\nThe decompress_sigcomp_message function in epan/sigcomp-udvm.c in the SigComp UDVM dissector in Wireshark 1.10.x before 1.10.11 allows remote attackers to cause a denial of service (buffer over-read and application crash) via a crafted packet.\n\n## Package\nwireshark\n\n## Files to modify\n- epan/geoip_db.c\n\n## Upstream Fix\n```diff\nIndex: epan/geoip_db.c\n===================================================================\n--- epan/geoip_db.c.orig\t2012-06-05 17:33:40.000000000 +0100\n+++ epan/geoip_db.c\t2012-06-21 21:55:14.000000000 +0100\n@@ -177,6 +177,9 @@ geoip_db_init(void) {\n geoip_dat_scan_dir(geoip_db_paths[i].path);\n }\n }\n+ if (num_geoip_db_paths < 1) {\n+ geoip_dat_scan_dir(\"/var/lib/GeoIP\");\n+ }\n \n /* add fake databases for latitude and longitude (using \"City\" in reality) */\n {\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "Index: epan/geoip_db.c\n===================================================================\n--- epan/geoip_db.c.orig\t2012-06-05 17:33:40.000000000 +0100\n+++ epan/geoip_db.c\t2012-06-21 21:55:14.000000000 +0100\n@@ -177,6 +177,9 @@ geoip_db_init(void) {\n geoip_dat_scan_dir(geoip_db_paths[i].path);\n }\n }\n+ if (num_geoip_db_paths < 1) {\n+ geoip_dat_scan_dir(\"/var/lib/GeoIP\");\n+ }\n \n /* add fake databases for latitude and longitude (using \"City\" in reality) */\n {" } ]
{ "id": "wireshark-3209-wireshark-1.2.0-geoip.patch", "cve_id": "CVE-2014-8710", "package": "wireshark", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": false, "license": "GPL-2.0-or-later AND GPL-3.0-or-later", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-8629\n\nThe xdr_nullstring function in lib/kadm5/kadm_rpc_xdr.c in kadmind in MIT Kerberos 5 (aka krb5) before 1.13.4 and 1.14.x before 1.14.1 does not verify whether '\\0' characters exist as expected, which allows remote authenticated users to obtain sensitive information or cause a denial of service (out-of-bounds read) via a crafted string.\n\n## Package\nkrb5\n\n## Files to modify\n- krb5/src/clients/ksu/main.c\n- krb5/src/clients/ksu/pam.c\n- krb5/src/clients/ksu/pam.h\n\n## Upstream Fix\n```diff\nModify ksu so that it performs account and session management on behalf of\nthe target user account, mimicking the action of regular su. The default\nservice name is \"ksu\", because on Fedora at least the configuration used\nis determined by whether or not a login shell is being opened, and so\nthis may need to vary, too. At run-time, ksu's behavior can be reset to\nthe earlier, non-PAM behavior by setting \"use_pam\" to false in the [ksu]\nsection of /etc/krb5.conf.\n\nWhen enabled, ksu gains a dependency on libpam.\n\nOriginally RT#5939, though it's changed since then to perform the account\nand session management before dropping privileges.\n\ndiff -Naur krb5/src/aclocal.m4 krb5/src/aclocal.m4\n--- krb5/src/aclocal.m4\t2014-01-13 17:12:47.509022000 +0100\n+++ krb5/src/aclocal.m4\t2014-01-13 17:13:24.552689000 +0100\n@@ -1668,3 +1668,70 @@\n ]))\n ])dnl\n dnl\n+dnl\n+dnl Use PAM instead of local crypt() compare for checking local passwords,\n+dnl and perform PAM account, session management, and password-changing where\n+dnl appropriate.\n+dnl \n+AC_DEFUN(KRB5_WITH_PAM,[\n+AC_ARG_WITH(pam,[AC_HELP_STRING(--with-pam,[compile with PAM support])],\n+\t withpam=\"$withval\",withpam=auto)\n+AC_ARG_WITH(pam-ksu-service,[AC_HELP_STRING(--with-ksu-service,[PAM service name for ksu [\"ksu\"]])],\n+\t withksupamservice=\"$withval\",withksupamservice=ksu)\n+old_LIBS=\"$LIBS\"\n+if test \"$withpam\" != no ; then\n+\tAC_MSG_RESULT([checking for PAM...])\n+\tPAM_LIBS=\n+\n+\tAC_CHECK_HEADERS(security/pam_appl.h)\n+\tif test \"x$ac_cv_header_security_pam_appl_h\" != xyes ; then\n+\t\tif test \"$withpam\" = auto ; then\n+\t\t\tAC_MSG_RESULT([Unable to locate security/pam_appl.h.])\n+\t\t\twithpam=no\n+\t\telse\n+\t\t\tAC_MSG_ERROR([Unable to locate security/pam_appl.h.])\n+\t\tfi\n+\tfi\n+\n+\tLIBS=\n+\tunset ac_cv_func_pam_start\n+\tAC_CHECK_FUNCS(putenv pam_start)\n+\tif test \"x$ac_cv_func_pam_start\" = xno ; then\n+\t\tunset ac_cv_func_pam_start\n+\t\tAC_CHECK_LIB(dl,dlopen)\n+\t\tAC_CHECK_FUNCS(pam_start)\n+\t\tif test \"x$ac_cv_func_pam_start\" = xno ; then\n+\t\t\tAC_CHECK_LIB(pam,pam_start)\n+\t\t\tunset ac_cv_func_pam_start\n+\t\t\tunset ac_cv_func_pam_getenvlist\n+\t\t\tAC_CHECK_FUNCS(pam_start pam_getenvlist)\n+\t\t\tif test \"x$ac_cv_func_pam_start\" = xyes ; then\n+\t\t\t\tPAM_LIBS=\"$LIBS\"\n+\t\t\telse\n+\t\t\t\tif test \"$withpam\" = auto ; then\n+\t\t\t\t\tAC_MSG_RESULT([Unable to locate libpam.])\n+\t\t\t\t\twithpam=no\n+\t\t\t\telse\n+\t\t\t\t\tAC_MSG_ERROR([Unable to locate libpam.])\n+\t\t\t\tfi\n+\t\t\tfi\n+\t\tfi\n+\tfi\n+\tif test \"$withpam\" != no ; then\n+\t\tAC_MSG_NOTICE([building with PAM support])\n+\t\tAC_DEFINE(USE_PAM,1,[Define if Kerberos-aware tools should support PAM])\n+\t\tAC_DEFINE_UNQUOTED(KSU_PAM_SERVICE,\"$withksupamservice\",\n+\t\t\t\t [Define to the name of the PAM service name to be used by ksu.])\n+\t\tPAM_LIBS=\"$LIBS\"\n+\t\tNON_PAM_MAN=\".\\\\\\\" \"\n+\t\tPAM_MAN=\n+\telse\n+\t\tPAM_MAN=\".\\\\\\\" \"\n+\t\tNON_PAM_MAN=\n+\tfi\n+fi\n+LIBS=\"$old_LIBS\"\n+AC_SUBST(PAM_LIBS)\n+AC_SUBST(PAM_MAN)\n+AC_SUBST(NON_PAM_MAN)\n+])dnl\ndiff -Naur krb5/src/clients/ksu/main.c krb5/src/clients/ksu/main.c\n--- krb5/src/clients/ksu/main.c\t2014-01-13 17:12:44.864970000 +0100\n+++ krb5/src/clients/ksu/main.c\t2014-01-13 17:13:24.563692000 +0100\n@@ -26,6 +26,7 @@\n * KSU was writen by: Ari Medvinsky, ari@isi.edu\n */\n \n+#include \"autoconf.h\"\n #include \"ksu.h\"\n #include \"adm_proto.h\"\n #include <sys/types.h>\n@@ -33,6 +34,10 @@\n #include <signal.h>\n #include <grp.h>\n \n+#ifdef USE_PAM\n+#include \"pam.h\"\n+#endif\n+\n /* globals */\n char * prog_name;\n int auth_debug =0;\n@@ -40,6 +45,7 @@\n char k5users_path[MAXPATHLEN];\n char * gb_err = NULL;\n int quiet = 0;\n+int force_fork = 0;\n /***********/\n \n #define _DEF_CSH \"/bin/csh\"\n@@ -584,6 +590,25 @@\n prog_name,target_user,client_name,\n source_user,ontty());\n \n+#ifdef USE_PAM\n+ if (appl_pam_enabled(ksu_context, \"ksu\")) {\n+ if (appl_pam_acct_mgmt(KSU_PAM_SERVICE, 1, target_user, NULL,\n+ NULL, source_user,\n+ ttyname(STDERR_FILENO)) != 0) {\n+ fprintf(stderr, \"Access denied for %s.\\n\", target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+ if (appl_pam_requires_chauthtok()) {\n+ fprintf(stderr, \"Password change required for %s.\\n\",\n+ target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+ force_fork++;\n+ }\n+#endif\n+\n /* Run authorization as target.*/\n if (krb5_seteuid(target_uid)) {\n com_err(prog_name, errno, _(\"while switching to target for \"\n@@ -648,6 +673,26 @@\n sweep_up(ksu_context, cc_target);\n exit(1);\n }\n+#ifdef USE_PAM\n+ } else {\n+ /* we always do PAM account management, even for root */\n+ if (appl_pam_enabled(ksu_context, \"ksu\")) {\n+ if (appl_pam_acct_mgmt(KSU_PAM_SERVICE, 1, target_user, NULL,\n+ NULL, source_user,\n+ ttyname(STDERR_FILENO)) != 0) {\n+ fprintf(stderr, \"Access denied for %s.\\n\", target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+ if (appl_pam_requires_chauthtok()) {\n+ fprintf(stderr, \"Password change required for %s.\\n\",\n+ target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+ force_fork++;\n+ }\n+#endif\n }\n \n if( some_rest_copy){\n@@ -717,6 +762,32 @@\n exit(1);\n }\n \n+#ifdef USE_PAM\n+ if (appl_pam_enabled(ksu_context, \"ksu\")) {\n+ if (appl_pam_session_open() != 0) {\n+ fprintf(stderr, \"Error opening session for %s.\\n\", target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+#ifdef DEBUG\n+ if (auth_debug){\n+ printf(\" Opened PAM session.\\n\");\n+ }\n+#endif\n+ if (appl_pam_cred_init()) {\n+ fprintf(stderr, \"Error initializing credentials for %s.\\n\",\n+ target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+#ifdef DEBUG\n+ if (auth_debug){\n+ printf(\" Initialized PAM credentials.\\n\");\n+ }\n+#endif\n+ }\n+#endif\n+\n /* set permissions */\n if (setgid(target_pwd->pw_gid) < 0) {\n perror(\"ksu: setgid\");\n@@ -789,7 +860,7 @@\n fprintf(stderr, \"program to be execed %s\\n\",params[0]);\n }\n \n- if( keep_target_cache ) {\n+ if( keep_target_cache && !force_fork ) {\n execv(params[0], params);\n com_err(prog_name, errno, _(\"while trying to execv %s\"), params[0]);\n sweep_up(ksu_context, cc_target);\n@@ -819,16 +890,35 @@\n if (ret_pid == -1) {\n com_err(prog_name, errno, _(\"while calling waitpid\"));\n }\n- sweep_up(ksu_context, cc_target);\n+ if( !keep_target_cache ) {\n+ sweep_up(ksu_context, cc_target);\n+ }\n exit (statusp);\n case -1:\n com_err(prog_name, errno, _(\"while trying to fork.\"));\n sweep_up(ksu_context, cc_target);\n exit (1);\n case 0:\n+#ifdef USE_PAM\n+ if (appl_pam_enabled(ksu_context, \"ksu\")) {\n+ if (appl_pam_setenv() != 0) {\n+ fprintf(stderr, \"Error setting up environment for %s.\\n\",\n+ target_user);\n+ exit (1);\n+ }\n+#ifdef DEBUG\n+ if (auth_debug){\n+ printf(\" Set up PAM environment.\\n\");\n+ }\n+#endif\n+ }\n+#endif\n execv(params[0], params);\n com_err(prog_name, errno, _(\"while trying to execv %s\"),\n params[0]);\n+ if( keep_target_cache ) {\n+ sweep_up(ksu_context, cc_target);\n+ }\n exit (1);\n }\n }\ndiff -Naur krb5/src/clients/ksu/Makefil\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "Modify ksu so that it performs account and session management on behalf of\nthe target user account, mimicking the action of regular su. The default\nservice name is \"ksu\", because on Fedora at least the configuration used\nis determined by whether or not a login shell is being opened, and so\nthis may need to vary, too. At run-time, ksu's behavior can be reset to\nthe earlier, non-PAM behavior by setting \"use_pam\" to false in the [ksu]\nsection of /etc/krb5.conf.\n\nWhen enabled, ksu gains a dependency on libpam.\n\nOriginally RT#5939, though it's changed since then to perform the account\nand session management before dropping privileges.\n\ndiff -Naur krb5/src/aclocal.m4 krb5/src/aclocal.m4\n--- krb5/src/aclocal.m4\t2014-01-13 17:12:47.509022000 +0100\n+++ krb5/src/aclocal.m4\t2014-01-13 17:13:24.552689000 +0100\n@@ -1668,3 +1668,70 @@\n ]))\n ])dnl\n dnl\n+dnl\n+dnl Use PAM instead of local crypt() compare for checking local passwords,\n+dnl and perform PAM account, session management, and password-changing where\n+dnl appropriate.\n+dnl \n+AC_DEFUN(KRB5_WITH_PAM,[\n+AC_ARG_WITH(pam,[AC_HELP_STRING(--with-pam,[compile with PAM support])],\n+\t withpam=\"$withval\",withpam=auto)\n+AC_ARG_WITH(pam-ksu-service,[AC_HELP_STRING(--with-ksu-service,[PAM service name for ksu [\"ksu\"]])],\n+\t withksupamservice=\"$withval\",withksupamservice=ksu)\n+old_LIBS=\"$LIBS\"\n+if test \"$withpam\" != no ; then\n+\tAC_MSG_RESULT([checking for PAM...])\n+\tPAM_LIBS=\n+\n+\tAC_CHECK_HEADERS(security/pam_appl.h)\n+\tif test \"x$ac_cv_header_security_pam_appl_h\" != xyes ; then\n+\t\tif test \"$withpam\" = auto ; then\n+\t\t\tAC_MSG_RESULT([Unable to locate security/pam_appl.h.])\n+\t\t\twithpam=no\n+\t\telse\n+\t\t\tAC_MSG_ERROR([Unable to locate security/pam_appl.h.])\n+\t\tfi\n+\tfi\n+\n+\tLIBS=\n+\tunset ac_cv_func_pam_start\n+\tAC_CHECK_FUNCS(putenv pam_start)\n+\tif test \"x$ac_cv_func_pam_start\" = xno ; then\n+\t\tunset ac_cv_func_pam_start\n+\t\tAC_CHECK_LIB(dl,dlopen)\n+\t\tAC_CHECK_FUNCS(pam_start)\n+\t\tif test \"x$ac_cv_func_pam_start\" = xno ; then\n+\t\t\tAC_CHECK_LIB(pam,pam_start)\n+\t\t\tunset ac_cv_func_pam_start\n+\t\t\tunset ac_cv_func_pam_getenvlist\n+\t\t\tAC_CHECK_FUNCS(pam_start pam_getenvlist)\n+\t\t\tif test \"x$ac_cv_func_pam_start\" = xyes ; then\n+\t\t\t\tPAM_LIBS=\"$LIBS\"\n+\t\t\telse\n+\t\t\t\tif test \"$withpam\" = auto ; then\n+\t\t\t\t\tAC_MSG_RESULT([Unable to locate libpam.])\n+\t\t\t\t\twithpam=no\n+\t\t\t\telse\n+\t\t\t\t\tAC_MSG_ERROR([Unable to locate libpam.])\n+\t\t\t\tfi\n+\t\t\tfi\n+\t\tfi\n+\tfi\n+\tif test \"$withpam\" != no ; then\n+\t\tAC_MSG_NOTICE([building with PAM support])\n+\t\tAC_DEFINE(USE_PAM,1,[Define if Kerberos-aware tools should support PAM])\n+\t\tAC_DEFINE_UNQUOTED(KSU_PAM_SERVICE,\"$withksupamservice\",\n+\t\t\t\t [Define to the name of the PAM service name to be used by ksu.])\n+\t\tPAM_LIBS=\"$LIBS\"\n+\t\tNON_PAM_MAN=\".\\\\\\\" \"\n+\t\tPAM_MAN=\n+\telse\n+\t\tPAM_MAN=\".\\\\\\\" \"\n+\t\tNON_PAM_MAN=\n+\tfi\n+fi\n+LIBS=\"$old_LIBS\"\n+AC_SUBST(PAM_LIBS)\n+AC_SUBST(PAM_MAN)\n+AC_SUBST(NON_PAM_MAN)\n+])dnl\ndiff -Naur krb5/src/clients/ksu/main.c krb5/src/clients/ksu/main.c\n--- krb5/src/clients/ksu/main.c\t2014-01-13 17:12:44.864970000 +0100\n+++ krb5/src/clients/ksu/main.c\t2014-01-13 17:13:24.563692000 +0100\n@@ -26,6 +26,7 @@\n * KSU was writen by: Ari Medvinsky, ari@isi.edu\n */\n \n+#include \"autoconf.h\"\n #include \"ksu.h\"\n #include \"adm_proto.h\"\n #include <sys/types.h>\n@@ -33,6 +34,10 @@\n #include <signal.h>\n #include <grp.h>\n \n+#ifdef USE_PAM\n+#include \"pam.h\"\n+#endif\n+\n /* globals */\n char * prog_name;\n int auth_debug =0;\n@@ -40,6 +45,7 @@\n char k5users_path[MAXPATHLEN];\n char * gb_err = NULL;\n int quiet = 0;\n+int force_fork = 0;\n /***********/\n \n #define _DEF_CSH \"/bin/csh\"\n@@ -584,6 +590,25 @@\n prog_name,target_user,client_name,\n source_user,ontty());\n \n+#ifdef USE_PAM\n+ if (appl_pam_enabled(ksu_context, \"ksu\")) {\n+ if (appl_pam_acct_mgmt(KSU_PAM_SERVICE, 1, target_user, NULL,\n+ NULL, source_user,\n+ ttyname(STDERR_FILENO)) != 0) {\n+ fprintf(stderr, \"Access denied for %s.\\n\", target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+ if (appl_pam_requires_chauthtok()) {\n+ fprintf(stderr, \"Password change required for %s.\\n\",\n+ target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+ force_fork++;\n+ }\n+#endif\n+\n /* Run authorization as target.*/\n if (krb5_seteuid(target_uid)) {\n com_err(prog_name, errno, _(\"while switching to target for \"\n@@ -648,6 +673,26 @@\n sweep_up(ksu_context, cc_target);\n exit(1);\n }\n+#ifdef USE_PAM\n+ } else {\n+ /* we always do PAM account management, even for root */\n+ if (appl_pam_enabled(ksu_context, \"ksu\")) {\n+ if (appl_pam_acct_mgmt(KSU_PAM_SERVICE, 1, target_user, NULL,\n+ NULL, source_user,\n+ ttyname(STDERR_FILENO)) != 0) {\n+ fprintf(stderr, \"Access denied for %s.\\n\", target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+ if (appl_pam_requires_chauthtok()) {\n+ fprintf(stderr, \"Password change required for %s.\\n\",\n+ target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+ force_fork++;\n+ }\n+#endif\n }\n \n if( some_rest_copy){\n@@ -717,6 +762,32 @@\n exit(1);\n }\n \n+#ifdef USE_PAM\n+ if (appl_pam_enabled(ksu_context, \"ksu\")) {\n+ if (appl_pam_session_open() != 0) {\n+ fprintf(stderr, \"Error opening session for %s.\\n\", target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+#ifdef DEBUG\n+ if (auth_debug){\n+ printf(\" Opened PAM session.\\n\");\n+ }\n+#endif\n+ if (appl_pam_cred_init()) {\n+ fprintf(stderr, \"Error initializing credentials for %s.\\n\",\n+ target_user);\n+ sweep_up(ksu_context, cc_target);\n+ exit(1);\n+ }\n+#ifdef DEBUG\n+ if (auth_debug){\n+ printf(\" Initialized PAM credentials.\\n\");\n+ }\n+#endif\n+ }\n+#endif\n+\n /* set permissions */\n if (setgid(target_pwd->pw_gid) < 0) {\n perror(\"ksu: setgid\");\n@@ -789,7 +860,7 @@\n fprintf(stderr, \"program to be execed %s\\n\",params[0]);\n }\n \n- if( keep_target_cache ) {\n+ if( keep_target_cache && !force_fork ) {\n execv(params[0], params);\n com_err(prog_name, errno, _(\"while trying to execv %s\"), params[0]);\n sweep_up(ksu_context, cc_target);\n@@ -819,16 +890,35 @@\n if (ret_pid == -1) {\n com_err(prog_name, errno, _(\"while calling waitpid\"));\n }\n- sweep_up(ksu_context, cc_target);\n+ if( !keep_target_cache ) {\n+ sweep_up(ksu_context, cc_target);\n+ }\n exit (statusp);\n case -1:\n com_err(prog_name, errno, _(\"while trying to fork.\"));\n sweep_up(ksu_context, cc_target);\n exit (1);\n case 0:\n+#ifdef USE_PAM\n+ if (appl_pam_enabled(ksu_context, \"ksu\")) {\n+ if (appl_pam_setenv() != 0) {\n+ fprintf(stderr, \"Error setting up environment for %s.\\n\",\n+ target_user);\n+ exit (1);\n+ }\n+#ifdef DEBUG\n+ if (auth_debug){\n+ printf(\" Set up PAM environment.\\n\");\n+ }\n+#endif\n+ }\n+#endif\n execv(params[0], params);\n com_err(prog_name, errno, _(\"while trying to execv %s\"),\n params[0]);\n+ if( keep_target_cache ) {\n+ sweep_up(ksu_context, cc_target);\n+ }\n exit (1);\n }\n }\ndiff -Naur krb5/src/clients/ksu/Makefile.in krb5/src/clients/ksu/Makefile.in\n--- krb5/src/clients/ksu/Makefile.in\t2014-01-13 17:12:44.868981000 +0100\n+++ krb5/src/clients/ksu/Makefile.in\t2014-01-13 17:13:24.580690000 +0100\n@@ -3,12 +3,14 @@\n DEFINES = -DGET_TGT_VIA_PASSWD -DPRINC_LOOK_AHEAD -DCMD_PATH='\"/bin /local/bin\"'\n \n KSU_LIBS=@KSU_LIBS@\n+PAM_LIBS=@PAM_LIBS@\n \n SRCS = \\\n \t$(srcdir)/krb_auth_su.c \\\n \t$(srcdir)/ccache.c \\\n \t$(srcdir)/authorization.c \\\n \t$(srcdir)/main.c \\\n+\t$(srcdir)/pam.c \\\n \t$(srcdir)/heuristic.c \\\n \t$(srcdir)/xmalloc.c \\\n \t$(srcdir)/setenv.c\n@@ -17,13 +19,17 @@\n \tccache.o \\\n \tauthorization.o \\\n \tmain.o \\\n+\tpam.o \\\n \theuristic.o \\\n \txmalloc.o @SETENVOBJ@\n \n all:: ksu\n \n ksu: $(OBJS) $(KRB5_BASE_DEPLIBS)\n-\t$(CC_LINK) -o $@ $(OBJS) $(KRB5_BASE_LIBS) $(KSU_LIBS)\n+\t$(CC_LINK) -o $@ $(OBJS) $(KRB5_BASE_LIBS) $(KSU_LIBS) $(PAM_LIBS)\n+\n+pam.o: pam.c\n+\t$(CC) $(ALL_CFLAGS) -c $<\n \n clean::\n \t$(RM) ksu\ndiff -Naur krb5/src/clients/ksu/pam.c krb5/src/clients/ksu/pam.c\n--- krb5/src/clients/ksu/pam.c\t1970-01-01 01:00:00.000000000 +0100\n+++ krb5/src/clients/ksu/pam.c\t2014-01-13 17:13:24.589692000 +0100\n@@ -0,0 +1,389 @@\n+/*\n+ * src/clients/ksu/pam.c\n+ *\n+ * Copyright 2007,2009,2010 Red Hat, Inc.\n+ *\n+ * All Rights Reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions are met:\n+ *\n+ * Redistributions of source code must retain the above copyright notice, this\n+ * list of conditions and the following disclaimer.\n+ *\n+ * Redistributions in binary form must reproduce the above copyright notice,\n+ * this list of conditions and the following disclaimer in the documentation\n+ * and/or other materials provided with the distribution.\n+ *\n+ * Neither the name of Red Hat, Inc. nor the names of its contributors may be\n+ * used to endorse or promote products derived from this software without\n+ * specific prior written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\n+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n+ * POSSIBILITY OF SUCH DAMAGE.\n+ * \n+ * Convenience wrappers for using PAM.\n+ */\n+\n+#include \"autoconf.h\"\n+#ifdef USE_PAM\n+#include <sys/types.h>\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <string.h>\n+#include <unistd.h>\n+#include \"k5-int.h\"\n+#include \"pam.h\"\n+\n+#ifndef MAXPWSIZE\n+#define MAXPWSIZE 128\n+#endif\n+\n+static int appl_pam_started;\n+static pid_t appl_pam_starter = -1;\n+static int appl_pam_session_opened;\n+static int appl_pam_creds_initialized;\n+static int appl_pam_pwchange_required;\n+static pam_handle_t *appl_pamh;\n+static struct pam_conv appl_pam_conv;\n+static char *appl_pam_user;\n+struct appl_pam_non_interactive_args {\n+\tconst char *user;\n+\tconst char *password;\n+};\n+\n+int\n+appl_pam_enabled(krb5_context context, const char *section)\n+{\n+\tint enabled = 1;\n+\tif ((context != NULL) && (context->profile != NULL)) {\n+\t\tif (profile_get_boolean(context->profile,\n+\t\t\t\t\tsection,\n+\t\t\t\t\tUSE_PAM_CONFIGURATION_KEYWORD,\n+\t\t\t\t\tNULL,\n+\t\t\t\t\tenabled, &enabled) != 0) {\n+\t\t\tenabled = 1;\n+\t\t}\n+\t}\n+\treturn enabled;\n+}\n+\n+void\n+appl_pam_cleanup(void)\n+{\n+\tif (getpid() != appl_pam_starter) {\n+\t\treturn;\n+\t}\n+#ifdef DEBUG\n+\tprintf(\"Called to clean up PAM.\\n\");\n+#endif\n+\tif (appl_pam_creds_initialized) {\n+#ifdef DEBUG\n+\t\tprintf(\"Deleting PAM credentials.\\n\");\n+#endif\n+\t\tpam_setcred(appl_pamh, PAM_DELETE_CRED);\n+\t\tappl_pam_creds_initialized = 0;\n+\t}\n+\tif (appl_pam_session_opened) {\n+#ifdef DEBUG\n+\t\tprintf(\"Closing PAM session.\\n\");\n+#endif\n+\t\tpam_close_session(appl_pamh, 0);\n+\t\tappl_pam_session_opened = 0;\n+\t}\n+\tappl_pam_pwchange_required = 0;\n+\tif (appl_pam_started) {\n+#ifdef DEBUG\n+\t\tprintf(\"Shutting down PAM.\\n\");\n+#endif\n+\t\tpam_end(appl_pamh, 0);\n+\t\tappl_pam_started = 0;\n+\t\tappl_pam_starter = -1;\n+\t\tfree(appl_pam_user);\n+\t\tappl_pam_user = NULL;\n+\t}\n+}\n+static int\n+appl_pam_interactive_converse(int num_msg, const struct pam_message **msg,\n+\t\t\t struct pam_response **presp, void *appdata_ptr)\n+{\n+\tconst struct pam_message *message;\n+\tstruct pam_response *resp;\n+\tint i, code;\n+\tchar *pwstring, pwbuf[MAXPWSIZE];\n+\tunsigned int pwsize;\n+\tresp = malloc(sizeof(struct pam_response) * num_msg);\n+\tif (resp == NULL) {\n+\t\treturn PAM_BUF_ERR;\n+\t}\n+\tmemset(resp, 0, sizeof(struct pam_response) * num_msg);\n+\tcode = PAM_SUCCESS;\n+\tfor (i = 0; i < num_msg; i++) {\n+\t\tmessage = &(msg[0][i]); /* XXX */\n+\t\tmessage = msg[i]; /* XXX */\n+\t\tpwstring = NULL;\n+\t\tswitch (message->msg_style) {\n+\t\tcase PAM_TEXT_INFO:\n+\t\tcase PAM_ERROR_MSG:\n+\t\t\tprintf(\"[%s]\\n\", message->msg ? message->msg : \"\");\n+\t\t\tfflush(stdout);\n+\t\t\tresp[i].resp = NULL;\n+\t\t\tresp[i].resp_retcode = PAM_SUCCESS;\n+\t\t\tbreak;\n+\t\tcase PAM_PROMPT_ECHO_ON:\n+\t\tcase PAM_PROMPT_ECHO_OFF:\n+\t\t\tif (message->msg_style == PAM_PROMPT_ECHO_ON) {\n+\t\t\t\tif (fgets(pwbuf, sizeof(pwbuf),\n+\t\t\t\t\t stdin) != NULL) {\n+\t\t\t\t\tpwbuf[strcspn(pwbuf, \"\\r\\n\")] = '\\0';\n+\t\t\t\t\tpwstring = pwbuf;\n+\t\t\t\t}\n+\t\t\t} else {\n+\t\t\t\tpwstring = getpass(message->msg ?\n+\t\t\t\t\t\t message->msg :\n+\t\t\t\t\t\t \"\");\n+\t\t\t}\n+\t\t\tif ((pwstring != NULL) && (pwstring[0] != '\\0')) {\n+\t\t\t\tpwsize = strlen(pwstring);\n+\t\t\t\tresp[i].resp = malloc(pwsize + 1);\n+\t\t\t\tif (resp[i].resp == NULL) {\n+\t\t\t\t\tresp[i].resp_retcode = PAM_BUF_ERR;\n+\t\t\t\t} else {\n+\t\t\t\t\tmemcpy(resp[i].resp, pwstring, pwsize);\n+\t\t\t\t\tresp[i].resp[pwsize] = '\\0';\n+\t\t\t\t\tresp[i].resp_retcode = PAM_SUCCESS;\n+\t\t\t\t}\n+\t\t\t} else {\n+\t\t\t\tresp[i].resp_retcode = PAM_CONV_ERR;\n+\t\t\t\tcode = PAM_CONV_ERR;\n+\t\t\t}\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\t*presp = resp;\n+\treturn code;\n+}\n+static int\n+appl_pam_non_interactive_converse(int num_msg,\n+\t\t\t\t const struct pam_message **msg,\n+\t\t\t\t struct pam_response **presp,\n+\t\t\t\t void *appdata_ptr)\n+{\n+\tconst struct pam_message *message;\n+\tstruct pam_response *resp;\n+\tint i, code;\n+\tunsigned int pwsize;\n+\tstruct appl_pam_non_interactive_args *args;\n+\tconst char *pwstring;\n+\tresp = malloc(sizeof(struct pam_response) * num_msg);\n+\tif (resp == NULL) {\n+\t\treturn PAM_BUF_ERR;\n+\t}\n+\targs = appdata_ptr;\n+\tmemset(resp, 0, sizeof(struct pam_response) * num_msg);\n+\tcode = PAM_SUCCESS;\n+\tfor (i = 0; i < num_msg; i++) {\n+\t\tmessage = &((*msg)[i]);\n+\t\tmessage = msg[i];\n+\t\tpwstring = NULL;\n+\t\tswitch (message->msg_style) {\n+\t\tcase PAM_TEXT_INFO:\n+\t\tcase PAM_ERROR_MSG:\n+\t\t\tbreak;\n+\t\tcase PAM_PROMPT_ECHO_ON:\n+\t\tcase PAM_PROMPT_ECHO_OFF:\n+\t\t\tif (message->msg_style == PAM_PROMPT_ECHO_ON) {\n+\t\t\t\t/* assume \"user\" */\n+\t\t\t\tpwstring = args->user;\n+\t\t\t} else {\n+\t\t\t\t/* assume \"password\" */\n+\t\t\t\tpwstring = args->password;\n+\t\t\t}\n+\t\t\tif ((pwstring != NULL) && (pwstring[0] != '\\0')) {\n+\t\t\t\tpwsize = strlen(pwstring);\n+\t\t\t\tresp[i].resp = malloc(pwsize + 1);\n+\t\t\t\tif (resp[i].resp == NULL) {\n+\t\t\t\t\tresp[i].resp_retcode = PAM_BUF_ERR;\n+\t\t\t\t} else {\n+\t\t\t\t\tmemcpy(resp[i].resp, pwstring, pwsize);\n+\t\t\t\t\tresp[i].resp[pwsize] = '\\0';\n+\t\t\t\t\tresp[i].resp_retcode = PAM_SUCCESS;\n+\t\t\t\t}\n+\t\t\t} else {\n+\t\t\t\tresp[i].resp_retcode = PAM_CONV_ERR;\n+\t\t\t\tcode = PAM_CONV_ERR;\n+\t\t\t}\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\t*presp = resp;\n+\treturn code;\n+}\n+static int\n+appl_pam_start(const char *service, int interactive,\n+\t const char *login_username,\n+\t const char *non_interactive_password,\n+\t const char *hostname,\n+\t const char *ruser,\n+\t const char *tty)\n+{\n+\tstatic int exit_handler_registered;\n+\tstatic struct appl_pam_non_interactive_args args;\n+\tint ret = 0;\n+\tif (appl_pam_started &&\n+\t (strcmp(login_username, appl_pam_user) != 0)) {\n+\t\tappl_pam_cleanup();\n+\t\tappl_pam_user = NULL;\n+\t}\n+\tif (!appl_pam_started) {\n+#ifdef DEBUG\n+\t\tprintf(\"Starting PAM up (service=\\\"%s\\\",user=\\\"%s\\\").\\n\",\n+\t\t service, login_username);\n+#endif\n+\t\tmemset(&appl_pam_conv, 0, sizeof(appl_pam_conv));\n+\t\tappl_pam_conv.conv = interactive ?\n+\t\t\t\t &appl_pam_interactive_converse :\n+\t\t\t\t &appl_pam_non_interactive_converse;\n+\t\tmemset(&args, 0, sizeof(args));\n+\t\targs.user = strdup(login_username);\n+\t\targs.password = non_interactive_password ?\n+\t\t\t\tstrdup(non_interactive_password) :\n+\t\t\t\tNULL;\n+\t\tappl_pam_conv.appdata_ptr = &args;\n+\t\tret = pam_start(service, login_username,\n+\t\t\t\t&appl_pam_conv, &appl_pamh);\n+\t\tif (ret == 0) {\n+\t\t\tif (hostname != NULL) {\n+#ifdef DEBUG\n+\t\t\t\tprintf(\"Setting PAM_RHOST to \\\"%s\\\".\\n\", hostname);\n+#endif\n+\t\t\t\tpam_set_item(appl_pamh, PAM_RHOST, hostname);\n+\t\t\t}\n+\t\t\tif (ruser != NULL) {\n+#ifdef DEBUG\n+\t\t\t\tprintf(\"Setting PAM_RUSER to \\\"%s\\\".\\n\", ruser);\n+#endif\n+\t\t\t\tpam_set_item(appl_pamh, PAM_RUSER, ruser);\n+\t\t\t}\n+\t\t\tif (tty != NULL) {\n+#ifdef DEBUG\n+\t\t\t\tprintf(\"Setting PAM_TTY to \\\"%s\\\".\\n\", tty);\n+#endif\n+\t\t\t\tpam_set_item(appl_pamh, PAM_TTY, tty);\n+\t\t\t}\n+\t\t\tif (!exit_handler_registered &&\n+\t\t\t (atexit(appl_pam_cleanup) != 0)) {\n+\t\t\t\tpam_end(appl_pamh, 0);\n+\t\t\t\tappl_pamh = NULL;\n+\t\t\t\tret = -1;\n+\t\t\t} else {\n+\t\t\t\tappl_pam_started = 1;\n+\t\t\t\tappl_pam_starter = getpid();\n+\t\t\t\tappl_pam_user = strdup(login_username);\n+\t\t\t\texit_handler_registered = 1;\n+\t\t\t}\n+\t\t}\n+\t}\n+\treturn ret;\n+}\n+int\n+appl_pam_acct_mgmt(const char *service, int interactive,\n+\t\t const char *login_username,\n+\t\t const char *non_interactive_password,\n+\t\t const char *hostname,\n+\t\t const char *ruser,\n+\t\t const char *tty)\n+{\n+\tint ret;\n+\tappl_pam_pwchange_required = 0;\n+\tret = appl_pam_start(service, interactive, login_username,\n+\t\t\t non_interactive_password, hostname, ruser, tty);\n+\tif (ret == 0) {\n+#ifdef DEBUG\n+\t\tprintf(\"Calling pam_acct_mgmt().\\n\");\n+#endif\n+\t\tret = pam_acct_mgmt(appl_pamh, 0);\n+\t\tswitch (ret) {\n+\t\tcase PAM_IGNORE:\n+\t\t\tret = 0;\n+\t\t\tbreak;\n+\t\tcase PAM_NEW_AUTHTOK_REQD:\n+\t\t\tappl_pam_pwchange_required = 1;\n+\t\t\tret = 0;\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\treturn ret;\n+}\n+int\n+appl_pam_requires_chauthtok(void)\n+{\n+\treturn appl_pam_pwchange_required;\n+}\n+int\n+appl_pam_session_open(void)\n+{\n+\tint ret = 0;\n+\tif (appl_pam_started) {\n+#ifdef DEBUG\n+\t\tprintf(\"Opening PAM session.\\n\");\n+#endif\n+\t\tret = pam_open_session(appl_pamh, 0);\n+\t\tif (ret == 0) {\n+\t\t\tappl_pam_session_opened = 1;\n+\t\t}\n+\t}\n+\treturn ret;\n+}\n+int\n+appl_pam_setenv(void)\n+{\n+\tint ret = 0;\n+#ifdef HAVE_PAM_GETENVLIST\n+#ifdef HAVE_PUTENV\n+\tint i;\n+\tchar **list;\n+\tif (appl_pam_started) {\n+\t\tlist = pam_getenvlist(appl_pamh);\n+\t\tfor (i = 0; ((list != NULL) && (list[i] != NULL)); i++) {\n+#ifdef DEBUG\n+\t\t\tprintf(\"Setting \\\"%s\\\" in environment.\\n\", list[i]);\n+#endif\n+\t\t\tputenv(list[i]);\n+\t\t}\n+\t}\n+#endif\n+#endif\n+\treturn ret;\n+}\n+int\n+appl_pam_cred_init(void)\n+{\n+\tint ret = 0;\n+\tif (appl_pam_started) {\n+#ifdef DEBUG\n+\t\tprintf(\"Initializing PAM credentials.\\n\");\n+#endif\n+\t\tret = pam_setcred(appl_pamh, PAM_ESTABLISH_CRED);\n+\t\tif (ret == 0) {\n+\t\t\tappl_pam_creds_initialized = 1;\n+\t\t}\n+\t}\n+\treturn ret;\n+}\n+#endif\ndiff -Naur krb5/src/clients/ksu/pam.h krb5/src/clients/ksu/pam.h\n--- krb5/src/clients/ksu/pam.h\t1970-01-01 01:00:00.000000000 +0100\n+++ krb5/src/clients/ksu/pam.h\t2014-01-13 17:13:24.595690000 +0100\n@@ -0,0 +1,57 @@\n+/*\n+ * src/clients/ksu/pam.h\n+ *\n+ * Copyright 2007,2009,2010 Red Hat, Inc.\n+ *\n+ * All Rights Reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions are met:\n+ *\n+ * Redistributions of source code must retain the above copyright notice, this\n+ * list of conditions and the following disclaimer.\n+ *\n+ * Redistributions in binary form must reproduce the above copyright notice,\n+ * this list of conditions and the following disclaimer in the documentation\n+ * and/or other materials provided with the distribution.\n+ *\n+ * Neither the name of Red Hat, Inc. nor the names of its contributors may be\n+ * used to endorse or promote products derived from this software without\n+ * specific prior written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\n+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n+ * POSSIBILITY OF SUCH DAMAGE.\n+ * \n+ * Convenience wrappers for using PAM.\n+ */\n+\n+#include <krb5.h>\n+#ifdef HAVE_SECURITY_PAM_APPL_H\n+#include <security/pam_appl.h>\n+#endif\n+\n+#define USE_PAM_CONFIGURATION_KEYWORD \"use_pam\"\n+\n+#ifdef USE_PAM\n+int appl_pam_enabled(krb5_context context, const char *section);\n+int appl_pam_acct_mgmt(const char *service, int interactive,\n+\t\t const char *local_username,\n+\t\t const char *non_interactive_password,\n+\t\t const char *hostname,\n+\t\t const char *ruser,\n+\t\t const char *tty);\n+int appl_pam_requires_chauthtok(void);\n+int appl_pam_session_open(void);\n+int appl_pam_setenv(void);\n+int appl_pam_cred_init(void);\n+void appl_pam_cleanup(void);\n+#endif\ndiff -Naur krb5/src/configure.in krb5/src/configure.in\n--- krb5/src/configure.in\t2014-01-13 17:12:48.401059000 +0100\n+++ krb5/src/configure.in\t2014-01-13 17:13:24.603693000 +0100\n@@ -1281,6 +1281,8 @@\n \n AC_PATH_PROG(GROFF, groff)\n \n+KRB5_WITH_PAM\n+\n # Make localedir work in autoconf 2.5x.\n if test \"${localedir+set}\" != set; then\n localedir='$(datadir)/locale'" } ]
{ "id": "krb5-4670-krb5-1.12-pam.patch", "cve_id": "CVE-2015-8629", "package": "krb5", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": false, "license": "MIT", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-6210\n\nsshd in OpenSSH before 7.3, when SHA256 or SHA512 are used for user password hashing, uses BLOWFISH hashing on a static password when the username does not exist, which allows remote attackers to enumerate users by leveraging the timing difference between responses when a large password is provided.\n\n## Package\nopenssh-askpass-gnome\n\n## Files to modify\n- openssh-6.6p1/monitor_wrap.c\n- openssh-6.6p1/sshd.c\n- openssh-6.6p1/audit.c\n- openssh-6.6p1/audit.h\n- openssh-6.6p1/audit-bsm.c\n\n## Upstream Fix\n```diff\n# HG changeset patch\n# Parent e36c46080118cbe550b059fb2454ed4ebef9f884\n# server key destruction and auditing\n# based on:\n# https://bugzilla.mindrot.org/show_bug.cgi?id=1402\n# https://bugzilla.mindrot.org/attachment.cgi?id=2015\n# by jchadima@redhat.com\n\ndiff --git a/openssh-6.6p1/audit-bsm.c b/openssh-6.6p1/audit-bsm.c\n--- a/openssh-6.6p1/audit-bsm.c\n+++ b/openssh-6.6p1/audit-bsm.c\n@@ -486,9 +486,27 @@ audit_kex_body(int ctos, char *enc, char\n \t/* not implemented */\n }\n \n void\n audit_session_key_free_body(int ctos, pid_t pid, uid_t uid)\n {\n \t/* not implemented */\n }\n+\n+void\n+audit_destroy_sensitive_data(const char *fp)\n+{\n+\t/* not implemented */\n+}\n+\n+void\n+audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)\n+{\n+\t/* not implemented */\n+}\n+\n+void\n+audit_generate_ephemeral_server_key(const char *fp)\n+{\n+\t/* not implemented */\n+}\n #endif /* BSM */\ndiff --git a/openssh-6.6p1/audit-linux.c b/openssh-6.6p1/audit-linux.c\n--- a/openssh-6.6p1/audit-linux.c\n+++ b/openssh-6.6p1/audit-linux.c\n@@ -351,9 +351,53 @@ audit_session_key_free_body(int ctos, pi\n \taudit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,\n \t\t\tbuf, NULL, get_remote_ipaddr(), NULL, 1);\n \taudit_close(audit_fd);\n \t/* do not abort if the error is EPERM and sshd is run as non root user */\n \tif ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))\n \t\terror(\"cannot write into audit\");\n }\n \n+void\n+audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)\n+{\n+\tchar buf[AUDIT_LOG_SIZE];\n+\tint audit_fd, audit_ok;\n+\n+\tsnprintf(buf, sizeof(buf), \"op=destroy kind=server fp=%s direction=? spid=%jd suid=%jd \",\n+\t\tfp, (intmax_t)pid, (intmax_t)uid);\n+\taudit_fd = audit_open();\n+\tif (audit_fd < 0) {\n+\t\tif (errno != EINVAL && errno != EPROTONOSUPPORT &&\n+\t\t\t\t\t errno != EAFNOSUPPORT)\n+\t\t\terror(\"cannot open audit\");\n+\t\treturn;\n+\t}\n+\taudit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,\n+\t\t\tbuf, NULL, get_remote_ipaddr(), NULL, 1);\n+\taudit_close(audit_fd);\n+\t/* do not abort if the error is EPERM and sshd is run as non root user */\n+\tif ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))\n+\t\terror(\"cannot write into audit\");\n+}\n+\n+void\n+audit_generate_ephemeral_server_key(const char *fp)\n+{\n+\tchar buf[AUDIT_LOG_SIZE];\n+\tint audit_fd, audit_ok;\n+\n+\tsnprintf(buf, sizeof(buf), \"op=create kind=server fp=%s direction=? \", fp);\n+\taudit_fd = audit_open();\n+\tif (audit_fd < 0) {\n+\t\tif (errno != EINVAL && errno != EPROTONOSUPPORT &&\n+\t\t\t\t\t errno != EAFNOSUPPORT)\n+\t\t\terror(\"cannot open audit\");\n+\t\treturn;\n+\t}\n+\taudit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,\n+\t\t\tbuf, NULL, 0, NULL, 1);\n+\taudit_close(audit_fd);\n+\t/* do not abort if the error is EPERM and sshd is run as non root user */\n+\tif ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))\n+\t\terror(\"cannot write into audit\");\n+}\n #endif /* USE_LINUX_AUDIT */\ndiff --git a/openssh-6.6p1/audit.c b/openssh-6.6p1/audit.c\n--- a/openssh-6.6p1/audit.c\n+++ b/openssh-6.6p1/audit.c\n@@ -285,10 +285,29 @@ audit_kex_body(int ctos, char *enc, char\n * This will be called on succesfull session key discard\n */\n void\n audit_session_key_free_body(int ctos, pid_t pid, uid_t uid)\n {\n \tdebug(\"audit session key discard euid %u direction %d from pid %ld uid %u\",\n \t\t(unsigned)geteuid(), ctos, (long)pid, (unsigned)uid);\n }\n+\n+/*\n+ * This will be called on destroy private part of the server key\n+ */\n+void\n+audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)\n+{\n+\tdebug(\"audit destroy sensitive data euid %d fingerprint %s from pid %ld uid %u\",\n+\t\tgeteuid(), fp, (long)pid, (unsigned)uid);\n+}\n+\n+/*\n+ * This will be called on generation of the ephemeral server key\n+ */\n+void\n+audit_generate_ephemeral_server_key(const char *)\n+{\n+\tdebug(\"audit create ephemeral server key euid %d fingerprint %s\", geteuid(), fp);\n+}\n # endif /* !defined CUSTOM_SSH_AUDIT_EVENTS */\n #endif /* SSH_AUDIT_EVENTS */\ndiff --git a/openssh-6.6p1/audit.h b/openssh-6.6p1/audit.h\n--- a/openssh-6.6p1/audit.h\n+++ b/openssh-6.6p1/audit.h\n@@ -59,10 +59,12 @@ ssh_audit_event_t audit_classify_auth(co\n int\taudit_keyusage(int, const char *, unsigned, char *, int);\n void\taudit_key(int, int *, const Key *);\n void\taudit_unsupported(int);\n void\taudit_kex(int, char *, char *, char *);\n void\taudit_unsupported_body(int);\n void\taudit_kex_body(int, char *, char *, char *, pid_t, uid_t);\n void\taudit_session_key_free(int ctos);\n void\taudit_session_key_free_body(int ctos, pid_t, uid_t);\n+void\taudit_destroy_sensitive_data(const char *, pid_t, uid_t);\n+void\taudit_generate_ephemeral_server_key(const char *);\n \n #endif /* _SSH_AUDIT_H */\ndiff --git a/openssh-6.6p1/key.c b/openssh-6.6p1/key.c\n--- a/openssh-6.6p1/key.c\n+++ b/openssh-6.6p1/key.c\n@@ -1964,16 +1964,43 @@ key_demote(const Key *k)\n \t\tfatal(\"key_demote: bad key type %d\", k->type);\n \t\tbreak;\n \t}\n \n \treturn (pk);\n }\n \n int\n+key_is_private(const Key *k)\n+{\n+\tswitch (k->type) {\n+\tcase KEY_RSA_CERT_V00:\n+\tcase KEY_RSA_CERT:\n+\tcase KEY_RSA1:\n+\tcase KEY_RSA:\n+\t\treturn k->rsa->d != NULL;\n+\tcase KEY_DSA_CERT_V00:\n+\tcase KEY_DSA_CERT:\n+\tcase KEY_DSA:\n+\t\treturn k->dsa->priv_key != NULL;\n+#ifdef OPENSSL_HAS_ECC\n+\tcase KEY_ECDSA_CERT:\n+\tcase KEY_ECDSA:\n+\t\treturn EC_KEY_get0_private_key(k->ecdsa) != NULL;\n+#endif\n+\tcase KEY_ED25519_CERT:\n+\tcase KEY_ED25519:\n+\t\treturn k->ed25519_sk != NULL;\n+\tdefault:\n+\t\tfatal(\"key_is_private: bad key type %d\", k->type);\n+\t\treturn 1;\n+\t}\n+}\n+\n+int\n key_is_cert(const Key *k)\n {\n \tif (k == NULL)\n \t\treturn 0;\n \treturn key_type_is_cert(k->type);\n }\n \n /* Return the cert-less equivalent to a certified key type */\ndiff --git a/openssh-6.6p1/key.h b/openssh-6.6p1/key.h\n--- a/openssh-6.6p1/key.h\n+++ b/openssh-6.6p1/key.h\n@@ -113,16 +113,17 @@ int\t\t key_read(Key *, char **);\n u_int\t\t key_size(const Key *);\n enum fp_type\t key_fp_type_select(void);\n char\t\t*key_fp_type_str(enum fp_type);\n \n Key\t*key_generate(int, u_int);\n Key\t*key_from_private(const Key *);\n int\t key_type_from_name(char *);\n int\t key_is_cert(const Key *);\n+int\t key_is_private(const Key *k);\n int\t key_type_is_cert(int);\n int\t key_type_plain(int);\n int\t key_to_certified(Key *, int);\n int\t key_drop_cert(Key *);\n int\t key_certify(Key *, Key *);\n void\t key_cert_copy(const Key *, struct Key *);\n int\t key_cert_check_authority(const Key *, int, int, const char *,\n \t const char **);\ndiff --git a/openssh-6.6p1/monitor.c b/openssh-6.6p1/monitor.c\n--- a/openssh-6.6p1/monitor.c\n+++ b/openssh-6.6p1/monitor.c\n@@ -109,16 +109,18 @@ extern u_int utmp_len;\n extern Newkeys *current_keys[];\n extern z_stream incoming_stream;\n extern z_stream outgoing_stream;\n extern u_char session_id[];\n extern Buffer auth_debug;\n extern int auth_debug_init;\n extern Buffer loginmsg;\n \n+extern void destroy_sensitive_data(int);\n+\n /* State exported from the child */\n \n struct {\n \tz_stream incoming;\n \tz_stream outgoing;\n \tu_char *keyin;\n \tu_int keyinlen;\n \tu_char *keyout;\n@@ -180,16 +182,17 @@ int mm_answer_gss_checkmic(int, Buffer *\n \n #ifdef SSH_AUDIT_EVENTS\n int mm_answer_audit_event(int, Buffer *);\n int mm_answer_audit_command(int, Buffer *);\n int mm_answer_audit_end_command(int, Buffer *);\n int mm_answer_audit_unsupported_body(int, Buffer *);\n int mm_answer_audit_kex_body(int, Buffer *);\n int mm_answer_audit_session_key_free_body(int, Buffer *);\n+int mm_answer_audit_server_key_free(int, Buffer *);\n #endif\n \n static int monitor_read_log(struct monitor *);\n \n static Authctxt *authctxt;\n static BIGNUM *ssh1_challenge = NULL;\t/* used for ssh1 rsa auth */\n \n /* local state for key verify */\n@@ -234,16 +237,17 @@ struct mon_table mon_dispatch_proto20[] \n {MONITOR_REQ_PAM_RESPOND, MON_ISAUTH, mm_answer_pam_respond},\n {MONITOR_REQ_PAM_FREE_CTX, MON_ONCE|MON_AUTHDECIDE, mm_answer_pam_free_ctx},\n #endif\n #ifdef SSH_AUDIT_EVENTS\n {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},\n {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},\n {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},\n {MONITOR_RE\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "# HG changeset patch\n# Parent e36c46080118cbe550b059fb2454ed4ebef9f884\n# server key destruction and auditing\n# based on:\n# https://bugzilla.mindrot.org/show_bug.cgi?id=1402\n# https://bugzilla.mindrot.org/attachment.cgi?id=2015\n# by jchadima@redhat.com\n\ndiff --git a/openssh-6.6p1/audit-bsm.c b/openssh-6.6p1/audit-bsm.c\n--- a/openssh-6.6p1/audit-bsm.c\n+++ b/openssh-6.6p1/audit-bsm.c\n@@ -486,9 +486,27 @@ audit_kex_body(int ctos, char *enc, char\n \t/* not implemented */\n }\n \n void\n audit_session_key_free_body(int ctos, pid_t pid, uid_t uid)\n {\n \t/* not implemented */\n }\n+\n+void\n+audit_destroy_sensitive_data(const char *fp)\n+{\n+\t/* not implemented */\n+}\n+\n+void\n+audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)\n+{\n+\t/* not implemented */\n+}\n+\n+void\n+audit_generate_ephemeral_server_key(const char *fp)\n+{\n+\t/* not implemented */\n+}\n #endif /* BSM */\ndiff --git a/openssh-6.6p1/audit-linux.c b/openssh-6.6p1/audit-linux.c\n--- a/openssh-6.6p1/audit-linux.c\n+++ b/openssh-6.6p1/audit-linux.c\n@@ -351,9 +351,53 @@ audit_session_key_free_body(int ctos, pi\n \taudit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,\n \t\t\tbuf, NULL, get_remote_ipaddr(), NULL, 1);\n \taudit_close(audit_fd);\n \t/* do not abort if the error is EPERM and sshd is run as non root user */\n \tif ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))\n \t\terror(\"cannot write into audit\");\n }\n \n+void\n+audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)\n+{\n+\tchar buf[AUDIT_LOG_SIZE];\n+\tint audit_fd, audit_ok;\n+\n+\tsnprintf(buf, sizeof(buf), \"op=destroy kind=server fp=%s direction=? spid=%jd suid=%jd \",\n+\t\tfp, (intmax_t)pid, (intmax_t)uid);\n+\taudit_fd = audit_open();\n+\tif (audit_fd < 0) {\n+\t\tif (errno != EINVAL && errno != EPROTONOSUPPORT &&\n+\t\t\t\t\t errno != EAFNOSUPPORT)\n+\t\t\terror(\"cannot open audit\");\n+\t\treturn;\n+\t}\n+\taudit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,\n+\t\t\tbuf, NULL, get_remote_ipaddr(), NULL, 1);\n+\taudit_close(audit_fd);\n+\t/* do not abort if the error is EPERM and sshd is run as non root user */\n+\tif ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))\n+\t\terror(\"cannot write into audit\");\n+}\n+\n+void\n+audit_generate_ephemeral_server_key(const char *fp)\n+{\n+\tchar buf[AUDIT_LOG_SIZE];\n+\tint audit_fd, audit_ok;\n+\n+\tsnprintf(buf, sizeof(buf), \"op=create kind=server fp=%s direction=? \", fp);\n+\taudit_fd = audit_open();\n+\tif (audit_fd < 0) {\n+\t\tif (errno != EINVAL && errno != EPROTONOSUPPORT &&\n+\t\t\t\t\t errno != EAFNOSUPPORT)\n+\t\t\terror(\"cannot open audit\");\n+\t\treturn;\n+\t}\n+\taudit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,\n+\t\t\tbuf, NULL, 0, NULL, 1);\n+\taudit_close(audit_fd);\n+\t/* do not abort if the error is EPERM and sshd is run as non root user */\n+\tif ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))\n+\t\terror(\"cannot write into audit\");\n+}\n #endif /* USE_LINUX_AUDIT */\ndiff --git a/openssh-6.6p1/audit.c b/openssh-6.6p1/audit.c\n--- a/openssh-6.6p1/audit.c\n+++ b/openssh-6.6p1/audit.c\n@@ -285,10 +285,29 @@ audit_kex_body(int ctos, char *enc, char\n * This will be called on succesfull session key discard\n */\n void\n audit_session_key_free_body(int ctos, pid_t pid, uid_t uid)\n {\n \tdebug(\"audit session key discard euid %u direction %d from pid %ld uid %u\",\n \t\t(unsigned)geteuid(), ctos, (long)pid, (unsigned)uid);\n }\n+\n+/*\n+ * This will be called on destroy private part of the server key\n+ */\n+void\n+audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)\n+{\n+\tdebug(\"audit destroy sensitive data euid %d fingerprint %s from pid %ld uid %u\",\n+\t\tgeteuid(), fp, (long)pid, (unsigned)uid);\n+}\n+\n+/*\n+ * This will be called on generation of the ephemeral server key\n+ */\n+void\n+audit_generate_ephemeral_server_key(const char *)\n+{\n+\tdebug(\"audit create ephemeral server key euid %d fingerprint %s\", geteuid(), fp);\n+}\n # endif /* !defined CUSTOM_SSH_AUDIT_EVENTS */\n #endif /* SSH_AUDIT_EVENTS */\ndiff --git a/openssh-6.6p1/audit.h b/openssh-6.6p1/audit.h\n--- a/openssh-6.6p1/audit.h\n+++ b/openssh-6.6p1/audit.h\n@@ -59,10 +59,12 @@ ssh_audit_event_t audit_classify_auth(co\n int\taudit_keyusage(int, const char *, unsigned, char *, int);\n void\taudit_key(int, int *, const Key *);\n void\taudit_unsupported(int);\n void\taudit_kex(int, char *, char *, char *);\n void\taudit_unsupported_body(int);\n void\taudit_kex_body(int, char *, char *, char *, pid_t, uid_t);\n void\taudit_session_key_free(int ctos);\n void\taudit_session_key_free_body(int ctos, pid_t, uid_t);\n+void\taudit_destroy_sensitive_data(const char *, pid_t, uid_t);\n+void\taudit_generate_ephemeral_server_key(const char *);\n \n #endif /* _SSH_AUDIT_H */\ndiff --git a/openssh-6.6p1/key.c b/openssh-6.6p1/key.c\n--- a/openssh-6.6p1/key.c\n+++ b/openssh-6.6p1/key.c\n@@ -1964,16 +1964,43 @@ key_demote(const Key *k)\n \t\tfatal(\"key_demote: bad key type %d\", k->type);\n \t\tbreak;\n \t}\n \n \treturn (pk);\n }\n \n int\n+key_is_private(const Key *k)\n+{\n+\tswitch (k->type) {\n+\tcase KEY_RSA_CERT_V00:\n+\tcase KEY_RSA_CERT:\n+\tcase KEY_RSA1:\n+\tcase KEY_RSA:\n+\t\treturn k->rsa->d != NULL;\n+\tcase KEY_DSA_CERT_V00:\n+\tcase KEY_DSA_CERT:\n+\tcase KEY_DSA:\n+\t\treturn k->dsa->priv_key != NULL;\n+#ifdef OPENSSL_HAS_ECC\n+\tcase KEY_ECDSA_CERT:\n+\tcase KEY_ECDSA:\n+\t\treturn EC_KEY_get0_private_key(k->ecdsa) != NULL;\n+#endif\n+\tcase KEY_ED25519_CERT:\n+\tcase KEY_ED25519:\n+\t\treturn k->ed25519_sk != NULL;\n+\tdefault:\n+\t\tfatal(\"key_is_private: bad key type %d\", k->type);\n+\t\treturn 1;\n+\t}\n+}\n+\n+int\n key_is_cert(const Key *k)\n {\n \tif (k == NULL)\n \t\treturn 0;\n \treturn key_type_is_cert(k->type);\n }\n \n /* Return the cert-less equivalent to a certified key type */\ndiff --git a/openssh-6.6p1/key.h b/openssh-6.6p1/key.h\n--- a/openssh-6.6p1/key.h\n+++ b/openssh-6.6p1/key.h\n@@ -113,16 +113,17 @@ int\t\t key_read(Key *, char **);\n u_int\t\t key_size(const Key *);\n enum fp_type\t key_fp_type_select(void);\n char\t\t*key_fp_type_str(enum fp_type);\n \n Key\t*key_generate(int, u_int);\n Key\t*key_from_private(const Key *);\n int\t key_type_from_name(char *);\n int\t key_is_cert(const Key *);\n+int\t key_is_private(const Key *k);\n int\t key_type_is_cert(int);\n int\t key_type_plain(int);\n int\t key_to_certified(Key *, int);\n int\t key_drop_cert(Key *);\n int\t key_certify(Key *, Key *);\n void\t key_cert_copy(const Key *, struct Key *);\n int\t key_cert_check_authority(const Key *, int, int, const char *,\n \t const char **);\ndiff --git a/openssh-6.6p1/monitor.c b/openssh-6.6p1/monitor.c\n--- a/openssh-6.6p1/monitor.c\n+++ b/openssh-6.6p1/monitor.c\n@@ -109,16 +109,18 @@ extern u_int utmp_len;\n extern Newkeys *current_keys[];\n extern z_stream incoming_stream;\n extern z_stream outgoing_stream;\n extern u_char session_id[];\n extern Buffer auth_debug;\n extern int auth_debug_init;\n extern Buffer loginmsg;\n \n+extern void destroy_sensitive_data(int);\n+\n /* State exported from the child */\n \n struct {\n \tz_stream incoming;\n \tz_stream outgoing;\n \tu_char *keyin;\n \tu_int keyinlen;\n \tu_char *keyout;\n@@ -180,16 +182,17 @@ int mm_answer_gss_checkmic(int, Buffer *\n \n #ifdef SSH_AUDIT_EVENTS\n int mm_answer_audit_event(int, Buffer *);\n int mm_answer_audit_command(int, Buffer *);\n int mm_answer_audit_end_command(int, Buffer *);\n int mm_answer_audit_unsupported_body(int, Buffer *);\n int mm_answer_audit_kex_body(int, Buffer *);\n int mm_answer_audit_session_key_free_body(int, Buffer *);\n+int mm_answer_audit_server_key_free(int, Buffer *);\n #endif\n \n static int monitor_read_log(struct monitor *);\n \n static Authctxt *authctxt;\n static BIGNUM *ssh1_challenge = NULL;\t/* used for ssh1 rsa auth */\n \n /* local state for key verify */\n@@ -234,16 +237,17 @@ struct mon_table mon_dispatch_proto20[] \n {MONITOR_REQ_PAM_RESPOND, MON_ISAUTH, mm_answer_pam_respond},\n {MONITOR_REQ_PAM_FREE_CTX, MON_ONCE|MON_AUTHDECIDE, mm_answer_pam_free_ctx},\n #endif\n #ifdef SSH_AUDIT_EVENTS\n {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},\n {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},\n {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},\n {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},\n+ {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},\n #endif\n #ifdef BSD_AUTH\n {MONITOR_REQ_BSDAUTHQUERY, MON_ISAUTH, mm_answer_bsdauthquery},\n {MONITOR_REQ_BSDAUTHRESPOND, MON_AUTH, mm_answer_bsdauthrespond},\n #endif\n #ifdef SKEY\n {MONITOR_REQ_SKEYQUERY, MON_ISAUTH, mm_answer_skeyquery},\n {MONITOR_REQ_SKEYRESPOND, MON_AUTH, mm_answer_skeyrespond},\n@@ -267,16 +271,17 @@ struct mon_table mon_dispatch_postauth20\n {MONITOR_REQ_TERM, 0, mm_answer_term},\n #ifdef SSH_AUDIT_EVENTS\n {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},\n {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT, mm_answer_audit_command},\n {MONITOR_REQ_AUDIT_END_COMMAND, MON_PERMIT, mm_answer_audit_end_command},\n {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},\n {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},\n {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},\n+ {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},\n #endif\n {0, 0, NULL}\n };\n \n struct mon_table mon_dispatch_proto15[] = {\n {MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow},\n {MONITOR_REQ_SESSKEY, MON_ONCE, mm_answer_sesskey},\n {MONITOR_REQ_SESSID, MON_ONCE, mm_answer_sessid},\n@@ -301,31 +306,33 @@ struct mon_table mon_dispatch_proto15[] \n {MONITOR_REQ_PAM_RESPOND, MON_ISAUTH, mm_answer_pam_respond},\n {MONITOR_REQ_PAM_FREE_CTX, MON_ONCE|MON_AUTHDECIDE, mm_answer_pam_free_ctx},\n #endif\n #ifdef SSH_AUDIT_EVENTS\n {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},\n {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},\n {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},\n {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},\n+ {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},\n #endif\n {0, 0, NULL}\n };\n \n struct mon_table mon_dispatch_postauth15[] = {\n {MONITOR_REQ_PTY, MON_ONCE, mm_answer_pty},\n {MONITOR_REQ_PTYCLEANUP, MON_ONCE, mm_answer_pty_cleanup},\n {MONITOR_REQ_TERM, 0, mm_answer_term},\n #ifdef SSH_AUDIT_EVENTS\n {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},\n {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT|MON_ONCE, mm_answer_audit_command},\n {MONITOR_REQ_AUDIT_END_COMMAND, MON_PERMIT, mm_answer_audit_end_command},\n {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},\n {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},\n {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},\n+ {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},\n #endif\n {0, 0, NULL}\n };\n \n struct mon_table *mon_dispatch;\n \n /* Specifies if a certain message is allowed at the moment */\n \n@@ -1739,16 +1746,18 @@ mm_answer_term(int sock, Buffer *req)\n \t/* The child is terminating */\n \tsession_destroy_all(&mm_session_close);\n \n #ifdef USE_PAM\n \tif (options.use_pam)\n \t\tsshpam_cleanup();\n #endif\n \n+\tdestroy_sensitive_data(0);\n+\n \twhile (waitpid(pmonitor->m_pid, &status, 0) == -1)\n \t\tif (errno != EINTR)\n \t\t\texit(1);\n \n \tres = WIFEXITED(status) ? WEXITSTATUS(status) : 1;\n \n \t/* Terminate process */\n \texit(res);\n@@ -2280,10 +2289,31 @@ mm_answer_audit_session_key_free_body(in\n \n \taudit_session_key_free_body(ctos, pid, uid);\n \n \tbuffer_clear(m);\n \n \tmm_request_send(sock, MONITOR_ANS_AUDIT_SESSION_KEY_FREE, m);\n \treturn 0;\n }\n+\n+int\n+mm_answer_audit_server_key_free(int sock, Buffer *m)\n+{\n+\tint len;\n+\tchar *fp;\n+\tpid_t pid;\n+\tuid_t uid;\n+\n+\tfp = buffer_get_string(m, &len);\n+\tpid = buffer_get_int64(m);\n+\tuid = buffer_get_int64(m);\n+\n+\taudit_destroy_sensitive_data(fp, pid, uid);\n+\n+\tfree(fp);\n+\tbuffer_clear(m);\n+\n+\tmm_request_send(sock, MONITOR_ANS_AUDIT_SERVER_KEY_FREE, m);\n+\treturn 0;\n+}\n #endif /* SSH_AUDIT_EVENTS */\n \ndiff --git a/openssh-6.6p1/monitor.h b/openssh-6.6p1/monitor.h\n--- a/openssh-6.6p1/monitor.h\n+++ b/openssh-6.6p1/monitor.h\n@@ -63,16 +63,17 @@ enum monitor_reqtype {\n \tMONITOR_REQ_PAM_QUERY = 106, MONITOR_ANS_PAM_QUERY = 107,\n \tMONITOR_REQ_PAM_RESPOND = 108, MONITOR_ANS_PAM_RESPOND = 109,\n \tMONITOR_REQ_PAM_FREE_CTX = 110, MONITOR_ANS_PAM_FREE_CTX = 111,\n \tMONITOR_REQ_AUDIT_EVENT = 112, MONITOR_REQ_AUDIT_COMMAND = 113,\n \tMONITOR_ANS_AUDIT_COMMAND = 114, MONITOR_REQ_AUDIT_END_COMMAND = 115,\n \tMONITOR_REQ_AUDIT_UNSUPPORTED = 116, MONITOR_ANS_AUDIT_UNSUPPORTED = 117,\n \tMONITOR_REQ_AUDIT_KEX = 118, MONITOR_ANS_AUDIT_KEX = 119,\n \tMONITOR_REQ_AUDIT_SESSION_KEY_FREE = 120, MONITOR_ANS_AUDIT_SESSION_KEY_FREE = 121,\n+\tMONITOR_REQ_AUDIT_SERVER_KEY_FREE = 122, MONITOR_ANS_AUDIT_SERVER_KEY_FREE = 123,\n \n };\n \n struct mm_master;\n struct monitor {\n \tint\t\t\t m_recvfd;\n \tint\t\t\t m_sendfd;\n \tint\t\t\t m_log_recvfd;\ndiff --git a/openssh-6.6p1/monitor_wrap.c b/openssh-6.6p1/monitor_wrap.c\n--- a/openssh-6.6p1/monitor_wrap.c\n+++ b/openssh-6.6p1/monitor_wrap.c\n@@ -1373,10 +1373,26 @@ mm_audit_session_key_free_body(int ctos,\n \tbuffer_put_int(&m, ctos);\n \tbuffer_put_int64(&m, pid);\n \tbuffer_put_int64(&m, uid);\n \tmm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_SESSION_KEY_FREE, &m);\n \tmm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUDIT_SESSION_KEY_FREE,\n \t\t\t\t &m);\n \tbuffer_free(&m);\n }\n+\n+void\n+mm_audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)\n+{\n+\tBuffer m;\n+\n+\tbuffer_init(&m);\n+\tbuffer_put_cstring(&m, fp);\n+\tbuffer_put_int64(&m, pid);\n+\tbuffer_put_int64(&m, uid);\n+\n+\tmm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_SERVER_KEY_FREE, &m);\n+\tmm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUDIT_SERVER_KEY_FREE,\n+\t\t\t\t &m);\n+\tbuffer_free(&m);\n+}\n #endif /* SSH_AUDIT_EVENTS */\n \ndiff --git a/openssh-6.6p1/monitor_wrap.h b/openssh-6.6p1/monitor_wrap.h\n--- a/openssh-6.6p1/monitor_wrap.h\n+++ b/openssh-6.6p1/monitor_wrap.h\n@@ -75,16 +75,17 @@ void mm_sshpam_free_ctx(void *);\n #ifdef SSH_AUDIT_EVENTS\n #include \"audit.h\"\n void mm_audit_event(ssh_audit_event_t);\n int mm_audit_run_command(const char *);\n void mm_audit_end_command(int, const char *);\n void mm_audit_unsupported_body(int);\n void mm_audit_kex_body(int, char *, char *, char *, pid_t, uid_t);\n void mm_audit_session_key_free_body(int, pid_t, uid_t);\n+void mm_audit_destroy_sensitive_data(const char *, pid_t, uid_t);\n #endif\n \n struct Session;\n void mm_terminate(void);\n int mm_pty_allocate(int *, int *, char *, size_t);\n void mm_session_pty_cleanup2(struct Session *);\n \n /* SSHv1 interfaces */\ndiff --git a/openssh-6.6p1/session.c b/openssh-6.6p1/session.c\n--- a/openssh-6.6p1/session.c\n+++ b/openssh-6.6p1/session.c\n@@ -132,17 +132,17 @@ static int session_pty_req(Session *);\n \n /* import */\n extern ServerOptions options;\n extern char *__progname;\n extern int log_stderr;\n extern int debug_flag;\n extern u_int utmp_len;\n extern int startup_pipe;\n-extern void destroy_sensitive_data(void);\n+extern void destroy_sensitive_data(int);\n extern Buffer loginmsg;\n \n /* original command from peer. */\n const char *original_command = NULL;\n \n /* data */\n static int sessions_first_unused = -1;\n static int sessions_nalloc = 0;\n@@ -1695,17 +1695,17 @@ do_child(Session *s, const char *command\n \tchar **env;\n \tint env_size;\n \tchar *argv[ARGV_MAX];\n \tconst char *shell, *shell0, *hostname = NULL;\n \tstruct passwd *pw = s->pw;\n \tint r = 0;\n \n \t/* remove hostkey from the child's memory */\n-\tdestroy_sensitive_data();\n+\tdestroy_sensitive_data(1);\n \t/* Don't audit this - both us and the parent would be talking to the\n \t monitor over a single socket, with no synchronization. */\n \tpacket_destroy_all(0, 1);\n \n \t/* Force a password change */\n \tif (s->authctxt->force_pwchange) {\n \t\tdo_setusercontext(pw);\n \t\tchild_close_fds();\ndiff --git a/openssh-6.6p1/sshd.c b/openssh-6.6p1/sshd.c\n--- a/openssh-6.6p1/sshd.c\n+++ b/openssh-6.6p1/sshd.c\n@@ -257,17 +257,17 @@ Buffer cfg;\n \n /* message to be displayed after login */\n Buffer loginmsg;\n \n /* Unprivileged user */\n struct passwd *privsep_pw = NULL;\n \n /* Prototypes for various functions defined later in this file. */\n-void destroy_sensitive_data(void);\n+void destroy_sensitive_data(int);\n void demote_sensitive_data(void);\n \n static void do_ssh1_kex(void);\n static void do_ssh2_kex(void);\n \n /*\n * Close all listening sockets\n */\n@@ -555,60 +555,107 @@ sshd_exchange_identification(int sock_in\n \t\tclose(sock_out);\n \t\tlogit(\"Protocol major versions differ for %s: %.200s vs. %.200s\",\n \t\t get_remote_ipaddr(),\n \t\t server_version_string, client_version_string);\n \t\tcleanup_exit(255);\n \t}\n }\n \n-/* Destroy the host and server keys. They will no longer be needed. */\n+/*\n+ * Destroy the host and server keys. They will no longer be needed. Careful,\n+ * this can be called from cleanup_exit() - i.e. from just about anywhere.\n+ */\n void\n-destroy_sensitive_data(void)\n+destroy_sensitive_data(int privsep)\n {\n \tint i;\n+\tpid_t pid;\n+\tuid_t uid;\n \n \tif (sensitive_data.server_key) {\n \t\tkey_free(sensitive_data.server_key);\n \t\tsensitive_data.server_key = NULL;\n \t}\n+\tpid = getpid();\n+\tuid = getuid();\n \tfor (i = 0; i < options.num_host_key_files; i++) {\n \t\tif (sensitive_data.host_keys[i]) {\n+#ifdef SSH_AUDIT_EVENTS\n+\t\t\tchar *fp;\n+\n+\t\t\tif (key_is_private(sensitive_data.host_keys[i]))\n+\t\t\t\tfp = key_fingerprint(sensitive_data.host_keys[i],\n+\t\t\t\t\tkey_fp_type_select(), SSH_FP_HEX);\n+\t\t\telse\n+\t\t\t\tfp = NULL;\n+#endif\n \t\t\tkey_free(sensitive_data.host_keys[i]);\n \t\t\tsensitive_data.host_keys[i] = NULL;\n+#ifdef SSH_AUDIT_EVENTS\n+\t\t\tif (fp != NULL) {\n+\t\t\t\tif (privsep)\n+\t\t\t\t\tPRIVSEP(audit_destroy_sensitive_data(fp,\n+\t\t\t\t\t\tpid, uid));\n+\t\t\t\telse\n+\t\t\t\t\taudit_destroy_sensitive_data(fp,\n+\t\t\t\t\t\tpid, uid);\n+\t\t\t\tfree(fp);\n+\t\t\t}\n+#endif\n \t\t}\n-\t\tif (sensitive_data.host_certificates[i]) {\n+\t\tif (sensitive_data.host_certificates\n+\t\t && sensitive_data.host_certificates[i]) {\n \t\t\tkey_free(sensitive_data.host_certificates[i]);\n \t\t\tsensitive_data.host_certificates[i] = NULL;\n \t\t}\n \t}\n \tsensitive_data.ssh1_host_key = NULL;\n \texplicit_bzero(sensitive_data.ssh1_cookie, SSH_SESSION_KEY_LENGTH);\n }\n \n /* Demote private to public keys for network child */\n void\n demote_sensitive_data(void)\n {\n \tKey *tmp;\n+\tpid_t pid;\n+\tuid_t uid;\n \tint i;\n \n+\tpid = getpid();\n+\tuid = getuid();\n \tif (sensitive_data.server_key) {\n \t\ttmp = key_demote(sensitive_data.server_key);\n \t\tkey_free(sensitive_data.server_key);\n \t\tsensitive_data.server_key = tmp;\n \t}\n \n \tfor (i = 0; i < options.num_host_key_files; i++) {\n \t\tif (sensitive_data.host_keys[i]) {\n+#ifdef SSH_AUDIT_EVENTS\n+\t\t\tchar *fp;\n+\n+\t\t\tif (key_is_private(sensitive_data.host_keys[i]))\n+\t\t\t\tfp = key_fingerprint(sensitive_data.host_keys[i],\n+\t\t\t\t\tkey_fp_type_select(), SSH_FP_HEX);\n+\t\t\telse\n+\t\t\t\tfp = NULL;\n+#endif\n \t\t\ttmp = key_demote(sensitive_data.host_keys[i]);\n \t\t\tkey_free(sensitive_data.host_keys[i]);\n \t\t\tsensitive_data.host_keys[i] = tmp;\n \t\t\tif (tmp->type == KEY_RSA1)\n \t\t\t\tsensitive_data.ssh1_host_key = tmp;\n+#ifdef SSH_AUDIT_EVENTS\n+\t\t\tif (fp != NULL) {\n+\t\t\t\taudit_destroy_sensitive_data(fp, pid, uid);\n+\t\t\t\tfree(fp);\n+\t\t\t}\n+#endif\n \t\t}\n \t\t/* Certs do not need demotion */\n \t}\n \n \t/* We do not clear ssh1_host key and cookie. XXX - Okay Niels? */\n }\n \n static void\n@@ -1199,16 +1246,17 @@ server_accept_loop(int *sock_in, int *so\n \n \t\t/* Wait in select until there is a connection. */\n \t\tret = select(maxfd+1, fdset, NULL, NULL, NULL);\n \t\tif (ret < 0 && errno != EINTR)\n \t\t\terror(\"select: %.100s\", strerror(errno));\n \t\tif (received_sigterm) {\n \t\t\tlogit(\"Received signal %d; terminating.\",\n \t\t\t (int) received_sigterm);\n+\t\t\tdestroy_sensitive_data(0);\n \t\t\tclose_listen_socks();\n \t\t\tunlink(options.pid_file);\n \t\t\texit(received_sigterm == SIGTERM ? 0 : 255);\n \t\t}\n \t\tif (key_used && key_do_regen) {\n \t\t\tgenerate_ephemeral_server_key();\n \t\t\tkey_used = 0;\n \t\t\tkey_do_regen = 0;\n@@ -2168,27 +2216,28 @@ main(int ac, char **av)\n \t/*\n \t * In privilege separation, we fork another child and prepare\n \t * file descriptor passing.\n \t */\n \tif (use_privsep) {\n \t\tprivsep_postauth(authctxt);\n \t\t/* the monitor process [priv] will not return */\n \t\tif (!compat20)\n-\t\t\tdestroy_sensitive_data();\n+\t\t\tdestroy_sensitive_data(0);\n \t}\n \n \tpacket_set_timeout(options.client_alive_interval,\n \t options.client_alive_count_max);\n \n \t/* Start session. */\n \tdo_authenticated(authctxt);\n \n \t/* The connection has been terminated. */\n \tpacket_destroy_all(1, 1);\n+\tdestroy_sensitive_data(1);\n \n \tpacket_get_state(MODE_IN, NULL, NULL, NULL, &ibytes);\n \tpacket_get_state(MODE_OUT, NULL, NULL, NULL, &obytes);\n \tverbose(\"Transferred: sent %llu, received %llu bytes\",\n \t (unsigned long long)obytes, (unsigned long long)ibytes);\n \n \tverbose(\"Closing connection to %.500s port %d\", remote_ip, remote_port);\n \n@@ -2413,17 +2462,17 @@ do_ssh1_kex(void)\n \t\t\tfatal(\"%s: hash failed\", __func__);\n \t\tssh_digest_free(md);\n \t\texplicit_bzero(buf, bytes);\n \t\tfree(buf);\n \t\tfor (i = 0; i < 16; i++)\n \t\t\tsession_id[i] = session_key[i] ^ session_key[i + 16];\n \t}\n \t/* Destroy the private and public keys. No longer. */\n-\tdestroy_sensitive_data();\n+\tdestroy_sensitive_data(0);\n \n \tif (use_privsep)\n \t\tmm_ssh1_session_id(session_id);\n \n \t/* Destroy the decrypted integer. It is no longer needed. */\n \tBN_clear_free(session_key_int);\n \n \t/* Set the session key. From this on all communications will be encrypted. */\n@@ -2559,16 +2608,18 @@ cleanup_exit(int i)\n \t\t\tdebug(\"Killing privsep child %d\", pmonitor->m_pid);\n \t\t\tif (kill(pmonitor->m_pid, SIGKILL) != 0 &&\n \t\t\t errno != ESRCH)\n \t\t\t\terror(\"%s: kill(%d): %s\", __func__,\n \t\t\t\t pmonitor->m_pid, strerror(errno));\n \t\t}\n \t}\n \tis_privsep_child = use_privsep && (pmonitor != NULL) && !mm_is_monitor();\n+\tif (sensitive_data.host_keys != NULL)\n+\t\tdestroy_sensitive_data(is_privsep_child);\n \tpacket_destroy_all(1, is_privsep_child);\n #ifdef SSH_AUDIT_EVENTS\n \t/* done after do_cleanup so it can cancel the PAM auth 'thread' */\n \tif ((the_authctxt == NULL || !the_authctxt->authenticated) &&\n \t (!use_privsep || mm_is_monitor()))\n \t\taudit_event(SSH_CONNECTION_ABANDON);\n #endif\n \t_exit(i);" } ]
{ "id": "openssh-askpass-gnome-5597-openssh-6.6p1-audit6-server_ke", "cve_id": "CVE-2016-6210", "package": "openssh-askpass-gnome", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": false, "license": "BSD-2-Clause", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-3119\n\nThe process_db_args function in plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c in the LDAP KDB module in kadmind in MIT Kerberos 5 (aka krb5) through 1.13.4 and 1.14.x through 1.14.1 mishandles the DB argument, which allows remote authenticated users to cause a denial of service (NULL pointer dereference and daemon crash) via a crafted request to modify a principal.\n\n## Package\nkrb5-mini\n\n## Files to modify\n- src/lib/krb5/krb/bld_princ.c\n\n## Upstream Fix\n```diff\nFrom f0c094a1b745d91ef2f9a4eae2149aac026a5789 Mon Sep 17 00:00:00 2001\nFrom: Greg Hudson <ghudson@mit.edu>\nDate: Fri, 25 Sep 2015 12:51:47 -0400\nSubject: [PATCH] Fix build_principal memory bug [CVE-2015-2697]\n\nIn build_principal_va(), use k5memdup0() instead of strdup() to make a\ncopy of the realm, to ensure that we allocate the correct number of\nbytes and do not read past the end of the input string. This bug\naffects krb5_build_principal(), krb5_build_principal_va(), and\nkrb5_build_principal_alloc_va(). krb5_build_principal_ext() is not\naffected.\n\nCVE-2015-2697:\n\nIn MIT krb5 1.7 and later, an authenticated attacker may be able to\ncause a KDC to crash using a TGS request with a large realm field\nbeginning with a null byte. If the KDC attempts to find a referral to\nanswer the request, it constructs a principal name for lookup using\nkrb5_build_principal() with the requested realm. Due to a bug in this\nfunction, the null byte causes only one byte be allocated for the\nrealm field of the constructed principal, far less than its length.\nSubsequent operations on the lookup principal may cause a read beyond\nthe end of the mapped memory region, causing the KDC process to crash.\n\nCVSSv2: AV:N/AC:L/Au:S/C:N/I:N/A:C/E:POC/RL:OF/RC:C\n\nticket: 8252 (new)\ntarget_version: 1.14\ntags: pullup\n---\n src/lib/krb5/krb/bld_princ.c | 6 ++----\n 1 file changed, 2 insertions(+), 4 deletions(-)\n\ndiff --git a/src/lib/krb5/krb/bld_princ.c b/src/lib/krb5/krb/bld_princ.c\nindex ab6fed897f1..8604268ceb8 100644\n--- a/src/lib/krb5/krb/bld_princ.c\n+++ b/src/lib/krb5/krb/bld_princ.c\n@@ -40,10 +40,8 @@ build_principal_va(krb5_context context, krb5_principal princ,\n data = malloc(size * sizeof(krb5_data));\n if (!data) { retval = ENOMEM; }\n \n- if (!retval) {\n- r = strdup(realm);\n- if (!r) { retval = ENOMEM; }\n- }\n+ if (!retval)\n+ r = k5memdup0(realm, rlen, &retval);\n \n while (!retval && (component = va_arg(ap, char *))) {\n if (count == size) {\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From f0c094a1b745d91ef2f9a4eae2149aac026a5789 Mon Sep 17 00:00:00 2001\nFrom: Greg Hudson <ghudson@mit.edu>\nDate: Fri, 25 Sep 2015 12:51:47 -0400\nSubject: [PATCH] Fix build_principal memory bug [CVE-2015-2697]\n\nIn build_principal_va(), use k5memdup0() instead of strdup() to make a\ncopy of the realm, to ensure that we allocate the correct number of\nbytes and do not read past the end of the input string. This bug\naffects krb5_build_principal(), krb5_build_principal_va(), and\nkrb5_build_principal_alloc_va(). krb5_build_principal_ext() is not\naffected.\n\nCVE-2015-2697:\n\nIn MIT krb5 1.7 and later, an authenticated attacker may be able to\ncause a KDC to crash using a TGS request with a large realm field\nbeginning with a null byte. If the KDC attempts to find a referral to\nanswer the request, it constructs a principal name for lookup using\nkrb5_build_principal() with the requested realm. Due to a bug in this\nfunction, the null byte causes only one byte be allocated for the\nrealm field of the constructed principal, far less than its length.\nSubsequent operations on the lookup principal may cause a read beyond\nthe end of the mapped memory region, causing the KDC process to crash.\n\nCVSSv2: AV:N/AC:L/Au:S/C:N/I:N/A:C/E:POC/RL:OF/RC:C\n\nticket: 8252 (new)\ntarget_version: 1.14\ntags: pullup\n\ndiff --git a/src/lib/krb5/krb/bld_princ.c b/src/lib/krb5/krb/bld_princ.c\nindex ab6fed8..8604268 100644\n--- a/src/lib/krb5/krb/bld_princ.c\n+++ b/src/lib/krb5/krb/bld_princ.c\n@@ -40,10 +40,8 @@ build_principal_va(krb5_context context, krb5_principal princ,\n data = malloc(size * sizeof(krb5_data));\n if (!data) { retval = ENOMEM; }\n \n- if (!retval) {\n- r = strdup(realm);\n- if (!r) { retval = ENOMEM; }\n- }\n+ if (!retval)\n+ r = k5memdup0(realm, rlen, &retval);\n \n while (!retval && (component = va_arg(ap, char *))) {\n if (count == size) {\n-- \n2.6.2" } ]
{ "id": "krb5-mini-4938-0100-Fix-build_principal-memor", "cve_id": "CVE-2016-3119", "package": "krb5-mini", "upstream_enriched": true, "upstream_commit": "f0c094a1b745d91ef2f9a4eae2149aac026a5789", "upstream_repo": "krb5/krb5", "tier": "adapted", "has_source_context": false, "license": "MIT", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-8779\n\nStack-based buffer overflow in the catopen function in the GNU C Library (aka glibc or libc6) before 2.23 allows context-dependent attackers to cause a denial of service (application crash) or possibly execute arbitrary code via a long catalog name.\n\n## Package\nglibc-utils\n\n## Files to modify\n- resolv/res_init.c\n- resolv/res_send.c\n- glibc-2.19.orig/resolv/res_init.c\n- glibc-2.19.orig/resolv/res_send.c\n\n## Target Source Code\n\n### resolv/res_init.c\n\n#### __res_vinit() [lines 148-353]\n```c\n\n/* This function has to be reachable by res_data.c but not publically. */\nint\n__res_vinit(res_state statp, int preinit) {\n\tFILE *fp;\n\tchar *cp, **pp;\n\tint n;\n\tchar buf[BUFSIZ];\n\tint nserv = 0; /* number of nameserver records read from file */\n#ifdef _LIBC\n\tint nservall = 0; /* number of NS records read, nserv IPv4 only */\n#endif\n\tint haveenv = 0;\n\tint havesearch = 0;\n#ifdef RESOLVSORT\n\tint nsort = 0;\n\tchar *net;\n#endif\n#ifndef RFC1535\n\tint dots;\n#endif\n#ifdef _LIBC\n\tstatp->_u._ext.initstamp = __res_initstamp;\n#endif\n\n\tif (!preinit) {\n\t\tstatp->retrans = RES_TIMEOUT;\n\t\tstatp->retry = RES_DFLRETRY;\n\t\tstatp->options = RES_DEFAULT;\n\t\tstatp->id = res_randomid();\n\t}\n\n\tstatp->nscount = 0;\n\tstatp->ndots = 1;\n\tstatp->pfcode = 0;\n\tstatp->_vcsock = -1;\n\tstatp->_flags = 0;\n\tstatp->qhook = NULL;\n\tstatp->rhook = NULL;\n\tstatp->_u._ext.nsinit = 0;\n/* ... 156 lines omitted ... */\n\t\t\t\tsa6->sin6_flowinfo = 0;\n\t\t\t\tsa6->sin6_addr = a6;\n\n\t\t\t\tif (__builtin_expect (el == NULL, 1))\n\t\t\t\t sa6->sin6_scope_id = 0;\n\t\t\t\telse {\n\t\t\t\t int try_numericscope = 1;\n\t\t\t\t if (IN6_IS_ADDR_LINKLOCAL (&a6)\n\t\t\t\t\t|| IN6_IS_ADDR_MC_LINKLOCAL (&a6)) {\n\t\t\t\t\tsa6->sin6_scope_id\n\t\t\t\t\t = if_nametoindex (el + 1);\n\t\t\t\t\tif (sa6->sin6_scope_id != 0)\n\t\t\t\t\t try_numericscope = 0;\n\t\t\t\t }\n\n\t\t\t\t if (try_numericscope) {\n\t\t\t\t\tchar *end;\n\t\t\t\t\tsa6->sin6_scope_id\n\t\t\t\t\t = (uint32_t) strtoul (el + 1, &end,\n\t\t\t\t\t\t\t\t10);\n```\n\n#### __res_iclose() [lines 598-627]\n```c\n * This routine is not expected to be user visible.\n */\nvoid\n__res_iclose(res_state statp, bool free_addr) {\n\tint ns;\n\n\tif (statp->_vcsock >= 0) {\n\t\tclose_not_cancel_no_status(statp->_vcsock);\n\t\tstatp->_vcsock = -1;\n\t\tstatp->_flags &= ~(RES_F_VC | RES_F_CONN);\n\t}\n#ifdef _LIBC\n\tfor (ns = 0; ns < MAXNS; ns++)\n#else\n\tfor (ns = 0; ns < statp->_u._ext.nscount; ns++)\n#endif\n\t\tif (statp->_u._ext.nsaddrs[ns]) {\n\t\t\tif (statp->_u._ext.nssocks[ns] != -1) {\n\t\t\t\tclose_not_cancel_no_status(statp->_u._ext.nssocks[ns]);\n\t\t\t\tstatp->_u._ext.nssocks[ns] = -1;\n\t\t\t}\n\t\t\tif (free_addr) {\n\t\t\t\tfree (statp->_u._ext.nsaddrs[ns]);\n\t\t\t\tstatp->_u._ext.nsaddrs[ns] = NULL;\n\t\t\t}\n\t\t}\n\tstatp->_u._ext.nsinit = 0;\n}\nlibc_hidden_def (__res_iclose)\n\n```\n\n### resolv/res_send.c\n\n#### evNowTime() [lines 165-177]\n```c\n}\n\nstatic void\nevNowTime(struct timespec *res) {\n\tstruct timeval now;\n\n\tif (gettimeofday(&now, NULL) < 0)\n\t\tevConsTime(res, 0, 0);\n\telse\n\t\tTIMEVAL_TO_TIMESPEC (&now, res);\n}\n\n\n```\n\n#### res_ourserver_p() [lines 211-248]\n```c\n *\tpaul vixie, 29may94\n */\nint\nres_ourserver_p(const res_state statp, const struct sockaddr_in6 *inp)\n{\n\tint ns;\n\n\tif (inp->sin6_family == AF_INET) {\n\t struct sockaddr_in *in4p = (struct sockaddr_in *) inp;\n\t in_port_t port = in4p->sin_port;\n\t in_addr_t addr = in4p->sin_addr.s_addr;\n\n\t for (ns = 0; ns < MAXNS; ns++) {\n\t\tconst struct sockaddr_in *srv =\n\t\t (struct sockaddr_in *)EXT(statp).nsaddrs[ns];\n\n\t\tif ((srv != NULL) && (srv->sin_family == AF_INET) &&\n\t\t (srv->sin_port == port) &&\n\t\t (srv->sin_addr.s_addr == INADDR_ANY ||\n\t\t srv->sin_addr.s_addr == addr))\n\t\t return (1);\n\t }\n\t} else if (inp->sin6_family == AF_INET6) {\n\t for (ns = 0; ns < MAXNS; ns++) {\n\t\tconst struct sockaddr_in6 *srv = EXT(statp).nsaddrs[ns];\n\t\tif ((srv != NULL) && (srv->sin6_family == AF_INET6) &&\n\t\t (srv->sin6_port == inp->sin6_port) &&\n\t\t !(memcmp(&srv->sin6_addr, &in6addr_any,\n\t\t\t sizeof (struct in6_addr)) &&\n\t\t memcmp(&srv->sin6_addr, &inp->sin6_addr,\n\t\t\t sizeof (struct in6_addr))))\n\t\t return (1);\n\t }\n\t}\n\treturn (0);\n}\n\n/* int\n```\n\n#### __libc_res_nsend() [lines 340-644]\n```c\nlibresolv_hidden_def (res_queriesmatch)\n\nint\n__libc_res_nsend(res_state statp, const u_char *buf, int buflen,\n\t\t const u_char *buf2, int buflen2,\n\t\t u_char *ans, int anssiz, u_char **ansp, u_char **ansp2,\n\t\t int *nansp2, int *resplen2)\n{\n int gotsomewhere, terrno, try, v_circuit, resplen, ns, n;\n\n\tif (statp->nscount == 0) {\n\t\t__set_errno (ESRCH);\n\t\treturn (-1);\n\t}\n\n\tif (anssiz < (buf2 == NULL ? 1 : 2) * HFIXEDSZ) {\n\t\t__set_errno (EINVAL);\n\t\treturn (-1);\n\t}\n\n#ifdef USE_HOOKS\n\tif (__builtin_expect (statp->qhook || statp->rhook, 0)) {\n\t\tif (anssiz < MAXPACKET && ansp) {\n\t\t\tu_char *buf = malloc (MAXPACKET);\n\t\t\tif (buf == NULL)\n\t\t\t\treturn (-1);\n\t\t\tmemcpy (buf, ans, HFIXEDSZ);\n\t\t\t*ansp = buf;\n\t\t\tans = buf;\n\t\t\tanssiz = MAXPACKET;\n\t\t}\n\t}\n#endif\n\n\tDprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_QUERY),\n\t\t(stdout, \";; res_send()\\n\"), buf, buflen);\n\tv_circuit = ((statp->options & RES_USEVC)\n\t\t || buflen > PACKETSZ\n\t\t || buflen2 > PACKETSZ);\n\tgotsomewhere = 0;\n\tterrno = ETIMEDOUT;\n\n\t/*\n\t * If the ns_addr_list in the resolver context has changed, then\n\t * invalidate our cached copy and the associated timing data.\n\t */\n\tif (EXT(statp).nsinit) {\n\t\tint needclose = 0;\n\n\t\tif (EXT(statp).nscount != statp->nscount)\n\t\t\tneedclose++;\n\t\telse\n\t\t\tfor (ns = 0; ns < MAXNS; ns++) {\n\t\t\t\tunsigned int map = EXT(statp).nsmap[ns];\n\t\t\t\tif (map < MAXNS\n\t\t\t\t && !sock_eq((struct sockaddr_in6 *)\n\t\t\t\t\t\t&statp->nsaddr_list[map],\n\t\t\t\t\t\tEXT(statp).nsaddrs[ns]))\n\t\t\t\t{\n\t\t\t\t\tneedclose++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\tif (needclose)\n\t\t\t__res_iclose(statp, false);\n\t}\n\n\t/*\n\t * Maybe initialize our private copy of the ns_addr_list.\n\t */\n\tif (EXT(statp).nsinit == 0) {\n\t\tunsigned char map[MAXNS];\n\n\t\tmemset (map, MAXNS, sizeof (map));\n\t\tfor (n = 0; n < MAXNS; n++) {\n\t\t\tns = EXT(statp).nsmap[n];\n\t\t\tif (ns < statp->nscount)\n\t\t\t\tmap[ns] = n;\n\t\t\telse if (ns < MAXNS) {\n\t\t\t\tfree(EXT(statp).nsaddrs[n]);\n\t\t\t\tEXT(statp).nsaddrs[n] = NULL;\n\t\t\t\tEXT(statp).nsmap[n] = MAXNS;\n\t\t\t}\n\t\t}\n\t\tn = statp->nscount;\n\t\tif (statp->nscount > EXT(statp).nscount)\n\t\t\tfor (n = EXT(statp).nscount, ns = 0;\n\t\t\t n < statp->nscount; n++) {\n\t\t\t\twhile (ns < MAXNS\n\t\t\t\t && EXT(statp).nsmap[ns] != MAXNS)\n\t\t\t\t\tns++;\n\t\t\t\tif (ns == MAXNS)\n\t\t\t\t\tbreak;\n\t\t\t\tEXT(statp).nsmap[ns] = n;\n\t\t\t\tmap[n] = ns++;\n\t\t\t}\n\t\tEXT(statp).nscount = n;\n\t\tfor (ns = 0; ns < EXT(statp).nscount; ns++) {\n\t\t\tn = map[ns];\n\t\t\tif (EXT(statp).nsaddrs[n] == NULL)\n\t\t\t\tEXT(statp).nsaddrs[n] =\n\t\t\t\t malloc(sizeof (struct sockaddr_in6));\n\t\t\tif (EXT(statp).nsaddrs[n] != NULL) {\n\t\t\t\tmemset (mempcpy(EXT(statp).nsaddrs[n],\n\t\t\t\t\t\t&statp->nsaddr_list[ns],\n\t\t\t\t\t\tsizeof (struct sockaddr_in)),\n\t\t\t\t\t'\\0',\n\t\t\t\t\tsizeof (struct sockaddr_in6)\n\t\t\t\t\t- sizeof (struct sockaddr_in));\n\t\t\t\tEXT(statp).nssocks[n] = -1;\n\t\t\t\tn++;\n\t\t\t}\n\t\t}\n\t\tEXT(statp).nsinit = 1;\n\t}\n\n\t/*\n\t * Some resolvers want to even out the load on their nameservers.\n\t * Note that RES_BLAST overrides RES_ROTATE.\n\t */\n\tif (__builtin_expect ((statp->options & RES_ROTATE) != 0, 0) &&\n\t (statp->options & RES_BLAST) == 0) {\n\t\tstruct sockaddr_in6 *ina;\n\t\tunsigned int map;\n\n\t\tn = 0;\n\t\twhile (n < MAXNS && EXT(statp).nsmap[n] == MAXNS)\n\t\t\tn++;\n/* ... 157 lines omitted ... */\n\t\t\t} while (!done);\n\n\t\t}\n#endif\n\t\treturn (resplen);\n next_ns: ;\n\t } /*foreach ns*/\n\t} /*foreach retry*/\n\t__res_iclose(statp, false);\n\tif (!v_circuit) {\n\t\tif (!gotsomewhere)\n\t\t\t__set_errno (ECONNREFUSED);\t/* no nameservers found */\n\t\telse\n\t\t\t__set_errno (ETIMEDOUT);\t/* no answer obtained */\n\t} else\n\t\t__set_errno (terrno);\n\treturn (-1);\n}\n\nint\n```\n\n#### libresolv_hidden_def() [lines 614-700]\n```c\n\t\t\t\t\tgoto next_ns;\n\t\t\t\tcase res_modified:\n\t\t\t\t\t/* give the hook another try */\n\t\t\t\t\tif (++loops < 42) /*doug adams*/\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t/*FALLTHROUGH*/\n\t\t\t\tcase res_error:\n\t\t\t\t\t/*FALLTHROUGH*/\n\t\t\t\tdefault:\n\t\t\t\t\treturn (-1);\n\t\t\t\t}\n\t\t\t} while (!done);\n\n\t\t}\n#endif\n\t\treturn (resplen);\n next_ns: ;\n\t } /*foreach ns*/\n\t} /*foreach retry*/\n\t__res_iclose(statp, false);\n\tif (!v_circuit) {\n\t\tif (!gotsomewhere)\n\t\t\t__set_errno (ECONNREFUSED);\t/* no nameservers found */\n\t\telse\n\t\t\t__set_errno (ETIMEDOUT);\t/* no answer obtained */\n\t} else\n\t\t__set_errno (terrno);\n\treturn (-1);\n}\n\nint\nres_nsend(res_state statp,\n\t const u_char *buf, int buflen, u_char *ans, int anssiz)\n{\n return __libc_res_nsend(statp, buf, buflen, NULL, 0, ans, anssiz,\n\t\t\t NULL, NULL, NULL, NULL);\n}\nlibresolv_hidden_def (res_nsend)\n\n/* Private */\n\nstatic int\nsend_vc(res_state statp,\n\tconst u_char *buf, int buflen, const u_char *buf2, int buflen2,\n\tu_char **ansp, int *anssizp,\n\tint *terrno, int ns, u_char **anscp, u_char **ansp2, int *anssizp2,\n\tint *resplen2)\n{\n\tconst HEADER *hp = (HEADER *) buf;\n\tconst HEADER *hp2 = (HEADER *) buf2;\n\tu_char *ans = *ansp;\n\tint orig_anssizp = *anssizp;\n\t// XXX REMOVE\n\t// int anssiz = *anssizp;\n\tHEADER *anhp = (HEADER *) ans;\n\tstruct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns];\n\tint truncating, connreset, resplen, n;\n\tstruct iovec iov[4];\n\tu_short len;\n\tu_short len2;\n\tu_char *cp;\n\n\tif (resplen2 != NULL)\n\t *resplen\n/* ... truncated ... */\n```\n\n\n## Upstream Fix\n```diff\nFrom 6c07233f12e00b9cf66fb5d4a9b7ddb897590912 Mon Sep 17 00:00:00 2001\nFrom: Andreas Schwab <schwab@suse.de>\nDate: Thu, 19 Feb 2015 15:52:08 +0100\nSubject: [PATCH] Simplify handling of nameserver configuration in resolver\n\n\t[BZ #13028]\n\t[BZ #17053]\n\t* resolv/res_init.c (__res_vinit): Remove use of ext.nsmap.\n\t* resolv/res_send.c (__libc_res_nsend): Likewise.\n\t(get_nsaddr): New function.\n\t(res_ourserver_p, send_vc, reopen): Use it instead of accessing\n\tstatp directly.\n---\n resolv/res_init.c | 47 +++++-----------\n resolv/res_send.c | 164 +++++++++++++++++++++++-------------------------------\n 2 files changed, 84 insertions(+), 127 deletions(-)\n\nIndex: glibc-2.19/resolv/res_init.c\n===================================================================\n--- glibc-2.19.orig/resolv/res_init.c\n+++ glibc-2.19/resolv/res_init.c\n@@ -153,10 +153,8 @@ __res_vinit(res_state statp, int preinit\n \tchar *cp, **pp;\n \tint n;\n \tchar buf[BUFSIZ];\n-\tint nserv = 0; /* number of nameserver records read from file */\n-#ifdef _LIBC\n-\tint nservall = 0; /* number of NS records read, nserv IPv4 only */\n-#endif\n+\tint nserv = 0; /* number of nameservers read from file */\n+\tint have_serv6 = 0;\n \tint haveenv = 0;\n \tint havesearch = 0;\n #ifdef RESOLVSORT\n@@ -184,15 +182,9 @@ __res_vinit(res_state statp, int preinit\n \tstatp->_flags = 0;\n \tstatp->qhook = NULL;\n \tstatp->rhook = NULL;\n-\tstatp->_u._ext.nsinit = 0;\n \tstatp->_u._ext.nscount = 0;\n-#ifdef _LIBC\n-\tstatp->_u._ext.nscount6 = 0;\n-\tfor (n = 0; n < MAXNS; n++) {\n-\t\tstatp->_u._ext.nsaddrs[n] = NULL;\n-\t\tstatp->_u._ext.nsmap[n] = MAXNS;\n-\t}\n-#endif\n+\tfor (n = 0; n < MAXNS; n++)\n+\t statp->_u._ext.nsaddrs[n] = NULL;\n \n \t/* Allow user to override the local domain definition */\n \tif ((cp = getenv(\"LOCALDOMAIN\")) != NULL) {\n@@ -296,11 +288,7 @@ __res_vinit(res_state statp, int preinit\n \t\t continue;\n \t\t}\n \t\t/* read nameservers to query */\n-#ifdef _LIBC\n-\t\tif (MATCH(buf, \"nameserver\") && nservall < MAXNS) {\n-#else\n \t\tif (MATCH(buf, \"nameserver\") && nserv < MAXNS) {\n-#endif\n \t\t struct in_addr a;\n \n \t\t cp = buf + sizeof(\"nameserver\") - 1;\n@@ -308,13 +296,12 @@ __res_vinit(res_state statp, int preinit\n \t\t\tcp++;\n \t\t if ((*cp != '\\0') && (*cp != '\\n')\n \t\t\t&& __inet_aton(cp, &a)) {\n-\t\t\tstatp->nsaddr_list[nservall].sin_addr = a;\n-\t\t\tstatp->nsaddr_list[nservall].sin_family = AF_INET;\n-\t\t\tstatp->nsaddr_list[nservall].sin_port =\n+\t\t\tstatp->nsaddr_list[nserv].sin_addr = a;\n+\t\t\tstatp->nsaddr_list[nserv].sin_family = AF_INET;\n+\t\t\tstatp->nsaddr_list[nserv].sin_port =\n \t\t\t\thtons(NAMESERVER_PORT);\n \t\t\tnserv++;\n #ifdef _LIBC\n-\t\t\tnservall++;\n \t\t } else {\n \t\t\tstruct in6_addr a6;\n \t\t\tchar *el;\n@@ -356,10 +343,11 @@ __res_vinit(res_state statp, int preinit\n \t\t\t\t }\n \t\t\t\t}\n \n-\t\t\t\tstatp->_u._ext.nsaddrs[nservall] = sa6;\n-\t\t\t\tstatp->_u._ext.nssocks[nservall] = -1;\n-\t\t\t\tstatp->_u._ext.nsmap[nservall] = MAXNS + 1;\n-\t\t\t\tnservall++;\n+\t\t\t\tstatp->nsaddr_list[nserv].sin_family = 0;\n+\t\t\t\tstatp->_u._ext.nsaddrs[nserv] = sa6;\n+\t\t\t\tstatp->_u._ext.nssocks[nserv] = -1;\n+\t\t\t\thave_serv6 = 1;\n+\t\t\t\tnserv++;\n \t\t\t }\n \t\t\t}\n #endif\n@@ -414,10 +402,9 @@ __res_vinit(res_state statp, int preinit\n \t\t continue;\n \t\t}\n \t }\n-\t statp->nscount = nservall;\n+\t statp->nscount = nserv;\n #ifdef _LIBC\n-\t if (nservall - nserv > 0) {\n-\t\tstatp->_u._ext.nscount6 = nservall - nserv;\n+\t if (have_serv6) {\n \t\t/* We try IPv6 servers again. */\n \t\tstatp->ipv6_unavail = false;\n \t }\n@@ -606,11 +593,7 @@ __res_iclose(res_state statp, bool free_\n \t\tstatp->_vcsock = -1;\n \t\tstatp->_flags &= ~(RES_F_VC | RES_F_CONN);\n \t}\n-#ifdef _LIBC\n-\tfor (ns = 0; ns < MAXNS; ns++)\n-#else\n \tfor (ns = 0; ns < statp->_u._ext.nscount; ns++)\n-#endif\n \t\tif (statp->_u._ext.nsaddrs[ns]) {\n \t\t\tif (statp->_u._ext.nssocks[ns] != -1) {\n \t\t\t\tclose_not_cancel_no_status(statp->_u._ext.nssocks[ns]);\n@@ -621,7 +604,6 @@ __res_iclose(res_state statp, bool free_\n \t\t\t\tstatp->_u._ext.nsaddrs[ns] = NULL;\n \t\t\t}\n \t\t}\n-\tstatp->_u._ext.nsinit = 0;\n }\n libc_hidden_def (__res_iclose)\n \nIndex: glibc-2.19/resolv/res_send.c\n===================================================================\n--- glibc-2.19.orig/resolv/res_send.c\n+++ glibc-2.19/resolv/res_send.c\n@@ -183,6 +183,7 @@ evNowTime(struct timespec *res) {\n \n /* Forward. */\n \n+static struct sockaddr *get_nsaddr (res_state, int);\n static int\t\tsend_vc(res_state, const u_char *, int,\n \t\t\t\tconst u_char *, int,\n \t\t\t\tu_char **, int *, int *, int, u_char **,\n@@ -220,20 +221,21 @@ res_ourserver_p(const res_state statp, c\n \t in_port_t port = in4p->sin_port;\n \t in_addr_t addr = in4p->sin_addr.s_addr;\n \n-\t for (ns = 0; ns < MAXNS; ns++) {\n+\t for (ns = 0; ns < statp->nscount; ns++) {\n \t\tconst struct sockaddr_in *srv =\n-\t\t (struct sockaddr_in *)EXT(statp).nsaddrs[ns];\n+\t\t (struct sockaddr_in *) get_nsaddr (statp, ns);\n \n-\t\tif ((srv != NULL) && (srv->sin_family == AF_INET) &&\n+\t\tif ((srv->sin_family == AF_INET) &&\n \t\t (srv->sin_port == port) &&\n \t\t (srv->sin_addr.s_addr == INADDR_ANY ||\n \t\t srv->sin_addr.s_addr == addr))\n \t\t return (1);\n \t }\n \t} else if (inp->sin6_family == AF_INET6) {\n-\t for (ns = 0; ns < MAXNS; ns++) {\n-\t\tconst struct sockaddr_in6 *srv = EXT(statp).nsaddrs[ns];\n-\t\tif ((srv != NULL) && (srv->sin6_family == AF_INET6) &&\n+\t for (ns = 0; ns < statp->nscount; ns++) {\n+\t\tconst struct sockaddr_in6 *srv\n+\t\t = (struct sockaddr_in6 *) get_nsaddr (statp, ns);\n+\t\tif ((srv->sin6_family == AF_INET6) &&\n \t\t (srv->sin6_port == inp->sin6_port) &&\n \t\t !(memcmp(&srv->sin6_addr, &in6addr_any,\n \t\t\t sizeof (struct in6_addr)) &&\n@@ -383,74 +385,48 @@ __libc_res_nsend(res_state statp, const\n \t * If the ns_addr_list in the resolver context has changed, then\n \t * invalidate our cached copy and the associated timing data.\n \t */\n-\tif (EXT(statp).nsinit) {\n+\tif (EXT(statp).nscount != 0) {\n \t\tint needclose = 0;\n \n \t\tif (EXT(statp).nscount != statp->nscount)\n \t\t\tneedclose++;\n \t\telse\n-\t\t\tfor (ns = 0; ns < MAXNS; ns++) {\n-\t\t\t\tunsigned int map = EXT(statp).nsmap[ns];\n-\t\t\t\tif (map < MAXNS\n+\t\t\tfor (ns = 0; ns < statp->nscount; ns++) {\n+\t\t\t\tif (statp->nsaddr_list[ns].sin_family != 0\n \t\t\t\t && !sock_eq((struct sockaddr_in6 *)\n-\t\t\t\t\t\t&statp->nsaddr_list[map],\n+\t\t\t\t\t\t&statp->nsaddr_list[ns],\n \t\t\t\t\t\tEXT(statp).nsaddrs[ns]))\n \t\t\t\t{\n \t\t\t\t\tneedclose++;\n \t\t\t\t\tbreak;\n \t\t\t\t}\n \t\t\t}\n-\t\tif (needclose)\n+\t\tif (needclose) {\n \t\t\t__res_iclose(statp, false);\n+\t\t\tEXT(statp).nscount = 0;\n+\t\t}\n \t}\n \n \t/*\n \t * Maybe initialize our private copy of the ns_addr_list.\n \t */\n-\tif (EXT(statp).nsinit == 0) {\n-\t\tunsigned char map[MAXNS];\n-\n-\t\tmemset (map, MAXNS, sizeof (map));\n-\t\tfor (n = 0; n < MAXNS; n++) {\n-\t\t\tns = EXT(statp).nsmap[n];\n-\t\t\tif (ns < statp->nscount)\n-\t\t\t\tmap[ns] = n;\n-\t\t\telse if (ns < MAXNS) {\n-\t\t\t\tfree(EXT(statp).nsaddrs[n]);\n-\t\t\t\tEXT(statp).nsaddrs[n] = NULL;\n-\t\t\t\tEXT(statp).nsmap[n] = MAXNS;\n-\t\t\t}\n-\t\t}\n-\t\tn = statp->nscount;\n-\t\tif (statp->nscount > EXT(statp).nscount)\n-\t\t\tfor (n = EXT(statp).nscount, ns = 0;\n-\t\t\t n < statp->nscount; n++) {\n-\t\t\t\twhile (ns < MAXNS\n-\t\t\t\t && EXT(statp).nsmap[ns] != MAXNS)\n-\t\t\t\t\tns++;\n-\t\t\t\tif (ns == MAXNS)\n-\t\t\t\t\tbreak;\n-\t\t\t\tEXT(statp).nsmap[ns] = n;\n-\t\t\t\tmap[n] = ns++;\n-\t\t\t}\n-\t\tEXT(statp).nscount = n;\n-\t\tfor (ns = 0; ns < EXT(statp).nscount; ns++) {\n-\t\t\tn = map[ns];\n-\t\t\tif (EXT(statp).nsaddrs[n] == NULL)\n-\t\t\t\tEXT(statp).nsaddrs[n] =\n+\tif (EXT(statp).nscount == 0) {\n+\t\tfor (ns = 0; ns < statp->nscount; ns++) {\n+\t\t\tEXT(statp).nssocks[ns] = -1;\n+\t\t\tif (statp->nsaddr_list[ns].sin_family == 0)\n+\t\t\t\tcontinue;\n+\t\t\tif (EXT(statp).nsaddrs[ns] == NULL)\n+\t\t\t\tEXT(statp).nsaddrs[ns] =\n \t\t\t\t malloc(sizeof (struct sockaddr_in6));\n-\t\t\tif (EXT(statp).nsaddrs[n] != NULL) {\n-\t\t\t\tmemset (mempcpy(EXT(statp).nsaddrs[n],\n+\t\t\tif (EXT(statp).nsaddrs[ns] != NULL)\n+\t\t\t\tmemset (mempcpy(EXT(statp).nsaddrs[ns],\n \t\t\t\t\t\t&statp->nsaddr_list[ns],\n \t\t\t\t\t\tsizeof (struct sockaddr_in)),\n \t\t\t\t\t'\\0',\n \t\t\t\t\tsizeof (struct sockaddr_in6)\n \t\t\t\t\t- sizeof (struct sockaddr_in));\n-\t\t\t\tEXT(statp).nssocks[n] = -1;\n-\t\t\t\tn++;\n-\t\t\t}\n \t\t}\n-\t\tEXT(statp)\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 6c07233f12e00b9cf66fb5d4a9b7ddb897590912 Mon Sep 17 00:00:00 2001\nFrom: Andreas Schwab <schwab@suse.de>\nDate: Thu, 19 Feb 2015 15:52:08 +0100\nSubject: [PATCH] Simplify handling of nameserver configuration in resolver\n\n\t[BZ #13028]\n\t[BZ #17053]\n\t* resolv/res_init.c (__res_vinit): Remove use of ext.nsmap.\n\t* resolv/res_send.c (__libc_res_nsend): Likewise.\n\t(get_nsaddr): New function.\n\t(res_ourserver_p, send_vc, reopen): Use it instead of accessing\n\tstatp directly.\n---\n resolv/res_init.c | 47 +++++-----------\n resolv/res_send.c | 164 +++++++++++++++++++++++-------------------------------\n 2 files changed, 84 insertions(+), 127 deletions(-)\n\nIndex: glibc-2.19/resolv/res_init.c\n===================================================================\n--- glibc-2.19.orig/resolv/res_init.c\n+++ glibc-2.19/resolv/res_init.c\n@@ -153,10 +153,8 @@ __res_vinit(res_state statp, int preinit\n \tchar *cp, **pp;\n \tint n;\n \tchar buf[BUFSIZ];\n-\tint nserv = 0; /* number of nameserver records read from file */\n-#ifdef _LIBC\n-\tint nservall = 0; /* number of NS records read, nserv IPv4 only */\n-#endif\n+\tint nserv = 0; /* number of nameservers read from file */\n+\tint have_serv6 = 0;\n \tint haveenv = 0;\n \tint havesearch = 0;\n #ifdef RESOLVSORT\n@@ -184,15 +182,9 @@ __res_vinit(res_state statp, int preinit\n \tstatp->_flags = 0;\n \tstatp->qhook = NULL;\n \tstatp->rhook = NULL;\n-\tstatp->_u._ext.nsinit = 0;\n \tstatp->_u._ext.nscount = 0;\n-#ifdef _LIBC\n-\tstatp->_u._ext.nscount6 = 0;\n-\tfor (n = 0; n < MAXNS; n++) {\n-\t\tstatp->_u._ext.nsaddrs[n] = NULL;\n-\t\tstatp->_u._ext.nsmap[n] = MAXNS;\n-\t}\n-#endif\n+\tfor (n = 0; n < MAXNS; n++)\n+\t statp->_u._ext.nsaddrs[n] = NULL;\n \n \t/* Allow user to override the local domain definition */\n \tif ((cp = getenv(\"LOCALDOMAIN\")) != NULL) {\n@@ -296,11 +288,7 @@ __res_vinit(res_state statp, int preinit\n \t\t continue;\n \t\t}\n \t\t/* read nameservers to query */\n-#ifdef _LIBC\n-\t\tif (MATCH(buf, \"nameserver\") && nservall < MAXNS) {\n-#else\n \t\tif (MATCH(buf, \"nameserver\") && nserv < MAXNS) {\n-#endif\n \t\t struct in_addr a;\n \n \t\t cp = buf + sizeof(\"nameserver\") - 1;\n@@ -308,13 +296,12 @@ __res_vinit(res_state statp, int preinit\n \t\t\tcp++;\n \t\t if ((*cp != '\\0') && (*cp != '\\n')\n \t\t\t&& __inet_aton(cp, &a)) {\n-\t\t\tstatp->nsaddr_list[nservall].sin_addr = a;\n-\t\t\tstatp->nsaddr_list[nservall].sin_family = AF_INET;\n-\t\t\tstatp->nsaddr_list[nservall].sin_port =\n+\t\t\tstatp->nsaddr_list[nserv].sin_addr = a;\n+\t\t\tstatp->nsaddr_list[nserv].sin_family = AF_INET;\n+\t\t\tstatp->nsaddr_list[nserv].sin_port =\n \t\t\t\thtons(NAMESERVER_PORT);\n \t\t\tnserv++;\n #ifdef _LIBC\n-\t\t\tnservall++;\n \t\t } else {\n \t\t\tstruct in6_addr a6;\n \t\t\tchar *el;\n@@ -356,10 +343,11 @@ __res_vinit(res_state statp, int preinit\n \t\t\t\t }\n \t\t\t\t}\n \n-\t\t\t\tstatp->_u._ext.nsaddrs[nservall] = sa6;\n-\t\t\t\tstatp->_u._ext.nssocks[nservall] = -1;\n-\t\t\t\tstatp->_u._ext.nsmap[nservall] = MAXNS + 1;\n-\t\t\t\tnservall++;\n+\t\t\t\tstatp->nsaddr_list[nserv].sin_family = 0;\n+\t\t\t\tstatp->_u._ext.nsaddrs[nserv] = sa6;\n+\t\t\t\tstatp->_u._ext.nssocks[nserv] = -1;\n+\t\t\t\thave_serv6 = 1;\n+\t\t\t\tnserv++;\n \t\t\t }\n \t\t\t}\n #endif\n@@ -414,10 +402,9 @@ __res_vinit(res_state statp, int preinit\n \t\t continue;\n \t\t}\n \t }\n-\t statp->nscount = nservall;\n+\t statp->nscount = nserv;\n #ifdef _LIBC\n-\t if (nservall - nserv > 0) {\n-\t\tstatp->_u._ext.nscount6 = nservall - nserv;\n+\t if (have_serv6) {\n \t\t/* We try IPv6 servers again. */\n \t\tstatp->ipv6_unavail = false;\n \t }\n@@ -606,11 +593,7 @@ __res_iclose(res_state statp, bool free_\n \t\tstatp->_vcsock = -1;\n \t\tstatp->_flags &= ~(RES_F_VC | RES_F_CONN);\n \t}\n-#ifdef _LIBC\n-\tfor (ns = 0; ns < MAXNS; ns++)\n-#else\n \tfor (ns = 0; ns < statp->_u._ext.nscount; ns++)\n-#endif\n \t\tif (statp->_u._ext.nsaddrs[ns]) {\n \t\t\tif (statp->_u._ext.nssocks[ns] != -1) {\n \t\t\t\tclose_not_cancel_no_status(statp->_u._ext.nssocks[ns]);\n@@ -621,7 +604,6 @@ __res_iclose(res_state statp, bool free_\n \t\t\t\tstatp->_u._ext.nsaddrs[ns] = NULL;\n \t\t\t}\n \t\t}\n-\tstatp->_u._ext.nsinit = 0;\n }\n libc_hidden_def (__res_iclose)\n \nIndex: glibc-2.19/resolv/res_send.c\n===================================================================\n--- glibc-2.19.orig/resolv/res_send.c\n+++ glibc-2.19/resolv/res_send.c\n@@ -183,6 +183,7 @@ evNowTime(struct timespec *res) {\n \n /* Forward. */\n \n+static struct sockaddr *get_nsaddr (res_state, int);\n static int\t\tsend_vc(res_state, const u_char *, int,\n \t\t\t\tconst u_char *, int,\n \t\t\t\tu_char **, int *, int *, int, u_char **,\n@@ -220,20 +221,21 @@ res_ourserver_p(const res_state statp, c\n \t in_port_t port = in4p->sin_port;\n \t in_addr_t addr = in4p->sin_addr.s_addr;\n \n-\t for (ns = 0; ns < MAXNS; ns++) {\n+\t for (ns = 0; ns < statp->nscount; ns++) {\n \t\tconst struct sockaddr_in *srv =\n-\t\t (struct sockaddr_in *)EXT(statp).nsaddrs[ns];\n+\t\t (struct sockaddr_in *) get_nsaddr (statp, ns);\n \n-\t\tif ((srv != NULL) && (srv->sin_family == AF_INET) &&\n+\t\tif ((srv->sin_family == AF_INET) &&\n \t\t (srv->sin_port == port) &&\n \t\t (srv->sin_addr.s_addr == INADDR_ANY ||\n \t\t srv->sin_addr.s_addr == addr))\n \t\t return (1);\n \t }\n \t} else if (inp->sin6_family == AF_INET6) {\n-\t for (ns = 0; ns < MAXNS; ns++) {\n-\t\tconst struct sockaddr_in6 *srv = EXT(statp).nsaddrs[ns];\n-\t\tif ((srv != NULL) && (srv->sin6_family == AF_INET6) &&\n+\t for (ns = 0; ns < statp->nscount; ns++) {\n+\t\tconst struct sockaddr_in6 *srv\n+\t\t = (struct sockaddr_in6 *) get_nsaddr (statp, ns);\n+\t\tif ((srv->sin6_family == AF_INET6) &&\n \t\t (srv->sin6_port == inp->sin6_port) &&\n \t\t !(memcmp(&srv->sin6_addr, &in6addr_any,\n \t\t\t sizeof (struct in6_addr)) &&\n@@ -383,74 +385,48 @@ __libc_res_nsend(res_state statp, const\n \t * If the ns_addr_list in the resolver context has changed, then\n \t * invalidate our cached copy and the associated timing data.\n \t */\n-\tif (EXT(statp).nsinit) {\n+\tif (EXT(statp).nscount != 0) {\n \t\tint needclose = 0;\n \n \t\tif (EXT(statp).nscount != statp->nscount)\n \t\t\tneedclose++;\n \t\telse\n-\t\t\tfor (ns = 0; ns < MAXNS; ns++) {\n-\t\t\t\tunsigned int map = EXT(statp).nsmap[ns];\n-\t\t\t\tif (map < MAXNS\n+\t\t\tfor (ns = 0; ns < statp->nscount; ns++) {\n+\t\t\t\tif (statp->nsaddr_list[ns].sin_family != 0\n \t\t\t\t && !sock_eq((struct sockaddr_in6 *)\n-\t\t\t\t\t\t&statp->nsaddr_list[map],\n+\t\t\t\t\t\t&statp->nsaddr_list[ns],\n \t\t\t\t\t\tEXT(statp).nsaddrs[ns]))\n \t\t\t\t{\n \t\t\t\t\tneedclose++;\n \t\t\t\t\tbreak;\n \t\t\t\t}\n \t\t\t}\n-\t\tif (needclose)\n+\t\tif (needclose) {\n \t\t\t__res_iclose(statp, false);\n+\t\t\tEXT(statp).nscount = 0;\n+\t\t}\n \t}\n \n \t/*\n \t * Maybe initialize our private copy of the ns_addr_list.\n \t */\n-\tif (EXT(statp).nsinit == 0) {\n-\t\tunsigned char map[MAXNS];\n-\n-\t\tmemset (map, MAXNS, sizeof (map));\n-\t\tfor (n = 0; n < MAXNS; n++) {\n-\t\t\tns = EXT(statp).nsmap[n];\n-\t\t\tif (ns < statp->nscount)\n-\t\t\t\tmap[ns] = n;\n-\t\t\telse if (ns < MAXNS) {\n-\t\t\t\tfree(EXT(statp).nsaddrs[n]);\n-\t\t\t\tEXT(statp).nsaddrs[n] = NULL;\n-\t\t\t\tEXT(statp).nsmap[n] = MAXNS;\n-\t\t\t}\n-\t\t}\n-\t\tn = statp->nscount;\n-\t\tif (statp->nscount > EXT(statp).nscount)\n-\t\t\tfor (n = EXT(statp).nscount, ns = 0;\n-\t\t\t n < statp->nscount; n++) {\n-\t\t\t\twhile (ns < MAXNS\n-\t\t\t\t && EXT(statp).nsmap[ns] != MAXNS)\n-\t\t\t\t\tns++;\n-\t\t\t\tif (ns == MAXNS)\n-\t\t\t\t\tbreak;\n-\t\t\t\tEXT(statp).nsmap[ns] = n;\n-\t\t\t\tmap[n] = ns++;\n-\t\t\t}\n-\t\tEXT(statp).nscount = n;\n-\t\tfor (ns = 0; ns < EXT(statp).nscount; ns++) {\n-\t\t\tn = map[ns];\n-\t\t\tif (EXT(statp).nsaddrs[n] == NULL)\n-\t\t\t\tEXT(statp).nsaddrs[n] =\n+\tif (EXT(statp).nscount == 0) {\n+\t\tfor (ns = 0; ns < statp->nscount; ns++) {\n+\t\t\tEXT(statp).nssocks[ns] = -1;\n+\t\t\tif (statp->nsaddr_list[ns].sin_family == 0)\n+\t\t\t\tcontinue;\n+\t\t\tif (EXT(statp).nsaddrs[ns] == NULL)\n+\t\t\t\tEXT(statp).nsaddrs[ns] =\n \t\t\t\t malloc(sizeof (struct sockaddr_in6));\n-\t\t\tif (EXT(statp).nsaddrs[n] != NULL) {\n-\t\t\t\tmemset (mempcpy(EXT(statp).nsaddrs[n],\n+\t\t\tif (EXT(statp).nsaddrs[ns] != NULL)\n+\t\t\t\tmemset (mempcpy(EXT(statp).nsaddrs[ns],\n \t\t\t\t\t\t&statp->nsaddr_list[ns],\n \t\t\t\t\t\tsizeof (struct sockaddr_in)),\n \t\t\t\t\t'\\0',\n \t\t\t\t\tsizeof (struct sockaddr_in6)\n \t\t\t\t\t- sizeof (struct sockaddr_in));\n-\t\t\t\tEXT(statp).nssocks[n] = -1;\n-\t\t\t\tn++;\n-\t\t\t}\n \t\t}\n-\t\tEXT(statp).nsinit = 1;\n+\t\tEXT(statp).nscount = statp->nscount;\n \t}\n \n \t/*\n@@ -459,44 +435,37 @@ __libc_res_nsend(res_state statp, const\n \t */\n \tif (__builtin_expect ((statp->options & RES_ROTATE) != 0, 0) &&\n \t (statp->options & RES_BLAST) == 0) {\n-\t\tstruct sockaddr_in6 *ina;\n-\t\tunsigned int map;\n-\n-\t\tn = 0;\n-\t\twhile (n < MAXNS && EXT(statp).nsmap[n] == MAXNS)\n-\t\t\tn++;\n-\t\tif (n < MAXNS) {\n-\t\t\tina = EXT(statp).nsaddrs[n];\n-\t\t\tmap = EXT(statp).nsmap[n];\n-\t\t\tfor (;;) {\n-\t\t\t\tns = n + 1;\n-\t\t\t\twhile (ns < MAXNS\n-\t\t\t\t && EXT(statp).nsmap[ns] == MAXNS)\n-\t\t\t\t\tns++;\n-\t\t\t\tif (ns == MAXNS)\n-\t\t\t\t\tbreak;\n-\t\t\t\tEXT(statp).nsaddrs[n] = EXT(statp).nsaddrs[ns];\n-\t\t\t\tEXT(statp).nsmap[n] = EXT(statp).nsmap[ns];\n-\t\t\t\tn = ns;\n-\t\t\t}\n-\t\t\tEXT(statp).nsaddrs[n] = ina;\n-\t\t\tEXT(statp).nsmap[n] = map;\n-\t\t}\n+\t\tstruct sockaddr_in ina;\n+\t\tstruct sockaddr_in6 *inp;\n+\t\tint lastns = statp->nscount - 1;\n+\t\tint fd;\n+\n+\t\tinp = EXT(statp).nsaddrs[0];\n+\t\tina = statp->nsaddr_list[0];\n+\t\tfd = EXT(statp).nssocks[0];\n+\t\tfor (ns = 0; ns < lastns; ns++) {\n+\t\t EXT(statp).nsaddrs[ns] = EXT(statp).nsaddrs[ns + 1];\n+\t\t statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1];\n+\t\t EXT(statp).nssocks[ns] = EXT(statp).nssocks[ns + 1];\n+\t\t}\n+\t\tEXT(statp).nsaddrs[lastns] = inp;\n+\t\tstatp->nsaddr_list[lastns] = ina;\n+\t\tEXT(statp).nssocks[lastns] = fd;\n \t}\n \n \t/*\n \t * Send request, RETRY times, or until successful.\n \t */\n \tfor (try = 0; try < statp->retry; try++) {\n-\t for (ns = 0; ns < MAXNS; ns++)\n+\t for (ns = 0; ns < statp->nscount; ns++)\n \t {\n #ifdef DEBUG\n \t\tchar tmpbuf[40];\n #endif\n-\t\tstruct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns];\n+#if defined USE_HOOKS || defined DEBUG\n+\t\tstruct sockaddr *nsap = get_nsaddr (statp, ns);\n+#endif\n \n-\t\tif (nsap == NULL)\n-\t\t\tgoto next_ns;\n \t same_ns:\n #ifdef USE_HOOKS\n \t\tif (__builtin_expect (statp->qhook != NULL, 0)) {\n@@ -535,9 +504,9 @@ __libc_res_nsend(res_state statp, const\n \n \t\tDprint(statp->options & RES_DEBUG,\n \t\t (stdout, \";; Querying server (# %d) address = %s\\n\",\n-\t\t\tns + 1, inet_ntop(nsap->sin6_family,\n-\t\t\t\t\t (nsap->sin6_family == AF_INET6\n-\t\t\t\t\t ? &nsap->sin6_addr\n+\t\t\tns + 1, inet_ntop(nsap->sa_family,\n+\t\t\t\t\t (nsap->sa_family == AF_INET6\n+\t\t\t\t\t ? &((struct sockaddr_in6 *) nsap)->sin6_addr\n \t\t\t\t\t : &((struct sockaddr_in *) nsap)->sin_addr),\n \t\t\t\t\t tmpbuf, sizeof (tmpbuf))));\n \n@@ -653,6 +622,21 @@ libresolv_hidden_def (res_nsend)\n \n /* Private */\n \n+static struct sockaddr *\n+get_nsaddr (res_state statp, int n)\n+{\n+\n+ if (statp->nsaddr_list[n].sin_family == 0 && EXT(statp).nsaddrs[n] != NULL)\n+ /* EXT(statp).nsaddrs[n] holds an address that is larger than\n+ struct sockaddr, and user code did not update\n+ statp->nsaddr_list[n]. */\n+ return (struct sockaddr *) EXT(statp).nsaddrs[n];\n+ else\n+ /* User code updated statp->nsaddr_list[n], or statp->nsaddr_list[n]\n+ has the same content as EXT(statp).nsaddrs[n]. */\n+ return (struct sockaddr *) (void *) &statp->nsaddr_list[n];\n+}\n+\n static int\n send_vc(res_state statp,\n \tconst u_char *buf, int buflen, const u_char *buf2, int buflen2,\n@@ -667,7 +651,7 @@ send_vc(res_state statp,\n \t// XXX REMOVE\n \t// int anssiz = *anssizp;\n \tHEADER *anhp = (HEADER *) ans;\n-\tstruct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns];\n+\tstruct sockaddr *nsap = get_nsaddr (statp, ns);\n \tint truncating, connreset, resplen, n;\n \tstruct iovec iov[4];\n \tu_short len;\n@@ -687,8 +671,8 @@ send_vc(res_state statp,\n \n \t\tif (getpeername(statp->_vcsock,\n \t\t\t\t(struct sockaddr *)&peer, &size) < 0 ||\n-\t\t !sock_eq(&peer, nsap)) {\n-\t\t __res_iclose(statp, false);\n+\t\t !sock_eq(&peer, (struct sockaddr_in6 *) nsap)) {\n+\t\t\t__res_iclose(statp, false);\n \t\t\tstatp->_flags &= ~RES_F_VC;\n \t\t}\n \t}\n@@ -697,20 +681,19 @@ send_vc(res_state statp,\n \t\tif (statp->_vcsock >= 0)\n \t\t __res_iclose(statp, false);\n \n-\t\tstatp->_vcsock = socket(nsap->sin6_family, SOCK_STREAM, 0);\n+\t\tstatp->_vcsock = socket(nsap->sa_family, SOCK_STREAM, 0);\n \t\tif (statp->_vcsock < 0) {\n \t\t\t*terrno = errno;\n \t\t\tPerror(statp, stderr, \"socket(vc)\", errno);\n \t\t\treturn (-1);\n \t\t}\n \t\t__set_errno (0);\n-\t\tif (connect(statp->_vcsock, (struct sockaddr *)nsap,\n-\t\t\t nsap->sin6_family == AF_INET\n+\t\tif (connect(statp->_vcsock, nsap,\n+\t\t\t nsap->sa_family == AF_INET\n \t\t\t ? sizeof (struct sockaddr_in)\n \t\t\t : sizeof (struct sockaddr_in6)) < 0) {\n \t\t\t*terrno = errno;\n-\t\t\tAerror(statp, stderr, \"connect/vc\", errno,\n-\t\t\t (struct sockaddr *) nsap);\n+\t\t\tAerror(statp, stderr, \"connect/vc\", errno, nsap);\n \t\t\t__res_iclose(statp, false);\n \t\t\treturn (0);\n \t\t}\n@@ -914,8 +897,7 @@ static int\n reopen (res_state statp, int *terrno, int ns)\n {\n \tif (EXT(statp).nssocks[ns] == -1) {\n-\t\tstruct sockaddr *nsap\n-\t\t = (struct sockaddr *) EXT(statp).nsaddrs[ns];\n+\t\tstruct sockaddr *nsap = get_nsaddr (statp, ns);\n \t\tsocklen_t slen;\n \n \t\t/* only try IPv6 if IPv6 NS and if not failed before */" } ]
{ "id": "glibc-utils-4693-resolv-nameserver-handling.pat", "cve_id": "CVE-2015-8779", "package": "glibc-utils", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 2168, "context_files": 2 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-3119\n\nThe process_db_args function in plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c in the LDAP KDB module in kadmind in MIT Kerberos 5 (aka krb5) through 1.13.4 and 1.14.x through 1.14.1 mishandles the DB argument, which allows remote authenticated users to cause a denial of service (NULL pointer dereference and daemon crash) via a crafted request to modify a principal.\n\n## Package\nkrb5\n\n## Files to modify\n- src/appl/user_user/server.c\n- src/lib/krb5/krb/recvauth.c\n\n## Upstream Fix\n```diff\nFrom 102bb6ebf20f9174130c85c3b052ae104e5073ec Mon Sep 17 00:00:00 2001\nFrom: Greg Hudson <ghudson@mit.edu>\nDate: Tue, 9 Dec 2014 12:37:44 -0500\nSubject: [PATCH] Fix krb5_read_message handling [CVE-2014-5355]\n\nIn recvauth_common, do not use strcmp against the data fields of\nkrb5_data objects populated by krb5_read_message(), as there is no\nguarantee that they are C strings. Instead, create an expected\nkrb5_data value and use data_eq().\n\nIn the sample user-to-user server application, check that the received\nclient principal name is null-terminated before using it with printf\nand krb5_parse_name.\n\nCVE-2014-5355:\n\nIn MIT krb5, when a server process uses the krb5_recvauth function, an\nunauthenticated remote attacker can cause a NULL dereference by\nsending a zero-byte version string, or a read beyond the end of\nallocated storage by sending a non-null-terminated version string.\nThe example user-to-user server application (uuserver) is similarly\nvulnerable to a zero-length or non-null-terminated principal name\nstring.\n\nThe krb5_recvauth function reads two version strings from the client\nusing krb5_read_message(), which produces a krb5_data structure\ncontaining a length and a pointer to an octet sequence. krb5_recvauth\nassumes that the data pointer is a valid C string and passes it to\nstrcmp() to verify the versions. If the client sends an empty octet\nsequence, the data pointer will be NULL and strcmp() will dereference\na NULL pointer, causing the process to crash. If the client sends a\nnon-null-terminated octet sequence, strcmp() will read beyond the end\nof the allocated storage, possibly causing the process to crash.\n\nuuserver similarly uses krb5_read_message() to read a client principal\nname, and then passes it to printf() and krb5_parse_name() without\nverifying that it is a valid C string.\n\nThe krb5_recvauth function is used by kpropd and the Kerberized\nversions of the BSD rlogin and rsh daemons. These daemons are usually\nrun out of inetd or in a mode which forks before processing incoming\nconnections, so a process crash will generally not result in a\ncomplete denial of service.\n\nThanks to Tim Uglow for discovering this issue.\n\nCVSSv2: AV:N/AC:L/Au:N/C:N/I:N/A:P/E:POC/RL:OF/RC:C\n\n[tlyu@mit.edu: CVSS score]\n\nticket: 8050 (new)\ntarget_version: 1.13.1\ntags: pullup\n---\n src/appl/user_user/server.c | 4 +++-\n src/lib/krb5/krb/recvauth.c | 9 ++++++---\n 2 files changed, 9 insertions(+), 4 deletions(-)\n\ndiff --git a/src/appl/user_user/server.c b/src/appl/user_user/server.c\nindex 09ea4e0ed74..f2b5b614e30 100644\n--- a/src/appl/user_user/server.c\n+++ b/src/appl/user_user/server.c\n@@ -111,8 +111,10 @@ int main(argc, argv)\n }\n #endif\n \n+ /* principal name must be sent null-terminated. */\n retval = krb5_read_message(context, (krb5_pointer) &sock, &pname_data);\n- if (retval) {\n+ if (retval || pname_data.length == 0 ||\n+ pname_data.data[pname_data.length - 1] != '\\0') {\n com_err (\"uu-server\", retval, \"reading pname\");\n return 2;\n }\ndiff --git a/src/lib/krb5/krb/recvauth.c b/src/lib/krb5/krb/recvauth.c\nindex da83628303f..5adc6dd14ab 100644\n--- a/src/lib/krb5/krb/recvauth.c\n+++ b/src/lib/krb5/krb/recvauth.c\n@@ -59,6 +59,7 @@ recvauth_common(krb5_context context,\n krb5_rcache rcache = 0;\n krb5_octet response;\n krb5_data null_server;\n+ krb5_data d;\n int need_error_free = 0;\n int local_rcache = 0, local_authcon = 0;\n \n@@ -77,7 +78,8 @@ recvauth_common(krb5_context context,\n */\n if ((retval = krb5_read_message(context, fd, &inbuf)))\n return(retval);\n- if (strcmp(inbuf.data, sendauth_version)) {\n+ d = make_data((char *)sendauth_version, strlen(sendauth_version) + 1);\n+ if (!data_eq(inbuf, d)) {\n problem = KRB5_SENDAUTH_BADAUTHVERS;\n response = 1;\n }\n@@ -93,8 +95,9 @@ recvauth_common(krb5_context context,\n */\n if ((retval = krb5_read_message(context, fd, &inbuf)))\n return(retval);\n- if (appl_version && strcmp(inbuf.data, appl_version)) {\n- if (!problem) {\n+ if (appl_version != NULL && !problem) {\n+ d = make_data(appl_version, strlen(appl_version) + 1);\n+ if (!data_eq(inbuf, d)) {\n problem = KRB5_SENDAUTH_BADAPPLVERS;\n response = 2;\n }\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 102bb6ebf20f9174130c85c3b052ae104e5073ec Mon Sep 17 00:00:00 2001\nFrom: Greg Hudson <ghudson@mit.edu>\nDate: Tue, 9 Dec 2014 12:37:44 -0500\nSubject: [PATCH] Fix krb5_read_message handling [CVE-2014-5355]\n\nIn recvauth_common, do not use strcmp against the data fields of\nkrb5_data objects populated by krb5_read_message(), as there is no\nguarantee that they are C strings. Instead, create an expected\nkrb5_data value and use data_eq().\n\nIn the sample user-to-user server application, check that the received\nclient principal name is null-terminated before using it with printf\nand krb5_parse_name.\n\nCVE-2014-5355:\n\nIn MIT krb5, when a server process uses the krb5_recvauth function, an\nunauthenticated remote attacker can cause a NULL dereference by\nsending a zero-byte version string, or a read beyond the end of\nallocated storage by sending a non-null-terminated version string.\nThe example user-to-user server application (uuserver) is similarly\nvulnerable to a zero-length or non-null-terminated principal name\nstring.\n\nThe krb5_recvauth function reads two version strings from the client\nusing krb5_read_message(), which produces a krb5_data structure\ncontaining a length and a pointer to an octet sequence. krb5_recvauth\nassumes that the data pointer is a valid C string and passes it to\nstrcmp() to verify the versions. If the client sends an empty octet\nsequence, the data pointer will be NULL and strcmp() will dereference\na NULL pointer, causing the process to crash. If the client sends a\nnon-null-terminated octet sequence, strcmp() will read beyond the end\nof the allocated storage, possibly causing the process to crash.\n\nuuserver similarly uses krb5_read_message() to read a client principal\nname, and then passes it to printf() and krb5_parse_name() without\nverifying that it is a valid C string.\n\nThe krb5_recvauth function is used by kpropd and the Kerberized\nversions of the BSD rlogin and rsh daemons. These daemons are usually\nrun out of inetd or in a mode which forks before processing incoming\nconnections, so a process crash will generally not result in a\ncomplete denial of service.\n\nThanks to Tim Uglow for discovering this issue.\n\nCVSSv2: AV:N/AC:L/Au:N/C:N/I:N/A:P/E:POC/RL:OF/RC:C\n\n[tlyu@mit.edu: CVSS score]\n\nticket: 8050 (new)\ntarget_version: 1.13.1\ntags: pullup\n---\n src/appl/user_user/server.c | 4 +++-\n src/lib/krb5/krb/recvauth.c | 9 ++++++---\n 2 files changed, 9 insertions(+), 4 deletions(-)\n\ndiff --git a/src/appl/user_user/server.c b/src/appl/user_user/server.c\nindex 09ea4e0..f2b5b61 100644\n--- a/src/appl/user_user/server.c\n+++ b/src/appl/user_user/server.c\n@@ -111,8 +111,10 @@ int main(argc, argv)\n }\n #endif\n \n+ /* principal name must be sent null-terminated. */\n retval = krb5_read_message(context, (krb5_pointer) &sock, &pname_data);\n- if (retval) {\n+ if (retval || pname_data.length == 0 ||\n+ pname_data.data[pname_data.length - 1] != '\\0') {\n com_err (\"uu-server\", retval, \"reading pname\");\n return 2;\n }\ndiff --git a/src/lib/krb5/krb/recvauth.c b/src/lib/krb5/krb/recvauth.c\nindex da836283..5adc6dd 100644\n--- a/src/lib/krb5/krb/recvauth.c\n+++ b/src/lib/krb5/krb/recvauth.c\n@@ -59,6 +59,7 @@ recvauth_common(krb5_context context,\n krb5_rcache rcache = 0;\n krb5_octet response;\n krb5_data null_server;\n+ krb5_data d;\n int need_error_free = 0;\n int local_rcache = 0, local_authcon = 0;\n \n@@ -77,7 +78,8 @@ recvauth_common(krb5_context context,\n */\n if ((retval = krb5_read_message(context, fd, &inbuf)))\n return(retval);\n- if (strcmp(inbuf.data, sendauth_version)) {\n+ d = make_data((char *)sendauth_version, strlen(sendauth_version) + 1);\n+ if (!data_eq(inbuf, d)) {\n problem = KRB5_SENDAUTH_BADAUTHVERS;\n response = 1;\n }\n@@ -93,8 +95,9 @@ recvauth_common(krb5_context context,\n */\n if ((retval = krb5_read_message(context, fd, &inbuf)))\n return(retval);\n- if (appl_version && strcmp(inbuf.data, appl_version)) {\n- if (!problem) {\n+ if (appl_version != NULL && !problem) {\n+ d = make_data(appl_version, strlen(appl_version) + 1);\n+ if (!data_eq(inbuf, d)) {\n problem = KRB5_SENDAUTH_BADAPPLVERS;\n response = 2;\n }\n-- \n1.8.5.2" } ]
{ "id": "krb5-4938-0001-Fix-krb5_read_message-han", "cve_id": "CVE-2016-3119", "package": "krb5", "upstream_enriched": true, "upstream_commit": "102bb6ebf20f9174130c85c3b052ae104e5073ec", "upstream_repo": "krb5/krb5", "tier": "adapted", "has_source_context": false, "license": "MIT", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-4042\n\nInteger overflow in the keycompare_mb function in sort.c in sort in GNU Coreutils through 8.23 might allow attackers to cause a denial of service (application crash) or possibly have unspecified other impact via long strings.\n\n## Package\ncoreutils\n\n## Files to modify\n- src/df.c\n\n## Upstream Fix\n```diff\nUpstream patch for df(1) on top of v8.23, to be removed with v8.24.\nhttp://git.sv.gnu.org/cgit/coreutils.git/commit/?id=2e81e6224340\n\nFrom 2e81e62243409c5c574b899f52b08c000e4d99fd Mon Sep 17 00:00:00 2001\nFrom: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>\nDate: Wed, 29 Oct 2014 02:49:17 +0000\nSubject: [PATCH] df: only suppress remote mounts of separate exports with\n --total\n\n* src/df.c (filter_mount_list): Separate remote locations are\ngenerally explicitly mounted, so list each even if they share\nthe same remote device and thus storage. However with --total\nkeep the suppression to give a more accurate value for the\ntotal storage available.\n(usage): Expand on the new implications of --total and move\nit in the options list according to alphabetic order.\ndoc/coreutils.texi (df invocation): Mention that --total impacts\non deduplication of remote file systems and also move location\naccording to alphabetic order.\n* tests/df/skip-duplicates.sh: Add remote test cases.\n* NEWS: Mention the change in behavior.\n\nReported in http://bugs.debian.org/737399\nReported in http://bugzilla.redhat.com/920806\nReported in http://bugzilla.opensuse.org/866010\nReported in http://bugzilla.opensuse.org/901905\n---\n NEWS | 8 ++++++++\n doc/coreutils.texi | 28 +++++++++++++++-------------\n src/df.c | 41 ++++++++++++++++++++++++++++-------------\n tests/df/skip-duplicates.sh | 31 ++++++++++++++++++++++++++++---\n 4 files changed, 79 insertions(+), 29 deletions(-)\n\nIndex: NEWS\n===================================================================\n--- NEWS.orig\n+++ NEWS\n@@ -1,5 +1,13 @@\n GNU coreutils NEWS -*- outline -*-\n \n+** Changes in behavior\n+\n+ df no longer suppresses separate exports of the same remote device, as\n+ these are generally explicitly mounted. The --total option does still\n+ suppress duplicate remote file systems.\n+ [suppression was introduced in coreutils-8.21]\n+\n+\n * Noteworthy changes in release 8.23 (2014-07-18) [stable]\n \n ** Bug fixes\nIndex: doc/coreutils.texi\n===================================================================\n--- doc/coreutils.texi.orig\n+++ doc/coreutils.texi\n@@ -11202,19 +11202,6 @@ due to permissions of the mount point et\n Scale sizes by @var{size} before printing them (@pxref{Block size}).\n For example, @option{-BG} prints sizes in units of 1,073,741,824 bytes.\n \n-@item --total\n-@opindex --total\n-@cindex grand total of disk size, usage and available space\n-Print a grand total of all arguments after all arguments have\n-been processed. This can be used to find out the total disk size, usage\n-and available space of all listed devices.\n-\n-For the grand total line, @command{df} prints @samp{\"total\"} into the\n-@var{source} column, and @samp{\"-\"} into the @var{target} column.\n-If there is no @var{source} column (see @option{--output}), then\n-@command{df} prints @samp{\"total\"} into the @var{target} column,\n-if present.\n-\n @optHumanReadable\n \n @item -H\n@@ -11355,6 +11342,21 @@ some systems (notably SunOS), doing this\n but in general this option makes @command{df} much slower, especially when\n there are many or very busy file systems.\n \n+@item --total\n+@opindex --total\n+@cindex grand total of disk size, usage and available space\n+Print a grand total of all arguments after all arguments have\n+been processed. This can be used to find out the total disk size, usage\n+and available space of all listed devices. If no arguments are specified\n+df will try harder to elide file systems insignificant to the total\n+available space, by suppressing duplicate remote file systems.\n+\n+For the grand total line, @command{df} prints @samp{\"total\"} into the\n+@var{source} column, and @samp{\"-\"} into the @var{target} column.\n+If there is no @var{source} column (see @option{--output}), then\n+@command{df} prints @samp{\"total\"} into the @var{target} column,\n+if present.\n+\n @item -t @var{fstype}\n @itemx --type=@var{fstype}\n @opindex -t\nIndex: src/df.c\n===================================================================\n--- src/df.c.orig\n+++ src/df.c\n@@ -640,18 +640,28 @@ filter_mount_list (bool devices_only)\n \n if (devlist)\n {\n- /* let \"real\" devices with '/' in the name win. */\n- if ((strchr (me->me_devname, '/')\n- && ! strchr (devlist->me->me_devname, '/'))\n- /* let a shorter mountdir win. */\n- || (strlen (devlist->me->me_mountdir)\n- > strlen (me->me_mountdir))\n- /* let an entry overmounted on a different device win... */\n- || (! STREQ (devlist->me->me_devname, me->me_devname)\n- /* ... but only when matching an existing mount point, to\n- avoid problematic replacement when given inaccurate mount\n- lists, seen with some chroot environments for example. */\n- && STREQ (me->me_mountdir, devlist->me->me_mountdir)))\n+ if (! print_grand_total && me->me_remote && devlist->me->me_remote\n+ && ! STREQ (devlist->me->me_devname, me->me_devname))\n+ {\n+ /* Don't discard remote entries with different locations,\n+ as these are more likely to be explicitly mounted.\n+ However avoid this when producing a total to give\n+ a more accurate value in that case. */\n+ }\n+ else if ((strchr (me->me_devname, '/')\n+ /* let \"real\" devices with '/' in the name win. */\n+ && ! strchr (devlist->me->me_devname, '/'))\n+ /* let a shorter mountdir win. */\n+ || (strlen (devlist->me->me_mountdir)\n+ > strlen (me->me_mountdir))\n+ /* let an entry overmounted on a new device win... */\n+ || (! STREQ (devlist->me->me_devname, me->me_devname)\n+ /* ... but only when matching an existing mnt point,\n+ to avoid problematic replacement when given\n+ inaccurate mount lists, seen with some chroot\n+ environments for example. */\n+ && STREQ (me->me_mountdir,\n+ devlist->me->me_mountdir)))\n {\n /* Discard mount entry for existing device. */\n discard_me = devlist->me;\n@@ -1403,7 +1413,6 @@ or all file systems by default.\\n\\\n -B, --block-size=SIZE scale sizes by SIZE before printing them; e.g.,\\n\\\n '-BM' prints sizes in units of 1,048,576 bytes;\\n\\\n see SIZE format below\\n\\\n- --total produce a grand total\\n\\\n -h, --human-readable print sizes in powers of 1024 (e.g., 1023M)\\n\\\n -H, --si print sizes in powers of 1000 (e.g., 1.1G)\\n\\\n \"), stdout);\n@@ -1419,6 +1428,12 @@ or all file systems by default.\\n\\\n or print all fields if FIELD_LIST is omitted.\\n\\\n -P, --portability use the POSIX output format\\n\\\n --sync invoke sync before getting usage info\\n\\\n+\"), stdout);\n+ fputs (_(\"\\\n+ --total elide all entries insignificant to available space,\\n\\\n+ and produce a grand total\\n\\\n+\"), stdout);\n+ fputs (_(\"\\\n -t, --type=TYPE limit listing to file systems of type TYPE\\n\\\n -T, --print-type print file system type\\n\\\n -x, --exclude-type=TYPE limit listing to file systems not of type TYPE\\n\\\nIndex: tests/df/skip-duplicates.sh\n===================================================================\n--- tests/df/skip-duplicates.sh.orig\n+++ tests/df/skip-duplicates.sh\n@@ -26,7 +26,12 @@ require_gcc_shared_\n df --local || skip_ \"df fails\"\n \n export CU_NONROOT_FS=$(df --local --o\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "Upstream patch for df(1) on top of v8.23, to be removed with v8.24.\nhttp://git.sv.gnu.org/cgit/coreutils.git/commit/?id=2e81e6224340\n\nFrom 2e81e62243409c5c574b899f52b08c000e4d99fd Mon Sep 17 00:00:00 2001\nFrom: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>\nDate: Wed, 29 Oct 2014 02:49:17 +0000\nSubject: [PATCH] df: only suppress remote mounts of separate exports with\n --total\n\n* src/df.c (filter_mount_list): Separate remote locations are\ngenerally explicitly mounted, so list each even if they share\nthe same remote device and thus storage. However with --total\nkeep the suppression to give a more accurate value for the\ntotal storage available.\n(usage): Expand on the new implications of --total and move\nit in the options list according to alphabetic order.\ndoc/coreutils.texi (df invocation): Mention that --total impacts\non deduplication of remote file systems and also move location\naccording to alphabetic order.\n* tests/df/skip-duplicates.sh: Add remote test cases.\n* NEWS: Mention the change in behavior.\n\nReported in http://bugs.debian.org/737399\nReported in http://bugzilla.redhat.com/920806\nReported in http://bugzilla.opensuse.org/866010\nReported in http://bugzilla.opensuse.org/901905\n---\n NEWS | 8 ++++++++\n doc/coreutils.texi | 28 +++++++++++++++-------------\n src/df.c | 41 ++++++++++++++++++++++++++++-------------\n tests/df/skip-duplicates.sh | 31 ++++++++++++++++++++++++++++---\n 4 files changed, 79 insertions(+), 29 deletions(-)\n\nIndex: NEWS\n===================================================================\n--- NEWS.orig\n+++ NEWS\n@@ -1,5 +1,13 @@\n GNU coreutils NEWS -*- outline -*-\n \n+** Changes in behavior\n+\n+ df no longer suppresses separate exports of the same remote device, as\n+ these are generally explicitly mounted. The --total option does still\n+ suppress duplicate remote file systems.\n+ [suppression was introduced in coreutils-8.21]\n+\n+\n * Noteworthy changes in release 8.23 (2014-07-18) [stable]\n \n ** Bug fixes\nIndex: doc/coreutils.texi\n===================================================================\n--- doc/coreutils.texi.orig\n+++ doc/coreutils.texi\n@@ -11202,19 +11202,6 @@ due to permissions of the mount point et\n Scale sizes by @var{size} before printing them (@pxref{Block size}).\n For example, @option{-BG} prints sizes in units of 1,073,741,824 bytes.\n \n-@item --total\n-@opindex --total\n-@cindex grand total of disk size, usage and available space\n-Print a grand total of all arguments after all arguments have\n-been processed. This can be used to find out the total disk size, usage\n-and available space of all listed devices.\n-\n-For the grand total line, @command{df} prints @samp{\"total\"} into the\n-@var{source} column, and @samp{\"-\"} into the @var{target} column.\n-If there is no @var{source} column (see @option{--output}), then\n-@command{df} prints @samp{\"total\"} into the @var{target} column,\n-if present.\n-\n @optHumanReadable\n \n @item -H\n@@ -11355,6 +11342,21 @@ some systems (notably SunOS), doing this\n but in general this option makes @command{df} much slower, especially when\n there are many or very busy file systems.\n \n+@item --total\n+@opindex --total\n+@cindex grand total of disk size, usage and available space\n+Print a grand total of all arguments after all arguments have\n+been processed. This can be used to find out the total disk size, usage\n+and available space of all listed devices. If no arguments are specified\n+df will try harder to elide file systems insignificant to the total\n+available space, by suppressing duplicate remote file systems.\n+\n+For the grand total line, @command{df} prints @samp{\"total\"} into the\n+@var{source} column, and @samp{\"-\"} into the @var{target} column.\n+If there is no @var{source} column (see @option{--output}), then\n+@command{df} prints @samp{\"total\"} into the @var{target} column,\n+if present.\n+\n @item -t @var{fstype}\n @itemx --type=@var{fstype}\n @opindex -t\nIndex: src/df.c\n===================================================================\n--- src/df.c.orig\n+++ src/df.c\n@@ -640,18 +640,28 @@ filter_mount_list (bool devices_only)\n \n if (devlist)\n {\n- /* let \"real\" devices with '/' in the name win. */\n- if ((strchr (me->me_devname, '/')\n- && ! strchr (devlist->me->me_devname, '/'))\n- /* let a shorter mountdir win. */\n- || (strlen (devlist->me->me_mountdir)\n- > strlen (me->me_mountdir))\n- /* let an entry overmounted on a different device win... */\n- || (! STREQ (devlist->me->me_devname, me->me_devname)\n- /* ... but only when matching an existing mount point, to\n- avoid problematic replacement when given inaccurate mount\n- lists, seen with some chroot environments for example. */\n- && STREQ (me->me_mountdir, devlist->me->me_mountdir)))\n+ if (! print_grand_total && me->me_remote && devlist->me->me_remote\n+ && ! STREQ (devlist->me->me_devname, me->me_devname))\n+ {\n+ /* Don't discard remote entries with different locations,\n+ as these are more likely to be explicitly mounted.\n+ However avoid this when producing a total to give\n+ a more accurate value in that case. */\n+ }\n+ else if ((strchr (me->me_devname, '/')\n+ /* let \"real\" devices with '/' in the name win. */\n+ && ! strchr (devlist->me->me_devname, '/'))\n+ /* let a shorter mountdir win. */\n+ || (strlen (devlist->me->me_mountdir)\n+ > strlen (me->me_mountdir))\n+ /* let an entry overmounted on a new device win... */\n+ || (! STREQ (devlist->me->me_devname, me->me_devname)\n+ /* ... but only when matching an existing mnt point,\n+ to avoid problematic replacement when given\n+ inaccurate mount lists, seen with some chroot\n+ environments for example. */\n+ && STREQ (me->me_mountdir,\n+ devlist->me->me_mountdir)))\n {\n /* Discard mount entry for existing device. */\n discard_me = devlist->me;\n@@ -1403,7 +1413,6 @@ or all file systems by default.\\n\\\n -B, --block-size=SIZE scale sizes by SIZE before printing them; e.g.,\\n\\\n '-BM' prints sizes in units of 1,048,576 bytes;\\n\\\n see SIZE format below\\n\\\n- --total produce a grand total\\n\\\n -h, --human-readable print sizes in powers of 1024 (e.g., 1023M)\\n\\\n -H, --si print sizes in powers of 1000 (e.g., 1.1G)\\n\\\n \"), stdout);\n@@ -1419,6 +1428,12 @@ or all file systems by default.\\n\\\n or print all fields if FIELD_LIST is omitted.\\n\\\n -P, --portability use the POSIX output format\\n\\\n --sync invoke sync before getting usage info\\n\\\n+\"), stdout);\n+ fputs (_(\"\\\n+ --total elide all entries insignificant to available space,\\n\\\n+ and produce a grand total\\n\\\n+\"), stdout);\n+ fputs (_(\"\\\n -t, --type=TYPE limit listing to file systems of type TYPE\\n\\\n -T, --print-type print file system type\\n\\\n -x, --exclude-type=TYPE limit listing to file systems not of type TYPE\\n\\\nIndex: tests/df/skip-duplicates.sh\n===================================================================\n--- tests/df/skip-duplicates.sh.orig\n+++ tests/df/skip-duplicates.sh\n@@ -26,7 +26,12 @@ require_gcc_shared_\n df --local || skip_ \"df fails\"\n \n export CU_NONROOT_FS=$(df --local --output=target 2>&1 | grep /. | head -n1)\n-test -z \"$CU_NONROOT_FS\" && unique_entries=1 || unique_entries=2\n+export CU_REMOTE_FS=$(df --local --output=target 2>&1 | grep /. |\n+ tail -n+2 | head -n1)\n+\n+unique_entries=1\n+test -z \"$CU_NONROOT_FS\" || unique_entries=$(expr $unique_entries + 1)\n+test -z \"$CU_REMOTE_FS\" || unique_entries=$(expr $unique_entries + 2)\n \n grep '^#define HAVE_MNTENT_H 1' $CONFIG_HEADER > /dev/null \\\n || skip_ \"no mntent.h available to confirm the interface\"\n@@ -46,6 +51,7 @@ cat > k.c <<'EOF' || framework_failure_\n struct mntent *getmntent (FILE *fp)\n {\n static char *nonroot_fs;\n+ static char *remote_fs;\n static int done;\n \n /* Prove that LD_PRELOAD works. */\n@@ -63,6 +69,9 @@ struct mntent *getmntent (FILE *fp)\n {.mnt_fsname=\"virtfs\", .mnt_dir=\"/NONROOT\", .mnt_type=\"fstype1\"},\n {.mnt_fsname=\"virtfs2\", .mnt_dir=\"/NONROOT\", .mnt_type=\"fstype2\"},\n {.mnt_fsname=\"netns\", .mnt_dir=\"net:[1234567]\"},\n+ {.mnt_fsname=\"rem:ote1\",.mnt_dir=\"/REMOTE\"},\n+ {.mnt_fsname=\"rem:ote1\",.mnt_dir=\"/REMOTE\"},\n+ {.mnt_fsname=\"rem:ote2\",.mnt_dir=\"/REMOTE\"},\n };\n \n if (done == 1)\n@@ -70,17 +79,26 @@ struct mntent *getmntent (FILE *fp)\n nonroot_fs = getenv (\"CU_NONROOT_FS\");\n if (!nonroot_fs || !*nonroot_fs)\n nonroot_fs = \"/\"; /* merge into / entries. */\n+\n+ remote_fs = getenv (\"CU_REMOTE_FS\");\n }\n \n if (done == 1 && !getenv (\"CU_TEST_DUPE_INVALID\"))\n done++; /* skip the first entry. */\n \n- while (done++ <= 7)\n+ while (done++ <= 10)\n {\n if (!mntents[done-2].mnt_type)\n mntents[done-2].mnt_type = \"-\";\n if (STREQ (mntents[done-2].mnt_dir, \"/NONROOT\"))\n mntents[done-2].mnt_dir = nonroot_fs;\n+ if (STREQ (mntents[done-2].mnt_dir, \"/REMOTE\"))\n+ {\n+ if (!remote_fs || !*remote_fs)\n+ continue;\n+ else\n+ mntents[done-2].mnt_dir = remote_fs;\n+ }\n return &mntents[done-2];\n }\n \n@@ -102,6 +120,12 @@ test -f x || skip_ \"internal test failur\n LD_PRELOAD=./k.so df -T >out || fail=1\n test $(wc -l <out) -eq $(expr 1 + $unique_entries) || { fail=1; cat out; }\n \n+# With --total we should suppress the duplicate but separate remote file system\n+LD_PRELOAD=./k.so df --total >out || fail=1\n+test \"$CU_REMOTE_FS\" && elide_remote=1 || elide_remote=0\n+test $(wc -l <out) -eq $(expr 2 + $unique_entries - $elide_remote) ||\n+ { fail=1; cat out; }\n+\n # Ensure we don't fail when unable to stat (currently) unavailable entries\n LD_PRELOAD=./k.so CU_TEST_DUPE_INVALID=1 df -T >out || fail=1\n test $(wc -l <out) -eq $(expr 1 + $unique_entries) || { fail=1; cat out; }\n@@ -118,7 +142,8 @@ test $(grep -c 'virtfs2.*fstype2' <out)\n \n # Ensure that filtering duplicates does not affect -a processing.\n LD_PRELOAD=./k.so df -a >out || fail=1\n-test $(wc -l <out) -eq 6 || { fail=1; cat out; }\n+total_fs=6; test \"$CU_REMOTE_FS\" && total_fs=$(expr $total_fs + 3)\n+test $(wc -l <out) -eq $total_fs || { fail=1; cat out; }\n # Ensure placeholder \"-\" values used for the eclipsed \"virtfs\"\n test $(grep -c 'virtfs *-' <out) -eq 1 || { fail=1; cat out; }" } ]
{ "id": "coreutils-3827-coreutils-df-total-suppress-se", "cve_id": "CVE-2015-4042", "package": "coreutils", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": false, "license": "GPL-3.0-or-later", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-6302\n\nThe tls_decrypt_ticket function in ssl/t1_lib.c in OpenSSL before 1.1.0 does not consider the HMAC size during validation of the ticket length, which allows remote attackers to cause a denial of service via a ticket that is too short.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i.orig/crypto/evp/encode.c\n- openssl-1.0.1i/crypto/evp/encode.c\n- crypto/evp/encode.c\n\n## Target Source Code\n\n### crypto/evp/encode.c\n\n#### EVP_EncodeUpdate() [lines 128-175]\n```c\n\tctx->line_num=0;\n\t}\n\nvoid EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,\n\t const unsigned char *in, int inl)\n\t{\n\tint i,j;\n\tunsigned int total=0;\n\n\t*outl=0;\n\tif (inl == 0) return;\n\tOPENSSL_assert(ctx->length <= (int)sizeof(ctx->enc_data));\n\tif ((ctx->num+inl) < ctx->length)\n\t\t{\n\t\tmemcpy(&(ctx->enc_data[ctx->num]),in,inl);\n\t\tctx->num+=inl;\n\t\treturn;\n\t\t}\n\tif (ctx->num != 0)\n\t\t{\n\t\ti=ctx->length-ctx->num;\n\t\tmemcpy(&(ctx->enc_data[ctx->num]),in,i);\n\t\tin+=i;\n\t\tinl-=i;\n\t\tj=EVP_EncodeBlock(out,ctx->enc_data,ctx->length);\n\t\tctx->num=0;\n\t\tout+=j;\n\t\t*(out++)='\\n';\n\t\t*out='\\0';\n\t\ttotal=j+1;\n\t\t}\n\twhile (inl >= ctx->length)\n\t\t{\n\t\tj=EVP_EncodeBlock(out,in,ctx->length);\n\t\tin+=ctx->length;\n\t\tinl-=ctx->length;\n\t\tout+=j;\n\t\t*(out++)='\\n';\n\t\t*out='\\0';\n\t\ttotal+=j+1;\n\t\t}\n\tif (inl != 0)\n\t\tmemcpy(&(ctx->enc_data[0]),in,inl);\n\tctx->num=inl;\n\t*outl=total;\n\t}\n\nvoid EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)\n```\n\n### doc/crypto/evp.pod\n\n#### region() [lines 1-56]\n```c\n=pod\n\n=head1 NAME\n\nevp - high-level cryptographic functions\n\n=head1 SYNOPSIS\n\n #include <openssl/evp.h>\n\n=head1 DESCRIPTION\n\nThe EVP library provides a high-level interface to cryptographic\nfunctions.\n\nB<EVP_Seal>I<...> and B<EVP_Open>I<...> provide public key encryption\nand decryption to implement digital \"envelopes\".\n\nThe B<EVP_Sign>I<...> and B<EVP_Verify>I<...> functions implement\ndigital signatures.\n\nSymmetric encryption is available with the B<EVP_Encrypt>I<...>\nfunctions. The B<EVP_Digest>I<...> functions provide message digests.\n\nThe B<EVP_PKEY>I<...> functions provide a high level interface to\nasymmetric algorithms.\n\nAlgorithms are loaded with OpenSSL_add_all_algorithms(3).\n\nAll the symmetric algorithms (ciphers), digests and asymmetric algorithms\n(public key algorithms) can be replaced by ENGINE modules providing alternative\nimplementations. If ENGINE implementations of ciphers or digests are registered\nas defaults, then the various EVP functions will automatically use those\nimplementations automatically in preference to built in software\nimplementations. For more information, consult the engine(3) man page.\n\nAlthough low level algorithm specific functions exist for many algorithms\ntheir use is discouraged. They cannot be used with an ENGINE and ENGINE\nversions of new algorithms cannot be accessed using the low level functions.\nAlso makes code harder to adapt to new algorithms and some options are not \ncleanly supported at the low level and some operations are more efficient\nusing the high level interface.\n\n=head1 SEE ALSO\n\nL<EVP_DigestInit(3)|EVP_DigestInit(3)>,\nL<EVP_EncryptInit(3)|EVP_EncryptInit(3)>,\nL<EVP_OpenInit(3)|EVP_OpenInit(3)>,\nL<EVP_SealInit(3)|EVP_SealInit(3)>,\nL<EVP_SignInit(3)|EVP_SignInit(3)>,\nL<EVP_VerifyInit(3)|EVP_VerifyInit(3)>,\nL<OpenSSL_add_all_algorithms(3)|OpenSSL_add_all_algorithms(3)>,\nL<engine(3)|engine(3)>\n\n=cut\n\n```\n\n\n## Upstream Fix\n```diff\nFrom 700daeecb890721176bd23effc4166221cdd0271 Mon Sep 17 00:00:00 2001\nFrom: Matt Caswell <matt@openssl.org>\nDate: Fri, 4 Mar 2016 10:17:17 +0000\nSubject: [PATCH] Avoid overflow in EVP_EncodeUpdate\n\nAn overflow can occur in the EVP_EncodeUpdate function which is used for\nBase64 encoding of binary data. If an attacker is able to supply very large\namounts of input data then a length check can overflow resulting in a heap\ncorruption. Due to the very large amounts of data involved this will most\nlikely result in a crash.\n\nInternally to OpenSSL the EVP_EncodeUpdate function is primarly used by the\nPEM_write_bio* family of functions. These are mainly used within the\nOpenSSL command line applications, so any application which processes\ndata from an untrusted source and outputs it as a PEM file should be\nconsidered vulnerable to this issue.\n\nUser applications that call these APIs directly with large amounts of\nuntrusted data may also be vulnerable.\n\nIssue reported by Guido Vranken.\n\nCVE-2016-2105\n---\n crypto/evp/encode.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\nFrom 29188216f818e5b34f3b17ee8ed31e8336f3817e Mon Sep 17 00:00:00 2001\nFrom: Matt Caswell <matt@openssl.org>\nDate: Mon, 25 Apr 2016 09:06:29 +0100\nSubject: [PATCH] Ensure EVP_EncodeUpdate handles an output length that is too long\n\nWith the EVP_EncodeUpdate function it is the caller's responsibility to\ndetermine how big the output buffer should be. The function writes the\namount actually used to |*outl|. However this could go negative with a\nsufficiently large value for |inl|. We add a check for this error\ncondition.\n\nFrom f332816ef87556b7e89b98206c14df1f128b6d9f Mon Sep 17 00:00:00 2001\nFrom: Matt Caswell <matt@openssl.org>\nDate: Mon, 25 Apr 2016 11:54:30 +0100\nSubject: [PATCH] Add documentation for EVP_EncodeInit() and similar functions\n\nIndex: openssl-1.0.1i/crypto/evp/encode.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/evp/encode.c\t2016-04-28 16:25:58.940079648 +0200\n+++ openssl-1.0.1i/crypto/evp/encode.c\t2016-04-28 16:34:49.279062747 +0200\n@@ -132,12 +132,12 @@ void EVP_EncodeUpdate(EVP_ENCODE_CTX *ct\n \t const unsigned char *in, int inl)\n \t{\n \tint i,j;\n-\tunsigned int total=0;\n+\tsize_t total=0;\n \n \t*outl=0;\n \tif (inl == 0) return;\n \tOPENSSL_assert(ctx->length <= (int)sizeof(ctx->enc_data));\n-\tif ((ctx->num+inl) < ctx->length)\n+\tif (ctx->length - ctx->num > inl)\n \t\t{\n \t\tmemcpy(&(ctx->enc_data[ctx->num]),in,inl);\n \t\tctx->num+=inl;\n@@ -156,7 +156,7 @@ void EVP_EncodeUpdate(EVP_ENCODE_CTX *ct\n \t\t*out='\\0';\n \t\ttotal=j+1;\n \t\t}\n-\twhile (inl >= ctx->length)\n+\twhile (inl >= ctx->length && total <= INT_MAX)\n \t\t{\n \t\tj=EVP_EncodeBlock(out,in,ctx->length);\n \t\tin+=ctx->length;\n@@ -166,6 +166,11 @@ void EVP_EncodeUpdate(EVP_ENCODE_CTX *ct\n \t\t*out='\\0';\n \t\ttotal+=j+1;\n \t\t}\n+\tif (total > INT_MAX) {\n+\t /* Too much output data! */\n+\t *outl = 0;\n+\t return;\n+\t}\n \tif (inl != 0)\n \t\tmemcpy(&(ctx->enc_data[0]),in,inl);\n \tctx->num=inl;\nIndex: openssl-1.0.1i/doc/crypto/EVP_EncodeInit.pod\n===================================================================\n--- /dev/null\t1970-01-01 00:00:00.000000000 +0000\n+++ openssl-1.0.1i/doc/crypto/EVP_EncodeInit.pod\t2016-04-28 16:25:58.940079648 +0200\n@@ -0,0 +1,145 @@\n+=pod\n+\n+=head1 NAME\n+\n+EVP_ENCODE_CTX_new, EVP_ENCODE_CTX_free, EVP_ENCODE_CTX_num, EVP_EncodeInit,\n+EVP_EncodeUpdate, EVP_EncodeFinal, EVP_EncodeBlock, EVP_DecodeInit,\n+EVP_DecodeUpdate, EVP_DecodeFinal, EVP_DecodeBlock - EVP base 64 encode/decode\n+routines\n+\n+=head1 SYNOPSIS\n+\n+ #include <openssl/evp.h>\n+\n+ EVP_ENCODE_CTX *EVP_ENCODE_CTX_new(void);\n+ void EVP_ENCODE_CTX_free(EVP_ENCODE_CTX *ctx);\n+ int EVP_ENCODE_CTX_num(EVP_ENCODE_CTX *ctx);\n+ void EVP_EncodeInit(EVP_ENCODE_CTX *ctx);\n+ void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,\n+ const unsigned char *in, int inl);\n+ void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl);\n+ int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n);\n+\n+ void EVP_DecodeInit(EVP_ENCODE_CTX *ctx);\n+ int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,\n+ const unsigned char *in, int inl);\n+ int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned\n+ char *out, int *outl);\n+ int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n);\n+\n+=head1 DESCRIPTION\n+\n+The EVP encode routines provide a high level interface to base 64 encoding and\n+decoding. Base 64 encoding converts binary data into a printable form that uses\n+the characters A-Z, a-z, 0-9, \"+\" and \"/\" to represent the data. For every 3\n+bytes of binary data provided approximately 4 bytes of base 64 encoded data will\n+be produced (see below). If the input data length is not a multiple of 3 then\n+the output data will be padded at the end using the \"=\" character.\n+\n+EVP_ENCODE_CTX_new() allocates, initializes and returns a context to be used for\n+the encode/decode functions.\n+\n+EVP_ENCODE_CTX_free() cleans up an encode/decode context B<ctx> and frees up the\n+space allocated to it.\n+\n+Encoding of binary base 64 data is performed in blocks of 48 input bytes (or\n+less for the final block). For each 48 byte input block encoded 64 bytes of base\n+64 data is output plus an additional newline character (i.e. 65 bytes in total).\n+The final block (which may be less than 48 bytes) will output 4 bytes for every\n+3 bytes of input. If the data length is not divisible by 3 then a full 4 bytes\n+is still output for the final 1 or 2 bytes of input. Similarly a newline\n+character will also be output.\n+\n+EVP_EncodeInit() initialises B<ctx> for the start of a new encoding operation.\n+\n+EVP_EncodeUpdate() encode B<inl> bytes of data found in the buffer pointed to by\n+B<in>. The output is stored in the buffer B<out> and the number of bytes output\n+is stored in B<*outl>. It is the caller's responsibility to ensure that the\n+buffer at B<out> is sufficiently large to accommodate the output data. Only full\n+blocks of data (48 bytes) will be immediately processed and output by this\n+function. Any remainder is held in the B<ctx> object and will be processed by a\n+subsequent call to EVP_EncodeUpdate() or EVP_EncodeFinal(). To calculate the\n+required size of the output buffer add together the value of B<inl> with the\n+amount of unprocessed data held in B<ctx> and divide the result by 48 (ignore\n+any remainder). This gives the number of blocks of data that will be processed.\n+Ensure the output buffer contains 65 bytes of storage for each block, plus an\n+additional byte for a NUL terminator. EVP_EncodeUpdate() may be called\n+repeatedly to process large amounts of input data. In the event of an error\n+EVP_EncodeUpdate() will set B<*outl> to 0.\n+\n+EVP_EncodeFinal() must be called at the end of an encoding operation. It will\n+process any partial block of data remaining in the B<ctx> object. The output\n+data will be stored in B<out> and the length of the data written will be stored\n+in B<*outl>. It is the caller's responsibility to ensure that B<out> is\n+sufficiently large to accommodate the output data which will never be more than\n+65 bytes plus an additional NUL terminator (i.e. 66 bytes in total).\n+\n+EVP_ENCODE_CTX_num() will return the number of as yet unprocessed bytes still to\n+be encoded or decoded that are pending in the B<ctx> object.\n+\n+EVP_EncodeBlock() encodes a full block of input data in B<f> and of length\n+B<dlen> and stores it in B<t>. For every 3 bytes of input provided 4 bytes of\n+output data will be produced. If B<dlen> is not divisible by 3 then the block is\n+encoded as a final block of data and the output is padded such that it is always\n+divisible by 4. Additionally a NUL terminator character will be added. For\n+example if 16 bytes of input data is provided then 24 bytes of encoded data is\n+created plus 1 byte for a NUL terminator (i.e. 25 bytes in total). The length of\n+the data generated I<without> the NUL terminator is return\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 700daeecb890721176bd23effc4166221cdd0271 Mon Sep 17 00:00:00 2001\nFrom: Matt Caswell <matt@openssl.org>\nDate: Fri, 4 Mar 2016 10:17:17 +0000\nSubject: [PATCH] Avoid overflow in EVP_EncodeUpdate\n\nAn overflow can occur in the EVP_EncodeUpdate function which is used for\nBase64 encoding of binary data. If an attacker is able to supply very large\namounts of input data then a length check can overflow resulting in a heap\ncorruption. Due to the very large amounts of data involved this will most\nlikely result in a crash.\n\nInternally to OpenSSL the EVP_EncodeUpdate function is primarly used by the\nPEM_write_bio* family of functions. These are mainly used within the\nOpenSSL command line applications, so any application which processes\ndata from an untrusted source and outputs it as a PEM file should be\nconsidered vulnerable to this issue.\n\nUser applications that call these APIs directly with large amounts of\nuntrusted data may also be vulnerable.\n\nIssue reported by Guido Vranken.\n\nCVE-2016-2105\n---\n crypto/evp/encode.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\nFrom 29188216f818e5b34f3b17ee8ed31e8336f3817e Mon Sep 17 00:00:00 2001\nFrom: Matt Caswell <matt@openssl.org>\nDate: Mon, 25 Apr 2016 09:06:29 +0100\nSubject: [PATCH] Ensure EVP_EncodeUpdate handles an output length that is too long\n\nWith the EVP_EncodeUpdate function it is the caller's responsibility to\ndetermine how big the output buffer should be. The function writes the\namount actually used to |*outl|. However this could go negative with a\nsufficiently large value for |inl|. We add a check for this error\ncondition.\n\nFrom f332816ef87556b7e89b98206c14df1f128b6d9f Mon Sep 17 00:00:00 2001\nFrom: Matt Caswell <matt@openssl.org>\nDate: Mon, 25 Apr 2016 11:54:30 +0100\nSubject: [PATCH] Add documentation for EVP_EncodeInit() and similar functions\n\nIndex: openssl-1.0.1i/crypto/evp/encode.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/evp/encode.c\t2016-04-28 16:25:58.940079648 +0200\n+++ openssl-1.0.1i/crypto/evp/encode.c\t2016-04-28 16:34:49.279062747 +0200\n@@ -132,12 +132,12 @@ void EVP_EncodeUpdate(EVP_ENCODE_CTX *ct\n \t const unsigned char *in, int inl)\n \t{\n \tint i,j;\n-\tunsigned int total=0;\n+\tsize_t total=0;\n \n \t*outl=0;\n \tif (inl == 0) return;\n \tOPENSSL_assert(ctx->length <= (int)sizeof(ctx->enc_data));\n-\tif ((ctx->num+inl) < ctx->length)\n+\tif (ctx->length - ctx->num > inl)\n \t\t{\n \t\tmemcpy(&(ctx->enc_data[ctx->num]),in,inl);\n \t\tctx->num+=inl;\n@@ -156,7 +156,7 @@ void EVP_EncodeUpdate(EVP_ENCODE_CTX *ct\n \t\t*out='\\0';\n \t\ttotal=j+1;\n \t\t}\n-\twhile (inl >= ctx->length)\n+\twhile (inl >= ctx->length && total <= INT_MAX)\n \t\t{\n \t\tj=EVP_EncodeBlock(out,in,ctx->length);\n \t\tin+=ctx->length;\n@@ -166,6 +166,11 @@ void EVP_EncodeUpdate(EVP_ENCODE_CTX *ct\n \t\t*out='\\0';\n \t\ttotal+=j+1;\n \t\t}\n+\tif (total > INT_MAX) {\n+\t /* Too much output data! */\n+\t *outl = 0;\n+\t return;\n+\t}\n \tif (inl != 0)\n \t\tmemcpy(&(ctx->enc_data[0]),in,inl);\n \tctx->num=inl;\nIndex: openssl-1.0.1i/doc/crypto/EVP_EncodeInit.pod\n===================================================================\n--- /dev/null\t1970-01-01 00:00:00.000000000 +0000\n+++ openssl-1.0.1i/doc/crypto/EVP_EncodeInit.pod\t2016-04-28 16:25:58.940079648 +0200\n@@ -0,0 +1,145 @@\n+=pod\n+\n+=head1 NAME\n+\n+EVP_ENCODE_CTX_new, EVP_ENCODE_CTX_free, EVP_ENCODE_CTX_num, EVP_EncodeInit,\n+EVP_EncodeUpdate, EVP_EncodeFinal, EVP_EncodeBlock, EVP_DecodeInit,\n+EVP_DecodeUpdate, EVP_DecodeFinal, EVP_DecodeBlock - EVP base 64 encode/decode\n+routines\n+\n+=head1 SYNOPSIS\n+\n+ #include <openssl/evp.h>\n+\n+ EVP_ENCODE_CTX *EVP_ENCODE_CTX_new(void);\n+ void EVP_ENCODE_CTX_free(EVP_ENCODE_CTX *ctx);\n+ int EVP_ENCODE_CTX_num(EVP_ENCODE_CTX *ctx);\n+ void EVP_EncodeInit(EVP_ENCODE_CTX *ctx);\n+ void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,\n+ const unsigned char *in, int inl);\n+ void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl);\n+ int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n);\n+\n+ void EVP_DecodeInit(EVP_ENCODE_CTX *ctx);\n+ int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,\n+ const unsigned char *in, int inl);\n+ int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned\n+ char *out, int *outl);\n+ int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n);\n+\n+=head1 DESCRIPTION\n+\n+The EVP encode routines provide a high level interface to base 64 encoding and\n+decoding. Base 64 encoding converts binary data into a printable form that uses\n+the characters A-Z, a-z, 0-9, \"+\" and \"/\" to represent the data. For every 3\n+bytes of binary data provided approximately 4 bytes of base 64 encoded data will\n+be produced (see below). If the input data length is not a multiple of 3 then\n+the output data will be padded at the end using the \"=\" character.\n+\n+EVP_ENCODE_CTX_new() allocates, initializes and returns a context to be used for\n+the encode/decode functions.\n+\n+EVP_ENCODE_CTX_free() cleans up an encode/decode context B<ctx> and frees up the\n+space allocated to it.\n+\n+Encoding of binary base 64 data is performed in blocks of 48 input bytes (or\n+less for the final block). For each 48 byte input block encoded 64 bytes of base\n+64 data is output plus an additional newline character (i.e. 65 bytes in total).\n+The final block (which may be less than 48 bytes) will output 4 bytes for every\n+3 bytes of input. If the data length is not divisible by 3 then a full 4 bytes\n+is still output for the final 1 or 2 bytes of input. Similarly a newline\n+character will also be output.\n+\n+EVP_EncodeInit() initialises B<ctx> for the start of a new encoding operation.\n+\n+EVP_EncodeUpdate() encode B<inl> bytes of data found in the buffer pointed to by\n+B<in>. The output is stored in the buffer B<out> and the number of bytes output\n+is stored in B<*outl>. It is the caller's responsibility to ensure that the\n+buffer at B<out> is sufficiently large to accommodate the output data. Only full\n+blocks of data (48 bytes) will be immediately processed and output by this\n+function. Any remainder is held in the B<ctx> object and will be processed by a\n+subsequent call to EVP_EncodeUpdate() or EVP_EncodeFinal(). To calculate the\n+required size of the output buffer add together the value of B<inl> with the\n+amount of unprocessed data held in B<ctx> and divide the result by 48 (ignore\n+any remainder). This gives the number of blocks of data that will be processed.\n+Ensure the output buffer contains 65 bytes of storage for each block, plus an\n+additional byte for a NUL terminator. EVP_EncodeUpdate() may be called\n+repeatedly to process large amounts of input data. In the event of an error\n+EVP_EncodeUpdate() will set B<*outl> to 0.\n+\n+EVP_EncodeFinal() must be called at the end of an encoding operation. It will\n+process any partial block of data remaining in the B<ctx> object. The output\n+data will be stored in B<out> and the length of the data written will be stored\n+in B<*outl>. It is the caller's responsibility to ensure that B<out> is\n+sufficiently large to accommodate the output data which will never be more than\n+65 bytes plus an additional NUL terminator (i.e. 66 bytes in total).\n+\n+EVP_ENCODE_CTX_num() will return the number of as yet unprocessed bytes still to\n+be encoded or decoded that are pending in the B<ctx> object.\n+\n+EVP_EncodeBlock() encodes a full block of input data in B<f> and of length\n+B<dlen> and stores it in B<t>. For every 3 bytes of input provided 4 bytes of\n+output data will be produced. If B<dlen> is not divisible by 3 then the block is\n+encoded as a final block of data and the output is padded such that it is always\n+divisible by 4. Additionally a NUL terminator character will be added. For\n+example if 16 bytes of input data is provided then 24 bytes of encoded data is\n+created plus 1 byte for a NUL terminator (i.e. 25 bytes in total). The length of\n+the data generated I<without> the NUL terminator is returned from the function.\n+\n+EVP_DecodeInit() initialises B<ctx> for the start of a new decoding operation.\n+\n+EVP_DecodeUpdate() decodes B<inl> bytes of data found in the buffer pointed to\n+by B<in>. The output is stored in the buffer B<out> and the number of bytes\n+output is stored in B<*outl>. It is the caller's responsibility to ensure that\n+the buffer at B<out> is sufficiently large to accommodate the output data. This\n+function will attempt to decode as much data as possible in 4 byte chunks. Any\n+whitespace, newline or carriage return characters are ignored. Any partial chunk\n+of unprocessed data (1, 2 or 3 bytes) that remains at the end will be held in\n+the B<ctx> object and processed by a subsequent call to EVP_DecodeUpdate(). If\n+any illegal base 64 characters are encountered or if the base 64 padding\n+character \"=\" is encountered in the middle of the data then the function returns\n+-1 to indicate an error. A return value of 0 or 1 indicates successful\n+processing of the data. A return value of 0 additionally indicates that the last\n+input data characters processed included the base 64 padding character \"=\" and\n+therefore no more non-padding character data is expected to be processed. For\n+every 4 valid base 64 bytes processed (ignoring whitespace, carriage returns and\n+line feeds), 3 bytes of binary output data will be produced (or less at the end\n+of the data where the padding character \"=\" has been used).\n+\n+EVP_DecodeFinal() must be called at the end of a decoding operation. If there\n+is any unprocessed data still in B<ctx> then the input data must not have been\n+a multiple of 4 and therefore an error has occurred. The function will return -1\n+in this case. Otherwise the function returns 1 on success.\n+\n+EVP_DecodeBlock() will decode the block of B<n> bytes of base 64 data contained\n+in B<f> and store the result in B<t>. Any leading whitespace will be trimmed as\n+will any trailing whitespace, newlines, carriage returns or EOF characters.\n+After such trimming the length of the data in B<f> must be divisbile by 4. For\n+every 4 input bytes exactly 3 output bytes will be produced. The output will be\n+padded with 0 bits if necessary to ensure that the output is always 3 bytes for\n+every 4 input bytes. This function will return the length of the data decoded or\n+-1 on error.\n+\n+=head1 RETURN VALUES\n+\n+EVP_ENCODE_CTX_new() returns a pointer to the newly allocated EVP_ENCODE_CTX\n+object or NULL on error.\n+\n+EVP_ENCODE_CTX_num() returns the number of bytes pending encoding or decoding in\n+B<ctx>.\n+\n+EVP_EncodeBlock() returns the number of bytes encoded excluding the NUL\n+terminator.\n+\n+EVP_DecodeUpdate() returns -1 on error and 0 or 1 on success. If 0 is returned\n+then no more non-padding base 64 characters are expected.\n+\n+EVP_DecodeFinal() returns -1 on error or 1 on success.\n+\n+EVP_DecodeBlock() returns the length of the data decoded or -1 on error.\n+\n+=head1 SEE ALSO\n+\n+L<evp(3)>\n+\n+=cut\nIndex: openssl-1.0.1i/doc/crypto/evp.pod\n===================================================================\n--- openssl-1.0.1i.orig/doc/crypto/evp.pod\t2016-04-28 16:25:57.866061427 +0200\n+++ openssl-1.0.1i/doc/crypto/evp.pod\t2016-04-28 16:36:43.400991700 +0200\n@@ -27,6 +27,10 @@ asymmetric algorithms.\n \n Algorithms are loaded with OpenSSL_add_all_algorithms(3).\n \n+The L<B<EVP_Encode>I<...>|EVP_EncodeInit(3)> and\n+L<B<EVP_Decode>I<...>|EVP_EncodeInit(3)> functions implement base 64 encoding\n+and decoding.\n+\n All the symmetric algorithms (ciphers), digests and asymmetric algorithms\n (public key algorithms) can be replaced by ENGINE modules providing alternative\n implementations. If ENGINE implementations of ciphers or digests are registered\n@@ -49,6 +53,7 @@ L<EVP_OpenInit(3)|EVP_OpenInit(3)>,\n L<EVP_SealInit(3)|EVP_SealInit(3)>,\n L<EVP_SignInit(3)|EVP_SignInit(3)>,\n L<EVP_VerifyInit(3)|EVP_VerifyInit(3)>,\n+L<EVP_EncodeInit(3)>,\n L<OpenSSL_add_all_algorithms(3)|OpenSSL_add_all_algorithms(3)>,\n L<engine(3)|engine(3)>" } ]
{ "id": "openssl-5667-openssl-CVE-2016-2105.patch", "cve_id": "CVE-2016-6302", "package": "openssl", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": true, "license": "OpenSSL", "context_tokens_est": 741, "context_files": 2 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-3706\n\nStack-based buffer overflow in the getaddrinfo function in sysdeps/posix/getaddrinfo.c in the GNU C Library (aka glibc or libc6) allows remote attackers to cause a denial of service (crash) via vectors involving hostent conversion. NOTE: this vulnerability exists because of an incomplete fix for CVE-2013-4458.\n\n## Package\nglibc-testsuite\n\n## Files to modify\n- resolv/res_init.c\n- resolv/res_send.c\n- glibc-2.19.orig/resolv/res_init.c\n- glibc-2.19.orig/resolv/res_send.c\n\n## Target Source Code\n\n### resolv/res_init.c\n\n#### __res_vinit() [lines 148-353]\n```c\n\n/* This function has to be reachable by res_data.c but not publically. */\nint\n__res_vinit(res_state statp, int preinit) {\n\tFILE *fp;\n\tchar *cp, **pp;\n\tint n;\n\tchar buf[BUFSIZ];\n\tint nserv = 0; /* number of nameserver records read from file */\n#ifdef _LIBC\n\tint nservall = 0; /* number of NS records read, nserv IPv4 only */\n#endif\n\tint haveenv = 0;\n\tint havesearch = 0;\n#ifdef RESOLVSORT\n\tint nsort = 0;\n\tchar *net;\n#endif\n#ifndef RFC1535\n\tint dots;\n#endif\n#ifdef _LIBC\n\tstatp->_u._ext.initstamp = __res_initstamp;\n#endif\n\n\tif (!preinit) {\n\t\tstatp->retrans = RES_TIMEOUT;\n\t\tstatp->retry = RES_DFLRETRY;\n\t\tstatp->options = RES_DEFAULT;\n\t\tstatp->id = res_randomid();\n\t}\n\n\tstatp->nscount = 0;\n\tstatp->ndots = 1;\n\tstatp->pfcode = 0;\n\tstatp->_vcsock = -1;\n\tstatp->_flags = 0;\n\tstatp->qhook = NULL;\n\tstatp->rhook = NULL;\n\tstatp->_u._ext.nsinit = 0;\n/* ... 156 lines omitted ... */\n\t\t\t\tsa6->sin6_flowinfo = 0;\n\t\t\t\tsa6->sin6_addr = a6;\n\n\t\t\t\tif (__builtin_expect (el == NULL, 1))\n\t\t\t\t sa6->sin6_scope_id = 0;\n\t\t\t\telse {\n\t\t\t\t int try_numericscope = 1;\n\t\t\t\t if (IN6_IS_ADDR_LINKLOCAL (&a6)\n\t\t\t\t\t|| IN6_IS_ADDR_MC_LINKLOCAL (&a6)) {\n\t\t\t\t\tsa6->sin6_scope_id\n\t\t\t\t\t = if_nametoindex (el + 1);\n\t\t\t\t\tif (sa6->sin6_scope_id != 0)\n\t\t\t\t\t try_numericscope = 0;\n\t\t\t\t }\n\n\t\t\t\t if (try_numericscope) {\n\t\t\t\t\tchar *end;\n\t\t\t\t\tsa6->sin6_scope_id\n\t\t\t\t\t = (uint32_t) strtoul (el + 1, &end,\n\t\t\t\t\t\t\t\t10);\n```\n\n#### __res_iclose() [lines 598-627]\n```c\n * This routine is not expected to be user visible.\n */\nvoid\n__res_iclose(res_state statp, bool free_addr) {\n\tint ns;\n\n\tif (statp->_vcsock >= 0) {\n\t\tclose_not_cancel_no_status(statp->_vcsock);\n\t\tstatp->_vcsock = -1;\n\t\tstatp->_flags &= ~(RES_F_VC | RES_F_CONN);\n\t}\n#ifdef _LIBC\n\tfor (ns = 0; ns < MAXNS; ns++)\n#else\n\tfor (ns = 0; ns < statp->_u._ext.nscount; ns++)\n#endif\n\t\tif (statp->_u._ext.nsaddrs[ns]) {\n\t\t\tif (statp->_u._ext.nssocks[ns] != -1) {\n\t\t\t\tclose_not_cancel_no_status(statp->_u._ext.nssocks[ns]);\n\t\t\t\tstatp->_u._ext.nssocks[ns] = -1;\n\t\t\t}\n\t\t\tif (free_addr) {\n\t\t\t\tfree (statp->_u._ext.nsaddrs[ns]);\n\t\t\t\tstatp->_u._ext.nsaddrs[ns] = NULL;\n\t\t\t}\n\t\t}\n\tstatp->_u._ext.nsinit = 0;\n}\nlibc_hidden_def (__res_iclose)\n\n```\n\n### resolv/res_send.c\n\n#### evNowTime() [lines 165-177]\n```c\n}\n\nstatic void\nevNowTime(struct timespec *res) {\n\tstruct timeval now;\n\n\tif (gettimeofday(&now, NULL) < 0)\n\t\tevConsTime(res, 0, 0);\n\telse\n\t\tTIMEVAL_TO_TIMESPEC (&now, res);\n}\n\n\n```\n\n#### res_ourserver_p() [lines 211-248]\n```c\n *\tpaul vixie, 29may94\n */\nint\nres_ourserver_p(const res_state statp, const struct sockaddr_in6 *inp)\n{\n\tint ns;\n\n\tif (inp->sin6_family == AF_INET) {\n\t struct sockaddr_in *in4p = (struct sockaddr_in *) inp;\n\t in_port_t port = in4p->sin_port;\n\t in_addr_t addr = in4p->sin_addr.s_addr;\n\n\t for (ns = 0; ns < MAXNS; ns++) {\n\t\tconst struct sockaddr_in *srv =\n\t\t (struct sockaddr_in *)EXT(statp).nsaddrs[ns];\n\n\t\tif ((srv != NULL) && (srv->sin_family == AF_INET) &&\n\t\t (srv->sin_port == port) &&\n\t\t (srv->sin_addr.s_addr == INADDR_ANY ||\n\t\t srv->sin_addr.s_addr == addr))\n\t\t return (1);\n\t }\n\t} else if (inp->sin6_family == AF_INET6) {\n\t for (ns = 0; ns < MAXNS; ns++) {\n\t\tconst struct sockaddr_in6 *srv = EXT(statp).nsaddrs[ns];\n\t\tif ((srv != NULL) && (srv->sin6_family == AF_INET6) &&\n\t\t (srv->sin6_port == inp->sin6_port) &&\n\t\t !(memcmp(&srv->sin6_addr, &in6addr_any,\n\t\t\t sizeof (struct in6_addr)) &&\n\t\t memcmp(&srv->sin6_addr, &inp->sin6_addr,\n\t\t\t sizeof (struct in6_addr))))\n\t\t return (1);\n\t }\n\t}\n\treturn (0);\n}\n\n/* int\n```\n\n#### __libc_res_nsend() [lines 340-644]\n```c\nlibresolv_hidden_def (res_queriesmatch)\n\nint\n__libc_res_nsend(res_state statp, const u_char *buf, int buflen,\n\t\t const u_char *buf2, int buflen2,\n\t\t u_char *ans, int anssiz, u_char **ansp, u_char **ansp2,\n\t\t int *nansp2, int *resplen2)\n{\n int gotsomewhere, terrno, try, v_circuit, resplen, ns, n;\n\n\tif (statp->nscount == 0) {\n\t\t__set_errno (ESRCH);\n\t\treturn (-1);\n\t}\n\n\tif (anssiz < (buf2 == NULL ? 1 : 2) * HFIXEDSZ) {\n\t\t__set_errno (EINVAL);\n\t\treturn (-1);\n\t}\n\n#ifdef USE_HOOKS\n\tif (__builtin_expect (statp->qhook || statp->rhook, 0)) {\n\t\tif (anssiz < MAXPACKET && ansp) {\n\t\t\tu_char *buf = malloc (MAXPACKET);\n\t\t\tif (buf == NULL)\n\t\t\t\treturn (-1);\n\t\t\tmemcpy (buf, ans, HFIXEDSZ);\n\t\t\t*ansp = buf;\n\t\t\tans = buf;\n\t\t\tanssiz = MAXPACKET;\n\t\t}\n\t}\n#endif\n\n\tDprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_QUERY),\n\t\t(stdout, \";; res_send()\\n\"), buf, buflen);\n\tv_circuit = ((statp->options & RES_USEVC)\n\t\t || buflen > PACKETSZ\n\t\t || buflen2 > PACKETSZ);\n\tgotsomewhere = 0;\n\tterrno = ETIMEDOUT;\n\n\t/*\n\t * If the ns_addr_list in the resolver context has changed, then\n\t * invalidate our cached copy and the associated timing data.\n\t */\n\tif (EXT(statp).nsinit) {\n\t\tint needclose = 0;\n\n\t\tif (EXT(statp).nscount != statp->nscount)\n\t\t\tneedclose++;\n\t\telse\n\t\t\tfor (ns = 0; ns < MAXNS; ns++) {\n\t\t\t\tunsigned int map = EXT(statp).nsmap[ns];\n\t\t\t\tif (map < MAXNS\n\t\t\t\t && !sock_eq((struct sockaddr_in6 *)\n\t\t\t\t\t\t&statp->nsaddr_list[map],\n\t\t\t\t\t\tEXT(statp).nsaddrs[ns]))\n\t\t\t\t{\n\t\t\t\t\tneedclose++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\tif (needclose)\n\t\t\t__res_iclose(statp, false);\n\t}\n\n\t/*\n\t * Maybe initialize our private copy of the ns_addr_list.\n\t */\n\tif (EXT(statp).nsinit == 0) {\n\t\tunsigned char map[MAXNS];\n\n\t\tmemset (map, MAXNS, sizeof (map));\n\t\tfor (n = 0; n < MAXNS; n++) {\n\t\t\tns = EXT(statp).nsmap[n];\n\t\t\tif (ns < statp->nscount)\n\t\t\t\tmap[ns] = n;\n\t\t\telse if (ns < MAXNS) {\n\t\t\t\tfree(EXT(statp).nsaddrs[n]);\n\t\t\t\tEXT(statp).nsaddrs[n] = NULL;\n\t\t\t\tEXT(statp).nsmap[n] = MAXNS;\n\t\t\t}\n\t\t}\n\t\tn = statp->nscount;\n\t\tif (statp->nscount > EXT(statp).nscount)\n\t\t\tfor (n = EXT(statp).nscount, ns = 0;\n\t\t\t n < statp->nscount; n++) {\n\t\t\t\twhile (ns < MAXNS\n\t\t\t\t && EXT(statp).nsmap[ns] != MAXNS)\n\t\t\t\t\tns++;\n\t\t\t\tif (ns == MAXNS)\n\t\t\t\t\tbreak;\n\t\t\t\tEXT(statp).nsmap[ns] = n;\n\t\t\t\tmap[n] = ns++;\n\t\t\t}\n\t\tEXT(statp).nscount = n;\n\t\tfor (ns = 0; ns < EXT(statp).nscount; ns++) {\n\t\t\tn = map[ns];\n\t\t\tif (EXT(statp).nsaddrs[n] == NULL)\n\t\t\t\tEXT(statp).nsaddrs[n] =\n\t\t\t\t malloc(sizeof (struct sockaddr_in6));\n\t\t\tif (EXT(statp).nsaddrs[n] != NULL) {\n\t\t\t\tmemset (mempcpy(EXT(statp).nsaddrs[n],\n\t\t\t\t\t\t&statp->nsaddr_list[ns],\n\t\t\t\t\t\tsizeof (struct sockaddr_in)),\n\t\t\t\t\t'\\0',\n\t\t\t\t\tsizeof (struct sockaddr_in6)\n\t\t\t\t\t- sizeof (struct sockaddr_in));\n\t\t\t\tEXT(statp).nssocks[n] = -1;\n\t\t\t\tn++;\n\t\t\t}\n\t\t}\n\t\tEXT(statp).nsinit = 1;\n\t}\n\n\t/*\n\t * Some resolvers want to even out the load on their nameservers.\n\t * Note that RES_BLAST overrides RES_ROTATE.\n\t */\n\tif (__builtin_expect ((statp->options & RES_ROTATE) != 0, 0) &&\n\t (statp->options & RES_BLAST) == 0) {\n\t\tstruct sockaddr_in6 *ina;\n\t\tunsigned int map;\n\n\t\tn = 0;\n\t\twhile (n < MAXNS && EXT(statp).nsmap[n] == MAXNS)\n\t\t\tn++;\n/* ... 157 lines omitted ... */\n\t\t\t} while (!done);\n\n\t\t}\n#endif\n\t\treturn (resplen);\n next_ns: ;\n\t } /*foreach ns*/\n\t} /*foreach retry*/\n\t__res_iclose(statp, false);\n\tif (!v_circuit) {\n\t\tif (!gotsomewhere)\n\t\t\t__set_errno (ECONNREFUSED);\t/* no nameservers found */\n\t\telse\n\t\t\t__set_errno (ETIMEDOUT);\t/* no answer obtained */\n\t} else\n\t\t__set_errno (terrno);\n\treturn (-1);\n}\n\nint\n```\n\n#### libresolv_hidden_def() [lines 614-700]\n```c\n\t\t\t\t\tgoto next_ns;\n\t\t\t\tcase res_modified:\n\t\t\t\t\t/* give the hook another try */\n\t\t\t\t\tif (++loops < 42) /*doug adams*/\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t/*FALLTHROUGH*/\n\t\t\t\tcase res_error:\n\t\t\t\t\t/*FALLTHROUGH*/\n\t\t\t\tdefault:\n\t\t\t\t\treturn (-1);\n\t\t\t\t}\n\t\t\t} while (!done);\n\n\t\t}\n#endif\n\t\treturn (resplen);\n next_ns: ;\n\t } /*foreach ns*/\n\t} /*foreach retry*/\n\t__res_iclose(statp, false);\n\tif (!v_circuit) {\n\t\tif (!gotsomewhere)\n\t\t\t__set_errno (ECONNREFUSED);\t/* no nameservers found */\n\t\telse\n\t\t\t__set_errno (ETIMEDOUT);\t/* no answer obtained */\n\t} else\n\t\t__set_errno (terrno);\n\treturn (-1);\n}\n\nint\nres_nsend(res_state statp,\n\t const u_char *buf, int buflen, u_char *ans, int anssiz)\n{\n return __libc_res_nsend(statp, buf, buflen, NULL, 0, ans, anssiz,\n\t\t\t NULL, NULL, NULL, NULL);\n}\nlibresolv_hidden_def (res_nsend)\n\n/* Private */\n\nstatic int\nsend_vc(res_state statp,\n\tconst u_char *buf, int buflen, const u_char *buf2, int buflen2,\n\tu_char **ansp, int *anssizp,\n\tint *terrno, int ns, u_char **anscp, u_char **ansp2, int *anssizp2,\n\tint *resplen2)\n{\n\tconst HEADER *hp = (HEADER *) buf;\n\tconst HEADER *hp2 = (HEADER *) buf2;\n\tu_char *ans = *ansp;\n\tint orig_anssizp = *anssizp;\n\t// XXX REMOVE\n\t// int anssiz = *anssizp;\n\tHEADER *anhp = (HEADER *) ans;\n\tstruct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns];\n\tint truncating, connreset, resplen, n;\n\tstruct iovec iov[4];\n\tu_short len;\n\tu_short len2;\n\tu_char *cp;\n\n\tif (resplen2 != NULL)\n\t *resplen\n/* ... truncated ... */\n```\n\n\n## Upstream Fix\n```diff\nFrom 6c07233f12e00b9cf66fb5d4a9b7ddb897590912 Mon Sep 17 00:00:00 2001\nFrom: Andreas Schwab <schwab@suse.de>\nDate: Thu, 19 Feb 2015 15:52:08 +0100\nSubject: [PATCH] Simplify handling of nameserver configuration in resolver\n\n\t[BZ #13028]\n\t[BZ #17053]\n\t* resolv/res_init.c (__res_vinit): Remove use of ext.nsmap.\n\t* resolv/res_send.c (__libc_res_nsend): Likewise.\n\t(get_nsaddr): New function.\n\t(res_ourserver_p, send_vc, reopen): Use it instead of accessing\n\tstatp directly.\n---\n resolv/res_init.c | 47 +++++-----------\n resolv/res_send.c | 164 +++++++++++++++++++++++-------------------------------\n 2 files changed, 84 insertions(+), 127 deletions(-)\n\nIndex: glibc-2.19/resolv/res_init.c\n===================================================================\n--- glibc-2.19.orig/resolv/res_init.c\n+++ glibc-2.19/resolv/res_init.c\n@@ -153,10 +153,8 @@ __res_vinit(res_state statp, int preinit\n \tchar *cp, **pp;\n \tint n;\n \tchar buf[BUFSIZ];\n-\tint nserv = 0; /* number of nameserver records read from file */\n-#ifdef _LIBC\n-\tint nservall = 0; /* number of NS records read, nserv IPv4 only */\n-#endif\n+\tint nserv = 0; /* number of nameservers read from file */\n+\tint have_serv6 = 0;\n \tint haveenv = 0;\n \tint havesearch = 0;\n #ifdef RESOLVSORT\n@@ -184,15 +182,9 @@ __res_vinit(res_state statp, int preinit\n \tstatp->_flags = 0;\n \tstatp->qhook = NULL;\n \tstatp->rhook = NULL;\n-\tstatp->_u._ext.nsinit = 0;\n \tstatp->_u._ext.nscount = 0;\n-#ifdef _LIBC\n-\tstatp->_u._ext.nscount6 = 0;\n-\tfor (n = 0; n < MAXNS; n++) {\n-\t\tstatp->_u._ext.nsaddrs[n] = NULL;\n-\t\tstatp->_u._ext.nsmap[n] = MAXNS;\n-\t}\n-#endif\n+\tfor (n = 0; n < MAXNS; n++)\n+\t statp->_u._ext.nsaddrs[n] = NULL;\n \n \t/* Allow user to override the local domain definition */\n \tif ((cp = getenv(\"LOCALDOMAIN\")) != NULL) {\n@@ -296,11 +288,7 @@ __res_vinit(res_state statp, int preinit\n \t\t continue;\n \t\t}\n \t\t/* read nameservers to query */\n-#ifdef _LIBC\n-\t\tif (MATCH(buf, \"nameserver\") && nservall < MAXNS) {\n-#else\n \t\tif (MATCH(buf, \"nameserver\") && nserv < MAXNS) {\n-#endif\n \t\t struct in_addr a;\n \n \t\t cp = buf + sizeof(\"nameserver\") - 1;\n@@ -308,13 +296,12 @@ __res_vinit(res_state statp, int preinit\n \t\t\tcp++;\n \t\t if ((*cp != '\\0') && (*cp != '\\n')\n \t\t\t&& __inet_aton(cp, &a)) {\n-\t\t\tstatp->nsaddr_list[nservall].sin_addr = a;\n-\t\t\tstatp->nsaddr_list[nservall].sin_family = AF_INET;\n-\t\t\tstatp->nsaddr_list[nservall].sin_port =\n+\t\t\tstatp->nsaddr_list[nserv].sin_addr = a;\n+\t\t\tstatp->nsaddr_list[nserv].sin_family = AF_INET;\n+\t\t\tstatp->nsaddr_list[nserv].sin_port =\n \t\t\t\thtons(NAMESERVER_PORT);\n \t\t\tnserv++;\n #ifdef _LIBC\n-\t\t\tnservall++;\n \t\t } else {\n \t\t\tstruct in6_addr a6;\n \t\t\tchar *el;\n@@ -356,10 +343,11 @@ __res_vinit(res_state statp, int preinit\n \t\t\t\t }\n \t\t\t\t}\n \n-\t\t\t\tstatp->_u._ext.nsaddrs[nservall] = sa6;\n-\t\t\t\tstatp->_u._ext.nssocks[nservall] = -1;\n-\t\t\t\tstatp->_u._ext.nsmap[nservall] = MAXNS + 1;\n-\t\t\t\tnservall++;\n+\t\t\t\tstatp->nsaddr_list[nserv].sin_family = 0;\n+\t\t\t\tstatp->_u._ext.nsaddrs[nserv] = sa6;\n+\t\t\t\tstatp->_u._ext.nssocks[nserv] = -1;\n+\t\t\t\thave_serv6 = 1;\n+\t\t\t\tnserv++;\n \t\t\t }\n \t\t\t}\n #endif\n@@ -414,10 +402,9 @@ __res_vinit(res_state statp, int preinit\n \t\t continue;\n \t\t}\n \t }\n-\t statp->nscount = nservall;\n+\t statp->nscount = nserv;\n #ifdef _LIBC\n-\t if (nservall - nserv > 0) {\n-\t\tstatp->_u._ext.nscount6 = nservall - nserv;\n+\t if (have_serv6) {\n \t\t/* We try IPv6 servers again. */\n \t\tstatp->ipv6_unavail = false;\n \t }\n@@ -606,11 +593,7 @@ __res_iclose(res_state statp, bool free_\n \t\tstatp->_vcsock = -1;\n \t\tstatp->_flags &= ~(RES_F_VC | RES_F_CONN);\n \t}\n-#ifdef _LIBC\n-\tfor (ns = 0; ns < MAXNS; ns++)\n-#else\n \tfor (ns = 0; ns < statp->_u._ext.nscount; ns++)\n-#endif\n \t\tif (statp->_u._ext.nsaddrs[ns]) {\n \t\t\tif (statp->_u._ext.nssocks[ns] != -1) {\n \t\t\t\tclose_not_cancel_no_status(statp->_u._ext.nssocks[ns]);\n@@ -621,7 +604,6 @@ __res_iclose(res_state statp, bool free_\n \t\t\t\tstatp->_u._ext.nsaddrs[ns] = NULL;\n \t\t\t}\n \t\t}\n-\tstatp->_u._ext.nsinit = 0;\n }\n libc_hidden_def (__res_iclose)\n \nIndex: glibc-2.19/resolv/res_send.c\n===================================================================\n--- glibc-2.19.orig/resolv/res_send.c\n+++ glibc-2.19/resolv/res_send.c\n@@ -183,6 +183,7 @@ evNowTime(struct timespec *res) {\n \n /* Forward. */\n \n+static struct sockaddr *get_nsaddr (res_state, int);\n static int\t\tsend_vc(res_state, const u_char *, int,\n \t\t\t\tconst u_char *, int,\n \t\t\t\tu_char **, int *, int *, int, u_char **,\n@@ -220,20 +221,21 @@ res_ourserver_p(const res_state statp, c\n \t in_port_t port = in4p->sin_port;\n \t in_addr_t addr = in4p->sin_addr.s_addr;\n \n-\t for (ns = 0; ns < MAXNS; ns++) {\n+\t for (ns = 0; ns < statp->nscount; ns++) {\n \t\tconst struct sockaddr_in *srv =\n-\t\t (struct sockaddr_in *)EXT(statp).nsaddrs[ns];\n+\t\t (struct sockaddr_in *) get_nsaddr (statp, ns);\n \n-\t\tif ((srv != NULL) && (srv->sin_family == AF_INET) &&\n+\t\tif ((srv->sin_family == AF_INET) &&\n \t\t (srv->sin_port == port) &&\n \t\t (srv->sin_addr.s_addr == INADDR_ANY ||\n \t\t srv->sin_addr.s_addr == addr))\n \t\t return (1);\n \t }\n \t} else if (inp->sin6_family == AF_INET6) {\n-\t for (ns = 0; ns < MAXNS; ns++) {\n-\t\tconst struct sockaddr_in6 *srv = EXT(statp).nsaddrs[ns];\n-\t\tif ((srv != NULL) && (srv->sin6_family == AF_INET6) &&\n+\t for (ns = 0; ns < statp->nscount; ns++) {\n+\t\tconst struct sockaddr_in6 *srv\n+\t\t = (struct sockaddr_in6 *) get_nsaddr (statp, ns);\n+\t\tif ((srv->sin6_family == AF_INET6) &&\n \t\t (srv->sin6_port == inp->sin6_port) &&\n \t\t !(memcmp(&srv->sin6_addr, &in6addr_any,\n \t\t\t sizeof (struct in6_addr)) &&\n@@ -383,74 +385,48 @@ __libc_res_nsend(res_state statp, const\n \t * If the ns_addr_list in the resolver context has changed, then\n \t * invalidate our cached copy and the associated timing data.\n \t */\n-\tif (EXT(statp).nsinit) {\n+\tif (EXT(statp).nscount != 0) {\n \t\tint needclose = 0;\n \n \t\tif (EXT(statp).nscount != statp->nscount)\n \t\t\tneedclose++;\n \t\telse\n-\t\t\tfor (ns = 0; ns < MAXNS; ns++) {\n-\t\t\t\tunsigned int map = EXT(statp).nsmap[ns];\n-\t\t\t\tif (map < MAXNS\n+\t\t\tfor (ns = 0; ns < statp->nscount; ns++) {\n+\t\t\t\tif (statp->nsaddr_list[ns].sin_family != 0\n \t\t\t\t && !sock_eq((struct sockaddr_in6 *)\n-\t\t\t\t\t\t&statp->nsaddr_list[map],\n+\t\t\t\t\t\t&statp->nsaddr_list[ns],\n \t\t\t\t\t\tEXT(statp).nsaddrs[ns]))\n \t\t\t\t{\n \t\t\t\t\tneedclose++;\n \t\t\t\t\tbreak;\n \t\t\t\t}\n \t\t\t}\n-\t\tif (needclose)\n+\t\tif (needclose) {\n \t\t\t__res_iclose(statp, false);\n+\t\t\tEXT(statp).nscount = 0;\n+\t\t}\n \t}\n \n \t/*\n \t * Maybe initialize our private copy of the ns_addr_list.\n \t */\n-\tif (EXT(statp).nsinit == 0) {\n-\t\tunsigned char map[MAXNS];\n-\n-\t\tmemset (map, MAXNS, sizeof (map));\n-\t\tfor (n = 0; n < MAXNS; n++) {\n-\t\t\tns = EXT(statp).nsmap[n];\n-\t\t\tif (ns < statp->nscount)\n-\t\t\t\tmap[ns] = n;\n-\t\t\telse if (ns < MAXNS) {\n-\t\t\t\tfree(EXT(statp).nsaddrs[n]);\n-\t\t\t\tEXT(statp).nsaddrs[n] = NULL;\n-\t\t\t\tEXT(statp).nsmap[n] = MAXNS;\n-\t\t\t}\n-\t\t}\n-\t\tn = statp->nscount;\n-\t\tif (statp->nscount > EXT(statp).nscount)\n-\t\t\tfor (n = EXT(statp).nscount, ns = 0;\n-\t\t\t n < statp->nscount; n++) {\n-\t\t\t\twhile (ns < MAXNS\n-\t\t\t\t && EXT(statp).nsmap[ns] != MAXNS)\n-\t\t\t\t\tns++;\n-\t\t\t\tif (ns == MAXNS)\n-\t\t\t\t\tbreak;\n-\t\t\t\tEXT(statp).nsmap[ns] = n;\n-\t\t\t\tmap[n] = ns++;\n-\t\t\t}\n-\t\tEXT(statp).nscount = n;\n-\t\tfor (ns = 0; ns < EXT(statp).nscount; ns++) {\n-\t\t\tn = map[ns];\n-\t\t\tif (EXT(statp).nsaddrs[n] == NULL)\n-\t\t\t\tEXT(statp).nsaddrs[n] =\n+\tif (EXT(statp).nscount == 0) {\n+\t\tfor (ns = 0; ns < statp->nscount; ns++) {\n+\t\t\tEXT(statp).nssocks[ns] = -1;\n+\t\t\tif (statp->nsaddr_list[ns].sin_family == 0)\n+\t\t\t\tcontinue;\n+\t\t\tif (EXT(statp).nsaddrs[ns] == NULL)\n+\t\t\t\tEXT(statp).nsaddrs[ns] =\n \t\t\t\t malloc(sizeof (struct sockaddr_in6));\n-\t\t\tif (EXT(statp).nsaddrs[n] != NULL) {\n-\t\t\t\tmemset (mempcpy(EXT(statp).nsaddrs[n],\n+\t\t\tif (EXT(statp).nsaddrs[ns] != NULL)\n+\t\t\t\tmemset (mempcpy(EXT(statp).nsaddrs[ns],\n \t\t\t\t\t\t&statp->nsaddr_list[ns],\n \t\t\t\t\t\tsizeof (struct sockaddr_in)),\n \t\t\t\t\t'\\0',\n \t\t\t\t\tsizeof (struct sockaddr_in6)\n \t\t\t\t\t- sizeof (struct sockaddr_in));\n-\t\t\t\tEXT(statp).nssocks[n] = -1;\n-\t\t\t\tn++;\n-\t\t\t}\n \t\t}\n-\t\tEXT(statp)\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 6c07233f12e00b9cf66fb5d4a9b7ddb897590912 Mon Sep 17 00:00:00 2001\nFrom: Andreas Schwab <schwab@suse.de>\nDate: Thu, 19 Feb 2015 15:52:08 +0100\nSubject: [PATCH] Simplify handling of nameserver configuration in resolver\n\n\t[BZ #13028]\n\t[BZ #17053]\n\t* resolv/res_init.c (__res_vinit): Remove use of ext.nsmap.\n\t* resolv/res_send.c (__libc_res_nsend): Likewise.\n\t(get_nsaddr): New function.\n\t(res_ourserver_p, send_vc, reopen): Use it instead of accessing\n\tstatp directly.\n---\n resolv/res_init.c | 47 +++++-----------\n resolv/res_send.c | 164 +++++++++++++++++++++++-------------------------------\n 2 files changed, 84 insertions(+), 127 deletions(-)\n\nIndex: glibc-2.19/resolv/res_init.c\n===================================================================\n--- glibc-2.19.orig/resolv/res_init.c\n+++ glibc-2.19/resolv/res_init.c\n@@ -153,10 +153,8 @@ __res_vinit(res_state statp, int preinit\n \tchar *cp, **pp;\n \tint n;\n \tchar buf[BUFSIZ];\n-\tint nserv = 0; /* number of nameserver records read from file */\n-#ifdef _LIBC\n-\tint nservall = 0; /* number of NS records read, nserv IPv4 only */\n-#endif\n+\tint nserv = 0; /* number of nameservers read from file */\n+\tint have_serv6 = 0;\n \tint haveenv = 0;\n \tint havesearch = 0;\n #ifdef RESOLVSORT\n@@ -184,15 +182,9 @@ __res_vinit(res_state statp, int preinit\n \tstatp->_flags = 0;\n \tstatp->qhook = NULL;\n \tstatp->rhook = NULL;\n-\tstatp->_u._ext.nsinit = 0;\n \tstatp->_u._ext.nscount = 0;\n-#ifdef _LIBC\n-\tstatp->_u._ext.nscount6 = 0;\n-\tfor (n = 0; n < MAXNS; n++) {\n-\t\tstatp->_u._ext.nsaddrs[n] = NULL;\n-\t\tstatp->_u._ext.nsmap[n] = MAXNS;\n-\t}\n-#endif\n+\tfor (n = 0; n < MAXNS; n++)\n+\t statp->_u._ext.nsaddrs[n] = NULL;\n \n \t/* Allow user to override the local domain definition */\n \tif ((cp = getenv(\"LOCALDOMAIN\")) != NULL) {\n@@ -296,11 +288,7 @@ __res_vinit(res_state statp, int preinit\n \t\t continue;\n \t\t}\n \t\t/* read nameservers to query */\n-#ifdef _LIBC\n-\t\tif (MATCH(buf, \"nameserver\") && nservall < MAXNS) {\n-#else\n \t\tif (MATCH(buf, \"nameserver\") && nserv < MAXNS) {\n-#endif\n \t\t struct in_addr a;\n \n \t\t cp = buf + sizeof(\"nameserver\") - 1;\n@@ -308,13 +296,12 @@ __res_vinit(res_state statp, int preinit\n \t\t\tcp++;\n \t\t if ((*cp != '\\0') && (*cp != '\\n')\n \t\t\t&& __inet_aton(cp, &a)) {\n-\t\t\tstatp->nsaddr_list[nservall].sin_addr = a;\n-\t\t\tstatp->nsaddr_list[nservall].sin_family = AF_INET;\n-\t\t\tstatp->nsaddr_list[nservall].sin_port =\n+\t\t\tstatp->nsaddr_list[nserv].sin_addr = a;\n+\t\t\tstatp->nsaddr_list[nserv].sin_family = AF_INET;\n+\t\t\tstatp->nsaddr_list[nserv].sin_port =\n \t\t\t\thtons(NAMESERVER_PORT);\n \t\t\tnserv++;\n #ifdef _LIBC\n-\t\t\tnservall++;\n \t\t } else {\n \t\t\tstruct in6_addr a6;\n \t\t\tchar *el;\n@@ -356,10 +343,11 @@ __res_vinit(res_state statp, int preinit\n \t\t\t\t }\n \t\t\t\t}\n \n-\t\t\t\tstatp->_u._ext.nsaddrs[nservall] = sa6;\n-\t\t\t\tstatp->_u._ext.nssocks[nservall] = -1;\n-\t\t\t\tstatp->_u._ext.nsmap[nservall] = MAXNS + 1;\n-\t\t\t\tnservall++;\n+\t\t\t\tstatp->nsaddr_list[nserv].sin_family = 0;\n+\t\t\t\tstatp->_u._ext.nsaddrs[nserv] = sa6;\n+\t\t\t\tstatp->_u._ext.nssocks[nserv] = -1;\n+\t\t\t\thave_serv6 = 1;\n+\t\t\t\tnserv++;\n \t\t\t }\n \t\t\t}\n #endif\n@@ -414,10 +402,9 @@ __res_vinit(res_state statp, int preinit\n \t\t continue;\n \t\t}\n \t }\n-\t statp->nscount = nservall;\n+\t statp->nscount = nserv;\n #ifdef _LIBC\n-\t if (nservall - nserv > 0) {\n-\t\tstatp->_u._ext.nscount6 = nservall - nserv;\n+\t if (have_serv6) {\n \t\t/* We try IPv6 servers again. */\n \t\tstatp->ipv6_unavail = false;\n \t }\n@@ -606,11 +593,7 @@ __res_iclose(res_state statp, bool free_\n \t\tstatp->_vcsock = -1;\n \t\tstatp->_flags &= ~(RES_F_VC | RES_F_CONN);\n \t}\n-#ifdef _LIBC\n-\tfor (ns = 0; ns < MAXNS; ns++)\n-#else\n \tfor (ns = 0; ns < statp->_u._ext.nscount; ns++)\n-#endif\n \t\tif (statp->_u._ext.nsaddrs[ns]) {\n \t\t\tif (statp->_u._ext.nssocks[ns] != -1) {\n \t\t\t\tclose_not_cancel_no_status(statp->_u._ext.nssocks[ns]);\n@@ -621,7 +604,6 @@ __res_iclose(res_state statp, bool free_\n \t\t\t\tstatp->_u._ext.nsaddrs[ns] = NULL;\n \t\t\t}\n \t\t}\n-\tstatp->_u._ext.nsinit = 0;\n }\n libc_hidden_def (__res_iclose)\n \nIndex: glibc-2.19/resolv/res_send.c\n===================================================================\n--- glibc-2.19.orig/resolv/res_send.c\n+++ glibc-2.19/resolv/res_send.c\n@@ -183,6 +183,7 @@ evNowTime(struct timespec *res) {\n \n /* Forward. */\n \n+static struct sockaddr *get_nsaddr (res_state, int);\n static int\t\tsend_vc(res_state, const u_char *, int,\n \t\t\t\tconst u_char *, int,\n \t\t\t\tu_char **, int *, int *, int, u_char **,\n@@ -220,20 +221,21 @@ res_ourserver_p(const res_state statp, c\n \t in_port_t port = in4p->sin_port;\n \t in_addr_t addr = in4p->sin_addr.s_addr;\n \n-\t for (ns = 0; ns < MAXNS; ns++) {\n+\t for (ns = 0; ns < statp->nscount; ns++) {\n \t\tconst struct sockaddr_in *srv =\n-\t\t (struct sockaddr_in *)EXT(statp).nsaddrs[ns];\n+\t\t (struct sockaddr_in *) get_nsaddr (statp, ns);\n \n-\t\tif ((srv != NULL) && (srv->sin_family == AF_INET) &&\n+\t\tif ((srv->sin_family == AF_INET) &&\n \t\t (srv->sin_port == port) &&\n \t\t (srv->sin_addr.s_addr == INADDR_ANY ||\n \t\t srv->sin_addr.s_addr == addr))\n \t\t return (1);\n \t }\n \t} else if (inp->sin6_family == AF_INET6) {\n-\t for (ns = 0; ns < MAXNS; ns++) {\n-\t\tconst struct sockaddr_in6 *srv = EXT(statp).nsaddrs[ns];\n-\t\tif ((srv != NULL) && (srv->sin6_family == AF_INET6) &&\n+\t for (ns = 0; ns < statp->nscount; ns++) {\n+\t\tconst struct sockaddr_in6 *srv\n+\t\t = (struct sockaddr_in6 *) get_nsaddr (statp, ns);\n+\t\tif ((srv->sin6_family == AF_INET6) &&\n \t\t (srv->sin6_port == inp->sin6_port) &&\n \t\t !(memcmp(&srv->sin6_addr, &in6addr_any,\n \t\t\t sizeof (struct in6_addr)) &&\n@@ -383,74 +385,48 @@ __libc_res_nsend(res_state statp, const\n \t * If the ns_addr_list in the resolver context has changed, then\n \t * invalidate our cached copy and the associated timing data.\n \t */\n-\tif (EXT(statp).nsinit) {\n+\tif (EXT(statp).nscount != 0) {\n \t\tint needclose = 0;\n \n \t\tif (EXT(statp).nscount != statp->nscount)\n \t\t\tneedclose++;\n \t\telse\n-\t\t\tfor (ns = 0; ns < MAXNS; ns++) {\n-\t\t\t\tunsigned int map = EXT(statp).nsmap[ns];\n-\t\t\t\tif (map < MAXNS\n+\t\t\tfor (ns = 0; ns < statp->nscount; ns++) {\n+\t\t\t\tif (statp->nsaddr_list[ns].sin_family != 0\n \t\t\t\t && !sock_eq((struct sockaddr_in6 *)\n-\t\t\t\t\t\t&statp->nsaddr_list[map],\n+\t\t\t\t\t\t&statp->nsaddr_list[ns],\n \t\t\t\t\t\tEXT(statp).nsaddrs[ns]))\n \t\t\t\t{\n \t\t\t\t\tneedclose++;\n \t\t\t\t\tbreak;\n \t\t\t\t}\n \t\t\t}\n-\t\tif (needclose)\n+\t\tif (needclose) {\n \t\t\t__res_iclose(statp, false);\n+\t\t\tEXT(statp).nscount = 0;\n+\t\t}\n \t}\n \n \t/*\n \t * Maybe initialize our private copy of the ns_addr_list.\n \t */\n-\tif (EXT(statp).nsinit == 0) {\n-\t\tunsigned char map[MAXNS];\n-\n-\t\tmemset (map, MAXNS, sizeof (map));\n-\t\tfor (n = 0; n < MAXNS; n++) {\n-\t\t\tns = EXT(statp).nsmap[n];\n-\t\t\tif (ns < statp->nscount)\n-\t\t\t\tmap[ns] = n;\n-\t\t\telse if (ns < MAXNS) {\n-\t\t\t\tfree(EXT(statp).nsaddrs[n]);\n-\t\t\t\tEXT(statp).nsaddrs[n] = NULL;\n-\t\t\t\tEXT(statp).nsmap[n] = MAXNS;\n-\t\t\t}\n-\t\t}\n-\t\tn = statp->nscount;\n-\t\tif (statp->nscount > EXT(statp).nscount)\n-\t\t\tfor (n = EXT(statp).nscount, ns = 0;\n-\t\t\t n < statp->nscount; n++) {\n-\t\t\t\twhile (ns < MAXNS\n-\t\t\t\t && EXT(statp).nsmap[ns] != MAXNS)\n-\t\t\t\t\tns++;\n-\t\t\t\tif (ns == MAXNS)\n-\t\t\t\t\tbreak;\n-\t\t\t\tEXT(statp).nsmap[ns] = n;\n-\t\t\t\tmap[n] = ns++;\n-\t\t\t}\n-\t\tEXT(statp).nscount = n;\n-\t\tfor (ns = 0; ns < EXT(statp).nscount; ns++) {\n-\t\t\tn = map[ns];\n-\t\t\tif (EXT(statp).nsaddrs[n] == NULL)\n-\t\t\t\tEXT(statp).nsaddrs[n] =\n+\tif (EXT(statp).nscount == 0) {\n+\t\tfor (ns = 0; ns < statp->nscount; ns++) {\n+\t\t\tEXT(statp).nssocks[ns] = -1;\n+\t\t\tif (statp->nsaddr_list[ns].sin_family == 0)\n+\t\t\t\tcontinue;\n+\t\t\tif (EXT(statp).nsaddrs[ns] == NULL)\n+\t\t\t\tEXT(statp).nsaddrs[ns] =\n \t\t\t\t malloc(sizeof (struct sockaddr_in6));\n-\t\t\tif (EXT(statp).nsaddrs[n] != NULL) {\n-\t\t\t\tmemset (mempcpy(EXT(statp).nsaddrs[n],\n+\t\t\tif (EXT(statp).nsaddrs[ns] != NULL)\n+\t\t\t\tmemset (mempcpy(EXT(statp).nsaddrs[ns],\n \t\t\t\t\t\t&statp->nsaddr_list[ns],\n \t\t\t\t\t\tsizeof (struct sockaddr_in)),\n \t\t\t\t\t'\\0',\n \t\t\t\t\tsizeof (struct sockaddr_in6)\n \t\t\t\t\t- sizeof (struct sockaddr_in));\n-\t\t\t\tEXT(statp).nssocks[n] = -1;\n-\t\t\t\tn++;\n-\t\t\t}\n \t\t}\n-\t\tEXT(statp).nsinit = 1;\n+\t\tEXT(statp).nscount = statp->nscount;\n \t}\n \n \t/*\n@@ -459,44 +435,37 @@ __libc_res_nsend(res_state statp, const\n \t */\n \tif (__builtin_expect ((statp->options & RES_ROTATE) != 0, 0) &&\n \t (statp->options & RES_BLAST) == 0) {\n-\t\tstruct sockaddr_in6 *ina;\n-\t\tunsigned int map;\n-\n-\t\tn = 0;\n-\t\twhile (n < MAXNS && EXT(statp).nsmap[n] == MAXNS)\n-\t\t\tn++;\n-\t\tif (n < MAXNS) {\n-\t\t\tina = EXT(statp).nsaddrs[n];\n-\t\t\tmap = EXT(statp).nsmap[n];\n-\t\t\tfor (;;) {\n-\t\t\t\tns = n + 1;\n-\t\t\t\twhile (ns < MAXNS\n-\t\t\t\t && EXT(statp).nsmap[ns] == MAXNS)\n-\t\t\t\t\tns++;\n-\t\t\t\tif (ns == MAXNS)\n-\t\t\t\t\tbreak;\n-\t\t\t\tEXT(statp).nsaddrs[n] = EXT(statp).nsaddrs[ns];\n-\t\t\t\tEXT(statp).nsmap[n] = EXT(statp).nsmap[ns];\n-\t\t\t\tn = ns;\n-\t\t\t}\n-\t\t\tEXT(statp).nsaddrs[n] = ina;\n-\t\t\tEXT(statp).nsmap[n] = map;\n-\t\t}\n+\t\tstruct sockaddr_in ina;\n+\t\tstruct sockaddr_in6 *inp;\n+\t\tint lastns = statp->nscount - 1;\n+\t\tint fd;\n+\n+\t\tinp = EXT(statp).nsaddrs[0];\n+\t\tina = statp->nsaddr_list[0];\n+\t\tfd = EXT(statp).nssocks[0];\n+\t\tfor (ns = 0; ns < lastns; ns++) {\n+\t\t EXT(statp).nsaddrs[ns] = EXT(statp).nsaddrs[ns + 1];\n+\t\t statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1];\n+\t\t EXT(statp).nssocks[ns] = EXT(statp).nssocks[ns + 1];\n+\t\t}\n+\t\tEXT(statp).nsaddrs[lastns] = inp;\n+\t\tstatp->nsaddr_list[lastns] = ina;\n+\t\tEXT(statp).nssocks[lastns] = fd;\n \t}\n \n \t/*\n \t * Send request, RETRY times, or until successful.\n \t */\n \tfor (try = 0; try < statp->retry; try++) {\n-\t for (ns = 0; ns < MAXNS; ns++)\n+\t for (ns = 0; ns < statp->nscount; ns++)\n \t {\n #ifdef DEBUG\n \t\tchar tmpbuf[40];\n #endif\n-\t\tstruct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns];\n+#if defined USE_HOOKS || defined DEBUG\n+\t\tstruct sockaddr *nsap = get_nsaddr (statp, ns);\n+#endif\n \n-\t\tif (nsap == NULL)\n-\t\t\tgoto next_ns;\n \t same_ns:\n #ifdef USE_HOOKS\n \t\tif (__builtin_expect (statp->qhook != NULL, 0)) {\n@@ -535,9 +504,9 @@ __libc_res_nsend(res_state statp, const\n \n \t\tDprint(statp->options & RES_DEBUG,\n \t\t (stdout, \";; Querying server (# %d) address = %s\\n\",\n-\t\t\tns + 1, inet_ntop(nsap->sin6_family,\n-\t\t\t\t\t (nsap->sin6_family == AF_INET6\n-\t\t\t\t\t ? &nsap->sin6_addr\n+\t\t\tns + 1, inet_ntop(nsap->sa_family,\n+\t\t\t\t\t (nsap->sa_family == AF_INET6\n+\t\t\t\t\t ? &((struct sockaddr_in6 *) nsap)->sin6_addr\n \t\t\t\t\t : &((struct sockaddr_in *) nsap)->sin_addr),\n \t\t\t\t\t tmpbuf, sizeof (tmpbuf))));\n \n@@ -653,6 +622,21 @@ libresolv_hidden_def (res_nsend)\n \n /* Private */\n \n+static struct sockaddr *\n+get_nsaddr (res_state statp, int n)\n+{\n+\n+ if (statp->nsaddr_list[n].sin_family == 0 && EXT(statp).nsaddrs[n] != NULL)\n+ /* EXT(statp).nsaddrs[n] holds an address that is larger than\n+ struct sockaddr, and user code did not update\n+ statp->nsaddr_list[n]. */\n+ return (struct sockaddr *) EXT(statp).nsaddrs[n];\n+ else\n+ /* User code updated statp->nsaddr_list[n], or statp->nsaddr_list[n]\n+ has the same content as EXT(statp).nsaddrs[n]. */\n+ return (struct sockaddr *) (void *) &statp->nsaddr_list[n];\n+}\n+\n static int\n send_vc(res_state statp,\n \tconst u_char *buf, int buflen, const u_char *buf2, int buflen2,\n@@ -667,7 +651,7 @@ send_vc(res_state statp,\n \t// XXX REMOVE\n \t// int anssiz = *anssizp;\n \tHEADER *anhp = (HEADER *) ans;\n-\tstruct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns];\n+\tstruct sockaddr *nsap = get_nsaddr (statp, ns);\n \tint truncating, connreset, resplen, n;\n \tstruct iovec iov[4];\n \tu_short len;\n@@ -687,8 +671,8 @@ send_vc(res_state statp,\n \n \t\tif (getpeername(statp->_vcsock,\n \t\t\t\t(struct sockaddr *)&peer, &size) < 0 ||\n-\t\t !sock_eq(&peer, nsap)) {\n-\t\t __res_iclose(statp, false);\n+\t\t !sock_eq(&peer, (struct sockaddr_in6 *) nsap)) {\n+\t\t\t__res_iclose(statp, false);\n \t\t\tstatp->_flags &= ~RES_F_VC;\n \t\t}\n \t}\n@@ -697,20 +681,19 @@ send_vc(res_state statp,\n \t\tif (statp->_vcsock >= 0)\n \t\t __res_iclose(statp, false);\n \n-\t\tstatp->_vcsock = socket(nsap->sin6_family, SOCK_STREAM, 0);\n+\t\tstatp->_vcsock = socket(nsap->sa_family, SOCK_STREAM, 0);\n \t\tif (statp->_vcsock < 0) {\n \t\t\t*terrno = errno;\n \t\t\tPerror(statp, stderr, \"socket(vc)\", errno);\n \t\t\treturn (-1);\n \t\t}\n \t\t__set_errno (0);\n-\t\tif (connect(statp->_vcsock, (struct sockaddr *)nsap,\n-\t\t\t nsap->sin6_family == AF_INET\n+\t\tif (connect(statp->_vcsock, nsap,\n+\t\t\t nsap->sa_family == AF_INET\n \t\t\t ? sizeof (struct sockaddr_in)\n \t\t\t : sizeof (struct sockaddr_in6)) < 0) {\n \t\t\t*terrno = errno;\n-\t\t\tAerror(statp, stderr, \"connect/vc\", errno,\n-\t\t\t (struct sockaddr *) nsap);\n+\t\t\tAerror(statp, stderr, \"connect/vc\", errno, nsap);\n \t\t\t__res_iclose(statp, false);\n \t\t\treturn (0);\n \t\t}\n@@ -914,8 +897,7 @@ static int\n reopen (res_state statp, int *terrno, int ns)\n {\n \tif (EXT(statp).nssocks[ns] == -1) {\n-\t\tstruct sockaddr *nsap\n-\t\t = (struct sockaddr *) EXT(statp).nsaddrs[ns];\n+\t\tstruct sockaddr *nsap = get_nsaddr (statp, ns);\n \t\tsocklen_t slen;\n \n \t\t/* only try IPv6 if IPv6 NS and if not failed before */" } ]
{ "id": "glibc-testsuite-5158-resolv-nameserver-handling.pat", "cve_id": "CVE-2016-3706", "package": "glibc-testsuite", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 2168, "context_files": 2 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-3706\n\nStack-based buffer overflow in the getaddrinfo function in sysdeps/posix/getaddrinfo.c in the GNU C Library (aka glibc or libc6) allows remote attackers to cause a denial of service (crash) via vectors involving hostent conversion. NOTE: this vulnerability exists because of an incomplete fix for CVE-2013-4458.\n\n## Package\nglibc\n\n## Files to modify\n- resolv/res_init.c\n- resolv/res_send.c\n- glibc-2.19.orig/resolv/res_init.c\n- glibc-2.19.orig/resolv/res_send.c\n\n## Target Source Code\n\n### resolv/res_init.c\n\n#### __res_vinit() [lines 148-353]\n```c\n\n/* This function has to be reachable by res_data.c but not publically. */\nint\n__res_vinit(res_state statp, int preinit) {\n\tFILE *fp;\n\tchar *cp, **pp;\n\tint n;\n\tchar buf[BUFSIZ];\n\tint nserv = 0; /* number of nameserver records read from file */\n#ifdef _LIBC\n\tint nservall = 0; /* number of NS records read, nserv IPv4 only */\n#endif\n\tint haveenv = 0;\n\tint havesearch = 0;\n#ifdef RESOLVSORT\n\tint nsort = 0;\n\tchar *net;\n#endif\n#ifndef RFC1535\n\tint dots;\n#endif\n#ifdef _LIBC\n\tstatp->_u._ext.initstamp = __res_initstamp;\n#endif\n\n\tif (!preinit) {\n\t\tstatp->retrans = RES_TIMEOUT;\n\t\tstatp->retry = RES_DFLRETRY;\n\t\tstatp->options = RES_DEFAULT;\n\t\tstatp->id = res_randomid();\n\t}\n\n\tstatp->nscount = 0;\n\tstatp->ndots = 1;\n\tstatp->pfcode = 0;\n\tstatp->_vcsock = -1;\n\tstatp->_flags = 0;\n\tstatp->qhook = NULL;\n\tstatp->rhook = NULL;\n\tstatp->_u._ext.nsinit = 0;\n/* ... 156 lines omitted ... */\n\t\t\t\tsa6->sin6_flowinfo = 0;\n\t\t\t\tsa6->sin6_addr = a6;\n\n\t\t\t\tif (__builtin_expect (el == NULL, 1))\n\t\t\t\t sa6->sin6_scope_id = 0;\n\t\t\t\telse {\n\t\t\t\t int try_numericscope = 1;\n\t\t\t\t if (IN6_IS_ADDR_LINKLOCAL (&a6)\n\t\t\t\t\t|| IN6_IS_ADDR_MC_LINKLOCAL (&a6)) {\n\t\t\t\t\tsa6->sin6_scope_id\n\t\t\t\t\t = if_nametoindex (el + 1);\n\t\t\t\t\tif (sa6->sin6_scope_id != 0)\n\t\t\t\t\t try_numericscope = 0;\n\t\t\t\t }\n\n\t\t\t\t if (try_numericscope) {\n\t\t\t\t\tchar *end;\n\t\t\t\t\tsa6->sin6_scope_id\n\t\t\t\t\t = (uint32_t) strtoul (el + 1, &end,\n\t\t\t\t\t\t\t\t10);\n```\n\n#### __res_iclose() [lines 598-627]\n```c\n * This routine is not expected to be user visible.\n */\nvoid\n__res_iclose(res_state statp, bool free_addr) {\n\tint ns;\n\n\tif (statp->_vcsock >= 0) {\n\t\tclose_not_cancel_no_status(statp->_vcsock);\n\t\tstatp->_vcsock = -1;\n\t\tstatp->_flags &= ~(RES_F_VC | RES_F_CONN);\n\t}\n#ifdef _LIBC\n\tfor (ns = 0; ns < MAXNS; ns++)\n#else\n\tfor (ns = 0; ns < statp->_u._ext.nscount; ns++)\n#endif\n\t\tif (statp->_u._ext.nsaddrs[ns]) {\n\t\t\tif (statp->_u._ext.nssocks[ns] != -1) {\n\t\t\t\tclose_not_cancel_no_status(statp->_u._ext.nssocks[ns]);\n\t\t\t\tstatp->_u._ext.nssocks[ns] = -1;\n\t\t\t}\n\t\t\tif (free_addr) {\n\t\t\t\tfree (statp->_u._ext.nsaddrs[ns]);\n\t\t\t\tstatp->_u._ext.nsaddrs[ns] = NULL;\n\t\t\t}\n\t\t}\n\tstatp->_u._ext.nsinit = 0;\n}\nlibc_hidden_def (__res_iclose)\n\n```\n\n### resolv/res_send.c\n\n#### evNowTime() [lines 165-177]\n```c\n}\n\nstatic void\nevNowTime(struct timespec *res) {\n\tstruct timeval now;\n\n\tif (gettimeofday(&now, NULL) < 0)\n\t\tevConsTime(res, 0, 0);\n\telse\n\t\tTIMEVAL_TO_TIMESPEC (&now, res);\n}\n\n\n```\n\n#### res_ourserver_p() [lines 211-248]\n```c\n *\tpaul vixie, 29may94\n */\nint\nres_ourserver_p(const res_state statp, const struct sockaddr_in6 *inp)\n{\n\tint ns;\n\n\tif (inp->sin6_family == AF_INET) {\n\t struct sockaddr_in *in4p = (struct sockaddr_in *) inp;\n\t in_port_t port = in4p->sin_port;\n\t in_addr_t addr = in4p->sin_addr.s_addr;\n\n\t for (ns = 0; ns < MAXNS; ns++) {\n\t\tconst struct sockaddr_in *srv =\n\t\t (struct sockaddr_in *)EXT(statp).nsaddrs[ns];\n\n\t\tif ((srv != NULL) && (srv->sin_family == AF_INET) &&\n\t\t (srv->sin_port == port) &&\n\t\t (srv->sin_addr.s_addr == INADDR_ANY ||\n\t\t srv->sin_addr.s_addr == addr))\n\t\t return (1);\n\t }\n\t} else if (inp->sin6_family == AF_INET6) {\n\t for (ns = 0; ns < MAXNS; ns++) {\n\t\tconst struct sockaddr_in6 *srv = EXT(statp).nsaddrs[ns];\n\t\tif ((srv != NULL) && (srv->sin6_family == AF_INET6) &&\n\t\t (srv->sin6_port == inp->sin6_port) &&\n\t\t !(memcmp(&srv->sin6_addr, &in6addr_any,\n\t\t\t sizeof (struct in6_addr)) &&\n\t\t memcmp(&srv->sin6_addr, &inp->sin6_addr,\n\t\t\t sizeof (struct in6_addr))))\n\t\t return (1);\n\t }\n\t}\n\treturn (0);\n}\n\n/* int\n```\n\n#### __libc_res_nsend() [lines 340-644]\n```c\nlibresolv_hidden_def (res_queriesmatch)\n\nint\n__libc_res_nsend(res_state statp, const u_char *buf, int buflen,\n\t\t const u_char *buf2, int buflen2,\n\t\t u_char *ans, int anssiz, u_char **ansp, u_char **ansp2,\n\t\t int *nansp2, int *resplen2)\n{\n int gotsomewhere, terrno, try, v_circuit, resplen, ns, n;\n\n\tif (statp->nscount == 0) {\n\t\t__set_errno (ESRCH);\n\t\treturn (-1);\n\t}\n\n\tif (anssiz < (buf2 == NULL ? 1 : 2) * HFIXEDSZ) {\n\t\t__set_errno (EINVAL);\n\t\treturn (-1);\n\t}\n\n#ifdef USE_HOOKS\n\tif (__builtin_expect (statp->qhook || statp->rhook, 0)) {\n\t\tif (anssiz < MAXPACKET && ansp) {\n\t\t\tu_char *buf = malloc (MAXPACKET);\n\t\t\tif (buf == NULL)\n\t\t\t\treturn (-1);\n\t\t\tmemcpy (buf, ans, HFIXEDSZ);\n\t\t\t*ansp = buf;\n\t\t\tans = buf;\n\t\t\tanssiz = MAXPACKET;\n\t\t}\n\t}\n#endif\n\n\tDprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_QUERY),\n\t\t(stdout, \";; res_send()\\n\"), buf, buflen);\n\tv_circuit = ((statp->options & RES_USEVC)\n\t\t || buflen > PACKETSZ\n\t\t || buflen2 > PACKETSZ);\n\tgotsomewhere = 0;\n\tterrno = ETIMEDOUT;\n\n\t/*\n\t * If the ns_addr_list in the resolver context has changed, then\n\t * invalidate our cached copy and the associated timing data.\n\t */\n\tif (EXT(statp).nsinit) {\n\t\tint needclose = 0;\n\n\t\tif (EXT(statp).nscount != statp->nscount)\n\t\t\tneedclose++;\n\t\telse\n\t\t\tfor (ns = 0; ns < MAXNS; ns++) {\n\t\t\t\tunsigned int map = EXT(statp).nsmap[ns];\n\t\t\t\tif (map < MAXNS\n\t\t\t\t && !sock_eq((struct sockaddr_in6 *)\n\t\t\t\t\t\t&statp->nsaddr_list[map],\n\t\t\t\t\t\tEXT(statp).nsaddrs[ns]))\n\t\t\t\t{\n\t\t\t\t\tneedclose++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\tif (needclose)\n\t\t\t__res_iclose(statp, false);\n\t}\n\n\t/*\n\t * Maybe initialize our private copy of the ns_addr_list.\n\t */\n\tif (EXT(statp).nsinit == 0) {\n\t\tunsigned char map[MAXNS];\n\n\t\tmemset (map, MAXNS, sizeof (map));\n\t\tfor (n = 0; n < MAXNS; n++) {\n\t\t\tns = EXT(statp).nsmap[n];\n\t\t\tif (ns < statp->nscount)\n\t\t\t\tmap[ns] = n;\n\t\t\telse if (ns < MAXNS) {\n\t\t\t\tfree(EXT(statp).nsaddrs[n]);\n\t\t\t\tEXT(statp).nsaddrs[n] = NULL;\n\t\t\t\tEXT(statp).nsmap[n] = MAXNS;\n\t\t\t}\n\t\t}\n\t\tn = statp->nscount;\n\t\tif (statp->nscount > EXT(statp).nscount)\n\t\t\tfor (n = EXT(statp).nscount, ns = 0;\n\t\t\t n < statp->nscount; n++) {\n\t\t\t\twhile (ns < MAXNS\n\t\t\t\t && EXT(statp).nsmap[ns] != MAXNS)\n\t\t\t\t\tns++;\n\t\t\t\tif (ns == MAXNS)\n\t\t\t\t\tbreak;\n\t\t\t\tEXT(statp).nsmap[ns] = n;\n\t\t\t\tmap[n] = ns++;\n\t\t\t}\n\t\tEXT(statp).nscount = n;\n\t\tfor (ns = 0; ns < EXT(statp).nscount; ns++) {\n\t\t\tn = map[ns];\n\t\t\tif (EXT(statp).nsaddrs[n] == NULL)\n\t\t\t\tEXT(statp).nsaddrs[n] =\n\t\t\t\t malloc(sizeof (struct sockaddr_in6));\n\t\t\tif (EXT(statp).nsaddrs[n] != NULL) {\n\t\t\t\tmemset (mempcpy(EXT(statp).nsaddrs[n],\n\t\t\t\t\t\t&statp->nsaddr_list[ns],\n\t\t\t\t\t\tsizeof (struct sockaddr_in)),\n\t\t\t\t\t'\\0',\n\t\t\t\t\tsizeof (struct sockaddr_in6)\n\t\t\t\t\t- sizeof (struct sockaddr_in));\n\t\t\t\tEXT(statp).nssocks[n] = -1;\n\t\t\t\tn++;\n\t\t\t}\n\t\t}\n\t\tEXT(statp).nsinit = 1;\n\t}\n\n\t/*\n\t * Some resolvers want to even out the load on their nameservers.\n\t * Note that RES_BLAST overrides RES_ROTATE.\n\t */\n\tif (__builtin_expect ((statp->options & RES_ROTATE) != 0, 0) &&\n\t (statp->options & RES_BLAST) == 0) {\n\t\tstruct sockaddr_in6 *ina;\n\t\tunsigned int map;\n\n\t\tn = 0;\n\t\twhile (n < MAXNS && EXT(statp).nsmap[n] == MAXNS)\n\t\t\tn++;\n/* ... 157 lines omitted ... */\n\t\t\t} while (!done);\n\n\t\t}\n#endif\n\t\treturn (resplen);\n next_ns: ;\n\t } /*foreach ns*/\n\t} /*foreach retry*/\n\t__res_iclose(statp, false);\n\tif (!v_circuit) {\n\t\tif (!gotsomewhere)\n\t\t\t__set_errno (ECONNREFUSED);\t/* no nameservers found */\n\t\telse\n\t\t\t__set_errno (ETIMEDOUT);\t/* no answer obtained */\n\t} else\n\t\t__set_errno (terrno);\n\treturn (-1);\n}\n\nint\n```\n\n#### libresolv_hidden_def() [lines 614-700]\n```c\n\t\t\t\t\tgoto next_ns;\n\t\t\t\tcase res_modified:\n\t\t\t\t\t/* give the hook another try */\n\t\t\t\t\tif (++loops < 42) /*doug adams*/\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t/*FALLTHROUGH*/\n\t\t\t\tcase res_error:\n\t\t\t\t\t/*FALLTHROUGH*/\n\t\t\t\tdefault:\n\t\t\t\t\treturn (-1);\n\t\t\t\t}\n\t\t\t} while (!done);\n\n\t\t}\n#endif\n\t\treturn (resplen);\n next_ns: ;\n\t } /*foreach ns*/\n\t} /*foreach retry*/\n\t__res_iclose(statp, false);\n\tif (!v_circuit) {\n\t\tif (!gotsomewhere)\n\t\t\t__set_errno (ECONNREFUSED);\t/* no nameservers found */\n\t\telse\n\t\t\t__set_errno (ETIMEDOUT);\t/* no answer obtained */\n\t} else\n\t\t__set_errno (terrno);\n\treturn (-1);\n}\n\nint\nres_nsend(res_state statp,\n\t const u_char *buf, int buflen, u_char *ans, int anssiz)\n{\n return __libc_res_nsend(statp, buf, buflen, NULL, 0, ans, anssiz,\n\t\t\t NULL, NULL, NULL, NULL);\n}\nlibresolv_hidden_def (res_nsend)\n\n/* Private */\n\nstatic int\nsend_vc(res_state statp,\n\tconst u_char *buf, int buflen, const u_char *buf2, int buflen2,\n\tu_char **ansp, int *anssizp,\n\tint *terrno, int ns, u_char **anscp, u_char **ansp2, int *anssizp2,\n\tint *resplen2)\n{\n\tconst HEADER *hp = (HEADER *) buf;\n\tconst HEADER *hp2 = (HEADER *) buf2;\n\tu_char *ans = *ansp;\n\tint orig_anssizp = *anssizp;\n\t// XXX REMOVE\n\t// int anssiz = *anssizp;\n\tHEADER *anhp = (HEADER *) ans;\n\tstruct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns];\n\tint truncating, connreset, resplen, n;\n\tstruct iovec iov[4];\n\tu_short len;\n\tu_short len2;\n\tu_char *cp;\n\n\tif (resplen2 != NULL)\n\t *resplen\n/* ... truncated ... */\n```\n\n\n## Upstream Fix\n```diff\nFrom 6c07233f12e00b9cf66fb5d4a9b7ddb897590912 Mon Sep 17 00:00:00 2001\nFrom: Andreas Schwab <schwab@suse.de>\nDate: Thu, 19 Feb 2015 15:52:08 +0100\nSubject: [PATCH] Simplify handling of nameserver configuration in resolver\n\n\t[BZ #13028]\n\t[BZ #17053]\n\t* resolv/res_init.c (__res_vinit): Remove use of ext.nsmap.\n\t* resolv/res_send.c (__libc_res_nsend): Likewise.\n\t(get_nsaddr): New function.\n\t(res_ourserver_p, send_vc, reopen): Use it instead of accessing\n\tstatp directly.\n---\n resolv/res_init.c | 47 +++++-----------\n resolv/res_send.c | 164 +++++++++++++++++++++++-------------------------------\n 2 files changed, 84 insertions(+), 127 deletions(-)\n\nIndex: glibc-2.19/resolv/res_init.c\n===================================================================\n--- glibc-2.19.orig/resolv/res_init.c\n+++ glibc-2.19/resolv/res_init.c\n@@ -153,10 +153,8 @@ __res_vinit(res_state statp, int preinit\n \tchar *cp, **pp;\n \tint n;\n \tchar buf[BUFSIZ];\n-\tint nserv = 0; /* number of nameserver records read from file */\n-#ifdef _LIBC\n-\tint nservall = 0; /* number of NS records read, nserv IPv4 only */\n-#endif\n+\tint nserv = 0; /* number of nameservers read from file */\n+\tint have_serv6 = 0;\n \tint haveenv = 0;\n \tint havesearch = 0;\n #ifdef RESOLVSORT\n@@ -184,15 +182,9 @@ __res_vinit(res_state statp, int preinit\n \tstatp->_flags = 0;\n \tstatp->qhook = NULL;\n \tstatp->rhook = NULL;\n-\tstatp->_u._ext.nsinit = 0;\n \tstatp->_u._ext.nscount = 0;\n-#ifdef _LIBC\n-\tstatp->_u._ext.nscount6 = 0;\n-\tfor (n = 0; n < MAXNS; n++) {\n-\t\tstatp->_u._ext.nsaddrs[n] = NULL;\n-\t\tstatp->_u._ext.nsmap[n] = MAXNS;\n-\t}\n-#endif\n+\tfor (n = 0; n < MAXNS; n++)\n+\t statp->_u._ext.nsaddrs[n] = NULL;\n \n \t/* Allow user to override the local domain definition */\n \tif ((cp = getenv(\"LOCALDOMAIN\")) != NULL) {\n@@ -296,11 +288,7 @@ __res_vinit(res_state statp, int preinit\n \t\t continue;\n \t\t}\n \t\t/* read nameservers to query */\n-#ifdef _LIBC\n-\t\tif (MATCH(buf, \"nameserver\") && nservall < MAXNS) {\n-#else\n \t\tif (MATCH(buf, \"nameserver\") && nserv < MAXNS) {\n-#endif\n \t\t struct in_addr a;\n \n \t\t cp = buf + sizeof(\"nameserver\") - 1;\n@@ -308,13 +296,12 @@ __res_vinit(res_state statp, int preinit\n \t\t\tcp++;\n \t\t if ((*cp != '\\0') && (*cp != '\\n')\n \t\t\t&& __inet_aton(cp, &a)) {\n-\t\t\tstatp->nsaddr_list[nservall].sin_addr = a;\n-\t\t\tstatp->nsaddr_list[nservall].sin_family = AF_INET;\n-\t\t\tstatp->nsaddr_list[nservall].sin_port =\n+\t\t\tstatp->nsaddr_list[nserv].sin_addr = a;\n+\t\t\tstatp->nsaddr_list[nserv].sin_family = AF_INET;\n+\t\t\tstatp->nsaddr_list[nserv].sin_port =\n \t\t\t\thtons(NAMESERVER_PORT);\n \t\t\tnserv++;\n #ifdef _LIBC\n-\t\t\tnservall++;\n \t\t } else {\n \t\t\tstruct in6_addr a6;\n \t\t\tchar *el;\n@@ -356,10 +343,11 @@ __res_vinit(res_state statp, int preinit\n \t\t\t\t }\n \t\t\t\t}\n \n-\t\t\t\tstatp->_u._ext.nsaddrs[nservall] = sa6;\n-\t\t\t\tstatp->_u._ext.nssocks[nservall] = -1;\n-\t\t\t\tstatp->_u._ext.nsmap[nservall] = MAXNS + 1;\n-\t\t\t\tnservall++;\n+\t\t\t\tstatp->nsaddr_list[nserv].sin_family = 0;\n+\t\t\t\tstatp->_u._ext.nsaddrs[nserv] = sa6;\n+\t\t\t\tstatp->_u._ext.nssocks[nserv] = -1;\n+\t\t\t\thave_serv6 = 1;\n+\t\t\t\tnserv++;\n \t\t\t }\n \t\t\t}\n #endif\n@@ -414,10 +402,9 @@ __res_vinit(res_state statp, int preinit\n \t\t continue;\n \t\t}\n \t }\n-\t statp->nscount = nservall;\n+\t statp->nscount = nserv;\n #ifdef _LIBC\n-\t if (nservall - nserv > 0) {\n-\t\tstatp->_u._ext.nscount6 = nservall - nserv;\n+\t if (have_serv6) {\n \t\t/* We try IPv6 servers again. */\n \t\tstatp->ipv6_unavail = false;\n \t }\n@@ -606,11 +593,7 @@ __res_iclose(res_state statp, bool free_\n \t\tstatp->_vcsock = -1;\n \t\tstatp->_flags &= ~(RES_F_VC | RES_F_CONN);\n \t}\n-#ifdef _LIBC\n-\tfor (ns = 0; ns < MAXNS; ns++)\n-#else\n \tfor (ns = 0; ns < statp->_u._ext.nscount; ns++)\n-#endif\n \t\tif (statp->_u._ext.nsaddrs[ns]) {\n \t\t\tif (statp->_u._ext.nssocks[ns] != -1) {\n \t\t\t\tclose_not_cancel_no_status(statp->_u._ext.nssocks[ns]);\n@@ -621,7 +604,6 @@ __res_iclose(res_state statp, bool free_\n \t\t\t\tstatp->_u._ext.nsaddrs[ns] = NULL;\n \t\t\t}\n \t\t}\n-\tstatp->_u._ext.nsinit = 0;\n }\n libc_hidden_def (__res_iclose)\n \nIndex: glibc-2.19/resolv/res_send.c\n===================================================================\n--- glibc-2.19.orig/resolv/res_send.c\n+++ glibc-2.19/resolv/res_send.c\n@@ -183,6 +183,7 @@ evNowTime(struct timespec *res) {\n \n /* Forward. */\n \n+static struct sockaddr *get_nsaddr (res_state, int);\n static int\t\tsend_vc(res_state, const u_char *, int,\n \t\t\t\tconst u_char *, int,\n \t\t\t\tu_char **, int *, int *, int, u_char **,\n@@ -220,20 +221,21 @@ res_ourserver_p(const res_state statp, c\n \t in_port_t port = in4p->sin_port;\n \t in_addr_t addr = in4p->sin_addr.s_addr;\n \n-\t for (ns = 0; ns < MAXNS; ns++) {\n+\t for (ns = 0; ns < statp->nscount; ns++) {\n \t\tconst struct sockaddr_in *srv =\n-\t\t (struct sockaddr_in *)EXT(statp).nsaddrs[ns];\n+\t\t (struct sockaddr_in *) get_nsaddr (statp, ns);\n \n-\t\tif ((srv != NULL) && (srv->sin_family == AF_INET) &&\n+\t\tif ((srv->sin_family == AF_INET) &&\n \t\t (srv->sin_port == port) &&\n \t\t (srv->sin_addr.s_addr == INADDR_ANY ||\n \t\t srv->sin_addr.s_addr == addr))\n \t\t return (1);\n \t }\n \t} else if (inp->sin6_family == AF_INET6) {\n-\t for (ns = 0; ns < MAXNS; ns++) {\n-\t\tconst struct sockaddr_in6 *srv = EXT(statp).nsaddrs[ns];\n-\t\tif ((srv != NULL) && (srv->sin6_family == AF_INET6) &&\n+\t for (ns = 0; ns < statp->nscount; ns++) {\n+\t\tconst struct sockaddr_in6 *srv\n+\t\t = (struct sockaddr_in6 *) get_nsaddr (statp, ns);\n+\t\tif ((srv->sin6_family == AF_INET6) &&\n \t\t (srv->sin6_port == inp->sin6_port) &&\n \t\t !(memcmp(&srv->sin6_addr, &in6addr_any,\n \t\t\t sizeof (struct in6_addr)) &&\n@@ -383,74 +385,48 @@ __libc_res_nsend(res_state statp, const\n \t * If the ns_addr_list in the resolver context has changed, then\n \t * invalidate our cached copy and the associated timing data.\n \t */\n-\tif (EXT(statp).nsinit) {\n+\tif (EXT(statp).nscount != 0) {\n \t\tint needclose = 0;\n \n \t\tif (EXT(statp).nscount != statp->nscount)\n \t\t\tneedclose++;\n \t\telse\n-\t\t\tfor (ns = 0; ns < MAXNS; ns++) {\n-\t\t\t\tunsigned int map = EXT(statp).nsmap[ns];\n-\t\t\t\tif (map < MAXNS\n+\t\t\tfor (ns = 0; ns < statp->nscount; ns++) {\n+\t\t\t\tif (statp->nsaddr_list[ns].sin_family != 0\n \t\t\t\t && !sock_eq((struct sockaddr_in6 *)\n-\t\t\t\t\t\t&statp->nsaddr_list[map],\n+\t\t\t\t\t\t&statp->nsaddr_list[ns],\n \t\t\t\t\t\tEXT(statp).nsaddrs[ns]))\n \t\t\t\t{\n \t\t\t\t\tneedclose++;\n \t\t\t\t\tbreak;\n \t\t\t\t}\n \t\t\t}\n-\t\tif (needclose)\n+\t\tif (needclose) {\n \t\t\t__res_iclose(statp, false);\n+\t\t\tEXT(statp).nscount = 0;\n+\t\t}\n \t}\n \n \t/*\n \t * Maybe initialize our private copy of the ns_addr_list.\n \t */\n-\tif (EXT(statp).nsinit == 0) {\n-\t\tunsigned char map[MAXNS];\n-\n-\t\tmemset (map, MAXNS, sizeof (map));\n-\t\tfor (n = 0; n < MAXNS; n++) {\n-\t\t\tns = EXT(statp).nsmap[n];\n-\t\t\tif (ns < statp->nscount)\n-\t\t\t\tmap[ns] = n;\n-\t\t\telse if (ns < MAXNS) {\n-\t\t\t\tfree(EXT(statp).nsaddrs[n]);\n-\t\t\t\tEXT(statp).nsaddrs[n] = NULL;\n-\t\t\t\tEXT(statp).nsmap[n] = MAXNS;\n-\t\t\t}\n-\t\t}\n-\t\tn = statp->nscount;\n-\t\tif (statp->nscount > EXT(statp).nscount)\n-\t\t\tfor (n = EXT(statp).nscount, ns = 0;\n-\t\t\t n < statp->nscount; n++) {\n-\t\t\t\twhile (ns < MAXNS\n-\t\t\t\t && EXT(statp).nsmap[ns] != MAXNS)\n-\t\t\t\t\tns++;\n-\t\t\t\tif (ns == MAXNS)\n-\t\t\t\t\tbreak;\n-\t\t\t\tEXT(statp).nsmap[ns] = n;\n-\t\t\t\tmap[n] = ns++;\n-\t\t\t}\n-\t\tEXT(statp).nscount = n;\n-\t\tfor (ns = 0; ns < EXT(statp).nscount; ns++) {\n-\t\t\tn = map[ns];\n-\t\t\tif (EXT(statp).nsaddrs[n] == NULL)\n-\t\t\t\tEXT(statp).nsaddrs[n] =\n+\tif (EXT(statp).nscount == 0) {\n+\t\tfor (ns = 0; ns < statp->nscount; ns++) {\n+\t\t\tEXT(statp).nssocks[ns] = -1;\n+\t\t\tif (statp->nsaddr_list[ns].sin_family == 0)\n+\t\t\t\tcontinue;\n+\t\t\tif (EXT(statp).nsaddrs[ns] == NULL)\n+\t\t\t\tEXT(statp).nsaddrs[ns] =\n \t\t\t\t malloc(sizeof (struct sockaddr_in6));\n-\t\t\tif (EXT(statp).nsaddrs[n] != NULL) {\n-\t\t\t\tmemset (mempcpy(EXT(statp).nsaddrs[n],\n+\t\t\tif (EXT(statp).nsaddrs[ns] != NULL)\n+\t\t\t\tmemset (mempcpy(EXT(statp).nsaddrs[ns],\n \t\t\t\t\t\t&statp->nsaddr_list[ns],\n \t\t\t\t\t\tsizeof (struct sockaddr_in)),\n \t\t\t\t\t'\\0',\n \t\t\t\t\tsizeof (struct sockaddr_in6)\n \t\t\t\t\t- sizeof (struct sockaddr_in));\n-\t\t\t\tEXT(statp).nssocks[n] = -1;\n-\t\t\t\tn++;\n-\t\t\t}\n \t\t}\n-\t\tEXT(statp)\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 6c07233f12e00b9cf66fb5d4a9b7ddb897590912 Mon Sep 17 00:00:00 2001\nFrom: Andreas Schwab <schwab@suse.de>\nDate: Thu, 19 Feb 2015 15:52:08 +0100\nSubject: [PATCH] Simplify handling of nameserver configuration in resolver\n\n\t[BZ #13028]\n\t[BZ #17053]\n\t* resolv/res_init.c (__res_vinit): Remove use of ext.nsmap.\n\t* resolv/res_send.c (__libc_res_nsend): Likewise.\n\t(get_nsaddr): New function.\n\t(res_ourserver_p, send_vc, reopen): Use it instead of accessing\n\tstatp directly.\n---\n resolv/res_init.c | 47 +++++-----------\n resolv/res_send.c | 164 +++++++++++++++++++++++-------------------------------\n 2 files changed, 84 insertions(+), 127 deletions(-)\n\nIndex: glibc-2.19/resolv/res_init.c\n===================================================================\n--- glibc-2.19.orig/resolv/res_init.c\n+++ glibc-2.19/resolv/res_init.c\n@@ -153,10 +153,8 @@ __res_vinit(res_state statp, int preinit\n \tchar *cp, **pp;\n \tint n;\n \tchar buf[BUFSIZ];\n-\tint nserv = 0; /* number of nameserver records read from file */\n-#ifdef _LIBC\n-\tint nservall = 0; /* number of NS records read, nserv IPv4 only */\n-#endif\n+\tint nserv = 0; /* number of nameservers read from file */\n+\tint have_serv6 = 0;\n \tint haveenv = 0;\n \tint havesearch = 0;\n #ifdef RESOLVSORT\n@@ -184,15 +182,9 @@ __res_vinit(res_state statp, int preinit\n \tstatp->_flags = 0;\n \tstatp->qhook = NULL;\n \tstatp->rhook = NULL;\n-\tstatp->_u._ext.nsinit = 0;\n \tstatp->_u._ext.nscount = 0;\n-#ifdef _LIBC\n-\tstatp->_u._ext.nscount6 = 0;\n-\tfor (n = 0; n < MAXNS; n++) {\n-\t\tstatp->_u._ext.nsaddrs[n] = NULL;\n-\t\tstatp->_u._ext.nsmap[n] = MAXNS;\n-\t}\n-#endif\n+\tfor (n = 0; n < MAXNS; n++)\n+\t statp->_u._ext.nsaddrs[n] = NULL;\n \n \t/* Allow user to override the local domain definition */\n \tif ((cp = getenv(\"LOCALDOMAIN\")) != NULL) {\n@@ -296,11 +288,7 @@ __res_vinit(res_state statp, int preinit\n \t\t continue;\n \t\t}\n \t\t/* read nameservers to query */\n-#ifdef _LIBC\n-\t\tif (MATCH(buf, \"nameserver\") && nservall < MAXNS) {\n-#else\n \t\tif (MATCH(buf, \"nameserver\") && nserv < MAXNS) {\n-#endif\n \t\t struct in_addr a;\n \n \t\t cp = buf + sizeof(\"nameserver\") - 1;\n@@ -308,13 +296,12 @@ __res_vinit(res_state statp, int preinit\n \t\t\tcp++;\n \t\t if ((*cp != '\\0') && (*cp != '\\n')\n \t\t\t&& __inet_aton(cp, &a)) {\n-\t\t\tstatp->nsaddr_list[nservall].sin_addr = a;\n-\t\t\tstatp->nsaddr_list[nservall].sin_family = AF_INET;\n-\t\t\tstatp->nsaddr_list[nservall].sin_port =\n+\t\t\tstatp->nsaddr_list[nserv].sin_addr = a;\n+\t\t\tstatp->nsaddr_list[nserv].sin_family = AF_INET;\n+\t\t\tstatp->nsaddr_list[nserv].sin_port =\n \t\t\t\thtons(NAMESERVER_PORT);\n \t\t\tnserv++;\n #ifdef _LIBC\n-\t\t\tnservall++;\n \t\t } else {\n \t\t\tstruct in6_addr a6;\n \t\t\tchar *el;\n@@ -356,10 +343,11 @@ __res_vinit(res_state statp, int preinit\n \t\t\t\t }\n \t\t\t\t}\n \n-\t\t\t\tstatp->_u._ext.nsaddrs[nservall] = sa6;\n-\t\t\t\tstatp->_u._ext.nssocks[nservall] = -1;\n-\t\t\t\tstatp->_u._ext.nsmap[nservall] = MAXNS + 1;\n-\t\t\t\tnservall++;\n+\t\t\t\tstatp->nsaddr_list[nserv].sin_family = 0;\n+\t\t\t\tstatp->_u._ext.nsaddrs[nserv] = sa6;\n+\t\t\t\tstatp->_u._ext.nssocks[nserv] = -1;\n+\t\t\t\thave_serv6 = 1;\n+\t\t\t\tnserv++;\n \t\t\t }\n \t\t\t}\n #endif\n@@ -414,10 +402,9 @@ __res_vinit(res_state statp, int preinit\n \t\t continue;\n \t\t}\n \t }\n-\t statp->nscount = nservall;\n+\t statp->nscount = nserv;\n #ifdef _LIBC\n-\t if (nservall - nserv > 0) {\n-\t\tstatp->_u._ext.nscount6 = nservall - nserv;\n+\t if (have_serv6) {\n \t\t/* We try IPv6 servers again. */\n \t\tstatp->ipv6_unavail = false;\n \t }\n@@ -606,11 +593,7 @@ __res_iclose(res_state statp, bool free_\n \t\tstatp->_vcsock = -1;\n \t\tstatp->_flags &= ~(RES_F_VC | RES_F_CONN);\n \t}\n-#ifdef _LIBC\n-\tfor (ns = 0; ns < MAXNS; ns++)\n-#else\n \tfor (ns = 0; ns < statp->_u._ext.nscount; ns++)\n-#endif\n \t\tif (statp->_u._ext.nsaddrs[ns]) {\n \t\t\tif (statp->_u._ext.nssocks[ns] != -1) {\n \t\t\t\tclose_not_cancel_no_status(statp->_u._ext.nssocks[ns]);\n@@ -621,7 +604,6 @@ __res_iclose(res_state statp, bool free_\n \t\t\t\tstatp->_u._ext.nsaddrs[ns] = NULL;\n \t\t\t}\n \t\t}\n-\tstatp->_u._ext.nsinit = 0;\n }\n libc_hidden_def (__res_iclose)\n \nIndex: glibc-2.19/resolv/res_send.c\n===================================================================\n--- glibc-2.19.orig/resolv/res_send.c\n+++ glibc-2.19/resolv/res_send.c\n@@ -183,6 +183,7 @@ evNowTime(struct timespec *res) {\n \n /* Forward. */\n \n+static struct sockaddr *get_nsaddr (res_state, int);\n static int\t\tsend_vc(res_state, const u_char *, int,\n \t\t\t\tconst u_char *, int,\n \t\t\t\tu_char **, int *, int *, int, u_char **,\n@@ -220,20 +221,21 @@ res_ourserver_p(const res_state statp, c\n \t in_port_t port = in4p->sin_port;\n \t in_addr_t addr = in4p->sin_addr.s_addr;\n \n-\t for (ns = 0; ns < MAXNS; ns++) {\n+\t for (ns = 0; ns < statp->nscount; ns++) {\n \t\tconst struct sockaddr_in *srv =\n-\t\t (struct sockaddr_in *)EXT(statp).nsaddrs[ns];\n+\t\t (struct sockaddr_in *) get_nsaddr (statp, ns);\n \n-\t\tif ((srv != NULL) && (srv->sin_family == AF_INET) &&\n+\t\tif ((srv->sin_family == AF_INET) &&\n \t\t (srv->sin_port == port) &&\n \t\t (srv->sin_addr.s_addr == INADDR_ANY ||\n \t\t srv->sin_addr.s_addr == addr))\n \t\t return (1);\n \t }\n \t} else if (inp->sin6_family == AF_INET6) {\n-\t for (ns = 0; ns < MAXNS; ns++) {\n-\t\tconst struct sockaddr_in6 *srv = EXT(statp).nsaddrs[ns];\n-\t\tif ((srv != NULL) && (srv->sin6_family == AF_INET6) &&\n+\t for (ns = 0; ns < statp->nscount; ns++) {\n+\t\tconst struct sockaddr_in6 *srv\n+\t\t = (struct sockaddr_in6 *) get_nsaddr (statp, ns);\n+\t\tif ((srv->sin6_family == AF_INET6) &&\n \t\t (srv->sin6_port == inp->sin6_port) &&\n \t\t !(memcmp(&srv->sin6_addr, &in6addr_any,\n \t\t\t sizeof (struct in6_addr)) &&\n@@ -383,74 +385,48 @@ __libc_res_nsend(res_state statp, const\n \t * If the ns_addr_list in the resolver context has changed, then\n \t * invalidate our cached copy and the associated timing data.\n \t */\n-\tif (EXT(statp).nsinit) {\n+\tif (EXT(statp).nscount != 0) {\n \t\tint needclose = 0;\n \n \t\tif (EXT(statp).nscount != statp->nscount)\n \t\t\tneedclose++;\n \t\telse\n-\t\t\tfor (ns = 0; ns < MAXNS; ns++) {\n-\t\t\t\tunsigned int map = EXT(statp).nsmap[ns];\n-\t\t\t\tif (map < MAXNS\n+\t\t\tfor (ns = 0; ns < statp->nscount; ns++) {\n+\t\t\t\tif (statp->nsaddr_list[ns].sin_family != 0\n \t\t\t\t && !sock_eq((struct sockaddr_in6 *)\n-\t\t\t\t\t\t&statp->nsaddr_list[map],\n+\t\t\t\t\t\t&statp->nsaddr_list[ns],\n \t\t\t\t\t\tEXT(statp).nsaddrs[ns]))\n \t\t\t\t{\n \t\t\t\t\tneedclose++;\n \t\t\t\t\tbreak;\n \t\t\t\t}\n \t\t\t}\n-\t\tif (needclose)\n+\t\tif (needclose) {\n \t\t\t__res_iclose(statp, false);\n+\t\t\tEXT(statp).nscount = 0;\n+\t\t}\n \t}\n \n \t/*\n \t * Maybe initialize our private copy of the ns_addr_list.\n \t */\n-\tif (EXT(statp).nsinit == 0) {\n-\t\tunsigned char map[MAXNS];\n-\n-\t\tmemset (map, MAXNS, sizeof (map));\n-\t\tfor (n = 0; n < MAXNS; n++) {\n-\t\t\tns = EXT(statp).nsmap[n];\n-\t\t\tif (ns < statp->nscount)\n-\t\t\t\tmap[ns] = n;\n-\t\t\telse if (ns < MAXNS) {\n-\t\t\t\tfree(EXT(statp).nsaddrs[n]);\n-\t\t\t\tEXT(statp).nsaddrs[n] = NULL;\n-\t\t\t\tEXT(statp).nsmap[n] = MAXNS;\n-\t\t\t}\n-\t\t}\n-\t\tn = statp->nscount;\n-\t\tif (statp->nscount > EXT(statp).nscount)\n-\t\t\tfor (n = EXT(statp).nscount, ns = 0;\n-\t\t\t n < statp->nscount; n++) {\n-\t\t\t\twhile (ns < MAXNS\n-\t\t\t\t && EXT(statp).nsmap[ns] != MAXNS)\n-\t\t\t\t\tns++;\n-\t\t\t\tif (ns == MAXNS)\n-\t\t\t\t\tbreak;\n-\t\t\t\tEXT(statp).nsmap[ns] = n;\n-\t\t\t\tmap[n] = ns++;\n-\t\t\t}\n-\t\tEXT(statp).nscount = n;\n-\t\tfor (ns = 0; ns < EXT(statp).nscount; ns++) {\n-\t\t\tn = map[ns];\n-\t\t\tif (EXT(statp).nsaddrs[n] == NULL)\n-\t\t\t\tEXT(statp).nsaddrs[n] =\n+\tif (EXT(statp).nscount == 0) {\n+\t\tfor (ns = 0; ns < statp->nscount; ns++) {\n+\t\t\tEXT(statp).nssocks[ns] = -1;\n+\t\t\tif (statp->nsaddr_list[ns].sin_family == 0)\n+\t\t\t\tcontinue;\n+\t\t\tif (EXT(statp).nsaddrs[ns] == NULL)\n+\t\t\t\tEXT(statp).nsaddrs[ns] =\n \t\t\t\t malloc(sizeof (struct sockaddr_in6));\n-\t\t\tif (EXT(statp).nsaddrs[n] != NULL) {\n-\t\t\t\tmemset (mempcpy(EXT(statp).nsaddrs[n],\n+\t\t\tif (EXT(statp).nsaddrs[ns] != NULL)\n+\t\t\t\tmemset (mempcpy(EXT(statp).nsaddrs[ns],\n \t\t\t\t\t\t&statp->nsaddr_list[ns],\n \t\t\t\t\t\tsizeof (struct sockaddr_in)),\n \t\t\t\t\t'\\0',\n \t\t\t\t\tsizeof (struct sockaddr_in6)\n \t\t\t\t\t- sizeof (struct sockaddr_in));\n-\t\t\t\tEXT(statp).nssocks[n] = -1;\n-\t\t\t\tn++;\n-\t\t\t}\n \t\t}\n-\t\tEXT(statp).nsinit = 1;\n+\t\tEXT(statp).nscount = statp->nscount;\n \t}\n \n \t/*\n@@ -459,44 +435,37 @@ __libc_res_nsend(res_state statp, const\n \t */\n \tif (__builtin_expect ((statp->options & RES_ROTATE) != 0, 0) &&\n \t (statp->options & RES_BLAST) == 0) {\n-\t\tstruct sockaddr_in6 *ina;\n-\t\tunsigned int map;\n-\n-\t\tn = 0;\n-\t\twhile (n < MAXNS && EXT(statp).nsmap[n] == MAXNS)\n-\t\t\tn++;\n-\t\tif (n < MAXNS) {\n-\t\t\tina = EXT(statp).nsaddrs[n];\n-\t\t\tmap = EXT(statp).nsmap[n];\n-\t\t\tfor (;;) {\n-\t\t\t\tns = n + 1;\n-\t\t\t\twhile (ns < MAXNS\n-\t\t\t\t && EXT(statp).nsmap[ns] == MAXNS)\n-\t\t\t\t\tns++;\n-\t\t\t\tif (ns == MAXNS)\n-\t\t\t\t\tbreak;\n-\t\t\t\tEXT(statp).nsaddrs[n] = EXT(statp).nsaddrs[ns];\n-\t\t\t\tEXT(statp).nsmap[n] = EXT(statp).nsmap[ns];\n-\t\t\t\tn = ns;\n-\t\t\t}\n-\t\t\tEXT(statp).nsaddrs[n] = ina;\n-\t\t\tEXT(statp).nsmap[n] = map;\n-\t\t}\n+\t\tstruct sockaddr_in ina;\n+\t\tstruct sockaddr_in6 *inp;\n+\t\tint lastns = statp->nscount - 1;\n+\t\tint fd;\n+\n+\t\tinp = EXT(statp).nsaddrs[0];\n+\t\tina = statp->nsaddr_list[0];\n+\t\tfd = EXT(statp).nssocks[0];\n+\t\tfor (ns = 0; ns < lastns; ns++) {\n+\t\t EXT(statp).nsaddrs[ns] = EXT(statp).nsaddrs[ns + 1];\n+\t\t statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1];\n+\t\t EXT(statp).nssocks[ns] = EXT(statp).nssocks[ns + 1];\n+\t\t}\n+\t\tEXT(statp).nsaddrs[lastns] = inp;\n+\t\tstatp->nsaddr_list[lastns] = ina;\n+\t\tEXT(statp).nssocks[lastns] = fd;\n \t}\n \n \t/*\n \t * Send request, RETRY times, or until successful.\n \t */\n \tfor (try = 0; try < statp->retry; try++) {\n-\t for (ns = 0; ns < MAXNS; ns++)\n+\t for (ns = 0; ns < statp->nscount; ns++)\n \t {\n #ifdef DEBUG\n \t\tchar tmpbuf[40];\n #endif\n-\t\tstruct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns];\n+#if defined USE_HOOKS || defined DEBUG\n+\t\tstruct sockaddr *nsap = get_nsaddr (statp, ns);\n+#endif\n \n-\t\tif (nsap == NULL)\n-\t\t\tgoto next_ns;\n \t same_ns:\n #ifdef USE_HOOKS\n \t\tif (__builtin_expect (statp->qhook != NULL, 0)) {\n@@ -535,9 +504,9 @@ __libc_res_nsend(res_state statp, const\n \n \t\tDprint(statp->options & RES_DEBUG,\n \t\t (stdout, \";; Querying server (# %d) address = %s\\n\",\n-\t\t\tns + 1, inet_ntop(nsap->sin6_family,\n-\t\t\t\t\t (nsap->sin6_family == AF_INET6\n-\t\t\t\t\t ? &nsap->sin6_addr\n+\t\t\tns + 1, inet_ntop(nsap->sa_family,\n+\t\t\t\t\t (nsap->sa_family == AF_INET6\n+\t\t\t\t\t ? &((struct sockaddr_in6 *) nsap)->sin6_addr\n \t\t\t\t\t : &((struct sockaddr_in *) nsap)->sin_addr),\n \t\t\t\t\t tmpbuf, sizeof (tmpbuf))));\n \n@@ -653,6 +622,21 @@ libresolv_hidden_def (res_nsend)\n \n /* Private */\n \n+static struct sockaddr *\n+get_nsaddr (res_state statp, int n)\n+{\n+\n+ if (statp->nsaddr_list[n].sin_family == 0 && EXT(statp).nsaddrs[n] != NULL)\n+ /* EXT(statp).nsaddrs[n] holds an address that is larger than\n+ struct sockaddr, and user code did not update\n+ statp->nsaddr_list[n]. */\n+ return (struct sockaddr *) EXT(statp).nsaddrs[n];\n+ else\n+ /* User code updated statp->nsaddr_list[n], or statp->nsaddr_list[n]\n+ has the same content as EXT(statp).nsaddrs[n]. */\n+ return (struct sockaddr *) (void *) &statp->nsaddr_list[n];\n+}\n+\n static int\n send_vc(res_state statp,\n \tconst u_char *buf, int buflen, const u_char *buf2, int buflen2,\n@@ -667,7 +651,7 @@ send_vc(res_state statp,\n \t// XXX REMOVE\n \t// int anssiz = *anssizp;\n \tHEADER *anhp = (HEADER *) ans;\n-\tstruct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns];\n+\tstruct sockaddr *nsap = get_nsaddr (statp, ns);\n \tint truncating, connreset, resplen, n;\n \tstruct iovec iov[4];\n \tu_short len;\n@@ -687,8 +671,8 @@ send_vc(res_state statp,\n \n \t\tif (getpeername(statp->_vcsock,\n \t\t\t\t(struct sockaddr *)&peer, &size) < 0 ||\n-\t\t !sock_eq(&peer, nsap)) {\n-\t\t __res_iclose(statp, false);\n+\t\t !sock_eq(&peer, (struct sockaddr_in6 *) nsap)) {\n+\t\t\t__res_iclose(statp, false);\n \t\t\tstatp->_flags &= ~RES_F_VC;\n \t\t}\n \t}\n@@ -697,20 +681,19 @@ send_vc(res_state statp,\n \t\tif (statp->_vcsock >= 0)\n \t\t __res_iclose(statp, false);\n \n-\t\tstatp->_vcsock = socket(nsap->sin6_family, SOCK_STREAM, 0);\n+\t\tstatp->_vcsock = socket(nsap->sa_family, SOCK_STREAM, 0);\n \t\tif (statp->_vcsock < 0) {\n \t\t\t*terrno = errno;\n \t\t\tPerror(statp, stderr, \"socket(vc)\", errno);\n \t\t\treturn (-1);\n \t\t}\n \t\t__set_errno (0);\n-\t\tif (connect(statp->_vcsock, (struct sockaddr *)nsap,\n-\t\t\t nsap->sin6_family == AF_INET\n+\t\tif (connect(statp->_vcsock, nsap,\n+\t\t\t nsap->sa_family == AF_INET\n \t\t\t ? sizeof (struct sockaddr_in)\n \t\t\t : sizeof (struct sockaddr_in6)) < 0) {\n \t\t\t*terrno = errno;\n-\t\t\tAerror(statp, stderr, \"connect/vc\", errno,\n-\t\t\t (struct sockaddr *) nsap);\n+\t\t\tAerror(statp, stderr, \"connect/vc\", errno, nsap);\n \t\t\t__res_iclose(statp, false);\n \t\t\treturn (0);\n \t\t}\n@@ -914,8 +897,7 @@ static int\n reopen (res_state statp, int *terrno, int ns)\n {\n \tif (EXT(statp).nssocks[ns] == -1) {\n-\t\tstruct sockaddr *nsap\n-\t\t = (struct sockaddr *) EXT(statp).nsaddrs[ns];\n+\t\tstruct sockaddr *nsap = get_nsaddr (statp, ns);\n \t\tsocklen_t slen;\n \n \t\t/* only try IPv6 if IPv6 NS and if not failed before */" } ]
{ "id": "glibc-5158-resolv-nameserver-handling.pat", "cve_id": "CVE-2016-3706", "package": "glibc", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 2168, "context_files": 2 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2013-4288\n\nRace condition in PolicyKit (aka polkit) allows local users to bypass intended PolicyKit restrictions and gain privileges by starting a setuid or pkexec process before the authorization check is performed, related to (1) the polkit_unix_process_new API function, (2) the dbus API, or (3) the --process (unix-process) option for authorization to pkcheck.\n\n## Package\nsystemd-mini\n\n## Files to modify\n- systemd-195.orig/src/libudev/libudev-list.c\n- src/libudev/libudev-list.c\n\n## Target Source Code\n\n### src/libudev/libudev-list.c\n\n#### region() [lines 174-213]\n```c\n }\n }\n\n if (list->unique) {\n /* allocate or enlarge sorted array if needed */\n if (list->entries_cur >= list->entries_max) {\n unsigned int add;\n\n add = list->entries_max;\n if (add < 1)\n add = 64;\n list->entries = realloc(list->entries, (list->entries_max + add) * sizeof(struct udev_list_entry *));\n if (list->entries == NULL) {\n free(entry->name);\n free(entry->value);\n free(entry);\n return NULL;\n }\n list->entries_max += add;\n }\n\n /* the negative i returned the insertion index */\n i = (-i)-1;\n\n /* insert into sorted list */\n if ((unsigned int)i < list->entries_cur)\n udev_list_entry_insert_before(entry, list->entries[i]);\n else\n udev_list_entry_append(entry, list);\n\n /* insert into sorted array */\n memmove(&list->entries[i+1], &list->entries[i],\n (list->entries_cur - i) * sizeof(struct udev_list_entry *));\n list->entries[i] = entry;\n list->entries_cur++;\n } else {\n udev_list_entry_append(entry, list);\n }\n\n return entry;\n```\n\n\n## Upstream Fix\n```diff\nFrom cf2292f5ac87087f57dbd632a25a332c9d194ebf Mon Sep 17 00:00:00 2001\nFrom: Mauro Dreissig <mukadr@gmail.com>\nDate: Sun, 11 Nov 2012 22:07:51 -0200\nSubject: [PATCH] libudev: avoid leak during realloc failure\n\n---\n src/libudev/libudev-list.c | 6 ++++--\n 1 file changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/src/libudev/libudev-list.c b/src/libudev/libudev-list.c\nindex 1578aecaae133..59ba69e279a2d 100644\n--- a/src/libudev/libudev-list.c\n+++ b/src/libudev/libudev-list.c\n@@ -185,18 +185,20 @@ struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *\n if (list->unique) {\n /* allocate or enlarge sorted array if needed */\n if (list->entries_cur >= list->entries_max) {\n+ struct udev_list_entry **entries;\n unsigned int add;\n \n add = list->entries_max;\n if (add < 1)\n add = 64;\n- list->entries = realloc(list->entries, (list->entries_max + add) * sizeof(struct udev_list_entry *));\n- if (list->entries == NULL) {\n+ entries = realloc(list->entries, (list->entries_max + add) * sizeof(struct udev_list_entry *));\n+ if (entries == NULL) {\n free(entry->name);\n free(entry->value);\n free(entry);\n return NULL;\n }\n+ list->entries = entries;\n list->entries_max += add;\n }\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From cf2292f5ac87087f57dbd632a25a332c9d194ebf Mon Sep 17 00:00:00 2001\nFrom: Mauro Dreissig <mukadr@gmail.com>\nDate: Sun, 11 Nov 2012 22:07:51 -0200\nSubject: [PATCH] libudev: avoid leak during realloc failure\n\n---\n src/libudev/libudev-list.c | 6 ++++--\n 1 files changed, 4 insertions(+), 2 deletions(-)\n\nIndex: systemd-195/src/libudev/libudev-list.c\n===================================================================\n--- systemd-195.orig/src/libudev/libudev-list.c\n+++ systemd-195/src/libudev/libudev-list.c\n@@ -177,18 +177,20 @@ struct udev_list_entry *udev_list_entry_\n if (list->unique) {\n /* allocate or enlarge sorted array if needed */\n if (list->entries_cur >= list->entries_max) {\n+ struct udev_list_entry **entries;\n unsigned int add;\n \n add = list->entries_max;\n if (add < 1)\n add = 64;\n- list->entries = realloc(list->entries, (list->entries_max + add) * sizeof(struct udev_list_entry *));\n- if (list->entries == NULL) {\n+ entries = realloc(list->entries, (list->entries_max + add) * sizeof(struct udev_list_entry *));\n+ if (entries == NULL) {\n free(entry->name);\n free(entry->value);\n free(entry);\n return NULL;\n }\n+ list->entries = entries;\n list->entries_max += add;\n }" } ]
{ "id": "systemd-mini-2025-1011-libudev-avoid-leak-during", "cve_id": "CVE-2013-4288", "package": "systemd-mini", "upstream_enriched": true, "upstream_commit": "cf2292f5ac87087f57dbd632a25a332c9d194ebf", "upstream_repo": "systemd/systemd", "tier": "adapted", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 408, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-6302\n\nThe tls_decrypt_ticket function in ssl/t1_lib.c in OpenSSL before 1.1.0 does not consider the HMAC size during validation of the ticket length, which allows remote attackers to cause a denial of service via a ticket that is too short.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i/ssl/s3_clnt.c\n- openssl-1.0.1i.orig/ssl/s3_clnt.c\n\n## Target Source Code\n\n### ssl/s3_clnt.c\n\n#### ssl3_get_server_certificate() [lines 1084-1273]\n```c\n\treturn(-1);\n\t}\n\nint ssl3_get_server_certificate(SSL *s)\n\t{\n\tint al,i,ok,ret= -1;\n\tunsigned long n,nc,llen,l;\n\tX509 *x=NULL;\n\tconst unsigned char *q,*p;\n\tunsigned char *d;\n\tSTACK_OF(X509) *sk=NULL;\n\tSESS_CERT *sc;\n\tEVP_PKEY *pkey=NULL;\n\tint need_cert = 1; /* VRS: 0=> will allow null cert if auth == KRB5 */\n\n\tn=s->method->ssl_get_message(s,\n\t\tSSL3_ST_CR_CERT_A,\n\t\tSSL3_ST_CR_CERT_B,\n\t\t-1,\n\t\ts->max_cert_list,\n\t\t&ok);\n\n\tif (!ok) return((int)n);\n\n\tif ((s->s3->tmp.message_type == SSL3_MT_SERVER_KEY_EXCHANGE) ||\n\t\t((s->s3->tmp.new_cipher->algorithm_auth & SSL_aKRB5) && \n\t\t(s->s3->tmp.message_type == SSL3_MT_SERVER_DONE)))\n\t\t{\n\t\ts->s3->tmp.reuse_message=1;\n\t\treturn(1);\n\t\t}\n\n\tif (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE)\n\t\t{\n\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\tSSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_BAD_MESSAGE_TYPE);\n\t\tgoto f_err;\n\t\t}\n\tp=d=(unsigned char *)s->init_msg;\n\n\tif ((sk=sk_X509_new_null()) == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\n\tn2l3(p,llen);\n\tif (llen+3 != n)\n\t\t{\n\t\tal=SSL_AD_DECODE_ERROR;\n\t\tSSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_LENGTH_MISMATCH);\n\t\tgoto f_err;\n\t\t}\n\tfor (nc=0; nc<llen; )\n\t\t{\n\t\tn2l3(p,l);\n\t\tif ((l+nc+3) > llen)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);\n\t\t\tgoto f_err;\n\t\t\t}\n\n\t\tq=p;\n\t\tx=d2i_X509(NULL,&q,l);\n\t\tif (x == NULL)\n\t\t\t{\n\t\t\tal=SSL_AD_BAD_CERTIFICATE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_ASN1_LIB);\n/* ... 101 lines omitted ... */\n\t\ts->session->peer=NULL;\n\t\t}\n\ts->session->verify_result = s->verify_result;\n\n\tx=NULL;\n\tret=1;\n\n\tif (0)\n\t\t{\nf_err:\n\t\tssl3_send_alert(s,SSL3_AL_FATAL,al);\n\t\t}\nerr:\n\tEVP_PKEY_free(pkey);\n\tX509_free(x);\n\tsk_X509_pop_free(sk,X509_free);\n\treturn(ret);\n\t}\n\nint ssl3_get_key_exchange(SSL *s)\n```\n\n#### fclose() [lines 1984-1996]\n```c\n\tfor (nc=0; nc<llen; )\n\t\t{\n\t\tn2s(p,l);\n\t\tif ((l+nc+2) > llen)\n\t\t\t{\n\t\t\tif ((s->options & SSL_OP_NETSCAPE_CA_DN_BUG))\n\t\t\t\tgoto cont; /* netscape bugs */\n\t\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);\n\t\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_TOO_LONG);\n\t\t\tgoto err;\n\t\t\t}\n\n\t\tq=p;\n```\n\n\n## Upstream Fix\n```diff\nFrom ff553f837172ecb2b5c8eca257ec3c5619a4b299 Mon Sep 17 00:00:00 2001\nFrom: \"Dr. Stephen Henson\" <steve@openssl.org>\nDate: Sat, 17 Sep 2016 12:36:58 +0100\nSubject: [PATCH] Fix small OOB reads.\n\nIn ssl3_get_client_certificate, ssl3_get_server_certificate and\nssl3_get_certificate_request check we have enough room\nbefore reading a length.\n\nThanks to Shi Lei (Gear Team, Qihoo 360 Inc.) for reporting these bugs.\n\nCVE-2016-6306\n\nReviewed-by: Richard Levitte <levitte@openssl.org>\nReviewed-by: Matt Caswell <matt@openssl.org>\n---\n ssl/s3_clnt.c | 11 +++++++++++\n ssl/s3_srvr.c | 6 ++++++\n 2 files changed, 17 insertions(+)\n\ndiff --git a/ssl/s3_clnt.c b/ssl/s3_clnt.c\nindex 36833f7304edf..d2afaa5b9f208 100644\n--- a/ssl/s3_clnt.c\n+++ b/ssl/s3_clnt.c\n@@ -1216,6 +1216,12 @@ int ssl3_get_server_certificate(SSL *s)\n goto f_err;\n }\n for (nc = 0; nc < llen;) {\n+ if (nc + 3 > llen) {\n+ al = SSL_AD_DECODE_ERROR;\n+ SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,\n+ SSL_R_CERT_LENGTH_MISMATCH);\n+ goto f_err;\n+ }\n n2l3(p, l);\n if ((l + nc + 3) > llen) {\n al = SSL_AD_DECODE_ERROR;\n@@ -2171,6 +2177,11 @@ int ssl3_get_certificate_request(SSL *s)\n }\n \n for (nc = 0; nc < llen;) {\n+ if (nc + 2 > llen) {\n+ ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);\n+ SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST, SSL_R_CA_DN_TOO_LONG);\n+ goto err;\n+ }\n n2s(p, l);\n if ((l + nc + 2) > llen) {\n if ((s->options & SSL_OP_NETSCAPE_CA_DN_BUG))\ndiff --git a/ssl/s3_srvr.c b/ssl/s3_srvr.c\nindex 7c19753853c38..01ccd5d2ae78d 100644\n--- a/ssl/s3_srvr.c\n+++ b/ssl/s3_srvr.c\n@@ -3220,6 +3220,12 @@ int ssl3_get_client_certificate(SSL *s)\n goto f_err;\n }\n for (nc = 0; nc < llen;) {\n+ if (nc + 3 > llen) {\n+ al = SSL_AD_DECODE_ERROR;\n+ SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,\n+ SSL_R_CERT_LENGTH_MISMATCH);\n+ goto f_err;\n+ }\n n2l3(p, l);\n if ((l + nc + 3) > llen) {\n al = SSL_AD_DECODE_ERROR;\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "commit 52e623c4cb06fffa9d5e75c60b34b4bc130b12e9\nAuthor: Dr. Stephen Henson <steve@openssl.org>\nDate: Sat Sep 17 12:36:58 2016 +0100\n\n Fix small OOB reads.\n \n In ssl3_get_client_certificate, ssl3_get_server_certificate and\n ssl3_get_certificate_request check we have enough room\n before reading a length.\n \n Thanks to Shi Lei (Gear Team, Qihoo 360 Inc.) for reporting these bugs.\n \n CVE-2016-6306\n \n Reviewed-by: Richard Levitte <levitte@openssl.org>\n Reviewed-by: Matt Caswell <matt@openssl.org>\n (cherry picked from commit ff553f837172ecb2b5c8eca257ec3c5619a4b299)\n\nIndex: openssl-1.0.1i/ssl/s3_clnt.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s3_clnt.c\t2016-09-22 14:31:45.461807190 +0200\n+++ openssl-1.0.1i/ssl/s3_clnt.c\t2016-09-22 14:34:09.320045549 +0200\n@@ -1136,6 +1136,12 @@ int ssl3_get_server_certificate(SSL *s)\n \t\t}\n \tfor (nc=0; nc<llen; )\n \t\t{\n+ \tif (nc + 3 > llen) {\n+ \t\tal = SSL_AD_DECODE_ERROR;\n+ \t\tSSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,\n+ \t\tSSL_R_CERT_LENGTH_MISMATCH);\n+ \t\tgoto f_err;\n+ \t}\n \t\tn2l3(p,l);\n \t\tif ((l+nc+3) > llen)\n \t\t\t{\n@@ -1993,6 +1999,11 @@ fclose(out);\n \n \tfor (nc=0; nc<llen; )\n \t\t{\n+ \tif (nc + 2 > llen) {\n+ \t\tssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);\n+ \t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST, SSL_R_CA_DN_TOO_LONG);\n+ \t\tgoto err;\n+ \t}\n \t\tn2s(p,l);\n \t\tif ((l+nc+2) > llen)\n \t\t\t{" } ]
{ "id": "openssl-5650-openssl-CVE-2016-6306.patch", "cve_id": "CVE-2016-6302", "package": "openssl", "upstream_enriched": true, "upstream_commit": "ff553f837172ecb2b5c8eca257ec3c5619a4b299", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "license": "OpenSSL", "context_tokens_est": 558, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-2105\n\nInteger overflow in the EVP_EncodeUpdate function in crypto/evp/encode.c in OpenSSL before 1.0.1t and 1.0.2 before 1.0.2h allows remote attackers to cause a denial of service (heap memory corruption) via a large amount of binary data.\n\n## Package\nopenssl\n\n## Files to modify\n- ssl/s3_clnt.c\n- openssl-1.0.1i.orig/ssl/s3_clnt.c\n- openssl-1.0.1i/ssl/s3_clnt.c\n- openssl-1.0.1i/ssl/s3_srvr.c\n- openssl-1.0.1i.orig/ssl/s3_srvr.c\n\n## Target Source Code\n\n### ssl/s3_clnt.c\n\n#### ssl3_get_key_exchange() [lines 1270-1877]\n```c\n\treturn(ret);\n\t}\n\nint ssl3_get_key_exchange(SSL *s)\n\t{\n#ifndef OPENSSL_NO_RSA\n\tunsigned char *q,md_buf[EVP_MAX_MD_SIZE*2];\n#endif\n\tEVP_MD_CTX md_ctx;\n\tunsigned char *param,*p;\n\tint al,i,j,param_len,ok;\n\tlong n,alg_k,alg_a;\n\tEVP_PKEY *pkey=NULL;\n\tconst EVP_MD *md = NULL;\n#ifndef OPENSSL_NO_RSA\n\tRSA *rsa=NULL;\n#endif\n#ifndef OPENSSL_NO_DH\n\tDH *dh=NULL;\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tEC_KEY *ecdh = NULL;\n\tBN_CTX *bn_ctx = NULL;\n\tEC_POINT *srvr_ecpoint = NULL;\n\tint curve_nid = 0;\n\tint encoded_pt_len = 0;\n#endif\n\n\t/* use same message size as in ssl3_get_certificate_request()\n\t * as ServerKeyExchange message may be skipped */\n\tn=s->method->ssl_get_message(s,\n\t\tSSL3_ST_CR_KEY_EXCH_A,\n\t\tSSL3_ST_CR_KEY_EXCH_B,\n\t\t-1,\n\t\ts->max_cert_list,\n\t\t&ok);\n\tif (!ok) return((int)n);\n\n\tif (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE)\n\t\t{\n/* ... 55 lines omitted ... */\n\t\tchar tmp_id_hint[PSK_MAX_IDENTITY_LEN+1];\n\n\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\tn2s(p,i);\n\t\tparam_len=i+2;\n\t\t/* Store PSK identity hint for later use, hint is used\n\t\t * in ssl3_send_client_key_exchange. Assume that the\n\t\t * maximum length of a PSK identity hint can be as\n\t\t * long as the maximum length of a PSK identity. */\n\t\tif (i > PSK_MAX_IDENTITY_LEN)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,\n\t\t\t\tSSL_R_DATA_LENGTH_TOO_LONG);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (param_len > n)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,\n\t\t\t\tSSL_R_BAD_PSK_IDENTITY_HINT_LENGTH);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t/* If received PSK identity hint contains NULL\n\t\t * characters, the hint is truncated from the first\n\t\t * NULL. p may not be ending with NULL, so create a\n\t\t * NULL-terminated string. */\n\t\tmemcpy(tmp_id_hint, p, i);\n\t\tmemset(tmp_id_hint+i, 0, PSK_MAX_IDENTITY_LEN+1-i);\n/* ... 465 lines omitted ... */\n\tEVP_PKEY_free(pkey);\n#ifndef OPENSSL_NO_RSA\n\tif (rsa != NULL)\n\t\tRSA_free(rsa);\n#endif\n#ifndef OPENSSL_NO_DH\n\tif (dh != NULL)\n\t\tDH_free(dh);\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tBN_CTX_free(bn_ctx);\n\tEC_POINT_free(srvr_ecpoint);\n\tif (ecdh != NULL)\n\t\tEC_KEY_free(ecdh);\n#endif\n\tEVP_MD_CTX_cleanup(&md_ctx);\n\treturn(-1);\n\t}\n\nint ssl3_get_certificate_request(SSL *s)\n```\n\n#### ssl3_send_client_key_exchange() [lines 2232-2959]\n```c\n\t}\n\n\nint ssl3_send_client_key_exchange(SSL *s)\n\t{\n\tunsigned char *p,*d;\n\tint n;\n\tunsigned long alg_k;\n#ifndef OPENSSL_NO_RSA\n\tunsigned char *q;\n\tEVP_PKEY *pkey=NULL;\n#endif\n#ifndef OPENSSL_NO_KRB5\n\tKSSL_ERR kssl_err;\n#endif /* OPENSSL_NO_KRB5 */\n#ifndef OPENSSL_NO_ECDH\n\tEC_KEY *clnt_ecdh = NULL;\n\tconst EC_POINT *srvr_ecpoint = NULL;\n\tEVP_PKEY *srvr_pub_pkey = NULL;\n\tunsigned char *encodedPoint = NULL;\n\tint encoded_pt_len = 0;\n\tBN_CTX * bn_ctx = NULL;\n#endif\n\n\tif (s->state == SSL3_ST_CW_KEY_EXCH_A)\n\t\t{\n\t\td=(unsigned char *)s->init_buf->data;\n\t\tp= &(d[4]);\n\n\t\talg_k=s->s3->tmp.new_cipher->algorithm_mkey;\n\n\t\t/* Fool emacs indentation */\n\t\tif (0) {}\n#ifndef OPENSSL_NO_RSA\n\t\telse if (alg_k & SSL_kRSA)\n\t\t\t{\n\t\t\tRSA *rsa;\n\t\t\tunsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH];\n\n\t\t\tif (s->session->sess_cert == NULL)\n/* ... 630 lines omitted ... */\n\t\t\tif (s->session->psk_identity == NULL)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,\n\t\t\t\t\tERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto psk_err;\n\t\t\t\t}\n\n\t\t\ts->session->master_key_length =\n\t\t\t\ts->method->ssl3_enc->generate_master_secret(s,\n\t\t\t\t\ts->session->master_key,\n\t\t\t\t\tpsk_or_pre_ms, pre_ms_len); \n\t\t\tn = strlen(identity);\n\t\t\ts2n(n, p);\n\t\t\tmemcpy(p, identity, n);\n\t\t\tn+=2;\n\t\t\tpsk_err = 0;\n\t\tpsk_err:\n\t\t\tOPENSSL_cleanse(identity, PSK_MAX_IDENTITY_LEN);\n\t\t\tOPENSSL_cleanse(psk_or_pre_ms, sizeof(psk_or_pre_ms));\n\t\t\tif (psk_err != 0)\n\t\t\t\t{\n\t\t\t\tssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n#endif\n\t\telse\n/* ... 11 lines omitted ... */\n\t\ts->state=SSL3_ST_CW_KEY_EXCH_B;\n\t\t/* number of bytes to write */\n\t\ts->init_num=n+4;\n\t\ts->init_off=0;\n\t\t}\n\n\t/* SSL3_ST_CW_KEY_EXCH_B */\n\treturn(ssl3_do_write(s,SSL3_RT_HANDSHAKE));\nerr:\n#ifndef OPENSSL_NO_ECDH\n\tBN_CTX_free(bn_ctx);\n\tif (encodedPoint != NULL) OPENSSL_free(encodedPoint);\n\tif (clnt_ecdh != NULL) \n\t\tEC_KEY_free(clnt_ecdh);\n\tEVP_PKEY_free(srvr_pub_pkey);\n#endif\n\treturn(-1);\n\t}\n\nint ssl3_send_client_verify(SSL *s)\n```\n\n### ssl/s3_srvr.c\n\n#### ssl3_get_client_key_exchange() [lines 2126-2912]\n```c\n\treturn(-1);\n\t}\n\nint ssl3_get_client_key_exchange(SSL *s)\n\t{\n\tint i,al,ok;\n\tlong n;\n\tunsigned long alg_k;\n\tunsigned char *p;\n#ifndef OPENSSL_NO_RSA\n\tRSA *rsa=NULL;\n\tEVP_PKEY *pkey=NULL;\n#endif\n#ifndef OPENSSL_NO_DH\n\tBIGNUM *pub=NULL;\n\tDH *dh_srvr;\n#endif\n#ifndef OPENSSL_NO_KRB5\n\tKSSL_ERR kssl_err;\n#endif /* OPENSSL_NO_KRB5 */\n\n#ifndef OPENSSL_NO_ECDH\n\tEC_KEY *srvr_ecdh = NULL;\n\tEVP_PKEY *clnt_pub_pkey = NULL;\n\tEC_POINT *clnt_ecpoint = NULL;\n\tBN_CTX *bn_ctx = NULL; \n#endif\n\n\tn=s->method->ssl_get_message(s,\n\t\tSSL3_ST_SR_KEY_EXCH_A,\n\t\tSSL3_ST_SR_KEY_EXCH_B,\n\t\tSSL3_MT_CLIENT_KEY_EXCHANGE,\n\t\t2048, /* ??? */\n\t\t&ok);\n\n\tif (!ok) return((int)n);\n\tp=(unsigned char *)s->init_msg;\n\n\talg_k=s->s3->tmp.new_cipher->algorithm_mkey;\n\n/* ... 607 lines omitted ... */\n\t\tpsk_err:\n\t\t\tOPENSSL_cleanse(psk_or_pre_ms, sizeof(psk_or_pre_ms));\n\t\t\tif (psk_err != 0)\n\t\t\t\tgoto f_err;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_SRP\n\t\tif (alg_k & SSL_kSRP)\n\t\t\t{\n\t\t\tint param_len;\n\n\t\t\tn2s(p,i);\n\t\t\tparam_len=i+2;\n\t\t\tif (param_len > n)\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_SRP_A_LENGTH);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\tif (!(s->srp_ctx.A=BN_bin2bn(p,i,NULL)))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,ERR_R_BN_LIB);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (BN_ucmp(s->srp_ctx.A, s->srp_ctx.N) >= 0\n\t\t\t\t|| BN_is_zero(s->srp_ctx.A))\n/* ... 93 lines omitted ... */\n\t\tgoto f_err;\n\t\t}\n\n\treturn(1);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\n#if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_SRP)\nerr:\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tEVP_PKEY_free(clnt_pub_pkey);\n\tEC_POINT_free(clnt_ecpoint);\n\tif (srvr_ecdh != NULL) \n\t\tEC_KEY_free(srvr_ecdh);\n\tBN_CTX_free(bn_ctx);\n#endif\n\treturn(-1);\n\t}\n\nint ssl3_get_cert_verify(SSL *s)\n```\n\n\n## Upstream Fix\n```diff\nFrom 3c66a669dfc7b3792f7af0758ea26fe8502ce70c Mon Sep 17 00:00:00 2001\nFrom: \"Dr. Stephen Henson\" <steve@openssl.org>\nDate: Wed, 1 Jul 2015 23:40:03 +0100\nSubject: [PATCH] Fix PSK handling.\n\nThe PSK identity hint should be stored in the SSL_SESSION structure\nand not in the parent context (which will overwrite values used\nby other SSL structures with the same SSL_CTX).\n\nUse BUF_strndup when copying identity as it may not be null terminated.\n\nReviewed-by: Tim Hudson <tjh@openssl.org>\n---\n ssl/s3_clnt.c | 17 +++--------------\n ssl/s3_srvr.c | 2 +-\n 2 files changed, 4 insertions(+), 15 deletions(-)\n\ndiff --git a/ssl/s3_clnt.c b/ssl/s3_clnt.c\nindex 2346ce50c0701..6af145a8b744d 100644\n--- a/ssl/s3_clnt.c\n+++ b/ssl/s3_clnt.c\n@@ -1456,8 +1456,6 @@ int ssl3_get_key_exchange(SSL *s)\n \n #ifndef OPENSSL_NO_PSK\n if (alg_k & SSL_kPSK) {\n- char tmp_id_hint[PSK_MAX_IDENTITY_LEN + 1];\n-\n param_len = 2;\n if (param_len > n) {\n SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, SSL_R_LENGTH_TOO_SHORT);\n@@ -1483,17 +1481,8 @@ int ssl3_get_key_exchange(SSL *s)\n }\n param_len += i;\n \n- /*\n- * If received PSK identity hint contains NULL characters, the hint\n- * is truncated from the first NULL. p may not be ending with NULL,\n- * so create a NULL-terminated string.\n- */\n- memcpy(tmp_id_hint, p, i);\n- memset(tmp_id_hint + i, 0, PSK_MAX_IDENTITY_LEN + 1 - i);\n- if (s->ctx->psk_identity_hint != NULL)\n- OPENSSL_free(s->ctx->psk_identity_hint);\n- s->ctx->psk_identity_hint = BUF_strdup(tmp_id_hint);\n- if (s->ctx->psk_identity_hint == NULL) {\n+ s->session->psk_identity_hint = BUF_strndup((char *)p, i);\n+ if (s->session->psk_identity_hint == NULL) {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE);\n goto f_err;\n@@ -3077,7 +3066,7 @@ int ssl3_send_client_key_exchange(SSL *s)\n }\n \n memset(identity, 0, sizeof(identity));\n- psk_len = s->psk_client_callback(s, s->ctx->psk_identity_hint,\n+ psk_len = s->psk_client_callback(s, s->session->psk_identity_hint,\n identity, sizeof(identity) - 1,\n psk_or_pre_ms,\n sizeof(psk_or_pre_ms));\ndiff --git a/ssl/s3_srvr.c b/ssl/s3_srvr.c\nindex 8885694c02b34..acd3b9e964a23 100644\n--- a/ssl/s3_srvr.c\n+++ b/ssl/s3_srvr.c\n@@ -2780,7 +2780,7 @@ int ssl3_get_client_key_exchange(SSL *s)\n \n if (s->session->psk_identity != NULL)\n OPENSSL_free(s->session->psk_identity);\n- s->session->psk_identity = BUF_strdup((char *)p);\n+ s->session->psk_identity = BUF_strndup((char *)p, i);\n if (s->session->psk_identity == NULL) {\n SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE);\n goto psk_err;\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From d6be3124f22870f1888c532523b74ea5d89795eb Mon Sep 17 00:00:00 2001\nFrom: \"Dr. Stephen Henson\" <steve@openssl.org>\nDate: Wed, 1 Jul 2015 23:40:03 +0100\nSubject: [PATCH] Fix PSK handling.\n\nThe PSK identity hint should be stored in the SSL_SESSION structure\nand not in the parent context (which will overwrite values used\nby other SSL structures with the same SSL_CTX).\n\nUse BUF_strndup when copying identity as it may not be null terminated.\n\nReviewed-by: Tim Hudson <tjh@openssl.org>\n(cherry picked from commit 3c66a669dfc7b3792f7af0758ea26fe8502ce70c)\n---\n ssl/s3_clnt.c | 17 +++--------------\n ssl/s3_srvr.c | 2 +-\n 2 files changed, 4 insertions(+), 15 deletions(-)\n\nIndex: openssl-1.0.1i/ssl/s3_clnt.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s3_clnt.c\t2015-12-04 14:10:29.276897903 +0100\n+++ openssl-1.0.1i/ssl/s3_clnt.c\t2015-12-04 14:10:30.131911388 +0100\n@@ -1374,8 +1374,6 @@ int ssl3_get_key_exchange(SSL *s)\n #ifndef OPENSSL_NO_PSK\n \tif (alg_k & SSL_kPSK)\n \t\t{\n-\t\tchar tmp_id_hint[PSK_MAX_IDENTITY_LEN+1];\n-\n \t\tal=SSL_AD_HANDSHAKE_FAILURE;\n \t\tn2s(p,i);\n \t\tparam_len=i+2;\n@@ -1396,16 +1394,9 @@ int ssl3_get_key_exchange(SSL *s)\n \t\t\t\tSSL_R_BAD_PSK_IDENTITY_HINT_LENGTH);\n \t\t\tgoto f_err;\n \t\t\t}\n-\t\t/* If received PSK identity hint contains NULL\n-\t\t * characters, the hint is truncated from the first\n-\t\t * NULL. p may not be ending with NULL, so create a\n-\t\t * NULL-terminated string. */\n-\t\tmemcpy(tmp_id_hint, p, i);\n-\t\tmemset(tmp_id_hint+i, 0, PSK_MAX_IDENTITY_LEN+1-i);\n-\t\tif (s->ctx->psk_identity_hint != NULL)\n-\t\t\tOPENSSL_free(s->ctx->psk_identity_hint);\n-\t\ts->ctx->psk_identity_hint = BUF_strdup(tmp_id_hint);\n-\t\tif (s->ctx->psk_identity_hint == NULL)\n+\n+\t s->session->psk_identity_hint = BUF_strndup((char *)p, i);\n+ \tif (s->session->psk_identity_hint == NULL)\n \t\t\t{\n \t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE);\n \t\t\tgoto f_err;\n@@ -2911,7 +2902,7 @@ int ssl3_send_client_key_exchange(SSL *s\n \t\t\t\tgoto err;\n \t\t\t\t}\n \n-\t\t\tpsk_len = s->psk_client_callback(s, s->ctx->psk_identity_hint,\n+\t\t\tpsk_len = s->psk_client_callback(s, s->session->psk_identity_hint,\n \t\t\t\tidentity, PSK_MAX_IDENTITY_LEN,\n \t\t\t\tpsk_or_pre_ms, sizeof(psk_or_pre_ms));\n \t\t\tif (psk_len > PSK_MAX_PSK_LEN)\nIndex: openssl-1.0.1i/ssl/s3_srvr.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/s3_srvr.c\t2015-12-04 14:10:30.132911404 +0100\n+++ openssl-1.0.1i/ssl/s3_srvr.c\t2015-12-04 14:11:57.400287544 +0100\n@@ -2782,7 +2782,7 @@ int ssl3_get_client_key_exchange(SSL *s)\n \n \t\t\tif (s->session->psk_identity != NULL)\n \t\t\t\tOPENSSL_free(s->session->psk_identity);\n-\t\t\ts->session->psk_identity = BUF_strdup((char *)p);\n+\t\t\ts->session->psk_identity = BUF_strndup((char *)p, i);\n \t\t\tif (s->session->psk_identity == NULL)\n \t\t\t\t{\n \t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE," } ]
{ "id": "openssl-5050-openssl-CVE-2015-3196.patch", "cve_id": "CVE-2016-2105", "package": "openssl", "upstream_enriched": true, "upstream_commit": "3c66a669dfc7b3792f7af0758ea26fe8502ce70c", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "license": "OpenSSL", "context_tokens_est": 1525, "context_files": 2 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2014-8242\n\nlibrsync before 1.0.0 uses a truncated MD4 checksum to match blocks, which makes it easier for remote attackers to modify transmitted data via a birthday attack.\n\n## Package\nrsync\n\n## Files to modify\n- options.c\n- rsync-3.1.0.orig/checksum.c\n- compat.c\n- checksum.c\n- rsync-3.1.0.orig/options.c\n\n## Upstream Fix\n```diff\nFrom eac858085e3ac94ec0ab5061d11f52652c90a869 Mon Sep 17 00:00:00 2001\nFrom: Wayne Davison <wayned@samba.org>\nDate: Mon, 11 May 2015 12:36:20 -0700\nSubject: [PATCH] Add compat flag to allow proper seed checksum order. Fixes\n the equivalent of librsync's CVE-2014-8242 issue.\n\n---\n checksum.c | 17 +++++++++++++----\n compat.c | 5 +++++\n options.c | 1 +\n 3 files changed, 19 insertions(+), 4 deletions(-)\n\ndiff --git a/checksum.c b/checksum.c\nindex a1c2aa244..933b514b3 100644\n--- a/checksum.c\n+++ b/checksum.c\n@@ -23,6 +23,7 @@\n \n extern int checksum_seed;\n extern int protocol_version;\n+extern int proper_seed_order;\n \n /*\n a simple 32 bit checksum that can be upadted from either end\n@@ -54,10 +55,18 @@ void get_checksum2(char *buf, int32 len, char *sum)\n \tif (protocol_version >= 30) {\n \t\tuchar seedbuf[4];\n \t\tmd5_begin(&m);\n-\t\tmd5_update(&m, (uchar *)buf, len);\n-\t\tif (checksum_seed) {\n-\t\t\tSIVALu(seedbuf, 0, checksum_seed);\n-\t\t\tmd5_update(&m, seedbuf, 4);\n+\t\tif (proper_seed_order) {\n+\t\t\tif (checksum_seed) {\n+\t\t\t\tSIVALu(seedbuf, 0, checksum_seed);\n+\t\t\t\tmd5_update(&m, seedbuf, 4);\n+\t\t\t}\n+\t\t\tmd5_update(&m, (uchar *)buf, len);\n+\t\t} else {\n+\t\t\tmd5_update(&m, (uchar *)buf, len);\n+\t\t\tif (checksum_seed) {\n+\t\t\t\tSIVALu(seedbuf, 0, checksum_seed);\n+\t\t\t\tmd5_update(&m, seedbuf, 4);\n+\t\t\t}\n \t\t}\n \t\tmd5_result(&m, (uchar *)sum);\n \t} else {\ndiff --git a/compat.c b/compat.c\nindex 2454937f8..f89d466b9 100644\n--- a/compat.c\n+++ b/compat.c\n@@ -27,6 +27,7 @@ int inc_recurse = 0;\n int compat_flags = 0;\n int use_safe_inc_flist = 0;\n int want_xattr_optim = 0;\n+int proper_seed_order = 0;\n \n extern int am_server;\n extern int am_sender;\n@@ -78,6 +79,7 @@ int filesfrom_convert = 0;\n #define CF_SYMLINK_ICONV (1<<2)\n #define CF_SAFE_FLIST\t (1<<3)\n #define CF_AVOID_XATTR_OPTIM (1<<4)\n+#define CF_CHKSUM_SEED_FIX (1<<5)\n \n static const char *client_info;\n \n@@ -271,12 +273,15 @@ void setup_protocol(int f_out,int f_in)\n \t\t\t\tcompat_flags |= CF_SAFE_FLIST;\n \t\t\tif (local_server || strchr(client_info, 'x') != NULL)\n \t\t\t\tcompat_flags |= CF_AVOID_XATTR_OPTIM;\n+\t\t\tif (local_server || strchr(client_info, 'C') != NULL)\n+\t\t\t\tcompat_flags |= CF_CHKSUM_SEED_FIX;\n \t\t\twrite_byte(f_out, compat_flags);\n \t\t} else\n \t\t\tcompat_flags = read_byte(f_in);\n \t\t/* The inc_recurse var MUST be set to 0 or 1. */\n \t\tinc_recurse = compat_flags & CF_INC_RECURSE ? 1 : 0;\n \t\twant_xattr_optim = protocol_version >= 31 && !(compat_flags & CF_AVOID_XATTR_OPTIM);\n+\t\tproper_seed_order = compat_flags & CF_CHKSUM_SEED_FIX ? 1 : 0;\n \t\tif (am_sender) {\n \t\t\treceiver_symlink_times = am_server\n \t\t\t ? strchr(client_info, 'L') != NULL\ndiff --git a/options.c b/options.c\nindex 19c2b7db1..4128b598d 100644\n--- a/options.c\n+++ b/options.c\n@@ -2503,6 +2503,7 @@ void server_options(char **args, int *argc_p)\n #endif\n \t\teFlags[x++] = 'f'; /* flist I/O-error safety support */\n \t\teFlags[x++] = 'x'; /* xattr hardlink optimization not desired */\n+\t\teFlags[x++] = 'C'; /* support checksum seed order fix */\n #undef eFlags\n \t}\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From eac858085e3ac94ec0ab5061d11f52652c90a869 Mon Sep 17 00:00:00 2001\nFrom: Wayne Davison <wayned@samba.org>\nDate: Mon, 11 May 2015 12:36:20 -0700\nSubject: [PATCH] Add compat flag to allow proper seed checksum order. Fixes\n the equivalent of librsync's CVE-2014-8242 issue.\n\n---\n checksum.c | 17 +++++++++++++----\n compat.c | 5 +++++\n options.c | 1 +\n 3 files changed, 19 insertions(+), 4 deletions(-)\n\nIndex: rsync-3.1.0/checksum.c\n===================================================================\n--- rsync-3.1.0.orig/checksum.c\t2015-10-07 15:26:37.725611538 +0200\n+++ rsync-3.1.0/checksum.c\t2015-10-07 15:26:38.822626286 +0200\n@@ -23,6 +23,7 @@\n \n extern int checksum_seed;\n extern int protocol_version;\n+extern int proper_seed_order;\n \n /*\n a simple 32 bit checksum that can be upadted from either end\n@@ -54,10 +55,18 @@ void get_checksum2(char *buf, int32 len,\n \tif (protocol_version >= 30) {\n \t\tuchar seedbuf[4];\n \t\tmd5_begin(&m);\n-\t\tmd5_update(&m, (uchar *)buf, len);\n-\t\tif (checksum_seed) {\n-\t\t\tSIVALu(seedbuf, 0, checksum_seed);\n-\t\t\tmd5_update(&m, seedbuf, 4);\n+\t\tif (proper_seed_order) {\n+\t\t\tif (checksum_seed) {\n+\t\t\t\tSIVALu(seedbuf, 0, checksum_seed);\n+\t\t\t\tmd5_update(&m, seedbuf, 4);\n+\t\t\t}\n+\t\t\tmd5_update(&m, (uchar *)buf, len);\n+\t\t} else {\n+\t\t\tmd5_update(&m, (uchar *)buf, len);\n+\t\t\tif (checksum_seed) {\n+\t\t\t\tSIVALu(seedbuf, 0, checksum_seed);\n+\t\t\t\tmd5_update(&m, seedbuf, 4);\n+\t\t\t}\n \t\t}\n \t\tmd5_result(&m, (uchar *)sum);\n \t} else {\nIndex: rsync-3.1.0/compat.c\n===================================================================\n--- rsync-3.1.0.orig/compat.c\t2015-10-07 15:26:38.822626286 +0200\n+++ rsync-3.1.0/compat.c\t2015-10-07 15:28:45.553329106 +0200\n@@ -26,6 +26,7 @@ int file_extra_cnt = 0; /* count of file\n int inc_recurse = 0;\n int compat_flags = 0;\n int use_safe_inc_flist = 0;\n+int proper_seed_order = 0;\n \n extern int am_server;\n extern int am_sender;\n@@ -76,6 +77,7 @@ int filesfrom_convert = 0;\n #define CF_SYMLINK_TIMES (1<<1)\n #define CF_SYMLINK_ICONV (1<<2)\n #define CF_SAFE_FLIST\t (1<<3)\n+#define CF_CHKSUM_SEED_FIX (1<<5)\n \n static const char *client_info;\n \n@@ -253,11 +255,14 @@ void setup_protocol(int f_out,int f_in)\n #endif\n \t\t\tif (local_server || strchr(client_info, 'f') != NULL)\n \t\t\t\tcompat_flags |= CF_SAFE_FLIST;\n+\t\t\tif (local_server || strchr(client_info, 'C') != NULL)\n+\t\t\t\tcompat_flags |= CF_CHKSUM_SEED_FIX;\n \t\t\twrite_byte(f_out, compat_flags);\n \t\t} else\n \t\t\tcompat_flags = read_byte(f_in);\n \t\t/* The inc_recurse var MUST be set to 0 or 1. */\n \t\tinc_recurse = compat_flags & CF_INC_RECURSE ? 1 : 0;\n+\t\tproper_seed_order = compat_flags & CF_CHKSUM_SEED_FIX ? 1 : 0;\n \t\tif (am_sender) {\n \t\t\treceiver_symlink_times = am_server\n \t\t\t ? strchr(client_info, 'L') != NULL\nIndex: rsync-3.1.0/options.c\n===================================================================\n--- rsync-3.1.0.orig/options.c\t2015-10-07 15:26:38.823626300 +0200\n+++ rsync-3.1.0/options.c\t2015-10-07 15:30:33.161773618 +0200\n@@ -2481,6 +2481,7 @@ void server_options(char **args, int *ar\n #ifdef ICONV_OPTION\n \t\targstr[x++] = 's';\n #endif\n+\t\targstr[x++] = 'C'; /* support checksum seed order fix */\n \t}\n \n \tif (x >= (int)sizeof argstr) { /* Not possible... */" } ]
{ "id": "rsync-4076-rsync-equivalent_of_CVE-2014-8", "cve_id": "CVE-2014-8242", "package": "rsync", "upstream_enriched": true, "upstream_commit": "eac858085e3ac94ec0ab5061d11f52652c90a869", "upstream_repo": "RsyncProject/rsync", "tier": "adapted", "has_source_context": false, "license": "GPL-3.0-or-later", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-8868\n\nHeap-based buffer overflow in the ExponentialFunction::ExponentialFunction function in Poppler before 0.40.0 allows remote attackers to cause a denial of service (memory corruption and crash) or possibly execute arbitrary code via an invalid blend mode in the ExtGState dictionary in a crafted PDF document.\n\n## Package\npoppler-qt\n\n## Files to modify\n- poppler/GfxFont.h\n\n## Upstream Fix\n```diff\nFrom 01723aa17e836e818158dbdc56df642a290be300 Mon Sep 17 00:00:00 2001\nFrom: Adrian Johnson <ajohnson@redneon.com>\nDate: Tue, 30 Sep 2014 18:48:47 +0200\nSubject: Map Standard/Expert encoding ligatures to AGLFN names\n\nfor use with substitute fonts that are not compatible with the\nStandard 14 fonts.\n\nBug 80093\n\ndiff --git a/poppler/CairoFontEngine.cc b/poppler/CairoFontEngine.cc\nindex 1546594..4cf8d6b 100644\n--- a/poppler/CairoFontEngine.cc\n+++ b/poppler/CairoFontEngine.cc\n@@ -21,7 +21,7 @@\n // Copyright (C) 2006, 2007, 2010, 2011 Carlos Garcia Campos <carlosgc@gnome.org>\n // Copyright (C) 2007 Koji Otani <sho@bbr.jp>\n // Copyright (C) 2008, 2009 Chris Wilson <chris@chris-wilson.co.uk>\n-// Copyright (C) 2008, 2012 Adrian Johnson <ajohnson@redneon.com>\n+// Copyright (C) 2008, 2012, 2014 Adrian Johnson <ajohnson@redneon.com>\n // Copyright (C) 2009 Darren Kenny <darren.kenny@sun.com>\n // Copyright (C) 2010 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp>\n // Copyright (C) 2010 Jan Kümmel <jan+freedesktop@snorc.org>\n@@ -395,7 +395,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref,\n GfxFontType fontType;\n GfxFontLoc *fontLoc;\n char **enc;\n- char *name;\n+ const char *name;\n FoFiTrueType *ff;\n FoFiType1C *ff1c;\n Ref ref;\n@@ -457,7 +457,13 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref,\n for (i = 0; i < 256; ++i) {\n codeToGID[i] = 0;\n if ((name = enc[i])) {\n-\tcodeToGID[i] = FT_Get_Name_Index(face, name);\n+\tcodeToGID[i] = FT_Get_Name_Index(face, (char*)name);\n+\tif (codeToGID[i] == 0) {\n+\t name = GfxFont::getAlternateName(name);\n+\t if (name) {\n+\t codeToGID[i] = FT_Get_Name_Index(face, (char*)name);\n+\t }\n+\t}\n }\n }\n break;\ndiff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc\nindex 6f6a125..39f026a 100644\n--- a/poppler/GfxFont.cc\n+++ b/poppler/GfxFont.cc\n@@ -26,7 +26,7 @@\n // Copyright (C) 2009 Peter Kerzum <kerzum@yandex-team.ru>\n // Copyright (C) 2009, 2010 David Benjamin <davidben@mit.edu>\n // Copyright (C) 2011 Axel Strübing <axel.struebing@freenet.de>\n-// Copyright (C) 2011, 2012 Adrian Johnson <ajohnson@redneon.com>\n+// Copyright (C) 2011, 2012, 2014 Adrian Johnson <ajohnson@redneon.com>\n // Copyright (C) 2012 Yi Yang <ahyangyi@gmail.com>\n // Copyright (C) 2012 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp>\n // Copyright (C) 2012 Thomas Freitag <Thomas.Freitag@alfa.de>\n@@ -913,6 +913,33 @@ char *GfxFont::readEmbFontFile(XRef *xref, int *len) {\n return buf;\n }\n \n+\n+struct AlternateNameMap {\n+ const char *name;\n+ const char *alt;\n+};\n+\n+static const AlternateNameMap alternateNameMap[] =\n+{\n+ { \"fi\", \"f_i\" },\n+ { \"fl\", \"f_l\" },\n+ { \"ff\", \"f_f\" },\n+ { \"ffi\", \"f_f_i\" },\n+ { \"ffl\", \"f_f_l\" },\n+ { 0, 0 }\n+};\n+\n+const char *GfxFont::getAlternateName(const char *name) {\n+ const AlternateNameMap *map = alternateNameMap;\n+ while (map->name) {\n+ if (strcmp(name, map->name) == 0) {\n+ return map->alt;\n+ }\n+ map++;\n+ }\n+ return 0;\n+}\n+\n //------------------------------------------------------------------------\n // Gfx8BitFont\n //------------------------------------------------------------------------\ndiff --git a/poppler/GfxFont.h b/poppler/GfxFont.h\nindex f980668..1be8975 100644\n--- a/poppler/GfxFont.h\n+++ b/poppler/GfxFont.h\n@@ -20,7 +20,7 @@\n // Copyright (C) 2007 Jeff Muizelaar <jeff@infidigm.net>\n // Copyright (C) 2007 Koji Otani <sho@bbr.jp>\n // Copyright (C) 2011 Axel Strübing <axel.struebing@freenet.de>\n-// Copyright (C) 2011, 2012 Adrian Johnson <ajohnson@redneon.com>\n+// Copyright (C) 2011, 2012, 2014 Adrian Johnson <ajohnson@redneon.com>\n //\n // To see a description of the changes please see the Changelog file that\n // came with your tarball or type make ChangeLog if you are building from git\n@@ -263,6 +263,11 @@ public:\n // Return the name of the encoding\n GooString *getEncodingName() { return encodingName; }\n \n+ // Return AGLFN names of ligatures in the Standard and Expert encodings\n+ // for use with fonts that are not compatible with the Standard 14 fonts.\n+ // http://sourceforge.net/adobe/aglfn/wiki/AGL%20Specification/\n+ static const char *getAlternateName(const char *name);\n+\n protected:\n \n virtual ~GfxFont();\ndiff --git a/splash/SplashFTFontFile.cc b/splash/SplashFTFontFile.cc\nindex 34f6ce5..f0dcf50 100644\n--- a/splash/SplashFTFontFile.cc\n+++ b/splash/SplashFTFontFile.cc\n@@ -12,6 +12,7 @@\n // under GPL version 2 or later\n //\n // Copyright (C) 2006 Takashi Iwai <tiwai@suse.de>\n+// Copyright (C) 2014 Adrian Johnson <ajohnson@redneon.com>\n //\n // To see a description of the changes please see the Changelog file that\n // came with your tarball or type make ChangeLog if you are building from git\n@@ -28,6 +29,7 @@\n \n #include \"goo/gmem.h\"\n #include \"goo/GooString.h\"\n+#include \"poppler/GfxFont.h\"\n #include \"SplashFTFontEngine.h\"\n #include \"SplashFTFont.h\"\n #include \"SplashFTFontFile.h\"\n@@ -57,6 +59,12 @@ SplashFontFile *SplashFTFontFile::loadType1Font(SplashFTFontEngine *engineA,\n codeToGIDA[i] = 0;\n if ((name = encA[i])) {\n codeToGIDA[i] = (int)FT_Get_Name_Index(faceA, (char *)name);\n+ if (codeToGIDA[i] == 0) {\n+\tname = GfxFont::getAlternateName(name);\n+\tif (name) {\n+\t codeToGIDA[i] = FT_Get_Name_Index(faceA, (char *)name);\n+\t}\n+ }\n }\n }\n \n-- \ncgit v0.10.2\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 01723aa17e836e818158dbdc56df642a290be300 Mon Sep 17 00:00:00 2001\nFrom: Adrian Johnson <ajohnson@redneon.com>\nDate: Tue, 30 Sep 2014 18:48:47 +0200\nSubject: Map Standard/Expert encoding ligatures to AGLFN names\n\nfor use with substitute fonts that are not compatible with the\nStandard 14 fonts.\n\nBug 80093\n\ndiff --git a/poppler/CairoFontEngine.cc b/poppler/CairoFontEngine.cc\nindex 1546594..4cf8d6b 100644\n--- a/poppler/CairoFontEngine.cc\n+++ b/poppler/CairoFontEngine.cc\n@@ -21,7 +21,7 @@\n // Copyright (C) 2006, 2007, 2010, 2011 Carlos Garcia Campos <carlosgc@gnome.org>\n // Copyright (C) 2007 Koji Otani <sho@bbr.jp>\n // Copyright (C) 2008, 2009 Chris Wilson <chris@chris-wilson.co.uk>\n-// Copyright (C) 2008, 2012 Adrian Johnson <ajohnson@redneon.com>\n+// Copyright (C) 2008, 2012, 2014 Adrian Johnson <ajohnson@redneon.com>\n // Copyright (C) 2009 Darren Kenny <darren.kenny@sun.com>\n // Copyright (C) 2010 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp>\n // Copyright (C) 2010 Jan Kümmel <jan+freedesktop@snorc.org>\n@@ -395,7 +395,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref,\n GfxFontType fontType;\n GfxFontLoc *fontLoc;\n char **enc;\n- char *name;\n+ const char *name;\n FoFiTrueType *ff;\n FoFiType1C *ff1c;\n Ref ref;\n@@ -457,7 +457,13 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref,\n for (i = 0; i < 256; ++i) {\n codeToGID[i] = 0;\n if ((name = enc[i])) {\n-\tcodeToGID[i] = FT_Get_Name_Index(face, name);\n+\tcodeToGID[i] = FT_Get_Name_Index(face, (char*)name);\n+\tif (codeToGID[i] == 0) {\n+\t name = GfxFont::getAlternateName(name);\n+\t if (name) {\n+\t codeToGID[i] = FT_Get_Name_Index(face, (char*)name);\n+\t }\n+\t}\n }\n }\n break;\ndiff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc\nindex 6f6a125..39f026a 100644\n--- a/poppler/GfxFont.cc\n+++ b/poppler/GfxFont.cc\n@@ -26,7 +26,7 @@\n // Copyright (C) 2009 Peter Kerzum <kerzum@yandex-team.ru>\n // Copyright (C) 2009, 2010 David Benjamin <davidben@mit.edu>\n // Copyright (C) 2011 Axel Strübing <axel.struebing@freenet.de>\n-// Copyright (C) 2011, 2012 Adrian Johnson <ajohnson@redneon.com>\n+// Copyright (C) 2011, 2012, 2014 Adrian Johnson <ajohnson@redneon.com>\n // Copyright (C) 2012 Yi Yang <ahyangyi@gmail.com>\n // Copyright (C) 2012 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp>\n // Copyright (C) 2012 Thomas Freitag <Thomas.Freitag@alfa.de>\n@@ -913,6 +913,33 @@ char *GfxFont::readEmbFontFile(XRef *xref, int *len) {\n return buf;\n }\n \n+\n+struct AlternateNameMap {\n+ const char *name;\n+ const char *alt;\n+};\n+\n+static const AlternateNameMap alternateNameMap[] =\n+{\n+ { \"fi\", \"f_i\" },\n+ { \"fl\", \"f_l\" },\n+ { \"ff\", \"f_f\" },\n+ { \"ffi\", \"f_f_i\" },\n+ { \"ffl\", \"f_f_l\" },\n+ { 0, 0 }\n+};\n+\n+const char *GfxFont::getAlternateName(const char *name) {\n+ const AlternateNameMap *map = alternateNameMap;\n+ while (map->name) {\n+ if (strcmp(name, map->name) == 0) {\n+ return map->alt;\n+ }\n+ map++;\n+ }\n+ return 0;\n+}\n+\n //------------------------------------------------------------------------\n // Gfx8BitFont\n //------------------------------------------------------------------------\ndiff --git a/poppler/GfxFont.h b/poppler/GfxFont.h\nindex f980668..1be8975 100644\n--- a/poppler/GfxFont.h\n+++ b/poppler/GfxFont.h\n@@ -20,7 +20,7 @@\n // Copyright (C) 2007 Jeff Muizelaar <jeff@infidigm.net>\n // Copyright (C) 2007 Koji Otani <sho@bbr.jp>\n // Copyright (C) 2011 Axel Strübing <axel.struebing@freenet.de>\n-// Copyright (C) 2011, 2012 Adrian Johnson <ajohnson@redneon.com>\n+// Copyright (C) 2011, 2012, 2014 Adrian Johnson <ajohnson@redneon.com>\n //\n // To see a description of the changes please see the Changelog file that\n // came with your tarball or type make ChangeLog if you are building from git\n@@ -263,6 +263,11 @@ public:\n // Return the name of the encoding\n GooString *getEncodingName() { return encodingName; }\n \n+ // Return AGLFN names of ligatures in the Standard and Expert encodings\n+ // for use with fonts that are not compatible with the Standard 14 fonts.\n+ // http://sourceforge.net/adobe/aglfn/wiki/AGL%20Specification/\n+ static const char *getAlternateName(const char *name);\n+\n protected:\n \n virtual ~GfxFont();\ndiff --git a/splash/SplashFTFontFile.cc b/splash/SplashFTFontFile.cc\nindex 34f6ce5..f0dcf50 100644\n--- a/splash/SplashFTFontFile.cc\n+++ b/splash/SplashFTFontFile.cc\n@@ -12,6 +12,7 @@\n // under GPL version 2 or later\n //\n // Copyright (C) 2006 Takashi Iwai <tiwai@suse.de>\n+// Copyright (C) 2014 Adrian Johnson <ajohnson@redneon.com>\n //\n // To see a description of the changes please see the Changelog file that\n // came with your tarball or type make ChangeLog if you are building from git\n@@ -28,6 +29,7 @@\n \n #include \"goo/gmem.h\"\n #include \"goo/GooString.h\"\n+#include \"poppler/GfxFont.h\"\n #include \"SplashFTFontEngine.h\"\n #include \"SplashFTFont.h\"\n #include \"SplashFTFontFile.h\"\n@@ -57,6 +59,12 @@ SplashFontFile *SplashFTFontFile::loadType1Font(SplashFTFontEngine *engineA,\n codeToGIDA[i] = 0;\n if ((name = encA[i])) {\n codeToGIDA[i] = (int)FT_Get_Name_Index(faceA, (char *)name);\n+ if (codeToGIDA[i] == 0) {\n+\tname = GfxFont::getAlternateName(name);\n+\tif (name) {\n+\t codeToGIDA[i] = FT_Get_Name_Index(faceA, (char *)name);\n+\t}\n+ }\n }\n }\n \n-- \ncgit v0.10.2" } ]
{ "id": "poppler-qt-5045-poppler-ligatures.patch", "cve_id": "CVE-2015-8868", "package": "poppler-qt", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": false, "license": "GPL-2.0-only OR GPL-3.0-only", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-3706\n\nStack-based buffer overflow in the getaddrinfo function in sysdeps/posix/getaddrinfo.c in the GNU C Library (aka glibc or libc6) allows remote attackers to cause a denial of service (crash) via vectors involving hostent conversion. NOTE: this vulnerability exists because of an incomplete fix for CVE-2013-4458.\n\n## Package\nglibc-testsuite\n\n## Files to modify\n- resolv/res_init.c\n- resolv/res_send.c\n- glibc-2.19.orig/resolv/res_init.c\n- glibc-2.19.orig/resolv/res_send.c\n\n## Target Source Code\n\n### resolv/res_init.c\n\n#### __res_vinit() [lines 148-353]\n```c\n\n/* This function has to be reachable by res_data.c but not publically. */\nint\n__res_vinit(res_state statp, int preinit) {\n\tFILE *fp;\n\tchar *cp, **pp;\n\tint n;\n\tchar buf[BUFSIZ];\n\tint nserv = 0; /* number of nameserver records read from file */\n#ifdef _LIBC\n\tint nservall = 0; /* number of NS records read, nserv IPv4 only */\n#endif\n\tint haveenv = 0;\n\tint havesearch = 0;\n#ifdef RESOLVSORT\n\tint nsort = 0;\n\tchar *net;\n#endif\n#ifndef RFC1535\n\tint dots;\n#endif\n#ifdef _LIBC\n\tstatp->_u._ext.initstamp = __res_initstamp;\n#endif\n\n\tif (!preinit) {\n\t\tstatp->retrans = RES_TIMEOUT;\n\t\tstatp->retry = RES_DFLRETRY;\n\t\tstatp->options = RES_DEFAULT;\n\t\tstatp->id = res_randomid();\n\t}\n\n\tstatp->nscount = 0;\n\tstatp->ndots = 1;\n\tstatp->pfcode = 0;\n\tstatp->_vcsock = -1;\n\tstatp->_flags = 0;\n\tstatp->qhook = NULL;\n\tstatp->rhook = NULL;\n\tstatp->_u._ext.nsinit = 0;\n/* ... 156 lines omitted ... */\n\t\t\t\tsa6->sin6_flowinfo = 0;\n\t\t\t\tsa6->sin6_addr = a6;\n\n\t\t\t\tif (__builtin_expect (el == NULL, 1))\n\t\t\t\t sa6->sin6_scope_id = 0;\n\t\t\t\telse {\n\t\t\t\t int try_numericscope = 1;\n\t\t\t\t if (IN6_IS_ADDR_LINKLOCAL (&a6)\n\t\t\t\t\t|| IN6_IS_ADDR_MC_LINKLOCAL (&a6)) {\n\t\t\t\t\tsa6->sin6_scope_id\n\t\t\t\t\t = if_nametoindex (el + 1);\n\t\t\t\t\tif (sa6->sin6_scope_id != 0)\n\t\t\t\t\t try_numericscope = 0;\n\t\t\t\t }\n\n\t\t\t\t if (try_numericscope) {\n\t\t\t\t\tchar *end;\n\t\t\t\t\tsa6->sin6_scope_id\n\t\t\t\t\t = (uint32_t) strtoul (el + 1, &end,\n\t\t\t\t\t\t\t\t10);\n```\n\n#### __res_iclose() [lines 598-627]\n```c\n * This routine is not expected to be user visible.\n */\nvoid\n__res_iclose(res_state statp, bool free_addr) {\n\tint ns;\n\n\tif (statp->_vcsock >= 0) {\n\t\tclose_not_cancel_no_status(statp->_vcsock);\n\t\tstatp->_vcsock = -1;\n\t\tstatp->_flags &= ~(RES_F_VC | RES_F_CONN);\n\t}\n#ifdef _LIBC\n\tfor (ns = 0; ns < MAXNS; ns++)\n#else\n\tfor (ns = 0; ns < statp->_u._ext.nscount; ns++)\n#endif\n\t\tif (statp->_u._ext.nsaddrs[ns]) {\n\t\t\tif (statp->_u._ext.nssocks[ns] != -1) {\n\t\t\t\tclose_not_cancel_no_status(statp->_u._ext.nssocks[ns]);\n\t\t\t\tstatp->_u._ext.nssocks[ns] = -1;\n\t\t\t}\n\t\t\tif (free_addr) {\n\t\t\t\tfree (statp->_u._ext.nsaddrs[ns]);\n\t\t\t\tstatp->_u._ext.nsaddrs[ns] = NULL;\n\t\t\t}\n\t\t}\n\tstatp->_u._ext.nsinit = 0;\n}\nlibc_hidden_def (__res_iclose)\n\n```\n\n### resolv/res_send.c\n\n#### evNowTime() [lines 165-177]\n```c\n}\n\nstatic void\nevNowTime(struct timespec *res) {\n\tstruct timeval now;\n\n\tif (gettimeofday(&now, NULL) < 0)\n\t\tevConsTime(res, 0, 0);\n\telse\n\t\tTIMEVAL_TO_TIMESPEC (&now, res);\n}\n\n\n```\n\n#### res_ourserver_p() [lines 211-248]\n```c\n *\tpaul vixie, 29may94\n */\nint\nres_ourserver_p(const res_state statp, const struct sockaddr_in6 *inp)\n{\n\tint ns;\n\n\tif (inp->sin6_family == AF_INET) {\n\t struct sockaddr_in *in4p = (struct sockaddr_in *) inp;\n\t in_port_t port = in4p->sin_port;\n\t in_addr_t addr = in4p->sin_addr.s_addr;\n\n\t for (ns = 0; ns < MAXNS; ns++) {\n\t\tconst struct sockaddr_in *srv =\n\t\t (struct sockaddr_in *)EXT(statp).nsaddrs[ns];\n\n\t\tif ((srv != NULL) && (srv->sin_family == AF_INET) &&\n\t\t (srv->sin_port == port) &&\n\t\t (srv->sin_addr.s_addr == INADDR_ANY ||\n\t\t srv->sin_addr.s_addr == addr))\n\t\t return (1);\n\t }\n\t} else if (inp->sin6_family == AF_INET6) {\n\t for (ns = 0; ns < MAXNS; ns++) {\n\t\tconst struct sockaddr_in6 *srv = EXT(statp).nsaddrs[ns];\n\t\tif ((srv != NULL) && (srv->sin6_family == AF_INET6) &&\n\t\t (srv->sin6_port == inp->sin6_port) &&\n\t\t !(memcmp(&srv->sin6_addr, &in6addr_any,\n\t\t\t sizeof (struct in6_addr)) &&\n\t\t memcmp(&srv->sin6_addr, &inp->sin6_addr,\n\t\t\t sizeof (struct in6_addr))))\n\t\t return (1);\n\t }\n\t}\n\treturn (0);\n}\n\n/* int\n```\n\n#### __libc_res_nsend() [lines 340-644]\n```c\nlibresolv_hidden_def (res_queriesmatch)\n\nint\n__libc_res_nsend(res_state statp, const u_char *buf, int buflen,\n\t\t const u_char *buf2, int buflen2,\n\t\t u_char *ans, int anssiz, u_char **ansp, u_char **ansp2,\n\t\t int *nansp2, int *resplen2)\n{\n int gotsomewhere, terrno, try, v_circuit, resplen, ns, n;\n\n\tif (statp->nscount == 0) {\n\t\t__set_errno (ESRCH);\n\t\treturn (-1);\n\t}\n\n\tif (anssiz < (buf2 == NULL ? 1 : 2) * HFIXEDSZ) {\n\t\t__set_errno (EINVAL);\n\t\treturn (-1);\n\t}\n\n#ifdef USE_HOOKS\n\tif (__builtin_expect (statp->qhook || statp->rhook, 0)) {\n\t\tif (anssiz < MAXPACKET && ansp) {\n\t\t\tu_char *buf = malloc (MAXPACKET);\n\t\t\tif (buf == NULL)\n\t\t\t\treturn (-1);\n\t\t\tmemcpy (buf, ans, HFIXEDSZ);\n\t\t\t*ansp = buf;\n\t\t\tans = buf;\n\t\t\tanssiz = MAXPACKET;\n\t\t}\n\t}\n#endif\n\n\tDprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_QUERY),\n\t\t(stdout, \";; res_send()\\n\"), buf, buflen);\n\tv_circuit = ((statp->options & RES_USEVC)\n\t\t || buflen > PACKETSZ\n\t\t || buflen2 > PACKETSZ);\n\tgotsomewhere = 0;\n\tterrno = ETIMEDOUT;\n\n\t/*\n\t * If the ns_addr_list in the resolver context has changed, then\n\t * invalidate our cached copy and the associated timing data.\n\t */\n\tif (EXT(statp).nsinit) {\n\t\tint needclose = 0;\n\n\t\tif (EXT(statp).nscount != statp->nscount)\n\t\t\tneedclose++;\n\t\telse\n\t\t\tfor (ns = 0; ns < MAXNS; ns++) {\n\t\t\t\tunsigned int map = EXT(statp).nsmap[ns];\n\t\t\t\tif (map < MAXNS\n\t\t\t\t && !sock_eq((struct sockaddr_in6 *)\n\t\t\t\t\t\t&statp->nsaddr_list[map],\n\t\t\t\t\t\tEXT(statp).nsaddrs[ns]))\n\t\t\t\t{\n\t\t\t\t\tneedclose++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\tif (needclose)\n\t\t\t__res_iclose(statp, false);\n\t}\n\n\t/*\n\t * Maybe initialize our private copy of the ns_addr_list.\n\t */\n\tif (EXT(statp).nsinit == 0) {\n\t\tunsigned char map[MAXNS];\n\n\t\tmemset (map, MAXNS, sizeof (map));\n\t\tfor (n = 0; n < MAXNS; n++) {\n\t\t\tns = EXT(statp).nsmap[n];\n\t\t\tif (ns < statp->nscount)\n\t\t\t\tmap[ns] = n;\n\t\t\telse if (ns < MAXNS) {\n\t\t\t\tfree(EXT(statp).nsaddrs[n]);\n\t\t\t\tEXT(statp).nsaddrs[n] = NULL;\n\t\t\t\tEXT(statp).nsmap[n] = MAXNS;\n\t\t\t}\n\t\t}\n\t\tn = statp->nscount;\n\t\tif (statp->nscount > EXT(statp).nscount)\n\t\t\tfor (n = EXT(statp).nscount, ns = 0;\n\t\t\t n < statp->nscount; n++) {\n\t\t\t\twhile (ns < MAXNS\n\t\t\t\t && EXT(statp).nsmap[ns] != MAXNS)\n\t\t\t\t\tns++;\n\t\t\t\tif (ns == MAXNS)\n\t\t\t\t\tbreak;\n\t\t\t\tEXT(statp).nsmap[ns] = n;\n\t\t\t\tmap[n] = ns++;\n\t\t\t}\n\t\tEXT(statp).nscount = n;\n\t\tfor (ns = 0; ns < EXT(statp).nscount; ns++) {\n\t\t\tn = map[ns];\n\t\t\tif (EXT(statp).nsaddrs[n] == NULL)\n\t\t\t\tEXT(statp).nsaddrs[n] =\n\t\t\t\t malloc(sizeof (struct sockaddr_in6));\n\t\t\tif (EXT(statp).nsaddrs[n] != NULL) {\n\t\t\t\tmemset (mempcpy(EXT(statp).nsaddrs[n],\n\t\t\t\t\t\t&statp->nsaddr_list[ns],\n\t\t\t\t\t\tsizeof (struct sockaddr_in)),\n\t\t\t\t\t'\\0',\n\t\t\t\t\tsizeof (struct sockaddr_in6)\n\t\t\t\t\t- sizeof (struct sockaddr_in));\n\t\t\t\tEXT(statp).nssocks[n] = -1;\n\t\t\t\tn++;\n\t\t\t}\n\t\t}\n\t\tEXT(statp).nsinit = 1;\n\t}\n\n\t/*\n\t * Some resolvers want to even out the load on their nameservers.\n\t * Note that RES_BLAST overrides RES_ROTATE.\n\t */\n\tif (__builtin_expect ((statp->options & RES_ROTATE) != 0, 0) &&\n\t (statp->options & RES_BLAST) == 0) {\n\t\tstruct sockaddr_in6 *ina;\n\t\tunsigned int map;\n\n\t\tn = 0;\n\t\twhile (n < MAXNS && EXT(statp).nsmap[n] == MAXNS)\n\t\t\tn++;\n/* ... 157 lines omitted ... */\n\t\t\t} while (!done);\n\n\t\t}\n#endif\n\t\treturn (resplen);\n next_ns: ;\n\t } /*foreach ns*/\n\t} /*foreach retry*/\n\t__res_iclose(statp, false);\n\tif (!v_circuit) {\n\t\tif (!gotsomewhere)\n\t\t\t__set_errno (ECONNREFUSED);\t/* no nameservers found */\n\t\telse\n\t\t\t__set_errno (ETIMEDOUT);\t/* no answer obtained */\n\t} else\n\t\t__set_errno (terrno);\n\treturn (-1);\n}\n\nint\n```\n\n#### libresolv_hidden_def() [lines 614-700]\n```c\n\t\t\t\t\tgoto next_ns;\n\t\t\t\tcase res_modified:\n\t\t\t\t\t/* give the hook another try */\n\t\t\t\t\tif (++loops < 42) /*doug adams*/\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t/*FALLTHROUGH*/\n\t\t\t\tcase res_error:\n\t\t\t\t\t/*FALLTHROUGH*/\n\t\t\t\tdefault:\n\t\t\t\t\treturn (-1);\n\t\t\t\t}\n\t\t\t} while (!done);\n\n\t\t}\n#endif\n\t\treturn (resplen);\n next_ns: ;\n\t } /*foreach ns*/\n\t} /*foreach retry*/\n\t__res_iclose(statp, false);\n\tif (!v_circuit) {\n\t\tif (!gotsomewhere)\n\t\t\t__set_errno (ECONNREFUSED);\t/* no nameservers found */\n\t\telse\n\t\t\t__set_errno (ETIMEDOUT);\t/* no answer obtained */\n\t} else\n\t\t__set_errno (terrno);\n\treturn (-1);\n}\n\nint\nres_nsend(res_state statp,\n\t const u_char *buf, int buflen, u_char *ans, int anssiz)\n{\n return __libc_res_nsend(statp, buf, buflen, NULL, 0, ans, anssiz,\n\t\t\t NULL, NULL, NULL, NULL);\n}\nlibresolv_hidden_def (res_nsend)\n\n/* Private */\n\nstatic int\nsend_vc(res_state statp,\n\tconst u_char *buf, int buflen, const u_char *buf2, int buflen2,\n\tu_char **ansp, int *anssizp,\n\tint *terrno, int ns, u_char **anscp, u_char **ansp2, int *anssizp2,\n\tint *resplen2)\n{\n\tconst HEADER *hp = (HEADER *) buf;\n\tconst HEADER *hp2 = (HEADER *) buf2;\n\tu_char *ans = *ansp;\n\tint orig_anssizp = *anssizp;\n\t// XXX REMOVE\n\t// int anssiz = *anssizp;\n\tHEADER *anhp = (HEADER *) ans;\n\tstruct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns];\n\tint truncating, connreset, resplen, n;\n\tstruct iovec iov[4];\n\tu_short len;\n\tu_short len2;\n\tu_char *cp;\n\n\tif (resplen2 != NULL)\n\t *resplen\n/* ... truncated ... */\n```\n\n\n## Upstream Fix\n```diff\nFrom 6c07233f12e00b9cf66fb5d4a9b7ddb897590912 Mon Sep 17 00:00:00 2001\nFrom: Andreas Schwab <schwab@suse.de>\nDate: Thu, 19 Feb 2015 15:52:08 +0100\nSubject: [PATCH] Simplify handling of nameserver configuration in resolver\n\n\t[BZ #13028]\n\t[BZ #17053]\n\t* resolv/res_init.c (__res_vinit): Remove use of ext.nsmap.\n\t* resolv/res_send.c (__libc_res_nsend): Likewise.\n\t(get_nsaddr): New function.\n\t(res_ourserver_p, send_vc, reopen): Use it instead of accessing\n\tstatp directly.\n---\n resolv/res_init.c | 47 +++++-----------\n resolv/res_send.c | 164 +++++++++++++++++++++++-------------------------------\n 2 files changed, 84 insertions(+), 127 deletions(-)\n\nIndex: glibc-2.19/resolv/res_init.c\n===================================================================\n--- glibc-2.19.orig/resolv/res_init.c\n+++ glibc-2.19/resolv/res_init.c\n@@ -153,10 +153,8 @@ __res_vinit(res_state statp, int preinit\n \tchar *cp, **pp;\n \tint n;\n \tchar buf[BUFSIZ];\n-\tint nserv = 0; /* number of nameserver records read from file */\n-#ifdef _LIBC\n-\tint nservall = 0; /* number of NS records read, nserv IPv4 only */\n-#endif\n+\tint nserv = 0; /* number of nameservers read from file */\n+\tint have_serv6 = 0;\n \tint haveenv = 0;\n \tint havesearch = 0;\n #ifdef RESOLVSORT\n@@ -184,15 +182,9 @@ __res_vinit(res_state statp, int preinit\n \tstatp->_flags = 0;\n \tstatp->qhook = NULL;\n \tstatp->rhook = NULL;\n-\tstatp->_u._ext.nsinit = 0;\n \tstatp->_u._ext.nscount = 0;\n-#ifdef _LIBC\n-\tstatp->_u._ext.nscount6 = 0;\n-\tfor (n = 0; n < MAXNS; n++) {\n-\t\tstatp->_u._ext.nsaddrs[n] = NULL;\n-\t\tstatp->_u._ext.nsmap[n] = MAXNS;\n-\t}\n-#endif\n+\tfor (n = 0; n < MAXNS; n++)\n+\t statp->_u._ext.nsaddrs[n] = NULL;\n \n \t/* Allow user to override the local domain definition */\n \tif ((cp = getenv(\"LOCALDOMAIN\")) != NULL) {\n@@ -296,11 +288,7 @@ __res_vinit(res_state statp, int preinit\n \t\t continue;\n \t\t}\n \t\t/* read nameservers to query */\n-#ifdef _LIBC\n-\t\tif (MATCH(buf, \"nameserver\") && nservall < MAXNS) {\n-#else\n \t\tif (MATCH(buf, \"nameserver\") && nserv < MAXNS) {\n-#endif\n \t\t struct in_addr a;\n \n \t\t cp = buf + sizeof(\"nameserver\") - 1;\n@@ -308,13 +296,12 @@ __res_vinit(res_state statp, int preinit\n \t\t\tcp++;\n \t\t if ((*cp != '\\0') && (*cp != '\\n')\n \t\t\t&& __inet_aton(cp, &a)) {\n-\t\t\tstatp->nsaddr_list[nservall].sin_addr = a;\n-\t\t\tstatp->nsaddr_list[nservall].sin_family = AF_INET;\n-\t\t\tstatp->nsaddr_list[nservall].sin_port =\n+\t\t\tstatp->nsaddr_list[nserv].sin_addr = a;\n+\t\t\tstatp->nsaddr_list[nserv].sin_family = AF_INET;\n+\t\t\tstatp->nsaddr_list[nserv].sin_port =\n \t\t\t\thtons(NAMESERVER_PORT);\n \t\t\tnserv++;\n #ifdef _LIBC\n-\t\t\tnservall++;\n \t\t } else {\n \t\t\tstruct in6_addr a6;\n \t\t\tchar *el;\n@@ -356,10 +343,11 @@ __res_vinit(res_state statp, int preinit\n \t\t\t\t }\n \t\t\t\t}\n \n-\t\t\t\tstatp->_u._ext.nsaddrs[nservall] = sa6;\n-\t\t\t\tstatp->_u._ext.nssocks[nservall] = -1;\n-\t\t\t\tstatp->_u._ext.nsmap[nservall] = MAXNS + 1;\n-\t\t\t\tnservall++;\n+\t\t\t\tstatp->nsaddr_list[nserv].sin_family = 0;\n+\t\t\t\tstatp->_u._ext.nsaddrs[nserv] = sa6;\n+\t\t\t\tstatp->_u._ext.nssocks[nserv] = -1;\n+\t\t\t\thave_serv6 = 1;\n+\t\t\t\tnserv++;\n \t\t\t }\n \t\t\t}\n #endif\n@@ -414,10 +402,9 @@ __res_vinit(res_state statp, int preinit\n \t\t continue;\n \t\t}\n \t }\n-\t statp->nscount = nservall;\n+\t statp->nscount = nserv;\n #ifdef _LIBC\n-\t if (nservall - nserv > 0) {\n-\t\tstatp->_u._ext.nscount6 = nservall - nserv;\n+\t if (have_serv6) {\n \t\t/* We try IPv6 servers again. */\n \t\tstatp->ipv6_unavail = false;\n \t }\n@@ -606,11 +593,7 @@ __res_iclose(res_state statp, bool free_\n \t\tstatp->_vcsock = -1;\n \t\tstatp->_flags &= ~(RES_F_VC | RES_F_CONN);\n \t}\n-#ifdef _LIBC\n-\tfor (ns = 0; ns < MAXNS; ns++)\n-#else\n \tfor (ns = 0; ns < statp->_u._ext.nscount; ns++)\n-#endif\n \t\tif (statp->_u._ext.nsaddrs[ns]) {\n \t\t\tif (statp->_u._ext.nssocks[ns] != -1) {\n \t\t\t\tclose_not_cancel_no_status(statp->_u._ext.nssocks[ns]);\n@@ -621,7 +604,6 @@ __res_iclose(res_state statp, bool free_\n \t\t\t\tstatp->_u._ext.nsaddrs[ns] = NULL;\n \t\t\t}\n \t\t}\n-\tstatp->_u._ext.nsinit = 0;\n }\n libc_hidden_def (__res_iclose)\n \nIndex: glibc-2.19/resolv/res_send.c\n===================================================================\n--- glibc-2.19.orig/resolv/res_send.c\n+++ glibc-2.19/resolv/res_send.c\n@@ -183,6 +183,7 @@ evNowTime(struct timespec *res) {\n \n /* Forward. */\n \n+static struct sockaddr *get_nsaddr (res_state, int);\n static int\t\tsend_vc(res_state, const u_char *, int,\n \t\t\t\tconst u_char *, int,\n \t\t\t\tu_char **, int *, int *, int, u_char **,\n@@ -220,20 +221,21 @@ res_ourserver_p(const res_state statp, c\n \t in_port_t port = in4p->sin_port;\n \t in_addr_t addr = in4p->sin_addr.s_addr;\n \n-\t for (ns = 0; ns < MAXNS; ns++) {\n+\t for (ns = 0; ns < statp->nscount; ns++) {\n \t\tconst struct sockaddr_in *srv =\n-\t\t (struct sockaddr_in *)EXT(statp).nsaddrs[ns];\n+\t\t (struct sockaddr_in *) get_nsaddr (statp, ns);\n \n-\t\tif ((srv != NULL) && (srv->sin_family == AF_INET) &&\n+\t\tif ((srv->sin_family == AF_INET) &&\n \t\t (srv->sin_port == port) &&\n \t\t (srv->sin_addr.s_addr == INADDR_ANY ||\n \t\t srv->sin_addr.s_addr == addr))\n \t\t return (1);\n \t }\n \t} else if (inp->sin6_family == AF_INET6) {\n-\t for (ns = 0; ns < MAXNS; ns++) {\n-\t\tconst struct sockaddr_in6 *srv = EXT(statp).nsaddrs[ns];\n-\t\tif ((srv != NULL) && (srv->sin6_family == AF_INET6) &&\n+\t for (ns = 0; ns < statp->nscount; ns++) {\n+\t\tconst struct sockaddr_in6 *srv\n+\t\t = (struct sockaddr_in6 *) get_nsaddr (statp, ns);\n+\t\tif ((srv->sin6_family == AF_INET6) &&\n \t\t (srv->sin6_port == inp->sin6_port) &&\n \t\t !(memcmp(&srv->sin6_addr, &in6addr_any,\n \t\t\t sizeof (struct in6_addr)) &&\n@@ -383,74 +385,48 @@ __libc_res_nsend(res_state statp, const\n \t * If the ns_addr_list in the resolver context has changed, then\n \t * invalidate our cached copy and the associated timing data.\n \t */\n-\tif (EXT(statp).nsinit) {\n+\tif (EXT(statp).nscount != 0) {\n \t\tint needclose = 0;\n \n \t\tif (EXT(statp).nscount != statp->nscount)\n \t\t\tneedclose++;\n \t\telse\n-\t\t\tfor (ns = 0; ns < MAXNS; ns++) {\n-\t\t\t\tunsigned int map = EXT(statp).nsmap[ns];\n-\t\t\t\tif (map < MAXNS\n+\t\t\tfor (ns = 0; ns < statp->nscount; ns++) {\n+\t\t\t\tif (statp->nsaddr_list[ns].sin_family != 0\n \t\t\t\t && !sock_eq((struct sockaddr_in6 *)\n-\t\t\t\t\t\t&statp->nsaddr_list[map],\n+\t\t\t\t\t\t&statp->nsaddr_list[ns],\n \t\t\t\t\t\tEXT(statp).nsaddrs[ns]))\n \t\t\t\t{\n \t\t\t\t\tneedclose++;\n \t\t\t\t\tbreak;\n \t\t\t\t}\n \t\t\t}\n-\t\tif (needclose)\n+\t\tif (needclose) {\n \t\t\t__res_iclose(statp, false);\n+\t\t\tEXT(statp).nscount = 0;\n+\t\t}\n \t}\n \n \t/*\n \t * Maybe initialize our private copy of the ns_addr_list.\n \t */\n-\tif (EXT(statp).nsinit == 0) {\n-\t\tunsigned char map[MAXNS];\n-\n-\t\tmemset (map, MAXNS, sizeof (map));\n-\t\tfor (n = 0; n < MAXNS; n++) {\n-\t\t\tns = EXT(statp).nsmap[n];\n-\t\t\tif (ns < statp->nscount)\n-\t\t\t\tmap[ns] = n;\n-\t\t\telse if (ns < MAXNS) {\n-\t\t\t\tfree(EXT(statp).nsaddrs[n]);\n-\t\t\t\tEXT(statp).nsaddrs[n] = NULL;\n-\t\t\t\tEXT(statp).nsmap[n] = MAXNS;\n-\t\t\t}\n-\t\t}\n-\t\tn = statp->nscount;\n-\t\tif (statp->nscount > EXT(statp).nscount)\n-\t\t\tfor (n = EXT(statp).nscount, ns = 0;\n-\t\t\t n < statp->nscount; n++) {\n-\t\t\t\twhile (ns < MAXNS\n-\t\t\t\t && EXT(statp).nsmap[ns] != MAXNS)\n-\t\t\t\t\tns++;\n-\t\t\t\tif (ns == MAXNS)\n-\t\t\t\t\tbreak;\n-\t\t\t\tEXT(statp).nsmap[ns] = n;\n-\t\t\t\tmap[n] = ns++;\n-\t\t\t}\n-\t\tEXT(statp).nscount = n;\n-\t\tfor (ns = 0; ns < EXT(statp).nscount; ns++) {\n-\t\t\tn = map[ns];\n-\t\t\tif (EXT(statp).nsaddrs[n] == NULL)\n-\t\t\t\tEXT(statp).nsaddrs[n] =\n+\tif (EXT(statp).nscount == 0) {\n+\t\tfor (ns = 0; ns < statp->nscount; ns++) {\n+\t\t\tEXT(statp).nssocks[ns] = -1;\n+\t\t\tif (statp->nsaddr_list[ns].sin_family == 0)\n+\t\t\t\tcontinue;\n+\t\t\tif (EXT(statp).nsaddrs[ns] == NULL)\n+\t\t\t\tEXT(statp).nsaddrs[ns] =\n \t\t\t\t malloc(sizeof (struct sockaddr_in6));\n-\t\t\tif (EXT(statp).nsaddrs[n] != NULL) {\n-\t\t\t\tmemset (mempcpy(EXT(statp).nsaddrs[n],\n+\t\t\tif (EXT(statp).nsaddrs[ns] != NULL)\n+\t\t\t\tmemset (mempcpy(EXT(statp).nsaddrs[ns],\n \t\t\t\t\t\t&statp->nsaddr_list[ns],\n \t\t\t\t\t\tsizeof (struct sockaddr_in)),\n \t\t\t\t\t'\\0',\n \t\t\t\t\tsizeof (struct sockaddr_in6)\n \t\t\t\t\t- sizeof (struct sockaddr_in));\n-\t\t\t\tEXT(statp).nssocks[n] = -1;\n-\t\t\t\tn++;\n-\t\t\t}\n \t\t}\n-\t\tEXT(statp)\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 6c07233f12e00b9cf66fb5d4a9b7ddb897590912 Mon Sep 17 00:00:00 2001\nFrom: Andreas Schwab <schwab@suse.de>\nDate: Thu, 19 Feb 2015 15:52:08 +0100\nSubject: [PATCH] Simplify handling of nameserver configuration in resolver\n\n\t[BZ #13028]\n\t[BZ #17053]\n\t* resolv/res_init.c (__res_vinit): Remove use of ext.nsmap.\n\t* resolv/res_send.c (__libc_res_nsend): Likewise.\n\t(get_nsaddr): New function.\n\t(res_ourserver_p, send_vc, reopen): Use it instead of accessing\n\tstatp directly.\n---\n resolv/res_init.c | 47 +++++-----------\n resolv/res_send.c | 164 +++++++++++++++++++++++-------------------------------\n 2 files changed, 84 insertions(+), 127 deletions(-)\n\nIndex: glibc-2.19/resolv/res_init.c\n===================================================================\n--- glibc-2.19.orig/resolv/res_init.c\n+++ glibc-2.19/resolv/res_init.c\n@@ -153,10 +153,8 @@ __res_vinit(res_state statp, int preinit\n \tchar *cp, **pp;\n \tint n;\n \tchar buf[BUFSIZ];\n-\tint nserv = 0; /* number of nameserver records read from file */\n-#ifdef _LIBC\n-\tint nservall = 0; /* number of NS records read, nserv IPv4 only */\n-#endif\n+\tint nserv = 0; /* number of nameservers read from file */\n+\tint have_serv6 = 0;\n \tint haveenv = 0;\n \tint havesearch = 0;\n #ifdef RESOLVSORT\n@@ -184,15 +182,9 @@ __res_vinit(res_state statp, int preinit\n \tstatp->_flags = 0;\n \tstatp->qhook = NULL;\n \tstatp->rhook = NULL;\n-\tstatp->_u._ext.nsinit = 0;\n \tstatp->_u._ext.nscount = 0;\n-#ifdef _LIBC\n-\tstatp->_u._ext.nscount6 = 0;\n-\tfor (n = 0; n < MAXNS; n++) {\n-\t\tstatp->_u._ext.nsaddrs[n] = NULL;\n-\t\tstatp->_u._ext.nsmap[n] = MAXNS;\n-\t}\n-#endif\n+\tfor (n = 0; n < MAXNS; n++)\n+\t statp->_u._ext.nsaddrs[n] = NULL;\n \n \t/* Allow user to override the local domain definition */\n \tif ((cp = getenv(\"LOCALDOMAIN\")) != NULL) {\n@@ -296,11 +288,7 @@ __res_vinit(res_state statp, int preinit\n \t\t continue;\n \t\t}\n \t\t/* read nameservers to query */\n-#ifdef _LIBC\n-\t\tif (MATCH(buf, \"nameserver\") && nservall < MAXNS) {\n-#else\n \t\tif (MATCH(buf, \"nameserver\") && nserv < MAXNS) {\n-#endif\n \t\t struct in_addr a;\n \n \t\t cp = buf + sizeof(\"nameserver\") - 1;\n@@ -308,13 +296,12 @@ __res_vinit(res_state statp, int preinit\n \t\t\tcp++;\n \t\t if ((*cp != '\\0') && (*cp != '\\n')\n \t\t\t&& __inet_aton(cp, &a)) {\n-\t\t\tstatp->nsaddr_list[nservall].sin_addr = a;\n-\t\t\tstatp->nsaddr_list[nservall].sin_family = AF_INET;\n-\t\t\tstatp->nsaddr_list[nservall].sin_port =\n+\t\t\tstatp->nsaddr_list[nserv].sin_addr = a;\n+\t\t\tstatp->nsaddr_list[nserv].sin_family = AF_INET;\n+\t\t\tstatp->nsaddr_list[nserv].sin_port =\n \t\t\t\thtons(NAMESERVER_PORT);\n \t\t\tnserv++;\n #ifdef _LIBC\n-\t\t\tnservall++;\n \t\t } else {\n \t\t\tstruct in6_addr a6;\n \t\t\tchar *el;\n@@ -356,10 +343,11 @@ __res_vinit(res_state statp, int preinit\n \t\t\t\t }\n \t\t\t\t}\n \n-\t\t\t\tstatp->_u._ext.nsaddrs[nservall] = sa6;\n-\t\t\t\tstatp->_u._ext.nssocks[nservall] = -1;\n-\t\t\t\tstatp->_u._ext.nsmap[nservall] = MAXNS + 1;\n-\t\t\t\tnservall++;\n+\t\t\t\tstatp->nsaddr_list[nserv].sin_family = 0;\n+\t\t\t\tstatp->_u._ext.nsaddrs[nserv] = sa6;\n+\t\t\t\tstatp->_u._ext.nssocks[nserv] = -1;\n+\t\t\t\thave_serv6 = 1;\n+\t\t\t\tnserv++;\n \t\t\t }\n \t\t\t}\n #endif\n@@ -414,10 +402,9 @@ __res_vinit(res_state statp, int preinit\n \t\t continue;\n \t\t}\n \t }\n-\t statp->nscount = nservall;\n+\t statp->nscount = nserv;\n #ifdef _LIBC\n-\t if (nservall - nserv > 0) {\n-\t\tstatp->_u._ext.nscount6 = nservall - nserv;\n+\t if (have_serv6) {\n \t\t/* We try IPv6 servers again. */\n \t\tstatp->ipv6_unavail = false;\n \t }\n@@ -606,11 +593,7 @@ __res_iclose(res_state statp, bool free_\n \t\tstatp->_vcsock = -1;\n \t\tstatp->_flags &= ~(RES_F_VC | RES_F_CONN);\n \t}\n-#ifdef _LIBC\n-\tfor (ns = 0; ns < MAXNS; ns++)\n-#else\n \tfor (ns = 0; ns < statp->_u._ext.nscount; ns++)\n-#endif\n \t\tif (statp->_u._ext.nsaddrs[ns]) {\n \t\t\tif (statp->_u._ext.nssocks[ns] != -1) {\n \t\t\t\tclose_not_cancel_no_status(statp->_u._ext.nssocks[ns]);\n@@ -621,7 +604,6 @@ __res_iclose(res_state statp, bool free_\n \t\t\t\tstatp->_u._ext.nsaddrs[ns] = NULL;\n \t\t\t}\n \t\t}\n-\tstatp->_u._ext.nsinit = 0;\n }\n libc_hidden_def (__res_iclose)\n \nIndex: glibc-2.19/resolv/res_send.c\n===================================================================\n--- glibc-2.19.orig/resolv/res_send.c\n+++ glibc-2.19/resolv/res_send.c\n@@ -183,6 +183,7 @@ evNowTime(struct timespec *res) {\n \n /* Forward. */\n \n+static struct sockaddr *get_nsaddr (res_state, int);\n static int\t\tsend_vc(res_state, const u_char *, int,\n \t\t\t\tconst u_char *, int,\n \t\t\t\tu_char **, int *, int *, int, u_char **,\n@@ -220,20 +221,21 @@ res_ourserver_p(const res_state statp, c\n \t in_port_t port = in4p->sin_port;\n \t in_addr_t addr = in4p->sin_addr.s_addr;\n \n-\t for (ns = 0; ns < MAXNS; ns++) {\n+\t for (ns = 0; ns < statp->nscount; ns++) {\n \t\tconst struct sockaddr_in *srv =\n-\t\t (struct sockaddr_in *)EXT(statp).nsaddrs[ns];\n+\t\t (struct sockaddr_in *) get_nsaddr (statp, ns);\n \n-\t\tif ((srv != NULL) && (srv->sin_family == AF_INET) &&\n+\t\tif ((srv->sin_family == AF_INET) &&\n \t\t (srv->sin_port == port) &&\n \t\t (srv->sin_addr.s_addr == INADDR_ANY ||\n \t\t srv->sin_addr.s_addr == addr))\n \t\t return (1);\n \t }\n \t} else if (inp->sin6_family == AF_INET6) {\n-\t for (ns = 0; ns < MAXNS; ns++) {\n-\t\tconst struct sockaddr_in6 *srv = EXT(statp).nsaddrs[ns];\n-\t\tif ((srv != NULL) && (srv->sin6_family == AF_INET6) &&\n+\t for (ns = 0; ns < statp->nscount; ns++) {\n+\t\tconst struct sockaddr_in6 *srv\n+\t\t = (struct sockaddr_in6 *) get_nsaddr (statp, ns);\n+\t\tif ((srv->sin6_family == AF_INET6) &&\n \t\t (srv->sin6_port == inp->sin6_port) &&\n \t\t !(memcmp(&srv->sin6_addr, &in6addr_any,\n \t\t\t sizeof (struct in6_addr)) &&\n@@ -383,74 +385,48 @@ __libc_res_nsend(res_state statp, const\n \t * If the ns_addr_list in the resolver context has changed, then\n \t * invalidate our cached copy and the associated timing data.\n \t */\n-\tif (EXT(statp).nsinit) {\n+\tif (EXT(statp).nscount != 0) {\n \t\tint needclose = 0;\n \n \t\tif (EXT(statp).nscount != statp->nscount)\n \t\t\tneedclose++;\n \t\telse\n-\t\t\tfor (ns = 0; ns < MAXNS; ns++) {\n-\t\t\t\tunsigned int map = EXT(statp).nsmap[ns];\n-\t\t\t\tif (map < MAXNS\n+\t\t\tfor (ns = 0; ns < statp->nscount; ns++) {\n+\t\t\t\tif (statp->nsaddr_list[ns].sin_family != 0\n \t\t\t\t && !sock_eq((struct sockaddr_in6 *)\n-\t\t\t\t\t\t&statp->nsaddr_list[map],\n+\t\t\t\t\t\t&statp->nsaddr_list[ns],\n \t\t\t\t\t\tEXT(statp).nsaddrs[ns]))\n \t\t\t\t{\n \t\t\t\t\tneedclose++;\n \t\t\t\t\tbreak;\n \t\t\t\t}\n \t\t\t}\n-\t\tif (needclose)\n+\t\tif (needclose) {\n \t\t\t__res_iclose(statp, false);\n+\t\t\tEXT(statp).nscount = 0;\n+\t\t}\n \t}\n \n \t/*\n \t * Maybe initialize our private copy of the ns_addr_list.\n \t */\n-\tif (EXT(statp).nsinit == 0) {\n-\t\tunsigned char map[MAXNS];\n-\n-\t\tmemset (map, MAXNS, sizeof (map));\n-\t\tfor (n = 0; n < MAXNS; n++) {\n-\t\t\tns = EXT(statp).nsmap[n];\n-\t\t\tif (ns < statp->nscount)\n-\t\t\t\tmap[ns] = n;\n-\t\t\telse if (ns < MAXNS) {\n-\t\t\t\tfree(EXT(statp).nsaddrs[n]);\n-\t\t\t\tEXT(statp).nsaddrs[n] = NULL;\n-\t\t\t\tEXT(statp).nsmap[n] = MAXNS;\n-\t\t\t}\n-\t\t}\n-\t\tn = statp->nscount;\n-\t\tif (statp->nscount > EXT(statp).nscount)\n-\t\t\tfor (n = EXT(statp).nscount, ns = 0;\n-\t\t\t n < statp->nscount; n++) {\n-\t\t\t\twhile (ns < MAXNS\n-\t\t\t\t && EXT(statp).nsmap[ns] != MAXNS)\n-\t\t\t\t\tns++;\n-\t\t\t\tif (ns == MAXNS)\n-\t\t\t\t\tbreak;\n-\t\t\t\tEXT(statp).nsmap[ns] = n;\n-\t\t\t\tmap[n] = ns++;\n-\t\t\t}\n-\t\tEXT(statp).nscount = n;\n-\t\tfor (ns = 0; ns < EXT(statp).nscount; ns++) {\n-\t\t\tn = map[ns];\n-\t\t\tif (EXT(statp).nsaddrs[n] == NULL)\n-\t\t\t\tEXT(statp).nsaddrs[n] =\n+\tif (EXT(statp).nscount == 0) {\n+\t\tfor (ns = 0; ns < statp->nscount; ns++) {\n+\t\t\tEXT(statp).nssocks[ns] = -1;\n+\t\t\tif (statp->nsaddr_list[ns].sin_family == 0)\n+\t\t\t\tcontinue;\n+\t\t\tif (EXT(statp).nsaddrs[ns] == NULL)\n+\t\t\t\tEXT(statp).nsaddrs[ns] =\n \t\t\t\t malloc(sizeof (struct sockaddr_in6));\n-\t\t\tif (EXT(statp).nsaddrs[n] != NULL) {\n-\t\t\t\tmemset (mempcpy(EXT(statp).nsaddrs[n],\n+\t\t\tif (EXT(statp).nsaddrs[ns] != NULL)\n+\t\t\t\tmemset (mempcpy(EXT(statp).nsaddrs[ns],\n \t\t\t\t\t\t&statp->nsaddr_list[ns],\n \t\t\t\t\t\tsizeof (struct sockaddr_in)),\n \t\t\t\t\t'\\0',\n \t\t\t\t\tsizeof (struct sockaddr_in6)\n \t\t\t\t\t- sizeof (struct sockaddr_in));\n-\t\t\t\tEXT(statp).nssocks[n] = -1;\n-\t\t\t\tn++;\n-\t\t\t}\n \t\t}\n-\t\tEXT(statp).nsinit = 1;\n+\t\tEXT(statp).nscount = statp->nscount;\n \t}\n \n \t/*\n@@ -459,44 +435,37 @@ __libc_res_nsend(res_state statp, const\n \t */\n \tif (__builtin_expect ((statp->options & RES_ROTATE) != 0, 0) &&\n \t (statp->options & RES_BLAST) == 0) {\n-\t\tstruct sockaddr_in6 *ina;\n-\t\tunsigned int map;\n-\n-\t\tn = 0;\n-\t\twhile (n < MAXNS && EXT(statp).nsmap[n] == MAXNS)\n-\t\t\tn++;\n-\t\tif (n < MAXNS) {\n-\t\t\tina = EXT(statp).nsaddrs[n];\n-\t\t\tmap = EXT(statp).nsmap[n];\n-\t\t\tfor (;;) {\n-\t\t\t\tns = n + 1;\n-\t\t\t\twhile (ns < MAXNS\n-\t\t\t\t && EXT(statp).nsmap[ns] == MAXNS)\n-\t\t\t\t\tns++;\n-\t\t\t\tif (ns == MAXNS)\n-\t\t\t\t\tbreak;\n-\t\t\t\tEXT(statp).nsaddrs[n] = EXT(statp).nsaddrs[ns];\n-\t\t\t\tEXT(statp).nsmap[n] = EXT(statp).nsmap[ns];\n-\t\t\t\tn = ns;\n-\t\t\t}\n-\t\t\tEXT(statp).nsaddrs[n] = ina;\n-\t\t\tEXT(statp).nsmap[n] = map;\n-\t\t}\n+\t\tstruct sockaddr_in ina;\n+\t\tstruct sockaddr_in6 *inp;\n+\t\tint lastns = statp->nscount - 1;\n+\t\tint fd;\n+\n+\t\tinp = EXT(statp).nsaddrs[0];\n+\t\tina = statp->nsaddr_list[0];\n+\t\tfd = EXT(statp).nssocks[0];\n+\t\tfor (ns = 0; ns < lastns; ns++) {\n+\t\t EXT(statp).nsaddrs[ns] = EXT(statp).nsaddrs[ns + 1];\n+\t\t statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1];\n+\t\t EXT(statp).nssocks[ns] = EXT(statp).nssocks[ns + 1];\n+\t\t}\n+\t\tEXT(statp).nsaddrs[lastns] = inp;\n+\t\tstatp->nsaddr_list[lastns] = ina;\n+\t\tEXT(statp).nssocks[lastns] = fd;\n \t}\n \n \t/*\n \t * Send request, RETRY times, or until successful.\n \t */\n \tfor (try = 0; try < statp->retry; try++) {\n-\t for (ns = 0; ns < MAXNS; ns++)\n+\t for (ns = 0; ns < statp->nscount; ns++)\n \t {\n #ifdef DEBUG\n \t\tchar tmpbuf[40];\n #endif\n-\t\tstruct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns];\n+#if defined USE_HOOKS || defined DEBUG\n+\t\tstruct sockaddr *nsap = get_nsaddr (statp, ns);\n+#endif\n \n-\t\tif (nsap == NULL)\n-\t\t\tgoto next_ns;\n \t same_ns:\n #ifdef USE_HOOKS\n \t\tif (__builtin_expect (statp->qhook != NULL, 0)) {\n@@ -535,9 +504,9 @@ __libc_res_nsend(res_state statp, const\n \n \t\tDprint(statp->options & RES_DEBUG,\n \t\t (stdout, \";; Querying server (# %d) address = %s\\n\",\n-\t\t\tns + 1, inet_ntop(nsap->sin6_family,\n-\t\t\t\t\t (nsap->sin6_family == AF_INET6\n-\t\t\t\t\t ? &nsap->sin6_addr\n+\t\t\tns + 1, inet_ntop(nsap->sa_family,\n+\t\t\t\t\t (nsap->sa_family == AF_INET6\n+\t\t\t\t\t ? &((struct sockaddr_in6 *) nsap)->sin6_addr\n \t\t\t\t\t : &((struct sockaddr_in *) nsap)->sin_addr),\n \t\t\t\t\t tmpbuf, sizeof (tmpbuf))));\n \n@@ -653,6 +622,21 @@ libresolv_hidden_def (res_nsend)\n \n /* Private */\n \n+static struct sockaddr *\n+get_nsaddr (res_state statp, int n)\n+{\n+\n+ if (statp->nsaddr_list[n].sin_family == 0 && EXT(statp).nsaddrs[n] != NULL)\n+ /* EXT(statp).nsaddrs[n] holds an address that is larger than\n+ struct sockaddr, and user code did not update\n+ statp->nsaddr_list[n]. */\n+ return (struct sockaddr *) EXT(statp).nsaddrs[n];\n+ else\n+ /* User code updated statp->nsaddr_list[n], or statp->nsaddr_list[n]\n+ has the same content as EXT(statp).nsaddrs[n]. */\n+ return (struct sockaddr *) (void *) &statp->nsaddr_list[n];\n+}\n+\n static int\n send_vc(res_state statp,\n \tconst u_char *buf, int buflen, const u_char *buf2, int buflen2,\n@@ -667,7 +651,7 @@ send_vc(res_state statp,\n \t// XXX REMOVE\n \t// int anssiz = *anssizp;\n \tHEADER *anhp = (HEADER *) ans;\n-\tstruct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns];\n+\tstruct sockaddr *nsap = get_nsaddr (statp, ns);\n \tint truncating, connreset, resplen, n;\n \tstruct iovec iov[4];\n \tu_short len;\n@@ -687,8 +671,8 @@ send_vc(res_state statp,\n \n \t\tif (getpeername(statp->_vcsock,\n \t\t\t\t(struct sockaddr *)&peer, &size) < 0 ||\n-\t\t !sock_eq(&peer, nsap)) {\n-\t\t __res_iclose(statp, false);\n+\t\t !sock_eq(&peer, (struct sockaddr_in6 *) nsap)) {\n+\t\t\t__res_iclose(statp, false);\n \t\t\tstatp->_flags &= ~RES_F_VC;\n \t\t}\n \t}\n@@ -697,20 +681,19 @@ send_vc(res_state statp,\n \t\tif (statp->_vcsock >= 0)\n \t\t __res_iclose(statp, false);\n \n-\t\tstatp->_vcsock = socket(nsap->sin6_family, SOCK_STREAM, 0);\n+\t\tstatp->_vcsock = socket(nsap->sa_family, SOCK_STREAM, 0);\n \t\tif (statp->_vcsock < 0) {\n \t\t\t*terrno = errno;\n \t\t\tPerror(statp, stderr, \"socket(vc)\", errno);\n \t\t\treturn (-1);\n \t\t}\n \t\t__set_errno (0);\n-\t\tif (connect(statp->_vcsock, (struct sockaddr *)nsap,\n-\t\t\t nsap->sin6_family == AF_INET\n+\t\tif (connect(statp->_vcsock, nsap,\n+\t\t\t nsap->sa_family == AF_INET\n \t\t\t ? sizeof (struct sockaddr_in)\n \t\t\t : sizeof (struct sockaddr_in6)) < 0) {\n \t\t\t*terrno = errno;\n-\t\t\tAerror(statp, stderr, \"connect/vc\", errno,\n-\t\t\t (struct sockaddr *) nsap);\n+\t\t\tAerror(statp, stderr, \"connect/vc\", errno, nsap);\n \t\t\t__res_iclose(statp, false);\n \t\t\treturn (0);\n \t\t}\n@@ -914,8 +897,7 @@ static int\n reopen (res_state statp, int *terrno, int ns)\n {\n \tif (EXT(statp).nssocks[ns] == -1) {\n-\t\tstruct sockaddr *nsap\n-\t\t = (struct sockaddr *) EXT(statp).nsaddrs[ns];\n+\t\tstruct sockaddr *nsap = get_nsaddr (statp, ns);\n \t\tsocklen_t slen;\n \n \t\t/* only try IPv6 if IPv6 NS and if not failed before */" } ]
{ "id": "glibc-testsuite-5322-resolv-nameserver-handling.pat", "cve_id": "CVE-2016-3706", "package": "glibc-testsuite", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 2168, "context_files": 2 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2008-4311\n\nThe default configuration of system.conf in D-Bus (aka DBus) before 1.2.6 omits the send_type attribute in certain rules, which allows local users to bypass intended access restrictions by (1) sending messages, related to send_requested_reply; and possibly (2) receiving messages, related to receive_requested_reply.\n\n## Package\ndbus-1\n\n## Files to modify\n- dbus-1.4.1.orig/bus/bus.c\n- dbus/dbus-sysdeps.h\n- dbus-1.4.1.orig/dbus/dbus-sysdeps.h\n- dbus/dbus-sysdeps-util-unix.c\n- dbus-1.4.1.orig/dbus/dbus-sysdeps-util-unix.c\n\n## Upstream Fix\n```diff\nIndex: dbus-1.4.1/bus/bus.c\n===================================================================\n--- dbus-1.4.1.orig/bus/bus.c\n+++ dbus-1.4.1/bus/bus.c\n@@ -636,6 +636,24 @@ oom:\n return FALSE;\n }\n \n+static void\n+raise_file_descriptor_limit (BusContext *context)\n+{\n+\n+ /* I just picked this out of thin air; we need some extra\n+ * descriptors for things like any internal pipes we create,\n+ * inotify, connections to SELinux, etc.\n+ */\n+ unsigned int arbitrary_extra_fds = 32;\n+ unsigned int limit;\n+\n+ limit = context->limits.max_completed_connections +\n+ context->limits.max_incomplete_connections\n+ + arbitrary_extra_fds;\n+\n+ _dbus_request_file_descriptor_limit (limit);\n+}\n+\n static dbus_bool_t\n process_config_postinit (BusContext *context,\n \t\t\t BusConfigParser *parser,\n@@ -644,6 +662,8 @@ process_config_postinit (BusContext\n DBusHashTable *service_context_table;\n DBusList *watched_dirs = NULL;\n \n+ raise_file_descriptor_limit (context);\n+\n service_context_table = bus_config_parser_steal_service_context_table (parser);\n if (!bus_registry_set_service_context_table (context->registry,\n \t\t\t\t\t service_context_table))\nIndex: dbus-1.4.1/configure.in\n===================================================================\n--- dbus-1.4.1.orig/configure.in\n+++ dbus-1.4.1/configure.in\n@@ -534,6 +534,8 @@ fi\n \n AC_CHECK_HEADERS(dirent.h)\n \n+AC_CHECK_HEADERS(sys/resource.h)\n+\n AC_CHECK_HEADERS(execinfo.h, [AC_CHECK_FUNCS(backtrace)])\n \n AC_CHECK_HEADERS(errno.h)\nIndex: dbus-1.4.1/dbus/dbus-sysdeps.h\n===================================================================\n--- dbus-1.4.1.orig/dbus/dbus-sysdeps.h\n+++ dbus-1.4.1/dbus/dbus-sysdeps.h\n@@ -527,6 +527,8 @@ void _dbus_flush_caches (void);\n const char *\n _dbus_replace_install_prefix (const char *configure_time_path);\n \n+void _dbus_request_file_descriptor_limit (unsigned int limit);\n+\n /** @} */\n \n DBUS_END_DECLS\nIndex: dbus-1.4.1/dbus/dbus-sysdeps-util-unix.c\n===================================================================\n--- dbus-1.4.1.orig/dbus/dbus-sysdeps-util-unix.c\n+++ dbus-1.4.1/dbus/dbus-sysdeps-util-unix.c\n@@ -42,6 +42,9 @@\n #include <errno.h>\n #include <fcntl.h>\n #include <sys/stat.h>\n+#ifdef HAVE_SYS_RESOURCE_H\n+#include <sys/resource.h>\n+#endif\n #include <grp.h>\n #include <sys/socket.h>\n #include <dirent.h>\n@@ -369,6 +372,56 @@ _dbus_change_to_daemon_user (const char\n }\n #endif /* !HAVE_LIBAUDIT */\n \n+\n+/**\n+ * Attempt to ensure that the current process can open\n+ * at least @limit file descriptors.\n+ *\n+ * If @limit is lower than the current, it will not be\n+ * lowered. No error is returned if the request can\n+ * not be satisfied.\n+ *\n+ * @limit Number of file descriptors\n+ */\n+void\n+_dbus_request_file_descriptor_limit (unsigned int limit)\n+{\n+#ifdef HAVE_SETRLIMIT\n+ struct rlimit lim;\n+ struct rlimit target_lim;\n+ unsigned int current_limit;\n+\n+ /* No point to doing this practically speaking\n+ * if we're not uid 0. We expect the system\n+ * bus to use this before we change UID, and\n+ * the session bus takes the Linux default\n+ * of 1024 for both cur and max.\n+ */\n+ if (getuid () != 0)\n+ return;\n+\n+ if (getrlimit (RLIMIT_NOFILE, &lim) < 0)\n+ return;\n+\n+ if (lim.rlim_cur >= limit)\n+ return;\n+\n+ /* Ignore \"maximum limit\", assume we have the \"superuser\"\n+ * privileges. On Linux this is CAP_SYS_RESOURCE.\n+ */\n+ target_lim.rlim_cur = target_lim.rlim_max = limit;\n+ /* Also ignore errors; if we fail, we will at least work\n+ * up to whatever limit we had, which seems better than\n+ * just outright aborting.\n+ *\n+ * However, in the future we should probably log this so OS builders\n+ * have a chance to notice any misconfiguration like dbus-daemon\n+ * being started without CAP_SYS_RESOURCE.\n+ */\n+ setrlimit (RLIMIT_NOFILE, &target_lim);\n+#endif\n+}\n+\n void \n _dbus_init_system_log (void)\n {\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "Index: dbus-1.4.1/bus/bus.c\n===================================================================\n--- dbus-1.4.1.orig/bus/bus.c\n+++ dbus-1.4.1/bus/bus.c\n@@ -636,6 +636,24 @@ oom:\n return FALSE;\n }\n \n+static void\n+raise_file_descriptor_limit (BusContext *context)\n+{\n+\n+ /* I just picked this out of thin air; we need some extra\n+ * descriptors for things like any internal pipes we create,\n+ * inotify, connections to SELinux, etc.\n+ */\n+ unsigned int arbitrary_extra_fds = 32;\n+ unsigned int limit;\n+\n+ limit = context->limits.max_completed_connections +\n+ context->limits.max_incomplete_connections\n+ + arbitrary_extra_fds;\n+\n+ _dbus_request_file_descriptor_limit (limit);\n+}\n+\n static dbus_bool_t\n process_config_postinit (BusContext *context,\n \t\t\t BusConfigParser *parser,\n@@ -644,6 +662,8 @@ process_config_postinit (BusContext\n DBusHashTable *service_context_table;\n DBusList *watched_dirs = NULL;\n \n+ raise_file_descriptor_limit (context);\n+\n service_context_table = bus_config_parser_steal_service_context_table (parser);\n if (!bus_registry_set_service_context_table (context->registry,\n \t\t\t\t\t service_context_table))\nIndex: dbus-1.4.1/configure.in\n===================================================================\n--- dbus-1.4.1.orig/configure.in\n+++ dbus-1.4.1/configure.in\n@@ -534,6 +534,8 @@ fi\n \n AC_CHECK_HEADERS(dirent.h)\n \n+AC_CHECK_HEADERS(sys/resource.h)\n+\n AC_CHECK_HEADERS(execinfo.h, [AC_CHECK_FUNCS(backtrace)])\n \n AC_CHECK_HEADERS(errno.h)\nIndex: dbus-1.4.1/dbus/dbus-sysdeps.h\n===================================================================\n--- dbus-1.4.1.orig/dbus/dbus-sysdeps.h\n+++ dbus-1.4.1/dbus/dbus-sysdeps.h\n@@ -527,6 +527,8 @@ void _dbus_flush_caches (void);\n const char *\n _dbus_replace_install_prefix (const char *configure_time_path);\n \n+void _dbus_request_file_descriptor_limit (unsigned int limit);\n+\n /** @} */\n \n DBUS_END_DECLS\nIndex: dbus-1.4.1/dbus/dbus-sysdeps-util-unix.c\n===================================================================\n--- dbus-1.4.1.orig/dbus/dbus-sysdeps-util-unix.c\n+++ dbus-1.4.1/dbus/dbus-sysdeps-util-unix.c\n@@ -42,6 +42,9 @@\n #include <errno.h>\n #include <fcntl.h>\n #include <sys/stat.h>\n+#ifdef HAVE_SYS_RESOURCE_H\n+#include <sys/resource.h>\n+#endif\n #include <grp.h>\n #include <sys/socket.h>\n #include <dirent.h>\n@@ -369,6 +372,56 @@ _dbus_change_to_daemon_user (const char\n }\n #endif /* !HAVE_LIBAUDIT */\n \n+\n+/**\n+ * Attempt to ensure that the current process can open\n+ * at least @limit file descriptors.\n+ *\n+ * If @limit is lower than the current, it will not be\n+ * lowered. No error is returned if the request can\n+ * not be satisfied.\n+ *\n+ * @limit Number of file descriptors\n+ */\n+void\n+_dbus_request_file_descriptor_limit (unsigned int limit)\n+{\n+#ifdef HAVE_SETRLIMIT\n+ struct rlimit lim;\n+ struct rlimit target_lim;\n+ unsigned int current_limit;\n+\n+ /* No point to doing this practically speaking\n+ * if we're not uid 0. We expect the system\n+ * bus to use this before we change UID, and\n+ * the session bus takes the Linux default\n+ * of 1024 for both cur and max.\n+ */\n+ if (getuid () != 0)\n+ return;\n+\n+ if (getrlimit (RLIMIT_NOFILE, &lim) < 0)\n+ return;\n+\n+ if (lim.rlim_cur >= limit)\n+ return;\n+\n+ /* Ignore \"maximum limit\", assume we have the \"superuser\"\n+ * privileges. On Linux this is CAP_SYS_RESOURCE.\n+ */\n+ target_lim.rlim_cur = target_lim.rlim_max = limit;\n+ /* Also ignore errors; if we fail, we will at least work\n+ * up to whatever limit we had, which seems better than\n+ * just outright aborting.\n+ *\n+ * However, in the future we should probably log this so OS builders\n+ * have a chance to notice any misconfiguration like dbus-daemon\n+ * being started without CAP_SYS_RESOURCE.\n+ */\n+ setrlimit (RLIMIT_NOFILE, &target_lim);\n+#endif\n+}\n+\n void \n _dbus_init_system_log (void)\n {" } ]
{ "id": "dbus-1-1001-dbus-1.2.10-fd-limit-backport.", "cve_id": "CVE-2008-4311", "package": "dbus-1", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": false, "license": "AFL-2.1 OR GPL-2.0-or-later", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2013-7345\n\nThe BEGIN regular expression in the awk script detector in magic/Magdir/commands in file before 5.15 uses multiple wildcards with unlimited repetitions, which allows context-dependent attackers to cause a denial of service (CPU consumption) via a crafted ASCII file that triggers a large amount of backtracking, as demonstrated via a file with many newline characters.\n\n## Package\nfile\n\n## Files to modify\n- src/softmagic.c\n\n## Upstream Fix\n```diff\nFrom 70c65d2e1841491f59168db1f905e8b14083fb1c Mon Sep 17 00:00:00 2001\nFrom: Christos Zoulas <christos@zoulas.com>\nDate: Tue, 4 Mar 2014 17:42:19 +0000\nSubject: [PATCH] off by one in out of bounds calculations (Jan Kaluza)\n\n---\n src/softmagic.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/src/softmagic.c b/src/softmagic.c\nindex 170de95906..5ed3998e26 100644\n--- a/src/softmagic.c\n+++ b/src/softmagic.c\n@@ -32,7 +32,7 @@\n #include \"file.h\"\n \n #ifndef\tlint\n-FILE_RCSID(\"@(#)$File: softmagic.c,v 1.176 2014/02/18 17:59:21 kim Exp $\")\n+FILE_RCSID(\"@(#)$File: softmagic.c,v 1.177 2014/02/21 14:32:48 christos Exp $\")\n #endif\t/* lint */\n \n #include \"magic.h\"\n@@ -72,7 +72,7 @@ private void cvt_16(union VALUETYPE *, const struct magic *);\n private void cvt_32(union VALUETYPE *, const struct magic *);\n private void cvt_64(union VALUETYPE *, const struct magic *);\n \n-#define OFFSET_OOB(n, o, i)\t((n) < (o) || (i) >= ((n) - (o)))\n+#define OFFSET_OOB(n, o, i)\t((n) < (o) || (i) > ((n) - (o)))\n /*\n * softmagic - lookup one file in parsed, in-memory copy of database\n * Passed the name and FILE * of one file to be typed.\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 70c65d2e1841491f59168db1f905e8b14083fb1c Mon Sep 17 00:00:00 2001\nFrom: Christos Zoulas <christos@zoulas.com>\nDate: Tue, 4 Mar 2014 17:42:19 +0000\nSubject: [PATCH] off by one in out of bounds calculations (Jan Kaluza)\n\n---\n src/softmagic.c | 4 +-\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git src/softmagic.c src/softmagic.c\nindex 170de95..5ed3998 100644\n--- src/softmagic.c\n+++ src/softmagic.c\n@@ -72,7 +72,7 @@ private void cvt_16(union VALUETYPE *, const struct magic *);\n private void cvt_32(union VALUETYPE *, const struct magic *);\n private void cvt_64(union VALUETYPE *, const struct magic *);\n \n-#define OFFSET_OOB(n, o, i)\t((n) < (o) || (i) >= ((n) - (o)))\n+#define OFFSET_OOB(n, o, i)\t((n) < (o) || (i) > ((n) - (o)))\n /*\n * softmagic - lookup one file in parsed, in-memory copy of database\n * Passed the name and FILE * of one file to be typed.\n-- \n1.7.9.2" } ]
{ "id": "file-2688-0001-off-by-one-in-out-of-boun", "cve_id": "CVE-2013-7345", "package": "file", "upstream_enriched": true, "upstream_commit": "70c65d2e1841491f59168db1f905e8b14083fb1c", "upstream_repo": "file/file", "tier": "adapted", "has_source_context": false, "license": "BSD-2-Clause", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-3194\n\ncrypto/rsa/rsa_ameth.c in OpenSSL 1.0.1 before 1.0.1q and 1.0.2 before 1.0.2e allows remote attackers to cause a denial of service (NULL pointer dereference and application crash) via an RSA PSS ASN.1 signature that lacks a mask generation function parameter.\n\n## Package\nopenssl\n\n## Files to modify\n- crypto/bio/b_print.c\n\n## Target Source Code\n\n### crypto/bio/b_print.c\n\n#### region() [lines 17-114]\n```c\n * the code are not to be removed.\n * If this package is used in a product, Eric Young should be given attribution\n * as the author of the parts of the library used.\n * This can be in the form of a textual message at program startup or\n * in documentation (online or textual) provided with the package.\n * \n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions\n * are met:\n * 1. Redistributions of source code must retain the copyright\n * notice, this list of conditions and the following disclaimer.\n * 2. Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in the\n * documentation and/or other materials provided with the distribution.\n * 3. All advertising materials mentioning features or use of this software\n * must display the following acknowledgement:\n * \"This product includes cryptographic software written by\n * Eric Young (eay@cryptsoft.com)\"\n * The word 'cryptographic' can be left out if the rouines from the library\n * being used are not cryptographic related :-).\n * 4. If you include any Windows specific code (or a derivative thereof) from \n * the apps directory (application code) you must include an acknowledgement:\n * \"This product includes software written by Tim Hudson (tjh@cryptsoft.com)\"\n * \n * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n * SUCH DAMAGE.\n * \n * The licence and distribution terms for any publically available version or\n * derivative of this code cannot be changed. i.e. this code cannot simply be\n * copied and put under another distribution licence\n * [including the GNU Public Licence.]\n */\n\n/* disable assert() unless BIO_DEBUG has been defined */\n#ifndef BIO_DEBUG\n# ifndef NDEBUG\n# define NDEBUG\n# endif\n#endif\n\n/* \n * Stolen from tjh's ssl/ssl_trc.c stuff.\n */\n\n#include <stdio.h>\n#include <string.h>\n#include <ctype.h>\n#include <assert.h>\n#include <limits.h>\n#include \"cryptlib.h\"\n#ifndef NO_SYS_TYPES_H\n#include <sys/types.h>\n#endif\n#include <openssl/bn.h> /* To get BN_LLONG properly defined */\n#include <openssl/bio.h>\n\n#if defined(BN_LLONG) || defined(SIXTY_FOUR_BIT)\n# ifndef HAVE_LONG_LONG\n# define HAVE_LONG_LONG 1\n# endif\n#endif\n\n/***************************************************************************/\n\n/*\n * Copyright Patrick Powell 1995\n * This code is based on code written by Patrick Powell <papowell@astart.com>\n * It may be used for any purpose as long as this notice remains intact\n * on all source code distributions.\n */\n\n/*\n * This code contains numerious changes and enhancements which were\n * made by lots of contributors over the last years to Patrick Powell's\n * original code:\n *\n * o Patrick Powell <papowell@astart.com> (1995)\n * o Brandon Long <blong@fiction.net> (1996, for Mutt)\n * o Thomas Roessler <roessler@guug.de> (1998, for Mutt)\n * o Michael Elkins <me@cs.hmc.edu> (1998, for Mutt)\n * o Andrew Tridgell <tridge@samba.org> (1998, for Samba)\n * o Luke Mewburn <lukem@netbsd.org> (1999, for LukemFTP)\n * o Ralf S. Engelschall <rse@engelschall.com> (1999, for Pth)\n * o ... (for OpenSSL)\n */\n\n#ifdef HAVE_LONG_DOUBLE\n#define LDOUBLE long double\n#else\n```\n\n#### region() [lines 40-810]\n```c\n * \n * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n * SUCH DAMAGE.\n * \n * The licence and distribution terms for any publically available version or\n * derivative of this code cannot be changed. i.e. this code cannot simply be\n * copied and put under another distribution licence\n * [including the GNU Public Licence.]\n */\n\n/* disable assert() unless BIO_DEBUG has been defined */\n#ifndef BIO_DEBUG\n# ifndef NDEBUG\n# define NDEBUG\n# endif\n#endif\n\n/* \n * Stolen from tjh's ssl/ssl_trc.c stuff.\n */\n\n#include <stdio.h>\n#include <string.h>\n#include <ctype.h>\n#include <assert.h>\n#include <limits.h>\n#include \"cryptlib.h\"\n#ifndef NO_SYS_TYPES_H\n#include <sys/types.h>\n#endif\n#include <openssl/bn.h> /* To get BN_LLONG properly defined */\n#include <openssl/bio.h>\n\n#if defined(BN_LLONG) || defined(SIXTY_FOUR_BIT)\n# ifndef HAVE_LONG_LONG\n# define HAVE_LONG_LONG 1\n# endif\n#endif\n\n/***************************************************************************/\n\n/*\n * Copyright Patrick Powell 1995\n * This code is based on code written by Patrick Powell <papowell@astart.com>\n * It may be used for any purpose as long as this notice remains intact\n * on all source code distributions.\n */\n\n/*\n * This code contains numerious changes and enhancements which were\n * made by lots of contributors over the last years to Patrick Powell's\n * original code:\n *\n * o Patrick Powell <papowell@astart.com> (1995)\n * o Brandon Long <blong@fiction.net> (1996, for Mutt)\n * o Thomas Roessler <roessler@guug.de> (1998, for Mutt)\n * o Michael Elkins <me@cs.hmc.edu> (1998, for Mutt)\n * o Andrew Tridgell <tridge@samba.org> (1998, for Samba)\n * o Luke Mewburn <lukem@netbsd.org> (1999, for LukemFTP)\n * o Ralf S. Engelschall <rse@engelschall.com> (1999, for Pth)\n * o ... (for OpenSSL)\n */\n\n#ifdef HAVE_LONG_DOUBLE\n#define LDOUBLE long double\n#else\n#define LDOUBLE double\n#endif\n\n#ifdef HAVE_LONG_LONG\n# if defined(_WIN32) && !defined(__GNUC__)\n# define LLONG __int64\n# else\n# define LLONG long long\n# endif\n#else\n#define LLONG long\n#endif\n\nstatic void fmtstr (char **, char **, size_t *, size_t *,\n\t\t\tconst char *, int, int, int);\nstatic void fmtint (char **, char **, size_t *, size_t *,\n\t\t\tLLONG, int, int, int, int);\nstatic void fmtfp (char **, char **, size_t *, size_t *,\n\t\t\tLDOUBLE, int, int, int);\nstatic void doapr_outch (char **, char **, size_t *, size_t *, int);\nstatic void _dopr(char **sbuffer, char **buffer,\n\t\t size_t *maxlen, size_t *retlen, int *truncated,\n\t\t const char *format, va_list args);\n\n/* format read states */\n#define DP_S_DEFAULT 0\n#define DP_S_FLAGS 1\n#define DP_S_MIN 2\n#define DP_S_DOT 3\n#define DP_S_MAX 4\n#define DP_S_MOD 5\n#define DP_S_CONV 6\n#define DP_S_DONE 7\n\n/* format flags - Bits */\n#define DP_F_MINUS (1 << 0)\n#define DP_F_PLUS (1 << 1)\n#define DP_F_SPACE (1 << 2)\n#define DP_F_NUM (1 << 3)\n#define DP_F_ZERO (1 << 4)\n#define DP_F_UP (1 << 5)\n#define DP_F_UNSIGNED (1 << 6)\n\n/* conversion flags */\n#define DP_C_SHORT 1\n#define DP_C_LONG 2\n#define DP_C_LDOUBLE 3\n#define DP_C_LLONG 4\n\n/* some handy macros */\n#define char_to_int(p) (p - '0')\n#define OSSL_MAX(p,q) ((p >= q) ? p : q)\n\nstatic void\n_dopr(\n char **sbuffer,\n char **buffer,\n size_t *maxlen,\n size_t *retlen,\n int *truncated,\n const char *format,\n va_list args)\n{\n char ch;\n LLONG value;\n LDOUBLE fvalue;\n char *strvalue;\n int min;\n int max;\n int state;\n int flags;\n int cflags;\n size_t currlen;\n\n state = DP_S_DEFAULT;\n flags = currlen = cflags = min = 0;\n max = -1;\n ch = *format++;\n\n while (state != DP_S_DONE) {\n if (ch == '\\0' || (buffer == NULL && currlen >= *maxlen))\n state = DP_S_DONE;\n\n switch (state) {\n case DP_S_DEFAULT:\n if (ch == '%')\n state = DP_S_FLAGS;\n else\n doapr_outch(sbuffer,buffer, &currlen, maxlen, ch);\n ch = *format++;\n break;\n case DP_S_FLAGS:\n switch (ch) {\n case '-':\n flags |= DP_F_MINUS;\n ch = *format++;\n break;\n case '+':\n flags |= DP_F_PLUS;\n ch = *format++;\n break;\n case ' ':\n flags |= DP_F_SPACE;\n ch = *format++;\n break;\n case '#':\n flags |= DP_F_NUM;\n ch = *format++;\n break;\n case '0':\n flags |= DP_F_ZERO;\n ch = *format++;\n break;\n default:\n state = DP_S_MIN;\n break;\n }\n break;\n case DP_S_MIN:\n if (isdigit((unsigned char)ch)) {\n min = 10 * min + char_to_int(ch);\n ch = *format++;\n } else if (ch == '*') {\n min = va_arg(args, int);\n ch = *format++;\n state = DP_S_DOT;\n } else\n state = DP_S_DOT;\n break;\n case DP_S_DOT:\n if (ch == '.') {\n state = DP_S_MAX;\n ch = *format++;\n } else\n state = DP_S_MOD;\n break;\n case DP_S_MAX:\n if (isdigit((unsigned char)ch)) {\n if (max < 0)\n max = 0;\n max = 10 * max + char_to_int(ch);\n ch = *format++;\n } else if (ch == '*') {\n max = va_arg(args, int);\n ch = *format++;\n state = DP_S_MOD;\n } else\n state = DP_S_MOD;\n break;\n case DP_S_MOD:\n switch (ch) {\n case 'h':\n cflags = DP_C_SHORT;\n ch = *format++;\n break;\n case 'l':\n if (*format == 'l') {\n cflags = DP_C_LLONG;\n format++;\n } else\n cflags = DP_C_LONG;\n ch = *format++;\n break;\n case 'q':\n cflags = DP_C_LLONG;\n ch = *format++;\n break;\n case 'L':\n cflags = DP_C_LDOUBLE;\n ch = *format++;\n break;\n default:\n break;\n }\n state = DP_S_CONV;\n break;\n case DP_S_CONV:\n switch (ch) {\n case 'd':\n case 'i':\n switch (cflags) {\n case DP_C_SHORT:\n value = (short int)va_arg(args, int);\n break;\n case DP_C_LONG:\n value = va_arg(args, long int);\n break;\n case DP_C_LLONG:\n value = va_arg(args, LLONG);\n break;\n default:\n value = va_arg(args, int);\n break;\n }\n fmtint(sbuffer, buffer, &currlen, maxlen,\n value, 10, min, max, flags);\n break;\n case 'X':\n flags |= DP_F_UP;\n /* FALLTHROUGH */\n case 'x':\n case 'o':\n case 'u':\n flags |= DP_F_UNSIGNED;\n switch (cflags) {\n case DP_C_SHORT:\n value = (unsigned short int)va_arg(args, unsigned int);\n break;\n case DP_C_LONG:\n value = (LLONG) va_arg(args,\n unsigned long int);\n break;\n case DP_C_LLONG:\n value = va_arg(args, unsigned LLONG);\n break;\n default:\n value = (LLONG) va_arg(args,\n unsigned int);\n break;\n }\n fmtint(sbuffer, buffer, &currlen, maxlen, value,\n ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),\n min, max, flags);\n break;\n case 'f':\n if (cflags == DP_C_LDOUBLE)\n fvalue = va_arg(args, LDOUBLE);\n else\n fvalue = va_arg(args, double);\n fmtfp(sbuffer, buffer, &currlen, maxlen,\n fvalue, min, max, flags);\n break;\n case 'E':\n flags |= DP_F_UP;\n case 'e':\n if (cflags == DP_C_LDOUBLE)\n fvalue = va_arg(args, LDOUBLE);\n else\n fvalue = va_arg(args, double);\n break;\n case 'G':\n flags |= DP_F_UP;\n case 'g':\n if (cflags == DP_C_LDOUBLE)\n fvalue = va_arg(args, LDOUBLE);\n else\n fvalue = va_arg(args, double);\n break;\n case 'c':\n doapr_outch(sbuffer, buffer, &currlen, maxlen,\n va_arg(args, int));\n break;\n case 's':\n strvalue = va_arg(args, char *);\n if (max < 0) {\n\t\t if (buffer)\n\t\t\tmax = INT_MAX;\n\t\t else\n\t\t\tmax = *maxlen;\n\t\t}\n fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,\n flags, min, max);\n break;\n case 'p':\n value = (long)va_arg(args, void *);\n fmtint(sbuffer, buffer, &currlen, maxlen,\n value, 16, min, max, flags|DP_F_NUM);\n break;\n case 'n': /* XXX */\n if (cflags == DP_C_SHORT) {\n short int *num;\n num = va_arg(args, short int *);\n *num = currlen;\n } else if (cflags == DP_C_LONG) { /* XXX */\n long int *num;\n num = va_arg(args, long int *);\n *num = (long int) currlen;\n } else if (cflags == DP_C_LLONG) { /* XXX */\n LLONG *num;\n num = va_arg(args, LLONG *);\n *num = (LLONG) currlen;\n } else {\n int *num;\n num = va_arg(args, int *);\n *num = currlen;\n }\n break;\n case '%':\n doapr_outch(sbuffer, buffer, &currlen, maxlen, ch);\n break;\n case 'w':\n /* not supported yet, treat as next char */\n ch = *format++;\n break;\n default:\n /* unknown, skip */\n break;\n }\n ch = *format++;\n state = DP_S_DEFAULT;\n flags = cflags = min = 0;\n max = -1;\n break;\n case DP_S_DONE:\n break;\n default:\n break;\n }\n }\n *truncated = (currlen > *maxlen - \n/* ... truncated ... */\n\n## Upstream Fix\n```diff\nFrom fd708c2242408187cff392e8b0850275ac99376f Mon Sep 17 00:00:00 2001\nFrom: =?UTF-8?q?Cristian=20Rodr=C3=ADguez?= <crrodriguez@opensuse.org>\nDate: Sun, 4 May 2014 23:36:54 -0400\nSubject: [PATCH] Axe builtin printf implementation, use glibc instead\n\n\ndiff --git a/crypto/bio/b_print.c b/crypto/bio/b_print.c\nindex 143a7cf..657beb7 100644\n--- a/crypto/bio/b_print.c\n+++ b/crypto/bio/b_print.c\n@@ -56,17 +56,9 @@\n * [including the GNU Public Licence.]\n */\n \n-/* disable assert() unless BIO_DEBUG has been defined */\n-#ifndef BIO_DEBUG\n-# ifndef NDEBUG\n-# define NDEBUG\n-# endif\n+#ifndef _GNU_SOURCE\n+#define _GNU_SOURCE\n #endif\n-\n-/* \n- * Stolen from tjh's ssl/ssl_trc.c stuff.\n- */\n-\n #include <stdio.h>\n #include <string.h>\n #include <ctype.h>\n@@ -79,690 +71,6 @@\n #include <openssl/bn.h> /* To get BN_LLONG properly defined */\n #include <openssl/bio.h>\n \n-#if defined(BN_LLONG) || defined(SIXTY_FOUR_BIT)\n-# ifndef HAVE_LONG_LONG\n-# define HAVE_LONG_LONG 1\n-# endif\n-#endif\n-\n-/***************************************************************************/\n-\n-/*\n- * Copyright Patrick Powell 1995\n- * This code is based on code written by Patrick Powell <papowell@astart.com>\n- * It may be used for any purpose as long as this notice remains intact\n- * on all source code distributions.\n- */\n-\n-/*\n- * This code contains numerious changes and enhancements which were\n- * made by lots of contributors over the last years to Patrick Powell's\n- * original code:\n- *\n- * o Patrick Powell <papowell@astart.com> (1995)\n- * o Brandon Long <blong@fiction.net> (1996, for Mutt)\n- * o Thomas Roessler <roessler@guug.de> (1998, for Mutt)\n- * o Michael Elkins <me@cs.hmc.edu> (1998, for Mutt)\n- * o Andrew Tridgell <tridge@samba.org> (1998, for Samba)\n- * o Luke Mewburn <lukem@netbsd.org> (1999, for LukemFTP)\n- * o Ralf S. Engelschall <rse@engelschall.com> (1999, for Pth)\n- * o ... (for OpenSSL)\n- */\n-\n-#ifdef HAVE_LONG_DOUBLE\n-#define LDOUBLE long double\n-#else\n-#define LDOUBLE double\n-#endif\n-\n-#ifdef HAVE_LONG_LONG\n-# if defined(_WIN32) && !defined(__GNUC__)\n-# define LLONG __int64\n-# else\n-# define LLONG long long\n-# endif\n-#else\n-#define LLONG long\n-#endif\n-\n-static void fmtstr (char **, char **, size_t *, size_t *,\n-\t\t\tconst char *, int, int, int);\n-static void fmtint (char **, char **, size_t *, size_t *,\n-\t\t\tLLONG, int, int, int, int);\n-static void fmtfp (char **, char **, size_t *, size_t *,\n-\t\t\tLDOUBLE, int, int, int);\n-static void doapr_outch (char **, char **, size_t *, size_t *, int);\n-static void _dopr(char **sbuffer, char **buffer,\n-\t\t size_t *maxlen, size_t *retlen, int *truncated,\n-\t\t const char *format, va_list args);\n-\n-/* format read states */\n-#define DP_S_DEFAULT 0\n-#define DP_S_FLAGS 1\n-#define DP_S_MIN 2\n-#define DP_S_DOT 3\n-#define DP_S_MAX 4\n-#define DP_S_MOD 5\n-#define DP_S_CONV 6\n-#define DP_S_DONE 7\n-\n-/* format flags - Bits */\n-#define DP_F_MINUS (1 << 0)\n-#define DP_F_PLUS (1 << 1)\n-#define DP_F_SPACE (1 << 2)\n-#define DP_F_NUM (1 << 3)\n-#define DP_F_ZERO (1 << 4)\n-#define DP_F_UP (1 << 5)\n-#define DP_F_UNSIGNED (1 << 6)\n-\n-/* conversion flags */\n-#define DP_C_SHORT 1\n-#define DP_C_LONG 2\n-#define DP_C_LDOUBLE 3\n-#define DP_C_LLONG 4\n-\n-/* some handy macros */\n-#define char_to_int(p) (p - '0')\n-#define OSSL_MAX(p,q) ((p >= q) ? p : q)\n-\n-static void\n-_dopr(\n- char **sbuffer,\n- char **buffer,\n- size_t *maxlen,\n- size_t *retlen,\n- int *truncated,\n- const char *format,\n- va_list args)\n-{\n- char ch;\n- LLONG value;\n- LDOUBLE fvalue;\n- char *strvalue;\n- int min;\n- int max;\n- int state;\n- int flags;\n- int cflags;\n- size_t currlen;\n-\n- state = DP_S_DEFAULT;\n- flags = currlen = cflags = min = 0;\n- max = -1;\n- ch = *format++;\n-\n- while (state != DP_S_DONE) {\n- if (ch == '\\0' || (buffer == NULL && currlen >= *maxlen))\n- state = DP_S_DONE;\n-\n- switch (state) {\n- case DP_S_DEFAULT:\n- if (ch == '%')\n- state = DP_S_FLAGS;\n- else\n- doapr_outch(sbuffer,buffer, &currlen, maxlen, ch);\n- ch = *format++;\n- break;\n- case DP_S_FLAGS:\n- switch (ch) {\n- case '-':\n- flags |= DP_F_MINUS;\n- ch = *format++;\n- break;\n- case '+':\n- flags |= DP_F_PLUS;\n- ch = *format++;\n- break;\n- case ' ':\n- flags |= DP_F_SPACE;\n- ch = *format++;\n- break;\n- case '#':\n- flags |= DP_F_NUM;\n- ch = *format++;\n- break;\n- case '0':\n- flags |= DP_F_ZERO;\n- ch = *format++;\n- break;\n- default:\n- state = DP_S_MIN;\n- break;\n- }\n- break;\n- case DP_S_MIN:\n- if (isdigit((unsigned char)ch)) {\n- min = 10 * min + char_to_int(ch);\n- ch = *format++;\n- } else if (ch == '*') {\n- min = va_arg(args, int);\n- ch = *format++;\n- state = DP_S_DOT;\n- } else\n- state = DP_S_DOT;\n- break;\n- case DP_S_DOT:\n- if (ch == '.') {\n- state = DP_S_MAX;\n- ch = *format++;\n- } else\n- state = DP_S_MOD;\n- break;\n- case DP_S_MAX:\n- if (isdigit((unsigned char)ch)) {\n- if (max < 0)\n- max = 0;\n- max = 10 * max + char_to_int(ch);\n- ch = *format++;\n- } else if (ch == '*') {\n- max = va_arg(args, int);\n- ch = *format++;\n- state = DP_S_MOD;\n- } else\n- state = DP_S_MOD;\n- break;\n- case DP_S_MOD:\n- switch (ch) {\n- case 'h':\n- cflags = DP_C_SHORT;\n- ch = *format++;\n- break;\n- case 'l':\n- if (*format == 'l') {\n- cflags = DP_C_LLONG;\n- format++;\n- } else\n- cflags = DP_C_LONG;\n- ch = *format++;\n- break;\n- case 'q':\n- cflags = DP_C_LLONG;\n- ch = *format++;\n- break;\n- case 'L':\n- cflags = DP_C_LDOUBLE;\n- ch = *format++;\n- break;\n- default:\n- break;\n- }\n- state = DP_S_CONV;\n- break;\n- case DP_S_CONV:\n- switch (ch) {\n- case 'd':\n- case 'i':\n- switch (cflags) {\n- case DP_C_SHORT:\n- value = (short int)va_arg(args, int);\n- break;\n- case DP_C_LONG:\n- value = va_arg(args, long int);\n- break;\n- case DP_C_LLONG:\n- value = va_arg(args, LLONG);\n- break;\n- default:\n- value = va_arg(args, int);\n- break;\n- }\n- fmtint(sbuffer, buffer, &currlen, maxlen,\n- value, 10, min, max, flags);\n- break;\n- case 'X':\n- flags |= DP_F_UP;\n- /* FALLTHROUGH */\n- case 'x':\n- case 'o':\n- case 'u':\n- flags |= DP_F_UNSIGNED;\n- switch (cflags) {\n- case DP_C_SHORT:\n- value = (unsigned short int)va_arg(args, unsigned int);\n- brea\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From fd708c2242408187cff392e8b0850275ac99376f Mon Sep 17 00:00:00 2001\nFrom: =?UTF-8?q?Cristian=20Rodr=C3=ADguez?= <crrodriguez@opensuse.org>\nDate: Sun, 4 May 2014 23:36:54 -0400\nSubject: [PATCH] Axe builtin printf implementation, use glibc instead\n\n\ndiff --git a/crypto/bio/b_print.c b/crypto/bio/b_print.c\nindex 143a7cf..657beb7 100644\n--- a/crypto/bio/b_print.c\n+++ b/crypto/bio/b_print.c\n@@ -56,17 +56,9 @@\n * [including the GNU Public Licence.]\n */\n \n-/* disable assert() unless BIO_DEBUG has been defined */\n-#ifndef BIO_DEBUG\n-# ifndef NDEBUG\n-# define NDEBUG\n-# endif\n+#ifndef _GNU_SOURCE\n+#define _GNU_SOURCE\n #endif\n-\n-/* \n- * Stolen from tjh's ssl/ssl_trc.c stuff.\n- */\n-\n #include <stdio.h>\n #include <string.h>\n #include <ctype.h>\n@@ -79,690 +71,6 @@\n #include <openssl/bn.h> /* To get BN_LLONG properly defined */\n #include <openssl/bio.h>\n \n-#if defined(BN_LLONG) || defined(SIXTY_FOUR_BIT)\n-# ifndef HAVE_LONG_LONG\n-# define HAVE_LONG_LONG 1\n-# endif\n-#endif\n-\n-/***************************************************************************/\n-\n-/*\n- * Copyright Patrick Powell 1995\n- * This code is based on code written by Patrick Powell <papowell@astart.com>\n- * It may be used for any purpose as long as this notice remains intact\n- * on all source code distributions.\n- */\n-\n-/*\n- * This code contains numerious changes and enhancements which were\n- * made by lots of contributors over the last years to Patrick Powell's\n- * original code:\n- *\n- * o Patrick Powell <papowell@astart.com> (1995)\n- * o Brandon Long <blong@fiction.net> (1996, for Mutt)\n- * o Thomas Roessler <roessler@guug.de> (1998, for Mutt)\n- * o Michael Elkins <me@cs.hmc.edu> (1998, for Mutt)\n- * o Andrew Tridgell <tridge@samba.org> (1998, for Samba)\n- * o Luke Mewburn <lukem@netbsd.org> (1999, for LukemFTP)\n- * o Ralf S. Engelschall <rse@engelschall.com> (1999, for Pth)\n- * o ... (for OpenSSL)\n- */\n-\n-#ifdef HAVE_LONG_DOUBLE\n-#define LDOUBLE long double\n-#else\n-#define LDOUBLE double\n-#endif\n-\n-#ifdef HAVE_LONG_LONG\n-# if defined(_WIN32) && !defined(__GNUC__)\n-# define LLONG __int64\n-# else\n-# define LLONG long long\n-# endif\n-#else\n-#define LLONG long\n-#endif\n-\n-static void fmtstr (char **, char **, size_t *, size_t *,\n-\t\t\tconst char *, int, int, int);\n-static void fmtint (char **, char **, size_t *, size_t *,\n-\t\t\tLLONG, int, int, int, int);\n-static void fmtfp (char **, char **, size_t *, size_t *,\n-\t\t\tLDOUBLE, int, int, int);\n-static void doapr_outch (char **, char **, size_t *, size_t *, int);\n-static void _dopr(char **sbuffer, char **buffer,\n-\t\t size_t *maxlen, size_t *retlen, int *truncated,\n-\t\t const char *format, va_list args);\n-\n-/* format read states */\n-#define DP_S_DEFAULT 0\n-#define DP_S_FLAGS 1\n-#define DP_S_MIN 2\n-#define DP_S_DOT 3\n-#define DP_S_MAX 4\n-#define DP_S_MOD 5\n-#define DP_S_CONV 6\n-#define DP_S_DONE 7\n-\n-/* format flags - Bits */\n-#define DP_F_MINUS (1 << 0)\n-#define DP_F_PLUS (1 << 1)\n-#define DP_F_SPACE (1 << 2)\n-#define DP_F_NUM (1 << 3)\n-#define DP_F_ZERO (1 << 4)\n-#define DP_F_UP (1 << 5)\n-#define DP_F_UNSIGNED (1 << 6)\n-\n-/* conversion flags */\n-#define DP_C_SHORT 1\n-#define DP_C_LONG 2\n-#define DP_C_LDOUBLE 3\n-#define DP_C_LLONG 4\n-\n-/* some handy macros */\n-#define char_to_int(p) (p - '0')\n-#define OSSL_MAX(p,q) ((p >= q) ? p : q)\n-\n-static void\n-_dopr(\n- char **sbuffer,\n- char **buffer,\n- size_t *maxlen,\n- size_t *retlen,\n- int *truncated,\n- const char *format,\n- va_list args)\n-{\n- char ch;\n- LLONG value;\n- LDOUBLE fvalue;\n- char *strvalue;\n- int min;\n- int max;\n- int state;\n- int flags;\n- int cflags;\n- size_t currlen;\n-\n- state = DP_S_DEFAULT;\n- flags = currlen = cflags = min = 0;\n- max = -1;\n- ch = *format++;\n-\n- while (state != DP_S_DONE) {\n- if (ch == '\\0' || (buffer == NULL && currlen >= *maxlen))\n- state = DP_S_DONE;\n-\n- switch (state) {\n- case DP_S_DEFAULT:\n- if (ch == '%')\n- state = DP_S_FLAGS;\n- else\n- doapr_outch(sbuffer,buffer, &currlen, maxlen, ch);\n- ch = *format++;\n- break;\n- case DP_S_FLAGS:\n- switch (ch) {\n- case '-':\n- flags |= DP_F_MINUS;\n- ch = *format++;\n- break;\n- case '+':\n- flags |= DP_F_PLUS;\n- ch = *format++;\n- break;\n- case ' ':\n- flags |= DP_F_SPACE;\n- ch = *format++;\n- break;\n- case '#':\n- flags |= DP_F_NUM;\n- ch = *format++;\n- break;\n- case '0':\n- flags |= DP_F_ZERO;\n- ch = *format++;\n- break;\n- default:\n- state = DP_S_MIN;\n- break;\n- }\n- break;\n- case DP_S_MIN:\n- if (isdigit((unsigned char)ch)) {\n- min = 10 * min + char_to_int(ch);\n- ch = *format++;\n- } else if (ch == '*') {\n- min = va_arg(args, int);\n- ch = *format++;\n- state = DP_S_DOT;\n- } else\n- state = DP_S_DOT;\n- break;\n- case DP_S_DOT:\n- if (ch == '.') {\n- state = DP_S_MAX;\n- ch = *format++;\n- } else\n- state = DP_S_MOD;\n- break;\n- case DP_S_MAX:\n- if (isdigit((unsigned char)ch)) {\n- if (max < 0)\n- max = 0;\n- max = 10 * max + char_to_int(ch);\n- ch = *format++;\n- } else if (ch == '*') {\n- max = va_arg(args, int);\n- ch = *format++;\n- state = DP_S_MOD;\n- } else\n- state = DP_S_MOD;\n- break;\n- case DP_S_MOD:\n- switch (ch) {\n- case 'h':\n- cflags = DP_C_SHORT;\n- ch = *format++;\n- break;\n- case 'l':\n- if (*format == 'l') {\n- cflags = DP_C_LLONG;\n- format++;\n- } else\n- cflags = DP_C_LONG;\n- ch = *format++;\n- break;\n- case 'q':\n- cflags = DP_C_LLONG;\n- ch = *format++;\n- break;\n- case 'L':\n- cflags = DP_C_LDOUBLE;\n- ch = *format++;\n- break;\n- default:\n- break;\n- }\n- state = DP_S_CONV;\n- break;\n- case DP_S_CONV:\n- switch (ch) {\n- case 'd':\n- case 'i':\n- switch (cflags) {\n- case DP_C_SHORT:\n- value = (short int)va_arg(args, int);\n- break;\n- case DP_C_LONG:\n- value = va_arg(args, long int);\n- break;\n- case DP_C_LLONG:\n- value = va_arg(args, LLONG);\n- break;\n- default:\n- value = va_arg(args, int);\n- break;\n- }\n- fmtint(sbuffer, buffer, &currlen, maxlen,\n- value, 10, min, max, flags);\n- break;\n- case 'X':\n- flags |= DP_F_UP;\n- /* FALLTHROUGH */\n- case 'x':\n- case 'o':\n- case 'u':\n- flags |= DP_F_UNSIGNED;\n- switch (cflags) {\n- case DP_C_SHORT:\n- value = (unsigned short int)va_arg(args, unsigned int);\n- break;\n- case DP_C_LONG:\n- value = (LLONG) va_arg(args,\n- unsigned long int);\n- break;\n- case DP_C_LLONG:\n- value = va_arg(args, unsigned LLONG);\n- break;\n- default:\n- value = (LLONG) va_arg(args,\n- unsigned int);\n- break;\n- }\n- fmtint(sbuffer, buffer, &currlen, maxlen, value,\n- ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),\n- min, max, flags);\n- break;\n- case 'f':\n- if (cflags == DP_C_LDOUBLE)\n- fvalue = va_arg(args, LDOUBLE);\n- else\n- fvalue = va_arg(args, double);\n- fmtfp(sbuffer, buffer, &currlen, maxlen,\n- fvalue, min, max, flags);\n- break;\n- case 'E':\n- flags |= DP_F_UP;\n- case 'e':\n- if (cflags == DP_C_LDOUBLE)\n- fvalue = va_arg(args, LDOUBLE);\n- else\n- fvalue = va_arg(args, double);\n- break;\n- case 'G':\n- flags |= DP_F_UP;\n- case 'g':\n- if (cflags == DP_C_LDOUBLE)\n- fvalue = va_arg(args, LDOUBLE);\n- else\n- fvalue = va_arg(args, double);\n- break;\n- case 'c':\n- doapr_outch(sbuffer, buffer, &currlen, maxlen,\n- va_arg(args, int));\n- break;\n- case 's':\n- strvalue = va_arg(args, char *);\n- if (max < 0) {\n-\t\t if (buffer)\n-\t\t\tmax = INT_MAX;\n-\t\t else\n-\t\t\tmax = *maxlen;\n-\t\t}\n- fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,\n- flags, min, max);\n- break;\n- case 'p':\n- value = (long)va_arg(args, void *);\n- fmtint(sbuffer, buffer, &currlen, maxlen,\n- value, 16, min, max, flags|DP_F_NUM);\n- break;\n- case 'n': /* XXX */\n- if (cflags == DP_C_SHORT) {\n- short int *num;\n- num = va_arg(args, short int *);\n- *num = currlen;\n- } else if (cflags == DP_C_LONG) { /* XXX */\n- long int *num;\n- num = va_arg(args, long int *);\n- *num = (long int) currlen;\n- } else if (cflags == DP_C_LLONG) { /* XXX */\n- LLONG *num;\n- num = va_arg(args, LLONG *);\n- *num = (LLONG) currlen;\n- } else {\n- int *num;\n- num = va_arg(args, int *);\n- *num = currlen;\n- }\n- break;\n- case '%':\n- doapr_outch(sbuffer, buffer, &currlen, maxlen, ch);\n- break;\n- case 'w':\n- /* not supported yet, treat as next char */\n- ch = *format++;\n- break;\n- default:\n- /* unknown, skip */\n- break;\n- }\n- ch = *format++;\n- state = DP_S_DEFAULT;\n- flags = cflags = min = 0;\n- max = -1;\n- break;\n- case DP_S_DONE:\n- break;\n- default:\n- break;\n- }\n- }\n- *truncated = (currlen > *maxlen - 1);\n- if (*truncated)\n- currlen = *maxlen - 1;\n- doapr_outch(sbuffer, buffer, &currlen, maxlen, '\\0');\n- *retlen = currlen - 1;\n- return;\n-}\n-\n-static void\n-fmtstr(\n- char **sbuffer,\n- char **buffer,\n- size_t *currlen,\n- size_t *maxlen,\n- const char *value,\n- int flags,\n- int min,\n- int max)\n-{\n- int padlen, strln;\n- int cnt = 0;\n-\n- if (value == 0)\n- value = \"<NULL>\";\n- for (strln = 0; value[strln]; ++strln)\n- ;\n- padlen = min - strln;\n- if (padlen < 0)\n- padlen = 0;\n- if (flags & DP_F_MINUS)\n- padlen = -padlen;\n-\n- while ((padlen > 0) && (cnt < max)) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');\n- --padlen;\n- ++cnt;\n- }\n- while (*value && (cnt < max)) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, *value++);\n- ++cnt;\n- }\n- while ((padlen < 0) && (cnt < max)) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');\n- ++padlen;\n- ++cnt;\n- }\n-}\n-\n-static void\n-fmtint(\n- char **sbuffer,\n- char **buffer,\n- size_t *currlen,\n- size_t *maxlen,\n- LLONG value,\n- int base,\n- int min,\n- int max,\n- int flags)\n-{\n- int signvalue = 0;\n- const char *prefix = \"\";\n- unsigned LLONG uvalue;\n- char convert[DECIMAL_SIZE(value)+3];\n- int place = 0;\n- int spadlen = 0;\n- int zpadlen = 0;\n- int caps = 0;\n-\n- if (max < 0)\n- max = 0;\n- uvalue = value;\n- if (!(flags & DP_F_UNSIGNED)) {\n- if (value < 0) {\n- signvalue = '-';\n- uvalue = -value;\n- } else if (flags & DP_F_PLUS)\n- signvalue = '+';\n- else if (flags & DP_F_SPACE)\n- signvalue = ' ';\n- }\n- if (flags & DP_F_NUM) {\n-\tif (base == 8) prefix = \"0\";\n-\tif (base == 16) prefix = \"0x\";\n- }\n- if (flags & DP_F_UP)\n- caps = 1;\n- do {\n- convert[place++] =\n- (caps ? \"0123456789ABCDEF\" : \"0123456789abcdef\")\n- [uvalue % (unsigned) base];\n- uvalue = (uvalue / (unsigned) base);\n- } while (uvalue && (place < (int)sizeof(convert)));\n- if (place == sizeof(convert))\n- place--;\n- convert[place] = 0;\n-\n- zpadlen = max - place;\n- spadlen = min - OSSL_MAX(max, place) - (signvalue ? 1 : 0) - strlen(prefix);\n- if (zpadlen < 0)\n- zpadlen = 0;\n- if (spadlen < 0)\n- spadlen = 0;\n- if (flags & DP_F_ZERO) {\n- zpadlen = OSSL_MAX(zpadlen, spadlen);\n- spadlen = 0;\n- }\n- if (flags & DP_F_MINUS)\n- spadlen = -spadlen;\n-\n- /* spaces */\n- while (spadlen > 0) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');\n- --spadlen;\n- }\n-\n- /* sign */\n- if (signvalue)\n- doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);\n-\n- /* prefix */\n- while (*prefix) {\n-\tdoapr_outch(sbuffer, buffer, currlen, maxlen, *prefix);\n-\tprefix++;\n- }\n-\n- /* zeros */\n- if (zpadlen > 0) {\n- while (zpadlen > 0) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, '0');\n- --zpadlen;\n- }\n- }\n- /* digits */\n- while (place > 0)\n- doapr_outch(sbuffer, buffer, currlen, maxlen, convert[--place]);\n-\n- /* left justified spaces */\n- while (spadlen < 0) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');\n- ++spadlen;\n- }\n- return;\n-}\n-\n-static LDOUBLE\n-abs_val(LDOUBLE value)\n-{\n- LDOUBLE result = value;\n- if (value < 0)\n- result = -value;\n- return result;\n-}\n-\n-static LDOUBLE\n-pow_10(int in_exp)\n-{\n- LDOUBLE result = 1;\n- while (in_exp) {\n- result *= 10;\n- in_exp--;\n- }\n- return result;\n-}\n-\n-static long\n-roundv(LDOUBLE value)\n-{\n- long intpart;\n- intpart = (long) value;\n- value = value - intpart;\n- if (value >= 0.5)\n- intpart++;\n- return intpart;\n-}\n-\n-static void\n-fmtfp(\n- char **sbuffer,\n- char **buffer,\n- size_t *currlen,\n- size_t *maxlen,\n- LDOUBLE fvalue,\n- int min,\n- int max,\n- int flags)\n-{\n- int signvalue = 0;\n- LDOUBLE ufvalue;\n- char iconvert[20];\n- char fconvert[20];\n- int iplace = 0;\n- int fplace = 0;\n- int padlen = 0;\n- int zpadlen = 0;\n- int caps = 0;\n- long intpart;\n- long fracpart;\n- long max10;\n-\n- if (max < 0)\n- max = 6;\n- ufvalue = abs_val(fvalue);\n- if (fvalue < 0)\n- signvalue = '-';\n- else if (flags & DP_F_PLUS)\n- signvalue = '+';\n- else if (flags & DP_F_SPACE)\n- signvalue = ' ';\n-\n- intpart = (long)ufvalue;\n-\n- /* sorry, we only support 9 digits past the decimal because of our\n- conversion method */\n- if (max > 9)\n- max = 9;\n-\n- /* we \"cheat\" by converting the fractional part to integer by\n- multiplying by a factor of 10 */\n- max10 = roundv(pow_10(max));\n- fracpart = roundv(pow_10(max) * (ufvalue - intpart));\n-\n- if (fracpart >= max10) {\n- intpart++;\n- fracpart -= max10;\n- }\n-\n- /* convert integer part */\n- do {\n- iconvert[iplace++] =\n- (caps ? \"0123456789ABCDEF\"\n- : \"0123456789abcdef\")[intpart % 10];\n- intpart = (intpart / 10);\n- } while (intpart && (iplace < (int)sizeof(iconvert)));\n- if (iplace == sizeof iconvert)\n- iplace--;\n- iconvert[iplace] = 0;\n-\n- /* convert fractional part */\n- do {\n- fconvert[fplace++] =\n- (caps ? \"0123456789ABCDEF\"\n- : \"0123456789abcdef\")[fracpart % 10];\n- fracpart = (fracpart / 10);\n- } while (fplace < max);\n- if (fplace == sizeof fconvert)\n- fplace--;\n- fconvert[fplace] = 0;\n-\n- /* -1 for decimal point, another -1 if we are printing a sign */\n- padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);\n- zpadlen = max - fplace;\n- if (zpadlen < 0)\n- zpadlen = 0;\n- if (padlen < 0)\n- padlen = 0;\n- if (flags & DP_F_MINUS)\n- padlen = -padlen;\n-\n- if ((flags & DP_F_ZERO) && (padlen > 0)) {\n- if (signvalue) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);\n- --padlen;\n- signvalue = 0;\n- }\n- while (padlen > 0) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, '0');\n- --padlen;\n- }\n- }\n- while (padlen > 0) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');\n- --padlen;\n- }\n- if (signvalue)\n- doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);\n-\n- while (iplace > 0)\n- doapr_outch(sbuffer, buffer, currlen, maxlen, iconvert[--iplace]);\n-\n- /*\n- * Decimal point. This should probably use locale to find the correct\n- * char to print out.\n- */\n- if (max > 0 || (flags & DP_F_NUM)) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, '.');\n-\n- while (fplace > 0)\n- doapr_outch(sbuffer, buffer, currlen, maxlen, fconvert[--fplace]);\n- }\n- while (zpadlen > 0) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, '0');\n- --zpadlen;\n- }\n-\n- while (padlen < 0) {\n- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');\n- ++padlen;\n- }\n-}\n-\n-static void\n-doapr_outch(\n- char **sbuffer,\n- char **buffer,\n- size_t *currlen,\n- size_t *maxlen,\n- int c)\n-{\n- /* If we haven't at least one buffer, someone has doe a big booboo */\n- assert(*sbuffer != NULL || buffer != NULL);\n-\n- if (buffer) {\n-\twhile (*currlen >= *maxlen) {\n-\t if (*buffer == NULL) {\n-\t\tif (*maxlen == 0)\n-\t\t *maxlen = 1024;\n-\t\t*buffer = OPENSSL_malloc(*maxlen);\n-\t\tif (*currlen > 0) {\n-\t\t assert(*sbuffer != NULL);\n-\t\t memcpy(*buffer, *sbuffer, *currlen);\n-\t\t}\n-\t\t*sbuffer = NULL;\n-\t } else {\n-\t\t*maxlen += 1024;\n-\t\t*buffer = OPENSSL_realloc(*buffer, *maxlen);\n-\t }\n-\t}\n-\t/* What to do if *buffer is NULL? */\n-\tassert(*sbuffer != NULL || *buffer != NULL);\n- }\n-\n- if (*currlen < *maxlen) {\n-\tif (*sbuffer)\n-\t (*sbuffer)[(*currlen)++] = (char)c;\n-\telse\n-\t (*buffer)[(*currlen)++] = (char)c;\n- }\n-\n- return;\n-}\n-\n /***************************************************************************/\n \n int BIO_printf (BIO *bio, const char *format, ...)\n@@ -778,65 +86,70 @@ int BIO_printf (BIO *bio, const char *format, ...)\n \treturn(ret);\n \t}\n \n+static ssize_t cookie_BIO_write(void *cookie, const char *buf, size_t size)\n+{\n+ int ret;\n+ ret = BIO_write(cookie, buf, size);\n+ /* BIO_write may return negative value on error,\n+ * but we must return 0 on that case\n+ */\n+ return (ret < 0) ? 0 : ret;\n+}\n+\n int BIO_vprintf (BIO *bio, const char *format, va_list args)\n-\t{\n+{\n+ FILE *fp;\n \tint ret;\n-\tsize_t retlen;\n-\tchar hugebuf[1024*2];\t/* Was previously 10k, which is unreasonable\n-\t\t\t\t in small-stack environments, like threads\n-\t\t\t\t or DOS programs. */\n-\tchar *hugebufp = hugebuf;\n-\tsize_t hugebufsize = sizeof(hugebuf);\n-\tchar *dynbuf = NULL;\n-\tint ignored;\n+ \n+ cookie_io_functions_t bio_funcs = {\n+ .read = NULL,\n+ .write = cookie_BIO_write,\n+ .seek = NULL,\n+ .close = NULL,\n+ };\n+\n+ fp = fopencookie(bio, \"w\", bio_funcs);\n+\n+ if (fp == NULL) \n+ return -1;\n+\n+ ret = vfprintf(fp, format, args);\n+\n+ fclose(fp);\n \n-\tdynbuf = NULL;\n-\tCRYPTO_push_info(\"doapr()\");\n-\t_dopr(&hugebufp, &dynbuf, &hugebufsize,\n-\t\t&retlen, &ignored, format, args);\n-\tif (dynbuf)\n-\t\t{\n-\t\tret=BIO_write(bio, dynbuf, (int)retlen);\n-\t\tOPENSSL_free(dynbuf);\n-\t\t}\n-\telse\n-\t\t{\n-\t\tret=BIO_write(bio, hugebuf, (int)retlen);\n-\t\t}\n-\tCRYPTO_pop_info();\n \treturn(ret);\n-\t}\n+}\n \n /* As snprintf is not available everywhere, we provide our own implementation.\n * This function has nothing to do with BIOs, but it's closely related\n * to BIO_printf, and we need *some* name prefix ...\n * (XXX the function should be renamed, but to what?) */\n int BIO_snprintf(char *buf, size_t n, const char *format, ...)\n-\t{\n+{\n \tva_list args;\n \tint ret;\n \n \tva_start(args, format);\n \n-\tret = BIO_vsnprintf(buf, n, format, args);\n+\tret = vsnprintf(buf, n, format, args);\n \n \tva_end(args);\n+\n+\tif (ret >= n || ret == -1) return (-1);\n+\n \treturn(ret);\n-\t}\n+}\n \n int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)\n-\t{\n-\tsize_t retlen;\n-\tint truncated;\n+{\n+\t\n+\tint ret;\n+\t\n+\tret = vsnprintf(buf, n, format, args);\n \n-\t_dopr(&buf, NULL, &n, &retlen, &truncated, format, args);\n+\tif (ret >= n || ret == -1)\n+\t\treturn (-1);\n \n-\tif (truncated)\n-\t\t/* In case of truncation, return -1 like traditional snprintf.\n-\t\t * (Current drafts for ISO/IEC 9899 say snprintf should return\n-\t\t * the number of characters that would have been written,\n-\t\t * had the buffer been large enough.) */\n-\t\treturn -1;\n-\telse\n-\t\treturn (retlen <= INT_MAX) ? (int)retlen : -1;\n-\t}\n+\treturn (ret);\n+\n+}\n-- \n1.8.4.5" } ]
{ "id": "openssl-4352-0001-Axe-builtin-printf-implem", "cve_id": "CVE-2015-3194", "package": "openssl", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": true, "license": "OpenSSL", "context_tokens_est": 4006, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2007-4772\n\nThe regular expression parser in TCL before 8.4.17, as used in PostgreSQL 8.2 before 8.2.6, 8.1 before 8.1.11, 8.0 before 8.0.15, and 7.4 before 7.4.19, allows context-dependent attackers to cause a denial of service (infinite loop) via a crafted regular expression.\n\n## Package\npostgresql94\n\n## Files to modify\n- postgresql-9.3.5.orig/src/include/pg_config_manual.h\n- postgresql-9.3.5.orig/src/backend/utils/misc/guc.c\n- postgresql-9.3.5.orig/src/bin/initdb/initdb.c\n- src/backend/utils/misc/guc.c\n- src/bin/initdb/initdb.c\n\n## Target Source Code\n\n### contrib/pg_upgrade/test.sh\n\n#### region() [lines 99-185]\n```c\nrm -rf \"$BASE_PGDATA\" \"$PGDATA\"\n\nlogdir=$PWD/log\nrm -rf \"$logdir\"\nmkdir \"$logdir\"\n\n# Clear out any environment vars that might cause libpq to connect to\n# the wrong postmaster (cf pg_regress.c)\n#\n# Some shells, such as NetBSD's, return non-zero from unset if the variable\n# is already unset. Since we are operating under 'set -e', this causes the\n# script to fail. To guard against this, set them all to an empty string first.\nPGDATABASE=\"\"; unset PGDATABASE\nPGUSER=\"\"; unset PGUSER\nPGSERVICE=\"\"; unset PGSERVICE\nPGSSLMODE=\"\"; unset PGSSLMODE\nPGREQUIRESSL=\"\"; unset PGREQUIRESSL\nPGCONNECT_TIMEOUT=\"\"; unset PGCONNECT_TIMEOUT\nPGHOSTADDR=\"\"; unset PGHOSTADDR\n\n# Select a non-conflicting port number, similarly to pg_regress.c\nPG_VERSION_NUM=`grep '#define PG_VERSION_NUM' $newsrc/src/include/pg_config.h | awk '{print $3}'`\nPGPORT=`expr $PG_VERSION_NUM % 16384 + 49152`\nexport PGPORT\n\ni=0\nwhile psql -X postgres </dev/null 2>/dev/null\ndo\n\ti=`expr $i + 1`\n\tif [ $i -eq 16 ]\n\tthen\n\t\techo port $PGPORT apparently in use\n\t\texit 1\n\tfi\n\tPGPORT=`expr $PGPORT + 1`\n\texport PGPORT\ndone\n\n# buildfarm may try to override port via EXTRA_REGRESS_OPTS ...\nEXTRA_REGRESS_OPTS=\"$EXTRA_REGRESS_OPTS --port=$PGPORT\"\nexport EXTRA_REGRESS_OPTS\n\n# enable echo so the user can see what is being executed\nset -x\n\n$oldbindir/initdb -N\n$oldbindir/pg_ctl start -l \"$logdir/postmaster1.log\" -o \"$POSTMASTER_OPTS\" -w\nif \"$MAKE\" -C \"$oldsrc\" installcheck; then\n\tpg_dumpall -f \"$temp_root\"/dump1.sql || pg_dumpall1_status=$?\n\tif [ \"$newsrc\" != \"$oldsrc\" ]; then\n\t\toldpgversion=`psql -A -t -d regression -c \"SHOW server_version_num\"`\n\t\tfix_sql=\"\"\n\t\tcase $oldpgversion in\n\t\t\t804??)\n\t\t\t\tfix_sql=\"UPDATE pg_proc SET probin = replace(probin::text, '$oldsrc', '$newsrc')::bytea WHERE probin LIKE '$oldsrc%'; DROP FUNCTION public.myfunc(integer);\"\n\t\t\t\t;;\n\t\t\t900??)\n\t\t\t\tfix_sql=\"SET bytea_output TO escape; UPDATE pg_proc SET probin = replace(probin::text, '$oldsrc', '$newsrc')::bytea WHERE probin LIKE '$oldsrc%';\"\n\t\t\t\t;;\n\t\t\t901??)\n\t\t\t\tfix_sql=\"UPDATE pg_proc SET probin = replace(probin, '$oldsrc', '$newsrc') WHERE probin LIKE '$oldsrc%';\"\n\t\t\t\t;;\n\t\tesac\n\t\tpsql -d regression -c \"$fix_sql;\" || psql_fix_sql_status=$?\n\n\t\tmv \"$temp_root\"/dump1.sql \"$temp_root\"/dump1.sql.orig\n\t\tsed \"s;$oldsrc;$newsrc;g\" \"$temp_root\"/dump1.sql.orig >\"$temp_root\"/dump1.sql\n\tfi\nelse\n\tmake_installcheck_status=$?\nfi\n$oldbindir/pg_ctl -m fast stop\nif [ -n \"$make_installcheck_status\" ]; then\n\texit 1\nfi\nif [ -n \"$psql_fix_sql_status\" ]; then\n\texit 1\nfi\nif [ -n \"$pg_dumpall1_status\" ]; then\n\techo \"pg_dumpall of pre-upgrade database cluster failed\"\n\texit 1\nfi\n\nPGDATA=$BASE_PGDATA\n\ninitdb -N\n\n```\n\n### src/backend/utils/misc/guc.c\n\n#### region() [lines 2932-3019]\n```c\n\t\tcheck_timezone, assign_timezone, show_timezone\n\t},\n\t{\n\t\t{\"timezone_abbreviations\", PGC_USERSET, CLIENT_CONN_LOCALE,\n\t\t\tgettext_noop(\"Selects a file of time zone abbreviations.\"),\n\t\t\tNULL\n\t\t},\n\t\t&timezone_abbreviations_string,\n\t\tNULL,\n\t\tcheck_timezone_abbreviations, assign_timezone_abbreviations, NULL\n\t},\n\n\t{\n\t\t{\"transaction_isolation\", PGC_USERSET, CLIENT_CONN_STATEMENT,\n\t\t\tgettext_noop(\"Sets the current transaction's isolation level.\"),\n\t\t\tNULL,\n\t\t\tGUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE\n\t\t},\n\t\t&XactIsoLevel_string,\n\t\t\"default\",\n\t\tcheck_XactIsoLevel, assign_XactIsoLevel, show_XactIsoLevel\n\t},\n\n\t{\n\t\t{\"unix_socket_group\", PGC_POSTMASTER, CONN_AUTH_SETTINGS,\n\t\t\tgettext_noop(\"Sets the owning group of the Unix-domain socket.\"),\n\t\t\tgettext_noop(\"The owning user of the socket is always the user \"\n\t\t\t\t\t\t \"that starts the server.\")\n\t\t},\n\t\t&Unix_socket_group,\n\t\t\"\",\n\t\tNULL, NULL, NULL\n\t},\n\n\t{\n\t\t{\"unix_socket_directories\", PGC_POSTMASTER, CONN_AUTH_SETTINGS,\n\t\t\tgettext_noop(\"Sets the directories where Unix-domain sockets will be created.\"),\n\t\t\tNULL,\n\t\t\tGUC_SUPERUSER_ONLY\n\t\t},\n\t\t&Unix_socket_directories,\n#ifdef HAVE_UNIX_SOCKETS\n\t\tDEFAULT_PGSOCKET_DIR,\n#else\n\t\t\"\",\n#endif\n\t\tNULL, NULL, NULL\n\t},\n\n\t{\n\t\t{\"listen_addresses\", PGC_POSTMASTER, CONN_AUTH_SETTINGS,\n\t\t\tgettext_noop(\"Sets the host name or IP address(es) to listen to.\"),\n\t\t\tNULL,\n\t\t\tGUC_LIST_INPUT\n\t\t},\n\t\t&ListenAddresses,\n\t\t\"localhost\",\n\t\tNULL, NULL, NULL\n\t},\n\n\t{\n\t\t{\"data_directory\", PGC_POSTMASTER, FILE_LOCATIONS,\n\t\t\tgettext_noop(\"Sets the server's data directory.\"),\n\t\t\tNULL,\n\t\t\tGUC_SUPERUSER_ONLY\n\t\t},\n\t\t&data_directory,\n\t\tNULL,\n\t\tNULL, NULL, NULL\n\t},\n\n\t{\n\t\t{\"config_file\", PGC_POSTMASTER, FILE_LOCATIONS,\n\t\t\tgettext_noop(\"Sets the server's main configuration file.\"),\n\t\t\tNULL,\n\t\t\tGUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY\n\t\t},\n\t\t&ConfigFileName,\n\t\tNULL,\n\t\tNULL, NULL, NULL\n\t},\n\n\t{\n\t\t{\"hba_file\", PGC_POSTMASTER, FILE_LOCATIONS,\n\t\t\tgettext_noop(\"Sets the server's \\\"hba\\\" configuration file.\"),\n\t\t\tNULL,\n\t\t\tGUC_SUPERUSER_ONLY\n\t\t},\n```\n\n### src/bin/initdb/initdb.c\n\n#### region() [lines 1165-1252]\n```c\n\t\tif (status == 0)\n\t\t\tbreak;\n\t}\n\tn_buffers = test_buffs;\n\n\tif ((n_buffers * (BLCKSZ / 1024)) % 1024 == 0)\n\t\tprintf(\"%dMB\\n\", (n_buffers * (BLCKSZ / 1024)) / 1024);\n\telse\n\t\tprintf(\"%dkB\\n\", n_buffers * (BLCKSZ / 1024));\n}\n\n/*\n * set up all the config files\n */\nstatic void\nsetup_config(void)\n{\n\tchar\t **conflines;\n\tchar\t\trepltok[MAXPGPATH];\n\tchar\t\tpath[MAXPGPATH];\n\tconst char *default_timezone;\n\n\tfputs(_(\"creating configuration files ... \"), stdout);\n\tfflush(stdout);\n\n\t/* postgresql.conf */\n\n\tconflines = readfile(conf_file);\n\n\tsnprintf(repltok, sizeof(repltok), \"max_connections = %d\", n_connections);\n\tconflines = replace_token(conflines, \"#max_connections = 100\", repltok);\n\n\tif ((n_buffers * (BLCKSZ / 1024)) % 1024 == 0)\n\t\tsnprintf(repltok, sizeof(repltok), \"shared_buffers = %dMB\",\n\t\t\t\t (n_buffers * (BLCKSZ / 1024)) / 1024);\n\telse\n\t\tsnprintf(repltok, sizeof(repltok), \"shared_buffers = %dkB\",\n\t\t\t\t n_buffers * (BLCKSZ / 1024));\n\tconflines = replace_token(conflines, \"#shared_buffers = 32MB\", repltok);\n\n#ifdef HAVE_UNIX_SOCKETS\n\tsnprintf(repltok, sizeof(repltok), \"#unix_socket_directories = '%s'\",\n\t\t\t DEFAULT_PGSOCKET_DIR);\n#else\n\tsnprintf(repltok, sizeof(repltok), \"#unix_socket_directories = ''\");\n#endif\n\tconflines = replace_token(conflines, \"#unix_socket_directories = '/tmp'\",\n\t\t\t\t\t\t\t repltok);\n\n#if DEF_PGPORT != 5432\n\tsnprintf(repltok, sizeof(repltok), \"#port = %d\", DEF_PGPORT);\n\tconflines = replace_token(conflines, \"#port = 5432\", repltok);\n#endif\n\n\tsnprintf(repltok, sizeof(repltok), \"lc_messages = '%s'\",\n\t\t\t escape_quotes(lc_messages));\n\tconflines = replace_token(conflines, \"#lc_messages = 'C'\", repltok);\n\n\tsnprintf(repltok, sizeof(repltok), \"lc_monetary = '%s'\",\n\t\t\t escape_quotes(lc_monetary));\n\tconflines = replace_token(conflines, \"#lc_monetary = 'C'\", repltok);\n\n\tsnprintf(repltok, sizeof(repltok), \"lc_numeric = '%s'\",\n\t\t\t escape_quotes(lc_numeric));\n\tconflines = replace_token(conflines, \"#lc_numeric = 'C'\", repltok);\n\n\tsnprintf(repltok, sizeof(repltok), \"lc_time = '%s'\",\n\t\t\t escape_quotes(lc_time));\n\tconflines = replace_token(conflines, \"#lc_time = 'C'\", repltok);\n\n\tswitch (locale_date_order(lc_time))\n\t{\n\t\tcase DATEORDER_YMD:\n\t\t\tstrcpy(repltok, \"datestyle = 'iso, ymd'\");\n\t\t\tbreak;\n\t\tcase DATEORDER_DMY:\n\t\t\tstrcpy(repltok, \"datestyle = 'iso, dmy'\");\n\t\t\tbreak;\n\t\tcase DATEORDER_MDY:\n\t\tdefault:\n\t\t\tstrcpy(repltok, \"datestyle = 'iso, mdy'\");\n\t\t\tbreak;\n\t}\n\tconflines = replace_token(conflines, \"#datestyle = 'iso, mdy'\", repltok);\n\n\tsnprintf(repltok, sizeof(repltok),\n\t\t\t \"default_text_search_config = 'pg_catalog.%s'\",\n\t\t\t escape_quotes(default_text_search_config));\n```\n\n### src/include/pg_config_manual.h\n\n#### region() [lines 105-192]\n```c\n\n/*\n * Disable UNIX sockets for certain operating systems.\n */\n#if defined(WIN32)\n#undef HAVE_UNIX_SOCKETS\n#endif\n\n/*\n * Define this if your operating system supports link()\n */\n#if !defined(WIN32) && !defined(__CYGWIN__)\n#define HAVE_WORKING_LINK 1\n#endif\n\n/*\n * USE_POSIX_FADVISE controls whether Postgres will attempt to use the\n * posix_fadvise() kernel call. Usually the automatic configure tests are\n * sufficient, but some older Linux distributions had broken versions of\n * posix_fadvise(). If necessary you can remove the #define here.\n */\n#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE)\n#define USE_POSIX_FADVISE\n#endif\n\n/*\n * USE_PREFETCH code should be compiled only if we have a way to implement\n * prefetching. (This is decoupled from USE_POSIX_FADVISE because there\n * might in future be support for alternative low-level prefetch APIs.)\n */\n#ifdef USE_POSIX_FADVISE\n#define USE_PREFETCH\n#endif\n\n/*\n * This is the default directory in which AF_UNIX socket files are\n * placed. Caution: changing this risks breaking your existing client\n * applications, which are likely to continue to look in the old\n * directory. But if you just hate the idea of sockets in /tmp,\n * here's where to twiddle it. You can also override this at runtime\n * with the postmaster's -k switch.\n */\n#define DEFAULT_PGSOCKET_DIR \"/tmp\"\n\n/*\n * The random() function is expected to yield values between 0 and\n * MAX_RANDOM_VALUE. Currently, all known implementations yield\n * 0..2^31-1, so we just hardwire this constant. We could do a\n * configure test if it proves to be necessary. CAUTION: Think not to\n * replace this with RAND_MAX. RAND_MAX defines the maximum value of\n * the older rand() function, which is often different from --- and\n * considerably inferior to --- random().\n */\n#define MAX_RANDOM_VALUE (0x7FFFFFFF)\n\n/*\n * Set the format style used by gcc to check printf type functions. We really\n * want the \"gnu_printf\" style set, which includes what glibc uses, such\n * as %m for error strings and %lld for 64 bit long longs. But not all gcc\n * compilers are known to support it, so we just use \"printf\" which all\n * gcc versions alive are known to support, except on Windows where\n * using \"gnu_printf\" style makes a dramatic difference. Maybe someday\n * we'll have a configure test for this, if we ever discover use of more\n * variants to be necessary.\n */\n#ifdef WIN32\n#define PG_PRINTF_ATTRIBUTE gnu_printf\n#else\n#define PG_PRINTF_ATTRIBUTE printf\n#endif\n\n/*\n * On PPC machines, decide whether to use the mutex hint bit in LWARX\n * instructions. Setting the hint bit will slightly improve spinlock\n * performance on POWER6 and later machines, but does nothing before that,\n * and will result in illegal-instruction failures on some pre-POWER4\n * machines. By default we use the hint bit when building for 64-bit PPC,\n * which should be safe in nearly all cases. You might want to override\n * this if you are building 32-bit code for a known-recent PPC machine.\n */\n#ifdef HAVE_PPC_LWARX_MUTEX_HINT\t/* must have assembler support in any case */\n#if defined(__ppc64__) || defined(__powerpc64__)\n#define USE_PPC_LWARX_MUTEX_HINT\n#endif\n#endif\n\n/*\n * On PPC machines, decide whether to use LWSYNC instructions in place of\n```\n\n\n## Upstream Fix\n```diff\nChange the built-in default socket directory to be /var/run/postgresql.\nFor backwards compatibility with (probably non-libpq-based) clients that\nmight still expect to find the socket in /tmp, also create a socket in\n/tmp. This is to resolve communication problems with clients operating\nunder systemd's PrivateTmp environment, which won't be using the same\nglobal /tmp directory as the server; see bug #825448.\n\nNote that we apply the socket directory change at the level of the\nhard-wired defaults in the C code, not by just twiddling the setting in\npostgresql.conf.sample; this is so that the change will take effect on\nserver package update, without requiring any existing postgresql.conf\nto be updated. (Of course, a user who dislikes this behavior can still\noverride it via postgresql.conf.)\n\n\nIndex: postgresql-9.3.5/contrib/pg_upgrade/test.sh\n===================================================================\n--- postgresql-9.3.5.orig/contrib/pg_upgrade/test.sh\t2014-07-25 12:48:53.890020586 +0200\n+++ postgresql-9.3.5/contrib/pg_upgrade/test.sh\t2014-07-25 12:54:10.221108886 +0200\n@@ -138,6 +138,12 @@\n EXTRA_REGRESS_OPTS=\"$EXTRA_REGRESS_OPTS --port=$PGPORT\"\n export EXTRA_REGRESS_OPTS\n \n+# we want the Unix sockets in $temp_root\n+PGHOST=$temp_root\n+export PGHOST\n+\n+POSTMASTER_OPTS=\"$POSTMASTER_OPTS -c unix_socket_directories='$PGHOST'\"\n+\n # enable echo so the user can see what is being executed\n set -x\n \nIndex: postgresql-9.3.5/src/backend/utils/misc/guc.c\n===================================================================\n--- postgresql-9.3.5.orig/src/backend/utils/misc/guc.c\t2014-07-25 12:48:53.893020625 +0200\n+++ postgresql-9.3.5/src/backend/utils/misc/guc.c\t2014-07-25 12:54:10.223108912 +0200\n@@ -2971,7 +2971,7 @@\n \t\t},\n \t\t&Unix_socket_directories,\n #ifdef HAVE_UNIX_SOCKETS\n-\t\tDEFAULT_PGSOCKET_DIR,\n+\t\tDEFAULT_PGSOCKET_DIR \", /tmp\",\n #else\n \t\t\"\",\n #endif\nIndex: postgresql-9.3.5/src/bin/initdb/initdb.c\n===================================================================\n--- postgresql-9.3.5.orig/src/bin/initdb/initdb.c\t2014-07-25 12:48:53.894020638 +0200\n+++ postgresql-9.3.5/src/bin/initdb/initdb.c\t2014-07-25 12:54:10.223108912 +0200\n@@ -1204,7 +1204,7 @@\n \n #ifdef HAVE_UNIX_SOCKETS\n \tsnprintf(repltok, sizeof(repltok), \"#unix_socket_directories = '%s'\",\n-\t\t\t DEFAULT_PGSOCKET_DIR);\n+\t\t\t DEFAULT_PGSOCKET_DIR \", /tmp\");\n #else\n \tsnprintf(repltok, sizeof(repltok), \"#unix_socket_directories = ''\");\n #endif\nIndex: postgresql-9.3.5/src/include/pg_config_manual.h\n===================================================================\n--- postgresql-9.3.5.orig/src/include/pg_config_manual.h\t2014-07-25 12:48:53.894020638 +0200\n+++ postgresql-9.3.5/src/include/pg_config_manual.h\t2014-07-25 12:54:10.224108925 +0200\n@@ -144,7 +144,7 @@\n * here's where to twiddle it. You can also override this at runtime\n * with the postmaster's -k switch.\n */\n-#define DEFAULT_PGSOCKET_DIR \"/tmp\"\n+#define DEFAULT_PGSOCKET_DIR \"/var/run/postgresql\"\n \n /*\n * The random() function is expected to yield values between 0 and\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "Change the built-in default socket directory to be /var/run/postgresql.\nFor backwards compatibility with (probably non-libpq-based) clients that\nmight still expect to find the socket in /tmp, also create a socket in\n/tmp. This is to resolve communication problems with clients operating\nunder systemd's PrivateTmp environment, which won't be using the same\nglobal /tmp directory as the server; see bug #825448.\n\nNote that we apply the socket directory change at the level of the\nhard-wired defaults in the C code, not by just twiddling the setting in\npostgresql.conf.sample; this is so that the change will take effect on\nserver package update, without requiring any existing postgresql.conf\nto be updated. (Of course, a user who dislikes this behavior can still\noverride it via postgresql.conf.)\n\n\nIndex: postgresql-9.3.5/contrib/pg_upgrade/test.sh\n===================================================================\n--- postgresql-9.3.5.orig/contrib/pg_upgrade/test.sh\t2014-07-25 12:48:53.890020586 +0200\n+++ postgresql-9.3.5/contrib/pg_upgrade/test.sh\t2014-07-25 12:54:10.221108886 +0200\n@@ -138,6 +138,12 @@\n EXTRA_REGRESS_OPTS=\"$EXTRA_REGRESS_OPTS --port=$PGPORT\"\n export EXTRA_REGRESS_OPTS\n \n+# we want the Unix sockets in $temp_root\n+PGHOST=$temp_root\n+export PGHOST\n+\n+POSTMASTER_OPTS=\"$POSTMASTER_OPTS -c unix_socket_directories='$PGHOST'\"\n+\n # enable echo so the user can see what is being executed\n set -x\n \nIndex: postgresql-9.3.5/src/backend/utils/misc/guc.c\n===================================================================\n--- postgresql-9.3.5.orig/src/backend/utils/misc/guc.c\t2014-07-25 12:48:53.893020625 +0200\n+++ postgresql-9.3.5/src/backend/utils/misc/guc.c\t2014-07-25 12:54:10.223108912 +0200\n@@ -2971,7 +2971,7 @@\n \t\t},\n \t\t&Unix_socket_directories,\n #ifdef HAVE_UNIX_SOCKETS\n-\t\tDEFAULT_PGSOCKET_DIR,\n+\t\tDEFAULT_PGSOCKET_DIR \", /tmp\",\n #else\n \t\t\"\",\n #endif\nIndex: postgresql-9.3.5/src/bin/initdb/initdb.c\n===================================================================\n--- postgresql-9.3.5.orig/src/bin/initdb/initdb.c\t2014-07-25 12:48:53.894020638 +0200\n+++ postgresql-9.3.5/src/bin/initdb/initdb.c\t2014-07-25 12:54:10.223108912 +0200\n@@ -1204,7 +1204,7 @@\n \n #ifdef HAVE_UNIX_SOCKETS\n \tsnprintf(repltok, sizeof(repltok), \"#unix_socket_directories = '%s'\",\n-\t\t\t DEFAULT_PGSOCKET_DIR);\n+\t\t\t DEFAULT_PGSOCKET_DIR \", /tmp\");\n #else\n \tsnprintf(repltok, sizeof(repltok), \"#unix_socket_directories = ''\");\n #endif\nIndex: postgresql-9.3.5/src/include/pg_config_manual.h\n===================================================================\n--- postgresql-9.3.5.orig/src/include/pg_config_manual.h\t2014-07-25 12:48:53.894020638 +0200\n+++ postgresql-9.3.5/src/include/pg_config_manual.h\t2014-07-25 12:54:10.224108925 +0200\n@@ -144,7 +144,7 @@\n * here's where to twiddle it. You can also override this at runtime\n * with the postmaster's -k switch.\n */\n-#define DEFAULT_PGSOCKET_DIR \"/tmp\"\n+#define DEFAULT_PGSOCKET_DIR \"/var/run/postgresql\"\n \n /*\n * The random() function is expected to yield values between 0 and" } ]
{ "id": "postgresql94-4741-postgresql-var-run-socket.patc", "cve_id": "CVE-2007-4772", "package": "postgresql94", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": true, "license": "PostgreSQL", "context_tokens_est": 2712, "context_files": 4 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-8779\n\nStack-based buffer overflow in the catopen function in the GNU C Library (aka glibc or libc6) before 2.23 allows context-dependent attackers to cause a denial of service (application crash) or possibly execute arbitrary code via a long catalog name.\n\n## Package\nglibc-testsuite\n\n## Files to modify\n- locale/findlocale.c\n- glibc-2.19.orig/locale/findlocale.c\n- glibc-2.19.orig/locale/setlocale.c\n- locale/setlocale.c\n- localedata/tst-setlocale3.c\n\n## Target Source Code\n\n### locale/findlocale.c\n\n#### region() [lines 1-64]\n```c\n/* Copyright (C) 1996-2014 Free Software Foundation, Inc.\n This file is part of the GNU C Library.\n Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.\n\n The GNU C Library is free software; you can redistribute it and/or\n modify it under the terms of the GNU Lesser General Public\n License as published by the Free Software Foundation; either\n version 2.1 of the License, or (at your option) any later version.\n\n The GNU C Library is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public\n License along with the GNU C Library; if not, see\n <http://www.gnu.org/licenses/>. */\n\n#include <assert.h>\n#include <locale.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\n#ifdef _POSIX_MAPPED_FILES\n# include <sys/mman.h>\n#endif\n\n#include \"localeinfo.h\"\n#include \"../iconv/gconv_charset.h\"\n#include \"../iconv/gconv_int.h\"\n\n\n#ifdef NL_CURRENT_INDIRECT\n# define DEFINE_CATEGORY(category, category_name, items, a) \\\nextern struct __locale_data _nl_C_##category; \\\nweak_extern (_nl_C_##category)\n# include \"categories.def\"\n# undef\tDEFINE_CATEGORY\n\n/* Array indexed by category of pointers to _nl_C_CATEGORY slots.\n Elements are zero for categories whose data is never used. */\nstruct __locale_data *const _nl_C[] attribute_hidden =\n {\n# define DEFINE_CATEGORY(category, category_name, items, a) \\\n [category] = &_nl_C_##category,\n# include \"categories.def\"\n# undef\tDEFINE_CATEGORY\n };\n#else\n# define _nl_C\t\t(_nl_C_locobj.__locales)\n#endif\n\n\n/* For each category we keep a list of records for the locale files\n which are somehow addressed. */\nstruct loaded_l10nfile *_nl_locale_file_list[__LC_LAST];\n\nconst char _nl_default_locale_path[] attribute_hidden = LOCALEDIR;\n\n\nstruct __locale_data *\ninternal_function\n_nl_find_locale (const char *locale_path, size_t locale_path_len,\n\t\t int category, const char **name)\n```\n\n#### region() [lines 18-104]\n```c\n\n#include <assert.h>\n#include <locale.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\n#ifdef _POSIX_MAPPED_FILES\n# include <sys/mman.h>\n#endif\n\n#include \"localeinfo.h\"\n#include \"../iconv/gconv_charset.h\"\n#include \"../iconv/gconv_int.h\"\n\n\n#ifdef NL_CURRENT_INDIRECT\n# define DEFINE_CATEGORY(category, category_name, items, a) \\\nextern struct __locale_data _nl_C_##c\n/* ... truncated ... */\n```\n\n### locale/setlocale.c\n\n#### setlocale() [lines 216-463]\n```c\n}\n\nchar *\nsetlocale (int category, const char *locale)\n{\n char *locale_path;\n size_t locale_path_len;\n const char *locpath_var;\n char *composite;\n\n /* Sanity check for CATEGORY argument. */\n if (__builtin_expect (category, 0) < 0\n || __builtin_expect (category, 0) >= __LC_LAST)\n ERROR_RETURN;\n\n /* Does user want name of current locale? */\n if (locale == NULL)\n return (char *) _nl_global_locale.__names[category];\n\n /* Protect global data. */\n __libc_rwlock_wrlock (__libc_setlocale_lock);\n\n if (strcmp (locale, _nl_global_locale.__names[category]) == 0)\n {\n /* Changing to the same thing. */\n __libc_rwlock_unlock (__libc_setlocale_lock);\n\n return (char *) _nl_global_locale.__names[category];\n }\n\n /* We perhaps really have to load some data. So we determine the\n path in which to look for the data now. The environment variable\n `LOCPATH' must only be used when the binary has no SUID or SGID\n bit set. If using the default path, we tell _nl_find_locale\n by passing null and it can check the canonical locale archive. */\n locale_path = NULL;\n locale_path_len = 0;\n\n locpath_var = getenv (\"LOCPATH\");\n if (locpath_var != NULL && locpath_var[0] != '\\0')\n/* ... 7 lines omitted ... */\n\t return NULL;\n\t}\n }\n\n if (category == LC_ALL)\n {\n /* The user wants to set all categories. The desired locales\n\t for the individual categories can be selected by using a\n\t composite locale name. This is a semi-colon separated list\n\t of entries of the form `CATEGORY=VALUE'. */\n const char *newnames[__LC_LAST];\n struct __locale_data *newdata[__LC_LAST];\n\n /* Set all name pointers to the argument name. */\n for (category = 0; category < __LC_LAST; ++category)\n\tif (category != LC_ALL)\n\t newnames[category] = (char *) locale;\n\n if (__builtin_expect (strchr (locale, ';') != NULL, 0))\n\t{\n\t /* This is a composite name. Make a copy and split it up. */\n\t char *np = strdupa (locale);\n\t char *cp;\n\t int cnt;\n\n\t while ((cp = strchr (np, '=')) != NULL)\n/* ... 155 lines omitted ... */\n\n\t setname (category, newname[0]);\n\t setname (LC_ALL, composite);\n\n\t /* We successfully loaded a new locale. Let the message catalog\n\t functions know about this. */\n\t ++_nl_msg_cat_cntr;\n\t}\n\n /* Critical section left. */\n __libc_rwlock_unlock (__libc_setlocale_lock);\n\n /* Free the resources (the locale path variable. */\n free (locale_path);\n\n return (char *) newname[0];\n }\n}\nli\n/* ... truncated ... */\n```\n\n### localedata/Makefile\n\n#### region() [lines 38-125]\n```c\n\t tst-ctype tst-wctype tst-langinfo tst-numeric\ntest-input := de_DE.ISO-8859-1 en_US.ISO-8859-1 da_DK.ISO-8859-1 \\\n\t hr_HR.ISO-8859-2 sv_SE.ISO-8859-1 tr_TR.UTF-8 fr_FR.UTF-8 \\\n\t si_LK.UTF-8\ntest-input-data = $(addsuffix .in, $(basename $(test-input)))\ntest-output := $(foreach s, .out .xout, \\\n\t\t\t $(addsuffix $s, $(basename $(test-input))))\nld-test-names := test1 test2 test3 test4 test5 test6 test7\nld-test-srcs := $(addprefix tests/,$(addsuffix .cm,$(ld-test-names)) \\\n\t\t\t\t $(addsuffix .def,$(ld-test-names)) \\\n\t\t\t\t $(addsuffix .ds,test5 test6) \\\n\t\t\t\t test6.c trans.def)\n\nfmon-tests = n01y12 n02n40 n10y31 n11y41 n12y11 n20n32 n30y20 n41n00 \\\n\t y01y10 y02n22 y22n42 y30y21 y32n31 y40y00 y42n21\n\ngenerated := $(test-input) $(test-output) sort-test.out tst-locale.out \\\n\t tst-mbswcs.out tst-leaks.mtrace mtrace-tst-leaks\ngenerated-dirs := $(ld-test-names) tt_TT de_DE.437\t\t\t\\\n\t\t $(addprefix tstfmon_,$(fmon-tests))\t\t\t\\\n\n# Get $(inst_i18ndir) defined.\ninclude ../Makeconfig\n\nifeq ($(run-built-tests),yes)\nlocale_test_suite := tst_iswalnum tst_iswalpha tst_iswcntrl \\\n\t\t tst_iswctype tst_iswdigit tst_iswgraph \\\n\t\t tst_iswlower tst_iswprint tst_iswpunct \\\n\t\t tst_iswspace tst_iswupper tst_iswxdigit tst_mblen \\\n\t\t tst_mbrlen tst_mbrtowc tst_mbsrtowcs tst_mbstowcs \\\n\t\t tst_mbtowc tst_strcoll tst_strfmon tst_strxfrm \\\n\t\t tst_swscanf tst_towctrans tst_towlower \\\n\t\t tst_towupper tst_wcrtomb tst_wcscat tst_wcschr \\\n\t\t tst_wcscmp tst_wcscoll tst_wcscpy tst_wcscspn \\\n\t\t tst_wcslen tst_wcsncat tst_wcsncmp tst_wcsncpy \\\n\t\t tst_wcspbrk tst_wcsrtombs tst_wcsspn tst_wcsstr \\\n\t\t tst_wcstod tst_wcstok tst_wcstombs tst_wcswidth \\\n\t\t tst_wcsxfrm tst_wctob tst_wctomb tst_wctrans \\\n\t\t tst_wctype tst_wcwidth\n\ntests = $(locale_test_suite) tst-digits tst-setlocale bug-iconv-trans \\\n\ttst-leaks tst-mbswcs6 tst-xlocale1 tst-xlocale2 bug-usesetlocale \\\n\ttst-strfmon1 tst-sscanf bug-setlocale1 tst-setlocale2\ntests-static = bug-setlocale1-static\ntests += $(tests-static)\nifeq (yes,$(build-shared))\nifneq (no,$(PERL))\ntests: $(objpfx)mtrace-tst-leaks\nendif\nendif\nendif\n\n# Files to install.\ninstall-others := $(addprefix $(inst_i18ndir)/, \\\n\t\t\t $(addsuffix .gz, $(charmaps)) \\\n\t\t\t $(locales))\n\ntests: $(objdir)/iconvdata/gconv-modules\n\ninclude ../Rules\n\n# Install the charmap files in gzipped format.\n$(inst_i18ndir)/charmaps/%.gz: charmaps/% $(+force)\n\t$(make-target-dir\n/* ... truncated ... */\n```\n\n### manual/locale.texi\n\n#### region() [lines 1-76]\n```c\n@node Locales, Message Translation, Character Set Handling, Top\n@c %MENU% The country and language can affect the behavior of library functions\n@chapter Locales and Internationalization\n\nDifferent countries and cultures have varying conventions for how to\ncommunicate. These conventions range from very simple ones, such as the\nformat for representing dates and times, to very complex ones, such as\nthe language spoken.\n\n@cindex internationalization\n@cindex locales\n@dfn{Internationalization} of software means programming it to be able\nto adapt to the user's favorite conventions. In @w{ISO C},\ninternationalization works by means of @dfn{locales}. Each locale\nspecifies a collection of conventions, one convention for each purpose.\nThe user chooses a set of conventions by specifying a locale (via\nenvironment variables).\n\nAll programs inherit the chosen locale as part of their environment.\nProvided the programs are written to obey the choice of locale, they\nwill follow the conventions preferred by the user.\n\n@menu\n* Effects of Locale:: Actions affected by the choice of\n locale.\n* Choosing Locale:: How the user specifies a locale.\n* Locale Categories:: Different purposes for which you can\n select a locale.\n* Setting the Locale:: How a program specifies the locale\n with library functions.\n* Standard Locales:: Locale names available on all systems.\n* Locale Information:: How to access the information for the locale.\n* Formatting Numbers:: A dedicated function to format numbers.\n* Yes-or-No Questions:: Check a Response against the locale.\n@end menu\n\n@node Effects of Locale, Choosing Locale, , Locales\n@section What Effects a Locale Has\n\nEach locale specifies conventions for several purposes, including the\nfollowing:\n\n@itemize @bullet\n@item\nWhat multibyte character sequences are valid, and how they are\ninterpreted (@pxref{Character Set Handling}).\n\n@item\nClassification of which characters in the local character set are\nconsidered alphabetic, and upper- and lower-case conversion conventions\n(@pxref{Character Handling}).\n\n@item\nThe collating sequence for the local language and character set\n(@pxref{Collation Functions}).\n\n@item\nFormatting of numbers and currency amounts (@pxref{General Numeric}).\n\n@item\nFormatting of dates and times (@pxref{Formatting Calendar Time}).\n\n@item\nWhat language to use for output, incl\n/* ... truncated ... */\n```\n\n\n### Type definitions\n\n```c\n/* from localeinfo.h */\nstruct __locale_data\n{\n const char *name;\n const char *filedata;\t\t/* Region mapping the file data. */\n off_t filesize;\t\t/* Size of the file (and the region). */\n enum\t\t\t\t/* Flavor of storage used for those. */\n {\n ld_malloced,\t\t/* Both are malloc'd. */\n ld_mapped,\t\t\t/* name is malloc'd, filedata mmap'd */\n ld_archive\t\t\t/* Both point into mmap'd archive regions. */\n } alloc;\n\n /* This provides a slot for category-specific code to cache data computed\n about this locale. That code can set a cleanup function to deallocate\n the data. */\n struct\n {\n void (*cleanup) (struct __locale_data *) internal_function;\n union\n {\n void *data;\n struct lc_time_data *time;\n const struct gconv_fcts *ctype;\n };\n } private;\n\n unsigned int usage_count;\t/* Counter for users. */\n\n int use_translit;\t\t/* Nonzero if the mb*towv*() and wc*tomb()\n\t\t\t\t functions should use transliteration. */\n\n unsigned int nstrings;\t/* Number of strings below. */\n union locale_data_value\n {\n const uint32_t *wstr;\n const char *string;\n unsigned int word;\t\t/* Note endian issues vs 64-bit pointers. */\n }\n values __flexarr;\t/* Items, usually pointers into `filedata'. */\n};\n\n/* from localeinfo.h */\nstruct __locale_data\n{\n const char *name;\n const char *filedata;\t\t/* Region mapping the file data. */\n off_t filesize;\t\t/* Size of the file (and the region). */\n enum\t\t\t\t/* Flavor of storage used for those. */\n {\n ld_malloced,\t\t/* Both are malloc'd. */\n ld_mapped,\t\t\t/* name is malloc'd, filedata mmap'd */\n ld_archive\t\t\t/* Both point into mmap'd archive regions. */\n } alloc;\n\n /* This provides a slot for category-specific code to cache data computed\n about this locale. That code can set a cleanup function to deallocate\n the data. */\n struct\n {\n void (*cleanup) (struct __locale_data *) internal_function;\n union\n {\n void *data;\n struct lc_time_data *time;\n const struct gconv_fcts *ctype;\n };\n } private;\n\n unsigned int usage_count;\t/* Counter for users. */\n\n int use_translit;\t\t/* Nonzero if the mb*towv*() and wc*tomb()\n\t\t\t\t functions should use transliteration. */\n\n unsigned int nstrings;\t/* Number of strings below. */\n union locale_data_value\n {\n const uint32_t *wstr;\n const char *string;\n unsigned int word;\t\t/* Note endian issues vs 64-bit pointers. */\n }\n values __flexarr;\t/* Items, usually pointers into `filedata'. */\n};\n```\n\n\n## Upstream Fix\n```diff\n2014-07-02 Florian Weimer <fweimer@redhat.com>\n\n\t* manual/locale.texi (Locale Names): New section documenting\n\tlocale name syntax. Adjust menu and node chaining accordingly.\n\t(Choosing Locale): Reference Locale Names, Locale Categories.\n\tMention setting LC_ALL=C. Reflect that name syntax is now\n\tdocumented.\n\t(Locale Categories): New section title. Reference Locale Names.\n\tLC_ALL is an environment variable, but not a category.\n\t(Setting the Locale): Remove \"locale -a\" invocation and LOCPATH\n\tdescription, now in Locale Name. Reference that section. Locale\n\tname syntax is now documented.\n\n\t[BZ #17137]\n\t* locale/findlocale.c (name_present, valid_locale_name): New\n\tfunctions.\n\t(_nl_find_locale): Use the loc_name variable to store name\n\tcandidates. Call name_present and valid_locale_name to check and\n\tvalidate locale names. Return an error if the locale is invalid.\n\n\t* localedata/tst-setlocale3.c: New file.\n\t* localedata/Makefile (tests): Add tst-setlocale3.\n\t(tst-setlocale3-ENV): New variable.\n\n\t* locale/setlocale.c (setlocale): Use strdup for allocating\n\tcomposite name copy.\n\nIndex: glibc-2.19/locale/findlocale.c\n===================================================================\n--- glibc-2.19.orig/locale/findlocale.c\n+++ glibc-2.19/locale/findlocale.c\n@@ -17,6 +17,7 @@\n <http://www.gnu.org/licenses/>. */\n \n #include <assert.h>\n+#include <errno.h>\n #include <locale.h>\n #include <stdlib.h>\n #include <string.h>\n@@ -57,6 +58,45 @@ struct loaded_l10nfile *_nl_locale_file_\n \n const char _nl_default_locale_path[] attribute_hidden = LOCALEDIR;\n \n+/* Checks if the name is actually present, that is, not NULL and not\n+ empty. */\n+static inline int\n+name_present (const char *name)\n+{\n+ return name != NULL && name[0] != '\\0';\n+}\n+\n+/* Checks that the locale name neither extremely long, nor contains a\n+ \"..\" path component (to prevent directory traversal). */\n+static inline int\n+valid_locale_name (const char *name)\n+{\n+ /* Not set. */\n+ size_t namelen = strlen (name);\n+ /* Name too long. The limit is arbitrary and prevents stack overflow\n+ issues later. */\n+ if (__glibc_unlikely (namelen > 255))\n+ return 0;\n+ /* Directory traversal attempt. */\n+ static const char slashdot[4] = {'/', '.', '.', '/'};\n+ if (__glibc_unlikely (memmem (name, namelen,\n+\t\t\t\tslashdot, sizeof (slashdot)) != NULL))\n+ return 0;\n+ if (namelen == 2 && __glibc_unlikely (name[0] == '.' && name [1] == '.'))\n+ return 0;\n+ if (namelen >= 3\n+ && __glibc_unlikely (((name[0] == '.'\n+\t\t\t && name[1] == '.'\n+\t\t\t && name[2] == '/')\n+\t\t\t || (name[namelen - 3] == '/'\n+\t\t\t\t&& name[namelen - 2] == '.'\n+\t\t\t\t&& name[namelen - 1] == '.'))))\n+ return 0;\n+ /* If there is a slash in the name, it must start with one. */\n+ if (__glibc_unlikely (memchr (name, '/', namelen) != NULL) && name[0] != '/')\n+ return 0;\n+ return 1;\n+}\n \n struct __locale_data *\n internal_function\n@@ -65,7 +105,7 @@ _nl_find_locale (const char *locale_path\n {\n int mask;\n /* Name of the locale for this category. */\n- char *loc_name;\n+ char *loc_name = (char *) *name;\n const char *language;\n const char *modifier;\n const char *territory;\n@@ -73,31 +113,39 @@ _nl_find_locale (const char *locale_path\n const char *normalized_codeset;\n struct loaded_l10nfile *locale_file;\n \n- if ((*name)[0] == '\\0')\n+ if (loc_name[0] == '\\0')\n {\n /* The user decides which locale to use by setting environment\n \t variables. */\n- *name = getenv (\"LC_ALL\");\n- if (*name == NULL || (*name)[0] == '\\0')\n-\t*name = getenv (_nl_category_names.str\n+ loc_name = getenv (\"LC_ALL\");\n+ if (!name_present (loc_name))\n+\tloc_name = getenv (_nl_category_names.str\n \t\t\t+ _nl_category_name_idxs[category]);\n- if (*name == NULL || (*name)[0] == '\\0')\n-\t*name = getenv (\"LANG\");\n+ if (!name_present (loc_name))\n+\tloc_name = getenv (\"LANG\");\n+ if (!name_present (loc_name))\n+\tloc_name = (char *) _nl_C_name;\n }\n \n- if (*name == NULL || (*name)[0] == '\\0'\n- || (__builtin_expect (__libc_enable_secure, 0)\n-\t && strchr (*name, '/') != NULL))\n- *name = (char *) _nl_C_name;\n+ /* We used to fall back to the C locale if the name contains a slash\n+ character '/', but we now check for directory traversal in\n+ valid_locale_name, so this is no longer necessary. */\n \n- if (__builtin_expect (strcmp (*name, _nl_C_name), 1) == 0\n- || __builtin_expect (strcmp (*name, _nl_POSIX_name), 1) == 0)\n+ if (__builtin_expect (strcmp (loc_name, _nl_C_name), 1) == 0\n+ || __builtin_expect (strcmp (loc_name, _nl_POSIX_name), 1) == 0)\n {\n /* We need not load anything. The needed data is contained in\n \t the library itself. */\n *name = (char *) _nl_C_name;\n return _nl_C[category];\n }\n+ else if (!valid_locale_name (loc_name))\n+ {\n+ __set_errno (EINVAL);\n+ return NULL;\n+ }\n+\n+ *name = loc_name;\n \n /* We really have to load some data. First we try the archive,\n but only if there was no LOCPATH environment variable specified. */\nIndex: glibc-2.19/locale/setlocale.c\n===================================================================\n--- glibc-2.19.orig/locale/setlocale.c\n+++ glibc-2.19/locale/setlocale.c\n@@ -272,6 +272,8 @@ setlocale (int category, const char *loc\n \t of entries of the form `CATEGORY=VALUE'. */\n const char *newnames[__LC_LAST];\n struct __locale_data *newdata[__LC_LAST];\n+ /* Copy of the locale argument, for in-place splitting. */\n+ char *locale_copy = NULL;\n \n /* Set all name pointers to the argument name. */\n for (category = 0; category < __LC_LAST; ++category)\n@@ -281,7 +283,13 @@ setlocale (int category, const char *loc\n if (__builtin_expect (strchr (locale, ';') != NULL, 0))\n \t{\n \t /* This is a composite name. Make a copy and split it up. */\n-\t char *np = strdupa (locale);\n+\t locale_copy = strdup (locale);\n+\t if (__glibc_unlikely (locale_copy == NULL))\n+\t {\n+\t __libc_rwlock_unlock (__libc_setlocale_lock);\n+\t return NULL;\n+\t }\n+\t char *np = locale_copy;\n \t char *cp;\n \t int cnt;\n \n@@ -299,6 +307,7 @@ setlocale (int category, const char *loc\n \t\t{\n \t\terror_return:\n \t\t __libc_rwlock_unlock (__libc_setlocale_lock);\n+\t\t free (locale_copy);\n \n \t\t /* Bogus category name. */\n \t\t ERROR_RETURN;\n@@ -391,8 +400,9 @@ setlocale (int category, const char *loc\n /* Critical section left. */\n __libc_rwlock_unlock (__libc_setlocale_lock);\n \n- /* Free the resources (the locale path variable). */\n+ /* Free the resources. */\n free (locale_path);\n+ free (locale_copy);\n \n return composite;\n }\nIndex: glibc-2.19/localedata/Makefile\n===================================================================\n--- glibc-2.19.orig/localedata/Makefile\n+++ glibc-2.19/localedata/Makefile\n@@ -77,7 +77,7 @@ locale_test_suite := tst_iswalnum tst_is\n \n tests = $(locale_test_suite) tst-digits tst-setlocale bug-iconv-trans \\\n \ttst-leaks tst-mbswcs6 tst-xlocale1 tst-xlocale2 bug-usesetlocale \\\n-\ttst-strfmon1 tst-sscanf bug-setlocale1 tst-setlocale2\n+\ttst-strfmon1 tst-sscanf bug-setlocale1 tst-setlocale2 tst-setlocale3\n tests-static = bug-setlocale1-static\n tests += $(tests-static)\n ifeq (yes,$(build-shared))\n@@ -292,6 +292,7 @@ bug-setlocale1-ARGS = -- $(host-test-pro\n bug-setlocale1-static-ENV = $(bug-setlocale1-ENV)\n bug-setlocale1-static-ARGS = $(bug-setlocale1-ARGS)\n tst-setlocale2-ENV = LOCPATH=$(common-objpfx)localedata\n+tst-setlocale3-ENV = LOCPATH=$(common-objpfx)localedata\n \n $(objdir)/iconvdata/gconv-modules:\n \t$(MAKE) -C ../iconvdata subdir=iconvdata $@\nIndex: glibc-2.19/localedata/tst-setlocale3.c\n===================================================================\n--- /dev/null\n+++ glibc-2.19/localedata/tst-setlocale3.c\n@@ -0,0 +1,203 @@\n+/* Regression test for setlocale invalid environment variable handling.\n+ Copyright (C) 2014 Free Software Foundation, Inc.\n+ This file is part of the GNU C Library.\n+\n+ The GN\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "2014-07-02 Florian Weimer <fweimer@redhat.com>\n\n\t* manual/locale.texi (Locale Names): New section documenting\n\tlocale name syntax. Adjust menu and node chaining accordingly.\n\t(Choosing Locale): Reference Locale Names, Locale Categories.\n\tMention setting LC_ALL=C. Reflect that name syntax is now\n\tdocumented.\n\t(Locale Categories): New section title. Reference Locale Names.\n\tLC_ALL is an environment variable, but not a category.\n\t(Setting the Locale): Remove \"locale -a\" invocation and LOCPATH\n\tdescription, now in Locale Name. Reference that section. Locale\n\tname syntax is now documented.\n\n\t[BZ #17137]\n\t* locale/findlocale.c (name_present, valid_locale_name): New\n\tfunctions.\n\t(_nl_find_locale): Use the loc_name variable to store name\n\tcandidates. Call name_present and valid_locale_name to check and\n\tvalidate locale names. Return an error if the locale is invalid.\n\n\t* localedata/tst-setlocale3.c: New file.\n\t* localedata/Makefile (tests): Add tst-setlocale3.\n\t(tst-setlocale3-ENV): New variable.\n\n\t* locale/setlocale.c (setlocale): Use strdup for allocating\n\tcomposite name copy.\n\nIndex: glibc-2.19/locale/findlocale.c\n===================================================================\n--- glibc-2.19.orig/locale/findlocale.c\n+++ glibc-2.19/locale/findlocale.c\n@@ -17,6 +17,7 @@\n <http://www.gnu.org/licenses/>. */\n \n #include <assert.h>\n+#include <errno.h>\n #include <locale.h>\n #include <stdlib.h>\n #include <string.h>\n@@ -57,6 +58,45 @@ struct loaded_l10nfile *_nl_locale_file_\n \n const char _nl_default_locale_path[] attribute_hidden = LOCALEDIR;\n \n+/* Checks if the name is actually present, that is, not NULL and not\n+ empty. */\n+static inline int\n+name_present (const char *name)\n+{\n+ return name != NULL && name[0] != '\\0';\n+}\n+\n+/* Checks that the locale name neither extremely long, nor contains a\n+ \"..\" path component (to prevent directory traversal). */\n+static inline int\n+valid_locale_name (const char *name)\n+{\n+ /* Not set. */\n+ size_t namelen = strlen (name);\n+ /* Name too long. The limit is arbitrary and prevents stack overflow\n+ issues later. */\n+ if (__glibc_unlikely (namelen > 255))\n+ return 0;\n+ /* Directory traversal attempt. */\n+ static const char slashdot[4] = {'/', '.', '.', '/'};\n+ if (__glibc_unlikely (memmem (name, namelen,\n+\t\t\t\tslashdot, sizeof (slashdot)) != NULL))\n+ return 0;\n+ if (namelen == 2 && __glibc_unlikely (name[0] == '.' && name [1] == '.'))\n+ return 0;\n+ if (namelen >= 3\n+ && __glibc_unlikely (((name[0] == '.'\n+\t\t\t && name[1] == '.'\n+\t\t\t && name[2] == '/')\n+\t\t\t || (name[namelen - 3] == '/'\n+\t\t\t\t&& name[namelen - 2] == '.'\n+\t\t\t\t&& name[namelen - 1] == '.'))))\n+ return 0;\n+ /* If there is a slash in the name, it must start with one. */\n+ if (__glibc_unlikely (memchr (name, '/', namelen) != NULL) && name[0] != '/')\n+ return 0;\n+ return 1;\n+}\n \n struct __locale_data *\n internal_function\n@@ -65,7 +105,7 @@ _nl_find_locale (const char *locale_path\n {\n int mask;\n /* Name of the locale for this category. */\n- char *loc_name;\n+ char *loc_name = (char *) *name;\n const char *language;\n const char *modifier;\n const char *territory;\n@@ -73,31 +113,39 @@ _nl_find_locale (const char *locale_path\n const char *normalized_codeset;\n struct loaded_l10nfile *locale_file;\n \n- if ((*name)[0] == '\\0')\n+ if (loc_name[0] == '\\0')\n {\n /* The user decides which locale to use by setting environment\n \t variables. */\n- *name = getenv (\"LC_ALL\");\n- if (*name == NULL || (*name)[0] == '\\0')\n-\t*name = getenv (_nl_category_names.str\n+ loc_name = getenv (\"LC_ALL\");\n+ if (!name_present (loc_name))\n+\tloc_name = getenv (_nl_category_names.str\n \t\t\t+ _nl_category_name_idxs[category]);\n- if (*name == NULL || (*name)[0] == '\\0')\n-\t*name = getenv (\"LANG\");\n+ if (!name_present (loc_name))\n+\tloc_name = getenv (\"LANG\");\n+ if (!name_present (loc_name))\n+\tloc_name = (char *) _nl_C_name;\n }\n \n- if (*name == NULL || (*name)[0] == '\\0'\n- || (__builtin_expect (__libc_enable_secure, 0)\n-\t && strchr (*name, '/') != NULL))\n- *name = (char *) _nl_C_name;\n+ /* We used to fall back to the C locale if the name contains a slash\n+ character '/', but we now check for directory traversal in\n+ valid_locale_name, so this is no longer necessary. */\n \n- if (__builtin_expect (strcmp (*name, _nl_C_name), 1) == 0\n- || __builtin_expect (strcmp (*name, _nl_POSIX_name), 1) == 0)\n+ if (__builtin_expect (strcmp (loc_name, _nl_C_name), 1) == 0\n+ || __builtin_expect (strcmp (loc_name, _nl_POSIX_name), 1) == 0)\n {\n /* We need not load anything. The needed data is contained in\n \t the library itself. */\n *name = (char *) _nl_C_name;\n return _nl_C[category];\n }\n+ else if (!valid_locale_name (loc_name))\n+ {\n+ __set_errno (EINVAL);\n+ return NULL;\n+ }\n+\n+ *name = loc_name;\n \n /* We really have to load some data. First we try the archive,\n but only if there was no LOCPATH environment variable specified. */\nIndex: glibc-2.19/locale/setlocale.c\n===================================================================\n--- glibc-2.19.orig/locale/setlocale.c\n+++ glibc-2.19/locale/setlocale.c\n@@ -272,6 +272,8 @@ setlocale (int category, const char *loc\n \t of entries of the form `CATEGORY=VALUE'. */\n const char *newnames[__LC_LAST];\n struct __locale_data *newdata[__LC_LAST];\n+ /* Copy of the locale argument, for in-place splitting. */\n+ char *locale_copy = NULL;\n \n /* Set all name pointers to the argument name. */\n for (category = 0; category < __LC_LAST; ++category)\n@@ -281,7 +283,13 @@ setlocale (int category, const char *loc\n if (__builtin_expect (strchr (locale, ';') != NULL, 0))\n \t{\n \t /* This is a composite name. Make a copy and split it up. */\n-\t char *np = strdupa (locale);\n+\t locale_copy = strdup (locale);\n+\t if (__glibc_unlikely (locale_copy == NULL))\n+\t {\n+\t __libc_rwlock_unlock (__libc_setlocale_lock);\n+\t return NULL;\n+\t }\n+\t char *np = locale_copy;\n \t char *cp;\n \t int cnt;\n \n@@ -299,6 +307,7 @@ setlocale (int category, const char *loc\n \t\t{\n \t\terror_return:\n \t\t __libc_rwlock_unlock (__libc_setlocale_lock);\n+\t\t free (locale_copy);\n \n \t\t /* Bogus category name. */\n \t\t ERROR_RETURN;\n@@ -391,8 +400,9 @@ setlocale (int category, const char *loc\n /* Critical section left. */\n __libc_rwlock_unlock (__libc_setlocale_lock);\n \n- /* Free the resources (the locale path variable). */\n+ /* Free the resources. */\n free (locale_path);\n+ free (locale_copy);\n \n return composite;\n }\nIndex: glibc-2.19/localedata/Makefile\n===================================================================\n--- glibc-2.19.orig/localedata/Makefile\n+++ glibc-2.19/localedata/Makefile\n@@ -77,7 +77,7 @@ locale_test_suite := tst_iswalnum tst_is\n \n tests = $(locale_test_suite) tst-digits tst-setlocale bug-iconv-trans \\\n \ttst-leaks tst-mbswcs6 tst-xlocale1 tst-xlocale2 bug-usesetlocale \\\n-\ttst-strfmon1 tst-sscanf bug-setlocale1 tst-setlocale2\n+\ttst-strfmon1 tst-sscanf bug-setlocale1 tst-setlocale2 tst-setlocale3\n tests-static = bug-setlocale1-static\n tests += $(tests-static)\n ifeq (yes,$(build-shared))\n@@ -292,6 +292,7 @@ bug-setlocale1-ARGS = -- $(host-test-pro\n bug-setlocale1-static-ENV = $(bug-setlocale1-ENV)\n bug-setlocale1-static-ARGS = $(bug-setlocale1-ARGS)\n tst-setlocale2-ENV = LOCPATH=$(common-objpfx)localedata\n+tst-setlocale3-ENV = LOCPATH=$(common-objpfx)localedata\n \n $(objdir)/iconvdata/gconv-modules:\n \t$(MAKE) -C ../iconvdata subdir=iconvdata $@\nIndex: glibc-2.19/localedata/tst-setlocale3.c\n===================================================================\n--- /dev/null\n+++ glibc-2.19/localedata/tst-setlocale3.c\n@@ -0,0 +1,203 @@\n+/* Regression test for setlocale invalid environment variable handling.\n+ Copyright (C) 2014 Free Software Foundation, Inc.\n+ This file is part of the GNU C Library.\n+\n+ The GNU C Library is free software; you can redistribute it and/or\n+ modify it under the terms of the GNU Lesser General Public\n+ License as published by the Free Software Foundation; either\n+ version 2.1 of the License, or (at your option) any later version.\n+\n+ The GNU C Library is distributed in the hope that it will be useful,\n+ but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ Lesser General Public License for more details.\n+\n+ You should have received a copy of the GNU Lesser General Public\n+ License along with the GNU C Library; if not, see\n+ <http://www.gnu.org/licenses/>. */\n+\n+#include <locale.h>\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <string.h>\n+\n+/* The result of setlocale may be overwritten by subsequent calls, so\n+ this wrapper makes a copy. */\n+static char *\n+setlocale_copy (int category, const char *locale)\n+{\n+ const char *result = setlocale (category, locale);\n+ if (result == NULL)\n+ return NULL;\n+ return strdup (result);\n+}\n+\n+static char *de_locale;\n+\n+static void\n+setlocale_fail (const char *envstring)\n+{\n+ setenv (\"LC_CTYPE\", envstring, 1);\n+ if (setlocale (LC_CTYPE, \"\") != NULL)\n+ {\n+ printf (\"unexpected setlocale success for \\\"%s\\\" locale\\n\", envstring);\n+ exit (1);\n+ }\n+ const char *newloc = setlocale (LC_CTYPE, NULL);\n+ if (strcmp (newloc, de_locale) != 0)\n+ {\n+ printf (\"failed setlocale call \\\"%s\\\" changed locale to \\\"%s\\\"\\n\",\n+\t envstring, newloc);\n+ exit (1);\n+ }\n+}\n+\n+static void\n+setlocale_success (const char *envstring)\n+{\n+ setenv (\"LC_CTYPE\", envstring, 1);\n+ char *newloc = setlocale_copy (LC_CTYPE, \"\");\n+ if (newloc == NULL)\n+ {\n+ printf (\"setlocale for \\\"%s\\\": %m\\n\", envstring);\n+ exit (1);\n+ }\n+ if (strcmp (newloc, de_locale) == 0)\n+ {\n+ printf (\"setlocale with LC_CTYPE=\\\"%s\\\" left locale at \\\"%s\\\"\\n\",\n+\t envstring, de_locale);\n+ exit (1);\n+ }\n+ if (setlocale (LC_CTYPE, de_locale) == NULL)\n+ {\n+ printf (\"restoring locale \\\"%s\\\" with LC_CTYPE=\\\"%s\\\": %m\\n\",\n+\t de_locale, envstring);\n+ exit (1);\n+ }\n+ char *newloc2 = setlocale_copy (LC_CTYPE, newloc);\n+ if (newloc2 == NULL)\n+ {\n+ printf (\"restoring locale \\\"%s\\\" following \\\"%s\\\": %m\\n\",\n+\t newloc, envstring);\n+ exit (1);\n+ }\n+ if (strcmp (newloc, newloc2) != 0)\n+ {\n+ printf (\"representation of locale \\\"%s\\\" changed from \\\"%s\\\" to \\\"%s\\\"\",\n+\t envstring, newloc, newloc2);\n+ exit (1);\n+ }\n+ free (newloc);\n+ free (newloc2);\n+\n+ if (setlocale (LC_CTYPE, de_locale) == NULL)\n+ {\n+ printf (\"restoring locale \\\"%s\\\" with LC_CTYPE=\\\"%s\\\": %m\\n\",\n+\t de_locale, envstring);\n+ exit (1);\n+ }\n+}\n+\n+/* Checks that a known-good locale still works if LC_ALL contains a\n+ value which should be ignored. */\n+static void\n+setlocale_ignore (const char *to_ignore)\n+{\n+ const char *fr_locale = \"fr_FR.UTF-8\";\n+ setenv (\"LC_CTYPE\", fr_locale, 1);\n+ char *expected_locale = setlocale_copy (LC_CTYPE, \"\");\n+ if (expected_locale == NULL)\n+ {\n+ printf (\"setlocale with LC_CTYPE=\\\"%s\\\" failed: %m\\n\", fr_locale);\n+ exit (1);\n+ }\n+ if (setlocale (LC_CTYPE, de_locale) == NULL)\n+ {\n+ printf (\"failed to restore locale: %m\\n\");\n+ exit (1);\n+ }\n+ unsetenv (\"LC_CTYPE\");\n+\n+ setenv (\"LC_ALL\", to_ignore, 1);\n+ setenv (\"LC_CTYPE\", fr_locale, 1);\n+ const char *actual_locale = setlocale (LC_CTYPE, \"\");\n+ if (actual_locale == NULL)\n+ {\n+ printf (\"setlocale with LC_ALL, LC_CTYPE=\\\"%s\\\" failed: %m\\n\",\n+\t fr_locale);\n+ exit (1);\n+ }\n+ if (strcmp (actual_locale, expected_locale) != 0)\n+ {\n+ printf (\"setlocale under LC_ALL failed: got \\\"%s\\\", expected \\\"%s\\\"\\n\",\n+\t actual_locale, expected_locale);\n+ exit (1);\n+ }\n+ unsetenv (\"LC_CTYPE\");\n+ setlocale_success (fr_locale);\n+ unsetenv (\"LC_ALL\");\n+ free (expected_locale);\n+}\n+\n+static int\n+do_test (void)\n+{\n+ /* The glibc test harness sets this environment variable\n+ uncondionally. */\n+ unsetenv (\"LC_ALL\");\n+\n+ de_locale = setlocale_copy (LC_CTYPE, \"de_DE.UTF-8\");\n+ if (de_locale == NULL)\n+ {\n+ printf (\"setlocale (LC_CTYPE, \\\"de_DE.UTF-8\\\"): %m\\n\");\n+ return 1;\n+ }\n+ setlocale_success (\"C\");\n+ setlocale_success (\"en_US.UTF-8\");\n+ setlocale_success (\"/en_US.UTF-8\");\n+ setlocale_success (\"//en_US.UTF-8\");\n+ setlocale_ignore (\"\");\n+\n+ setlocale_fail (\"does-not-exist\");\n+ setlocale_fail (\"/\");\n+ setlocale_fail (\"/../localedata/en_US.UTF-8\");\n+ setlocale_fail (\"en_US.UTF-8/\");\n+ setlocale_fail (\"en_US.UTF-8/..\");\n+ setlocale_fail (\"en_US.UTF-8/../en_US.UTF-8\");\n+ setlocale_fail (\"../localedata/en_US.UTF-8\");\n+ {\n+ size_t large_length = 1024;\n+ char *large_name = malloc (large_length + 1);\n+ if (large_name == NULL)\n+ {\n+\tputs (\"malloc failure\");\n+\treturn 1;\n+ }\n+ memset (large_name, '/', large_length);\n+ const char *suffix = \"en_US.UTF-8\";\n+ strcpy (large_name + large_length - strlen (suffix), suffix);\n+ setlocale_fail (large_name);\n+ free (large_name);\n+ }\n+ {\n+ size_t huge_length = 64 * 1024 * 1024;\n+ char *huge_name = malloc (huge_length + 1);\n+ if (huge_name == NULL)\n+ {\n+\tputs (\"malloc failure\");\n+\treturn 1;\n+ }\n+ memset (huge_name, 'X', huge_length);\n+ huge_name[huge_length] = '\\0';\n+ /* Construct a composite locale specification. */\n+ const char *prefix = \"LC_CTYPE=de_DE.UTF-8;LC_TIME=\";\n+ memcpy (huge_name, prefix, strlen (prefix));\n+ setlocale_fail (huge_name);\n+ free (huge_name);\n+ }\n+\n+ return 0;\n+}\n+\n+#define TEST_FUNCTION do_test ()\n+#include \"../test-skeleton.c\"\nIndex: glibc-2.19/manual/locale.texi\n===================================================================\n--- glibc-2.19.orig/manual/locale.texi\n+++ glibc-2.19/manual/locale.texi\n@@ -29,6 +29,7 @@ will follow the conventions preferred by\n * Setting the Locale:: How a program specifies the locale\n with library functions.\n * Standard Locales:: Locale names available on all systems.\n+* Locale Names:: Format of system-specific locale names.\n * Locale Information:: How to access the information for the locale.\n * Formatting Numbers:: A dedicated function to format numbers.\n * Yes-or-No Questions:: Check a Response against the locale.\n@@ -99,14 +100,16 @@ locale named @samp{espana-castellano} to\n most of Spain.\n \n The set of locales supported depends on the operating system you are\n-using, and so do their names. We can't make any promises about what\n-locales will exist, except for one standard locale called @samp{C} or\n-@samp{POSIX}. Later we will describe how to construct locales.\n-@comment (@pxref{Building Locale Files}).\n+using, and so do their names, except that the standard locale called\n+@samp{C} or @samp{POSIX} always exist. @xref{Locale Names}.\n+\n+In order to force the system to always use the default locale, the\n+user can set the @code{LC_ALL} environment variable to @samp{C}.\n \n @cindex combining locales\n-A user also has the option of specifying different locales for different\n-purposes---in effect, choosing a mixture of multiple locales.\n+A user also has the option of specifying different locales for\n+different purposes---in effect, choosing a mixture of multiple\n+locales. @xref{Locale Categories}.\n \n For example, the user might specify the locale @samp{espana-castellano}\n for most purposes, but specify the locale @samp{usa-english} for\n@@ -120,7 +123,7 @@ which locales apply. However, the user\n for a particular subset of those purposes.\n \n @node Locale Categories, Setting the Locale, Choosing Locale, Locales\n-@section Categories of Activities that Locales Affect\n+@section Locale Categories\n @cindex categories for locales\n @cindex locale categories\n \n@@ -128,7 +131,11 @@ The purposes that locales serve are grou\n that a user or a program can choose the locale for each category\n independently. Here is a table of categories; each name is both an\n environment variable that a user can set, and a macro name that you can\n-use as an argument to @code{setlocale}.\n+use as the first argument to @code{setlocale}.\n+\n+The contents of the environment variable (or the string in the second\n+argument to @code{setlocale}) has to be a valid locale name.\n+@xref{Locale Names}.\n \n @vtable @code\n @comment locale.h\n@@ -172,7 +179,7 @@ for affirmative and negative responses.\n @comment locale.h\n @comment ISO\n @item LC_ALL\n-This is not an environment variable; it is only a macro that you can use\n+This is not a category; it is only a macro that you can use\n with @code{setlocale} to set a single locale for all purposes. Setting\n this environment variable overwrites all selections by the other\n @code{LC_*} variables or @code{LANG}.\n@@ -355,13 +362,7 @@ The symbols in this section are defined\n @c strndup @ascuheap @acsmem\n @c strcasecmp_l ok (C locale)\n The function @code{setlocale} sets the current locale for category\n-@var{category} to @var{locale}. A list of all the locales the system\n-provides can be created by running\n-\n-@pindex locale\n-@smallexample\n- locale -a\n-@end smallexample\n+@var{category} to @var{locale}.\n \n If @var{category} is @code{LC_ALL}, this specifies the locale for all\n purposes. The other possible values of @var{category} specify an\n@@ -386,10 +387,9 @@ is passed in as @var{locale} parameter.\n \n When you read the current locale for category @code{LC_ALL}, the value\n encodes the entire combination of selected locales for all categories.\n-In this case, the value is not just a single locale name. In fact, we\n-don't make any promises about what it looks like. But if you specify\n-the same ``locale name'' with @code{LC_ALL} in a subsequent call to\n-@code{setlocale}, it restores the same combination of locale selections.\n+If you specify the same ``locale name'' with @code{LC_ALL} in a\n+subsequent call to @code{setlocale}, it restores the same combination\n+of locale selections.\n \n To be sure you can use the returned string encoding the currently selected\n locale at a later time, you must make a copy of the string. It is not\n@@ -405,20 +405,15 @@ for @var{category}.\n If a nonempty string is given for @var{locale}, then the locale of that\n name is used if possible.\n \n+The effective locale name (either the second argument to\n+@code{setlocale}, or if the argument is an empty string, the name\n+obtained from the process environment) must be valid locale name.\n+@xref{Locale Names}.\n+\n If you specify an invalid locale name, @code{setlocale} returns a null\n pointer and leaves the current locale unchanged.\n @end deftypefun\n \n-The path used for finding locale data can be set using the\n-@code{LOCPATH} environment variable. The default path for finding\n-locale data is system specific. It is computed from the value given\n-as the prefix while configuring the C library. This value normally is\n-@file{/usr} or @file{/}. For the former the complete path is:\n-\n-@smallexample\n-/usr/lib/locale\n-@end smallexample\n-\n Here is an example showing how you might use @code{setlocale} to\n temporarily switch to a new locale.\n \n@@ -458,7 +453,7 @@ locale categories, and future versions o\n portability, assume that any symbol beginning with @samp{LC_} might be\n defined in @file{locale.h}.\n \n-@node Standard Locales, Locale Information, Setting the Locale, Locales\n+@node Standard Locales, Locale Names, Setting the Locale, Locales\n @section Standard Locales\n \n The only locale names you can count on finding on all operating systems\n@@ -492,7 +487,94 @@ with the environment, rather than trying\n locale explicitly by name. Remember, different machines might have\n different sets of locales installed.\n \n-@node Locale Information, Formatting Numbers, Standard Locales, Locales\n+@node Locale Names, Locale Information, Standard Locales, Locales\n+@section Locale Names\n+\n+The following command prints a list of locales supported by the\n+system:\n+\n+@pindex locale\n+@smallexample\n+ locale -a\n+@end smallexample\n+\n+@strong{Portability Note:} With the notable exception of the standard\n+locale names @samp{C} and @samp{POSIX}, locale names are\n+system-specific.\n+\n+Most locale names follow XPG syntax and consist of up to four parts:\n+\n+@smallexample\n+@var{language}[_@var{territory}[.@var{codeset}]][@@@var{modifier}]\n+@end smallexample\n+\n+Beside the first part, all of them are allowed to be missing. If the\n+full specified locale is not found, less specific ones are looked for.\n+The various parts will be stripped off, in the following order:\n+\n+@enumerate\n+@item\n+codeset\n+@item\n+normalized codeset\n+@item\n+territory\n+@item\n+modifier\n+@end enumerate\n+\n+For example, the locale name @samp{de_AT.iso885915@@euro} denotes a\n+German-language locale for use in Austria, using the ISO-8859-15\n+(Latin-9) character set, and with the Euro as the currency symbol.\n+\n+In addition to locale names which follow XPG syntax, systems may\n+provide aliases such as @samp{german}. Both categories of names must\n+not contain the slash character @samp{/}.\n+\n+If the locale name starts with a slash @samp{/}, it is treated as a\n+path relative to the configured locale directories; see @code{LOCPATH}\n+below. The specified path must not contain a component @samp{..}, or\n+the name is invalid, and @code{setlocale} will fail.\n+\n+@strong{Portability Note:} POSIX suggests that if a locale name starts\n+with a slash @samp{/}, it is resolved as an absolute path. However,\n+@theglibc{} treats it as a relative path under the directories listed\n+in @code{LOCPATH} (or the default locale directory if @code{LOCPATH}\n+is unset).\n+\n+Locale names which are longer than an implementation-defined limit are\n+invalid and cause @code{setlocale} to fail.\n+\n+As a special case, locale names used with @code{LC_ALL} can combine\n+several locales, reflecting different locale settings for different\n+categories. For example, you might want to use a U.S. locale with ISO\n+A4 paper format, so you set @code{LANG} to @samp{en_US.UTF-8}, and\n+@code{LC_PAPER} to @samp{de_DE.UTF-8}. In this case, the\n+@code{LC_ALL}-style combined locale name is\n+\n+@smallexample\n+LC_CTYPE=en_US.UTF-8;LC_TIME=en_US.UTF-8;LC_PAPER=de_DE.UTF-8;@dots{}\n+@end smallexample\n+\n+followed by other category settings not shown here.\n+\n+@vindex LOCPATH\n+The path used for finding locale data can be set using the\n+@code{LOCPATH} environment variable. This variable lists the\n+directories in which to search for locale definitions, separated by a\n+colon @samp{:}.\n+\n+The default path for finding locale data is system specific. A typical\n+value for the @code{LOCPATH} default is:\n+\n+@smallexample\n+/usr/share/locale\n+@end smallexample\n+\n+The value of @code{LOCPATH} is ignored by privileged programs for\n+security reasons, and only the default directory is used.\n+\n+@node Locale Information, Formatting Numbers, Locale Names, Locales\n @section Accessing Locale Information\n \n There are several ways to access locale information. The simplest" } ]
{ "id": "glibc-testsuite-4693-setlocale-directory-traversal.", "cve_id": "CVE-2015-8779", "package": "glibc-testsuite", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 3232, "context_files": 4 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-2105\n\nInteger overflow in the EVP_EncodeUpdate function in crypto/evp/encode.c in OpenSSL before 1.0.1t and 1.0.2 before 1.0.2h allows remote attackers to cause a denial of service (heap memory corruption) via a large amount of binary data.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i/crypto/rand/rand_lib.c\n- openssl-1.0.1i.orig/crypto/rand/rand.h\n- openssl-1.0.1i.orig/crypto/fips/fips_drbg_rand.c\n- openssl-1.0.1i.orig/crypto/rand/rand_lib.c\n- openssl-1.0.1i/crypto/fips/fips_drbg_rand.c\n\n## Target Source Code\n\n### crypto/rand/md_rand.c\n\n#### region() [lines 104-196]\n```c\n * ====================================================================\n *\n * This product includes cryptographic software written by Eric Young\n * (eay@cryptsoft.com). This product includes software written by Tim\n * Hudson (tjh@cryptsoft.com).\n *\n */\n\n#define OPENSSL_FIPSEVP\n\n#ifdef MD_RAND_DEBUG\n# ifndef NDEBUG\n# define NDEBUG\n# endif\n#endif\n\n#include <assert.h>\n#include <stdio.h>\n#include <string.h>\n\n#include \"e_os.h\"\n\n#include <openssl/crypto.h>\n#include <openssl/rand.h>\n#include \"rand_lcl.h\"\n\n#include <openssl/err.h>\n\n#ifdef BN_DEBUG\n# define PREDICT\n#endif\n\n/* #define PREDICT\t1 */\n\n#define STATE_SIZE\t1023\nstatic int state_num=0,state_index=0;\nstatic unsigned char state[STATE_SIZE+MD_DIGEST_LENGTH];\nstatic unsigned char md[MD_DIGEST_LENGTH];\nstatic long md_count[2]={0,0};\nstatic double entropy=0;\nstatic int initialized=0;\n\nstatic unsigned int crypto_lock_rand = 0; /* may be set only when a thread\n * holds CRYPTO_LOCK_RAND\n * (to prevent double locking) */\n/* access to lockin_thread is synchronized by CRYPTO_LOCK_RAND2 */\nstatic CRYPTO_THREADID locking_threadid; /* valid iff crypto_lock_rand is set */\n\n\n#ifdef PREDICT\nint rand_predictable=0;\n#endif\n\nconst char RAND_version[]=\"RAND\" OPENSSL_VERSION_PTEXT;\n\nstatic void ssleay_rand_cleanup(void);\nstatic void ssleay_rand_seed(const void *buf, int num);\nstatic void ssleay_rand_add(const void *buf, int num, double add_entropy);\nstatic int ssleay_rand_nopseudo_bytes(unsigned char *buf, int num);\nstatic int ssleay_rand_pseudo_bytes(unsigned char *buf, int num);\nstatic int ssleay_rand_status(void);\n\nRAND_METHOD rand_ssleay_meth={\n\tssleay_rand_seed,\n\tssleay_rand_nopseudo_bytes,\n\tssleay_rand_cleanup,\n\tssleay_rand_add,\n\tssleay_rand_pseudo_bytes,\n\tssleay_rand_status\n\t}; \n\nRAND_METHOD *RAND_SSLeay(void)\n\t{\n\treturn(&rand_ssleay_meth);\n\t}\n\nstatic void ssleay_rand_cleanup(void)\n\t{\n\tOPENSSL_cleanse(state,sizeof(state));\n\tstate_num=0;\n\tstate_index=0;\n\tOPENSSL_cleanse(md,MD_DIGEST_LENGTH);\n\tmd_count[0]=0;\n\tmd_count[1]=0;\n\tentropy=0;\n\tinitialized=0;\n\t}\n\nstatic void ssleay_rand_add(const void *buf, int num, double add)\n\t{\n\tint i,j,k,st_idx;\n\tlong md_c[2];\n\tunsigned char local_md[MD_DIGEST_LENGTH];\n```\n\n#### ssleay_rand_add() [lines 189-331]\n```c\n\tinitialized=0;\n\t}\n\nstatic void ssleay_rand_add(const void *buf, int num, double add)\n\t{\n\tint i,j,k,st_idx;\n\tlong md_c[2];\n\tunsigned char local_md[MD_DIGEST_LENGTH];\n\tEVP_MD_CTX m;\n\tint do_not_lock;\n\n\tif (!num)\n\t\treturn;\n\n\t/*\n\t * (Based on the rand(3) manpage)\n\t *\n\t * The input is chopped up into units of 20 bytes (or less for\n\t * the last block). Each of these blocks is run through the hash\n\t * function as follows: The data passed to the hash function\n\t * is the current 'md', the same number of bytes from the 'state'\n\t * (the location determined by in incremented looping index) as\n\t * the current 'block', the new key data 'block', and 'count'\n\t * (which is incremented after each use).\n\t * The result of this is kept in 'md' and also xored into the\n\t * 'state' at the same locations that were used as input into the\n * hash function.\n\t */\n\n\t/* check if we already have the lock */\n\tif (crypto_lock_rand)\n\t\t{\n\t\tCRYPTO_THREADID cur;\n\t\tCRYPTO_THREADID_current(&cur);\n\t\tCRYPTO_r_lock(CRYPTO_LOCK_RAND2);\n\t\tdo_not_lock = !CRYPTO_THREADID_cmp(&locking_threadid, &cur);\n\t\tCRYPTO_r_unlock(CRYPTO_LOCK_RAND2);\n\t\t}\n\telse\n\t\tdo_not_lock = 0;\n/* ... 96 lines omitted ... */\n\n\tif (!do_not_lock) CRYPTO_w_lock(CRYPTO_LOCK_RAND);\n\t/* Don't just copy back local_md into md -- this could mean that\n\t * other thread's seeding remains without effect (except for\n\t * the incremented counter). By XORing it we keep at least as\n\t * much entropy as fits into md. */\n\tfor (k = 0; k < (int)sizeof(md); k++)\n\t\t{\n\t\tmd[k] ^= local_md[k];\n\t\t}\n\tif (entropy < ENTROPY_NEEDED) /* stop counting when we have enough */\n\t entropy += add;\n\tif (!do_not_lock) CRY\n/* ... truncated ... */\n```\n\n### crypto/rand/rand.h\n\n#### RAND_set_fips_drbg_type() [lines 85-151]\n```c\n\tvoid (*cleanup)(void);\n\tvoid (*add)(const void *buf, int num, double entropy);\n\tint (*pseudorand)(unsigned char *buf, int num);\n\tint (*status)(void);\n\t};\n\n#ifdef BN_DEBUG\nextern int rand_predictable;\n#endif\n\nint RAND_set_rand_method(const RAND_METHOD *meth);\nconst RAND_METHOD *RAND_get_rand_method(void);\n#ifndef OPENSSL_NO_ENGINE\nint RAND_set_rand_engine(ENGINE *engine);\n#endif\nRAND_METHOD *RAND_SSLeay(void);\nvoid RAND_cleanup(void );\nint RAND_bytes(unsigned char *buf,int num);\nint RAND_pseudo_bytes(unsigned char *buf,int num);\nvoid RAND_seed(const void *buf,int num);\nvoid RAND_add(const void *buf,int num,double entropy);\nint RAND_load_file(const char *file,long max_bytes);\nint RAND_write_file(const char *file);\nconst char *RAND_file_name(char *file,size_t num);\nint RAND_status(void);\nint RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes);\nint RAND_egd(const char *path);\nint RAND_egd_bytes(const char *path,int bytes);\nint RAND_poll(void);\n\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)\n\nvoid RAND_screen(void);\nint RAND_event(UINT, WPARAM, LPARAM);\n\n#endif\n\n#ifdef OPENSSL_FIPS\nvoid RAND_set_fips_drbg_type(int type, int flags);\nint RAND_init_fips(void);\n#endif\n\n/* BEGIN ERROR CODES */\n/* The following lines are auto generated by the script mkerr.pl. Any changes\n * made after this point may be overwritten when the script is next run.\n */\nvoid ERR_load_RAND_strings(void);\n\n/* Error codes for the RAND functions. */\n\n/* Function codes. */\n#define RAND_F_RAND_GET_RAND_METHOD\t\t\t 101\n#define RAND_F_RAND_INIT_FIPS\t\t\t\t 102\n#define RAND_F_SSLEAY_RAND_BYTES\t\t\t 100\n\n/* Reason codes. */\n#define RAND_R_DUAL_EC_DRBG_DISABLED\t\t\t 104\n#define RAND_R_ERROR_INITIALISING_DRBG\t\t\t 102\n#define RAND_R_ERROR_INSTANTIATING_DRBG\t\t\t 103\n#define RAND_R_NO_FIPS_RANDOM_METHOD_SET\t\t 101\n#define RAND_R_PRNG_NOT_SEEDED\t\t\t\t 100\n\n#ifdef __cplusplus\n}\n#endif\n#endif\n\n```\n\n### crypto/rand/rand_lib.c\n\n#### RAND_status() [lines 174-185]\n```c\n\treturn(-1);\n\t}\n\nint RAND_status(void)\n\t{\n\tconst RAND_METHOD *meth = RAND_get_rand_method();\n\tif (meth && meth->status)\n\t\treturn meth->status();\n\treturn 0;\n\t}\n\n#ifdef OPENSSL_FIPS\n```\n\n#### drbg_rand_add() [lines 236-246]\n```c\n * correctly seeded by RAND_poll().\n */\n\nstatic int drbg_rand_add(DRBG_CTX *ctx, const void *in, int inlen,\n\t\t\t\tdouble entropy)\n\t{\n\tRAND_SSLeay()->add(in, inlen, entropy);\n\treturn 1;\n\t}\n\nstatic int drbg_rand_seed(DRBG_CTX *ctx, const void *in, int inlen)\n```\n\n#### drbg_rand_seed() [lines 243-252]\n```c\n\treturn 1;\n\t}\n\nstatic int drbg_rand_seed(DRBG_CTX *ctx, const void *in, int inlen)\n\t{\n\tRAND_SSLeay()->seed(in, inlen);\n\treturn 1;\n\t}\n\n#ifndef OPENSSL_DRBG_DEFAULT_TYPE\n```\n\n\n## Upstream Fix\n```diff\nIndex: openssl-1.0.1i/crypto/fips/fips_drbg_rand.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/fips/fips_drbg_rand.c\t2014-10-15 14:16:52.709471327 +0200\n+++ openssl-1.0.1i/crypto/fips/fips_drbg_rand.c\t2014-10-15 14:16:52.834472848 +0200\n@@ -77,7 +77,8 @@ static int fips_drbg_bytes(unsigned char\n \tint rv = 0;\n \tunsigned char *adin = NULL;\n \tsize_t adinlen = 0;\n-\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n+\tint locked;\n+\tlocked = private_RAND_lock(1);\n \tdo \n \t\t{\n \t\tsize_t rcnt;\n@@ -109,7 +110,8 @@ static int fips_drbg_bytes(unsigned char\n \twhile (count);\n \trv = 1;\n \terr:\n-\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \treturn rv;\n \t}\n \n@@ -124,35 +126,51 @@ static int fips_drbg_status(void)\n \t{\n \tDRBG_CTX *dctx = &ossl_dctx;\n \tint rv;\n-\tCRYPTO_r_lock(CRYPTO_LOCK_RAND);\n+\tint locked;\n+\tlocked = private_RAND_lock(1);\n \trv = dctx->status == DRBG_STATUS_READY ? 1 : 0;\n-\tCRYPTO_r_unlock(CRYPTO_LOCK_RAND);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \treturn rv;\n \t}\n \n static void fips_drbg_cleanup(void)\n \t{\n \tDRBG_CTX *dctx = &ossl_dctx;\n-\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n+\tint locked;\n+\tlocked = private_RAND_lock(1);\n \tFIPS_drbg_uninstantiate(dctx);\n-\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \t}\n \n static int fips_drbg_seed(const void *seed, int seedlen)\n \t{\n \tDRBG_CTX *dctx = &ossl_dctx;\n+\tint locked;\n+\tint ret = 1;\n+\n+\tlocked = private_RAND_lock(1);\n \tif (dctx->rand_seed_cb)\n-\t\treturn dctx->rand_seed_cb(dctx, seed, seedlen);\n-\treturn 1;\n+\t\tret = dctx->rand_seed_cb(dctx, seed, seedlen);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n+\treturn ret;\n \t}\n \n static int fips_drbg_add(const void *seed, int seedlen,\n \t\t\t\t\tdouble add_entropy)\n \t{\n \tDRBG_CTX *dctx = &ossl_dctx;\n+\tint locked;\n+\tint ret = 1;\n+\n+\tlocked = private_RAND_lock(1);\n \tif (dctx->rand_add_cb)\n-\t\treturn dctx->rand_add_cb(dctx, seed, seedlen, add_entropy);\n-\treturn 1;\n+\t\tret = dctx->rand_add_cb(dctx, seed, seedlen, add_entropy);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n+\treturn ret;\n \t}\n \n static const RAND_METHOD rand_drbg_meth =\nIndex: openssl-1.0.1i/crypto/rand/md_rand.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/rand/md_rand.c\t2014-10-15 14:16:52.715471400 +0200\n+++ openssl-1.0.1i/crypto/rand/md_rand.c\t2014-10-15 14:16:52.834472848 +0200\n@@ -143,12 +143,6 @@ static long md_count[2]={0,0};\n static double entropy=0;\n static int initialized=0;\n \n-static unsigned int crypto_lock_rand = 0; /* may be set only when a thread\n- * holds CRYPTO_LOCK_RAND\n- * (to prevent double locking) */\n-/* access to lockin_thread is synchronized by CRYPTO_LOCK_RAND2 */\n-static CRYPTO_THREADID locking_threadid; /* valid iff crypto_lock_rand is set */\n-\n \n #ifdef PREDICT\n int rand_predictable=0;\n@@ -195,7 +189,7 @@ static void ssleay_rand_add(const void *\n \tlong md_c[2];\n \tunsigned char local_md[MD_DIGEST_LENGTH];\n \tEVP_MD_CTX m;\n-\tint do_not_lock;\n+\tint locked;\n \n \tif (!num)\n \t\treturn;\n@@ -215,19 +209,8 @@ static void ssleay_rand_add(const void *\n * hash function.\n \t */\n \n-\t/* check if we already have the lock */\n-\tif (crypto_lock_rand)\n-\t\t{\n-\t\tCRYPTO_THREADID cur;\n-\t\tCRYPTO_THREADID_current(&cur);\n-\t\tCRYPTO_r_lock(CRYPTO_LOCK_RAND2);\n-\t\tdo_not_lock = !CRYPTO_THREADID_cmp(&locking_threadid, &cur);\n-\t\tCRYPTO_r_unlock(CRYPTO_LOCK_RAND2);\n-\t\t}\n-\telse\n-\t\tdo_not_lock = 0;\n+\tlocked = private_RAND_lock(1);\n \n-\tif (!do_not_lock) CRYPTO_w_lock(CRYPTO_LOCK_RAND);\n \tst_idx=state_index;\n \n \t/* use our own copies of the counters so that even\n@@ -259,7 +242,8 @@ static void ssleay_rand_add(const void *\n \n \tmd_count[1] += (num / MD_DIGEST_LENGTH) + (num % MD_DIGEST_LENGTH > 0);\n \n-\tif (!do_not_lock) CRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \n \tEVP_MD_CTX_init(&m);\n \tfor (i=0; i<num; i+=MD_DIGEST_LENGTH)\n@@ -310,7 +294,7 @@ static void ssleay_rand_add(const void *\n \t\t}\n \tEVP_MD_CTX_cleanup(&m);\n \n-\tif (!do_not_lock) CRYPTO_w_lock(CRYPTO_LOCK_RAND);\n+\tlocked = private_RAND_lock(1);\n \t/* Don't just copy back local_md into md -- this could mean that\n \t * other thread's seeding remains without effect (except for\n \t * the incremented counter). By XORing it we keep at least as\n@@ -321,7 +305,8 @@ static void ssleay_rand_add(const void *\n \t\t}\n \tif (entropy < ENTROPY_NEEDED) /* stop counting when we have enough */\n \t entropy += add;\n-\tif (!do_not_lock) CRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \t\n #if !defined(OPENSSL_THREADS) && !defined(OPENSSL_SYS_WIN32)\n \tassert(md_c[1] == md_count[1]);\n@@ -346,6 +331,7 @@ int ssleay_rand_bytes(unsigned char *buf\n \tpid_t curr_pid = getpid();\n #endif\n \tint do_stir_pool = 0;\n+\tint locked;\n \n #ifdef PREDICT\n \tif (rand_predictable)\n@@ -383,13 +369,7 @@ int ssleay_rand_bytes(unsigned char *buf\n \t * global 'md'.\n \t */\n \tif (lock)\n-\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n-\n-\t/* prevent ssleay_rand_bytes() from trying to obtain the lock again */\n-\tCRYPTO_w_lock(CRYPTO_LOCK_RAND2);\n-\tCRYPTO_THREADID_current(&locking_threadid);\n-\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND2);\n-\tcrypto_lock_rand = 1;\n+\t\tlocked = private_RAND_lock(1);\n \n \t/* always poll for external entropy in FIPS mode, drbg provides the \n \t * expansion\n@@ -464,9 +444,8 @@ int ssleay_rand_bytes(unsigned char *buf\n \tmd_count[0] += 1;\n \n \t/* before unlocking, we must clear 'crypto_lock_rand' */\n-\tcrypto_lock_rand = 0;\n-\tif (lock)\n-\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\tif (lock && locked)\n+\t\tprivate_RAND_lock(0);\n \n \twhile (num > 0)\n \t\t{\n@@ -519,11 +498,11 @@ int ssleay_rand_bytes(unsigned char *buf\n \tMD_Update(&m,(unsigned char *)&(md_c[0]),sizeof(md_c));\n \tMD_Update(&m,local_md,MD_DIGEST_LENGTH);\n \tif (lock)\n-\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n+\t\tlocked = private_RAND_lock(1);\n \tMD_Update(&m,md,MD_DIGEST_LENGTH);\n \tMD_Final(&m,md);\n-\tif (lock)\n-\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\tif (lock && locked)\n+\t\tprivate_RAND_lock(0);\n \n \tEVP_MD_CTX_cleanup(&m);\n \tif (ok)\n@@ -553,32 +532,10 @@ static int ssleay_rand_pseudo_bytes(unsi\n \n static int ssleay_rand_status(void)\n \t{\n-\tCRYPTO_THREADID cur;\n \tint ret;\n-\tint do_not_lock;\n+\tint locked;\n \n-\tCRYPTO_THREADID_current(&cur);\n-\t/* check if we already have the lock\n-\t * (could happen if a RAND_poll() implementation calls RAND_status()) */\n-\tif (crypto_lock_rand)\n-\t\t{\n-\t\tCRYPTO_r_lock(CRYPTO_LOCK_RAND2);\n-\t\tdo_not_lock = !CRYPTO_THREADID_cmp(&locking_threadid, &cur);\n-\t\tCRYPTO_r_unlock(CRYPTO_LOCK_RAND2);\n-\t\t}\n-\telse\n-\t\tdo_not_lock = 0;\n-\t\n-\tif (!do_not_lock)\n-\t\t{\n-\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n-\t\t\n-\t\t/* prevent ssleay_rand_bytes() from trying to obtain the lock again */\n-\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND2);\n-\t\tCRYPTO_THREADID_cpy(&locking_threadid, &cur);\n-\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND2);\n-\t\tcrypto_lock_rand = 1;\n-\t\t}\n+\tlocked = private_RAND_lock(1);\n \t\n \tif (!initialized)\n \t\t{\n@@ -588,13 +545,8 @@ static int ssleay_rand_status(void)\n \n \tret = entropy >= ENTROPY_NEEDED;\n \n-\tif (!do_not_lock)\n-\t\t{\n-\t\t/* before unlocking, we must clear 'crypto_lock_rand' */\n-\t\tcrypto_lock_rand = 0;\n-\t\t\n-\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n-\t\t}\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \t\n \treturn ret;\n \t}\nIndex: openssl-1.0.1i/crypto/rand/rand.h\n===================================================================\n--- openssl-1.0.1i.orig/crypto/rand/rand.h\t2014-10-15 14:16:52.715471400 +0200\n+++ openssl-1.0.1i/crypto/rand/rand.h\t2014-10-15 14:16:52.834472848 +0200\n@@ -124,6 +124,8 @@ void RAND_set_fips_drbg_type(int type, i\n int RAND_init_fips(void);\n #endif\n \n+int private_RAND_lock(int lock);\n+\n /* BEGIN ERROR CODES */\n /* The following lines are auto generated by the script mkerr.pl. Any changes\n * made after this point may be overwritten when the script is next run.\nIndex: openssl-1.0.1i/crypto/rand/rand_lib.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/rand/rand_lib.c\t2\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "Index: openssl-1.0.1i/crypto/fips/fips_drbg_rand.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/fips/fips_drbg_rand.c\t2014-10-15 14:16:52.709471327 +0200\n+++ openssl-1.0.1i/crypto/fips/fips_drbg_rand.c\t2014-10-15 14:16:52.834472848 +0200\n@@ -77,7 +77,8 @@ static int fips_drbg_bytes(unsigned char\n \tint rv = 0;\n \tunsigned char *adin = NULL;\n \tsize_t adinlen = 0;\n-\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n+\tint locked;\n+\tlocked = private_RAND_lock(1);\n \tdo \n \t\t{\n \t\tsize_t rcnt;\n@@ -109,7 +110,8 @@ static int fips_drbg_bytes(unsigned char\n \twhile (count);\n \trv = 1;\n \terr:\n-\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \treturn rv;\n \t}\n \n@@ -124,35 +126,51 @@ static int fips_drbg_status(void)\n \t{\n \tDRBG_CTX *dctx = &ossl_dctx;\n \tint rv;\n-\tCRYPTO_r_lock(CRYPTO_LOCK_RAND);\n+\tint locked;\n+\tlocked = private_RAND_lock(1);\n \trv = dctx->status == DRBG_STATUS_READY ? 1 : 0;\n-\tCRYPTO_r_unlock(CRYPTO_LOCK_RAND);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \treturn rv;\n \t}\n \n static void fips_drbg_cleanup(void)\n \t{\n \tDRBG_CTX *dctx = &ossl_dctx;\n-\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n+\tint locked;\n+\tlocked = private_RAND_lock(1);\n \tFIPS_drbg_uninstantiate(dctx);\n-\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \t}\n \n static int fips_drbg_seed(const void *seed, int seedlen)\n \t{\n \tDRBG_CTX *dctx = &ossl_dctx;\n+\tint locked;\n+\tint ret = 1;\n+\n+\tlocked = private_RAND_lock(1);\n \tif (dctx->rand_seed_cb)\n-\t\treturn dctx->rand_seed_cb(dctx, seed, seedlen);\n-\treturn 1;\n+\t\tret = dctx->rand_seed_cb(dctx, seed, seedlen);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n+\treturn ret;\n \t}\n \n static int fips_drbg_add(const void *seed, int seedlen,\n \t\t\t\t\tdouble add_entropy)\n \t{\n \tDRBG_CTX *dctx = &ossl_dctx;\n+\tint locked;\n+\tint ret = 1;\n+\n+\tlocked = private_RAND_lock(1);\n \tif (dctx->rand_add_cb)\n-\t\treturn dctx->rand_add_cb(dctx, seed, seedlen, add_entropy);\n-\treturn 1;\n+\t\tret = dctx->rand_add_cb(dctx, seed, seedlen, add_entropy);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n+\treturn ret;\n \t}\n \n static const RAND_METHOD rand_drbg_meth =\nIndex: openssl-1.0.1i/crypto/rand/md_rand.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/rand/md_rand.c\t2014-10-15 14:16:52.715471400 +0200\n+++ openssl-1.0.1i/crypto/rand/md_rand.c\t2014-10-15 14:16:52.834472848 +0200\n@@ -143,12 +143,6 @@ static long md_count[2]={0,0};\n static double entropy=0;\n static int initialized=0;\n \n-static unsigned int crypto_lock_rand = 0; /* may be set only when a thread\n- * holds CRYPTO_LOCK_RAND\n- * (to prevent double locking) */\n-/* access to lockin_thread is synchronized by CRYPTO_LOCK_RAND2 */\n-static CRYPTO_THREADID locking_threadid; /* valid iff crypto_lock_rand is set */\n-\n \n #ifdef PREDICT\n int rand_predictable=0;\n@@ -195,7 +189,7 @@ static void ssleay_rand_add(const void *\n \tlong md_c[2];\n \tunsigned char local_md[MD_DIGEST_LENGTH];\n \tEVP_MD_CTX m;\n-\tint do_not_lock;\n+\tint locked;\n \n \tif (!num)\n \t\treturn;\n@@ -215,19 +209,8 @@ static void ssleay_rand_add(const void *\n * hash function.\n \t */\n \n-\t/* check if we already have the lock */\n-\tif (crypto_lock_rand)\n-\t\t{\n-\t\tCRYPTO_THREADID cur;\n-\t\tCRYPTO_THREADID_current(&cur);\n-\t\tCRYPTO_r_lock(CRYPTO_LOCK_RAND2);\n-\t\tdo_not_lock = !CRYPTO_THREADID_cmp(&locking_threadid, &cur);\n-\t\tCRYPTO_r_unlock(CRYPTO_LOCK_RAND2);\n-\t\t}\n-\telse\n-\t\tdo_not_lock = 0;\n+\tlocked = private_RAND_lock(1);\n \n-\tif (!do_not_lock) CRYPTO_w_lock(CRYPTO_LOCK_RAND);\n \tst_idx=state_index;\n \n \t/* use our own copies of the counters so that even\n@@ -259,7 +242,8 @@ static void ssleay_rand_add(const void *\n \n \tmd_count[1] += (num / MD_DIGEST_LENGTH) + (num % MD_DIGEST_LENGTH > 0);\n \n-\tif (!do_not_lock) CRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \n \tEVP_MD_CTX_init(&m);\n \tfor (i=0; i<num; i+=MD_DIGEST_LENGTH)\n@@ -310,7 +294,7 @@ static void ssleay_rand_add(const void *\n \t\t}\n \tEVP_MD_CTX_cleanup(&m);\n \n-\tif (!do_not_lock) CRYPTO_w_lock(CRYPTO_LOCK_RAND);\n+\tlocked = private_RAND_lock(1);\n \t/* Don't just copy back local_md into md -- this could mean that\n \t * other thread's seeding remains without effect (except for\n \t * the incremented counter). By XORing it we keep at least as\n@@ -321,7 +305,8 @@ static void ssleay_rand_add(const void *\n \t\t}\n \tif (entropy < ENTROPY_NEEDED) /* stop counting when we have enough */\n \t entropy += add;\n-\tif (!do_not_lock) CRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \t\n #if !defined(OPENSSL_THREADS) && !defined(OPENSSL_SYS_WIN32)\n \tassert(md_c[1] == md_count[1]);\n@@ -346,6 +331,7 @@ int ssleay_rand_bytes(unsigned char *buf\n \tpid_t curr_pid = getpid();\n #endif\n \tint do_stir_pool = 0;\n+\tint locked;\n \n #ifdef PREDICT\n \tif (rand_predictable)\n@@ -383,13 +369,7 @@ int ssleay_rand_bytes(unsigned char *buf\n \t * global 'md'.\n \t */\n \tif (lock)\n-\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n-\n-\t/* prevent ssleay_rand_bytes() from trying to obtain the lock again */\n-\tCRYPTO_w_lock(CRYPTO_LOCK_RAND2);\n-\tCRYPTO_THREADID_current(&locking_threadid);\n-\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND2);\n-\tcrypto_lock_rand = 1;\n+\t\tlocked = private_RAND_lock(1);\n \n \t/* always poll for external entropy in FIPS mode, drbg provides the \n \t * expansion\n@@ -464,9 +444,8 @@ int ssleay_rand_bytes(unsigned char *buf\n \tmd_count[0] += 1;\n \n \t/* before unlocking, we must clear 'crypto_lock_rand' */\n-\tcrypto_lock_rand = 0;\n-\tif (lock)\n-\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\tif (lock && locked)\n+\t\tprivate_RAND_lock(0);\n \n \twhile (num > 0)\n \t\t{\n@@ -519,11 +498,11 @@ int ssleay_rand_bytes(unsigned char *buf\n \tMD_Update(&m,(unsigned char *)&(md_c[0]),sizeof(md_c));\n \tMD_Update(&m,local_md,MD_DIGEST_LENGTH);\n \tif (lock)\n-\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n+\t\tlocked = private_RAND_lock(1);\n \tMD_Update(&m,md,MD_DIGEST_LENGTH);\n \tMD_Final(&m,md);\n-\tif (lock)\n-\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\tif (lock && locked)\n+\t\tprivate_RAND_lock(0);\n \n \tEVP_MD_CTX_cleanup(&m);\n \tif (ok)\n@@ -553,32 +532,10 @@ static int ssleay_rand_pseudo_bytes(unsi\n \n static int ssleay_rand_status(void)\n \t{\n-\tCRYPTO_THREADID cur;\n \tint ret;\n-\tint do_not_lock;\n+\tint locked;\n \n-\tCRYPTO_THREADID_current(&cur);\n-\t/* check if we already have the lock\n-\t * (could happen if a RAND_poll() implementation calls RAND_status()) */\n-\tif (crypto_lock_rand)\n-\t\t{\n-\t\tCRYPTO_r_lock(CRYPTO_LOCK_RAND2);\n-\t\tdo_not_lock = !CRYPTO_THREADID_cmp(&locking_threadid, &cur);\n-\t\tCRYPTO_r_unlock(CRYPTO_LOCK_RAND2);\n-\t\t}\n-\telse\n-\t\tdo_not_lock = 0;\n-\t\n-\tif (!do_not_lock)\n-\t\t{\n-\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n-\t\t\n-\t\t/* prevent ssleay_rand_bytes() from trying to obtain the lock again */\n-\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND2);\n-\t\tCRYPTO_THREADID_cpy(&locking_threadid, &cur);\n-\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND2);\n-\t\tcrypto_lock_rand = 1;\n-\t\t}\n+\tlocked = private_RAND_lock(1);\n \t\n \tif (!initialized)\n \t\t{\n@@ -588,13 +545,8 @@ static int ssleay_rand_status(void)\n \n \tret = entropy >= ENTROPY_NEEDED;\n \n-\tif (!do_not_lock)\n-\t\t{\n-\t\t/* before unlocking, we must clear 'crypto_lock_rand' */\n-\t\tcrypto_lock_rand = 0;\n-\t\t\n-\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n-\t\t}\n+\tif (locked)\n+\t\tprivate_RAND_lock(0);\n \t\n \treturn ret;\n \t}\nIndex: openssl-1.0.1i/crypto/rand/rand.h\n===================================================================\n--- openssl-1.0.1i.orig/crypto/rand/rand.h\t2014-10-15 14:16:52.715471400 +0200\n+++ openssl-1.0.1i/crypto/rand/rand.h\t2014-10-15 14:16:52.834472848 +0200\n@@ -124,6 +124,8 @@ void RAND_set_fips_drbg_type(int type, i\n int RAND_init_fips(void);\n #endif\n \n+int private_RAND_lock(int lock);\n+\n /* BEGIN ERROR CODES */\n /* The following lines are auto generated by the script mkerr.pl. Any changes\n * made after this point may be overwritten when the script is next run.\nIndex: openssl-1.0.1i/crypto/rand/rand_lib.c\n===================================================================\n--- openssl-1.0.1i.orig/crypto/rand/rand_lib.c\t2014-10-15 14:16:52.741471717 +0200\n+++ openssl-1.0.1i/crypto/rand/rand_lib.c\t2014-10-15 14:16:52.835472860 +0200\n@@ -182,6 +182,41 @@ int RAND_status(void)\n \treturn 0;\n \t}\n \n+int private_RAND_lock(int lock)\n+\t{\n+\tstatic int crypto_lock_rand;\n+\tstatic CRYPTO_THREADID locking_threadid;\n+\tint do_lock;\n+\n+\tif (!lock)\n+\t\t{\n+\t\tcrypto_lock_rand = 0;\n+\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\t\treturn 0;\n+\t\t}\n+\n+\t/* check if we already have the lock */\n+\tif (crypto_lock_rand)\n+\t\t{\n+\t\tCRYPTO_THREADID cur;\n+\t\tCRYPTO_THREADID_current(&cur);\n+\t\tCRYPTO_r_lock(CRYPTO_LOCK_RAND2);\n+\t\tdo_lock = !!CRYPTO_THREADID_cmp(&locking_threadid, &cur);\n+\t\tCRYPTO_r_unlock(CRYPTO_LOCK_RAND2);\n+\t\t}\n+ else\n+\t\tdo_lock = 1;\n+\tif (do_lock)\n+\t\t{\n+\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n+\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND2);\n+\t\tCRYPTO_THREADID_current(&locking_threadid);\n+\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND2);\n+\t\tcrypto_lock_rand = 1;\n+\t\t}\n+\treturn do_lock;\n+\t}\n+\n #ifdef OPENSSL_FIPS\n \n /* FIPS DRBG initialisation code. This sets up the DRBG for use by the\n@@ -242,9 +277,9 @@ static int drbg_rand_add(DRBG_CTX *ctx,\n \tRAND_SSLeay()->add(in, inlen, entropy);\n \tif (FIPS_rand_status())\n \t\t{\n-\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n+\t\tint locked = private_RAND_lock(1);\n \t\tFIPS_drbg_reseed(ctx, NULL, 0);\n-\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\t\tif (locked) private_RAND_lock(0);\n \t\t}\n \treturn 1;\n \t}\n@@ -254,9 +289,9 @@ static int drbg_rand_seed(DRBG_CTX *ctx,\n \tRAND_SSLeay()->seed(in, inlen);\n \tif (FIPS_rand_status())\n \t\t{\n-\t\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n+\t\tint locked = private_RAND_lock(1);\n \t\tFIPS_drbg_reseed(ctx, NULL, 0);\n-\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n+\t\tif (locked) private_RAND_lock(0);\n \t\t}\n \treturn 1;\n \t}" } ]
{ "id": "openssl-5050-openssl-1.0.1i-fipslocking.pat", "cve_id": "CVE-2016-2105", "package": "openssl", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": true, "license": "OpenSSL", "context_tokens_est": 1698, "context_files": 3 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-6323\n\nThe makecontext function in the GNU C Library (aka glibc or libc6) before 2.25 creates execution contexts incompatible with the unwinder on ARM EABI (32-bit) platforms, which might allow context-dependent attackers to cause a denial of service (hang), as demonstrated by applications compiled using gccgo, related to backtrace generation.\n\n## Package\nglibc\n\n## Files to modify\n- resolv/nss_dns/dns-canon.c\n- resolv/res_send.c\n- glibc-2.19.orig/resolv/nss_dns/dns-host.c\n- resolv/nss_dns/dns-network.c\n- glibc-2.19.orig/resolv/nss_dns/dns-network.c\n\n## Target Source Code\n\n### include/resolv.h\n\n#### libc_hidden_proto() [lines 9-100]\n```c\n while (0)\n\n#include <stdbool.h>\n#include <resolv/resolv.h>\n\n#ifdef _RESOLV_H_\n\n# ifndef NOT_IN_libc\n# define __resp __libc_resp\n# endif\nextern __thread struct __res_state *__resp attribute_tls_model_ie;\n# undef _res\n# define _res (*__resp)\n\n/* Now define the internal interfaces. */\nextern int __res_vinit (res_state, int);\nextern int __res_maybe_init (res_state, int);\nextern void _sethtent (int);\nextern void _endhtent (void);\nextern struct hostent *_gethtent (void);\nextern struct hostent *_gethtbyname (const char *__name);\nextern struct hostent *_gethtbyname2 (const char *__name, int __af);\nstruct hostent *_gethtbyaddr (const char *addr, size_t __len, int __af);\nextern u_int32_t _getlong (const u_char *__src);\nextern u_int16_t _getshort (const u_char *__src);\nextern void res_pquery (const res_state __statp, const u_char *__msg,\n\t\t\tint __len, FILE *__file);\nextern void res_send_setqhook (res_send_qhook __hook);\nextern void res_send_setrhook (res_send_rhook __hook);\nextern int res_ourserver_p (const res_state __statp,\n\t\t\t const struct sockaddr_in6 *__inp);\nextern void __res_iclose (res_state statp, bool free_addr);\nextern int __res_nopt(res_state statp, int n0, u_char *buf, int buflen,\n\t\t int anslen);\nlibc_hidden_proto (__res_ninit)\nlibc_hidden_proto (__res_maybe_init)\nlibc_hidden_proto (__res_nclose)\nlibc_hidden_proto (__res_iclose)\nlibc_hidden_proto (__res_randomid)\nlibc_hidden_proto (__res_state)\n\nint __libc_res_nquery (res_state, const char *, int, int, u_char *, int,\n\t\t u_char **, u_char **, int *, int *);\nint __libc_res_nsearch (res_state, const char *, int, int, u_char *, int,\n\t\t\tu_char **, u_char **, int *, int *);\nint __libc_res_nsend (res_state, const u_char *, int, const u_char *, int,\n\t\t u_char *, int, u_char\n/* ... truncated ... */\n```\n\n### resolv/gethnamaddr.c\n\n#### gethostbyname2() [lines 504-638]\n```c\n}\n\nstruct hostent *\ngethostbyname2(name, af)\n\tconst char *name;\n\tint af;\n{\n\tunion\n\t{\n\t querybuf *buf;\n\t u_char *ptr;\n\t} buf;\n\tquerybuf *origbuf;\n\tconst char *cp;\n\tchar *bp;\n\tint n, size, type, len;\n\tstruct hostent *ret;\n\n\tif (__res_maybe_init (&_res, 0) == -1) {\n\t\t__set_h_errno (NETDB_INTERNAL);\n\t\treturn (NULL);\n\t}\n\n\tswitch (af) {\n\tcase AF_INET:\n\t\tsize = INADDRSZ;\n\t\ttype = T_A;\n\t\tbreak;\n\tcase AF_INET6:\n\t\tsize = IN6ADDRSZ;\n\t\ttype = T_AAAA;\n\t\tbreak;\n\tdefault:\n\t\t__set_h_errno (NETDB_INTERNAL);\n\t\t__set_errno (EAFNOSUPPORT);\n\t\treturn (NULL);\n\t}\n\n\thost.h_addrtype = af;\n\thost.h_length = size;\n/* ... 68 lines omitted ... */\n\t\t\t\th_addr_ptrs[1] = NULL;\n\t\t\t\thost.h_addr_list = h_addr_ptrs;\n\t\t\t\t__set_h_errno (NETDB_SUCCESS);\n\t\t\t\treturn (&host);\n\t\t\t}\n\t\t\tif (!isxdigit(*cp) && *cp != ':' && *cp != '.')\n\t\t\t\tbreak;\n\t\t}\n\n\tbuf.buf = origbuf = (querybuf *) alloca (1024);\n\n\tif ((n = __libc_res_nsearch(&_res, name, C_IN, type, buf.buf->buf, 1024,\n\t\t\t\t &buf.ptr, NULL, NULL, NULL)) < 0) {\n\t\tif (buf.buf != origbuf)\n\t\t\tfree (buf.buf);\n\t\tDprintf(\"res_nsearch failed (%d)\\n\", n);\n\t\tif (errno == ECONNREFUSED)\n\t\t\treturn (_gethtbyname2(name, af));\n\t\treturn (NULL);\n\t}\n\tret = getanswer(buf.buf, n, name, type);\n\tif (buf.buf != origbuf)\n\t\tfree (buf.buf);\n\treturn ret;\n}\nlibresolv_hidden_def (gethostbyname2)\n\n```\n\n#### gethostbyaddr() [lines 637-785]\n```c\nlibresolv_hidden_def (gethostbyname2)\n\nstruct hostent *\ngethostbyaddr(addr, len, af)\n\tconst void *addr;\n\tsocklen_t len;\n\tint af;\n{\n\tconst u_char *uaddr = (const u_char *)addr;\n\tstatic const u_char mapped[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0xff,0xff };\n\tstatic const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 };\n\tint n;\n\tsocklen_t size;\n\tunion\n\t{\n\t querybuf *buf;\n\t u_char *ptr;\n\t} buf;\n\tquerybuf *orig_buf;\n\tstruct hoste\n/* ... truncated ... */\n```\n\n### resolv/nss_dns/dns-canon.c\n\n#### _nss_dns_getcanonname_r() [lines 45-157]\n```c\n\n\nenum nss_status\n_nss_dns_getcanonname_r (const char *name, char *buffer, size_t buflen,\n\t\t\t char **result,int *errnop, int *h_errnop)\n{\n /* Just an alibi buffer, res_nquery will allocate a real buffer for\n us. */\n unsigned char buf[20];\n union\n {\n querybuf *buf;\n unsigned char *ptr;\n } ansp = { .ptr = buf };\n enum nss_status status = NSS_STATUS_UNAVAIL;\n\n for (int i = 0; i < nqtypes; ++i)\n {\n int r = __libc_res_nquery (&_res, name, ns_c_in, qtypes[i],\n\t\t\t\t buf, sizeof (buf), &ansp.ptr, NULL, NULL,\n\t\t\t\t NULL);\n if (r > 0)\n\t{\n\t /* We need to decode the response. Just one question record.\n\t And if we got no answers we bail out, too. */\n\t if (ansp.buf->hdr.qdcount != htons (1))\n\t continue;\n\n\t /* Number of answers. */\n\t unsigned int ancount = ntohs (ansp.buf->hdr.ancount);\n\n\t /* Beginning and end of the buffer with query, answer, and the\n\t rest. */\n\t unsigned char *ptr = &ansp.buf->buf[sizeof (HEADER)];\n\t unsigned char *endptr = ansp.ptr + r;\n\n\t /* Skip over the query. This is the name, type, and class. */\n\t int s = __dn_skipname (ptr, endptr);\n\t if (s < 0)\n\t {\n\t unavail:\n\t status = NSS_STATUS_UNAVAIL;\n\t break;\n\t }\n\n\t /* Skip over the name and the two 16-bit values containing type\n\t and class. */\n\t ptr += s + 2 * sizeof (uint16_t);\n\n\t while (ancount-- > 0)\n\t {\n\t /* Now the reply. First again the name from the query,\n\t\t then type, class, TTL, and the length of the RDATA.\n\t\t We remember the name start. */\n\t unsigned char *namestart = ptr;\n\t s = __dn_skipname (ptr, endptr);\n\t if (s < 0)\n\t\tgoto unavail;\n\n\t ptr += s;\n\n\t /* Check whether type and class match. */\n\t uint_fast16_t type;\n\t NS_GET16 (type, ptr);\n\t \n/* ... truncated ... */\n```\n\n### resolv/nss_dns/dns-host.c\n\n#### _nss_dns_gethostbyname3_r() [lines 140-250]\n```c\nhidden_proto (_nss_dns_gethostbyname3_r)\n\nenum nss_status\n_nss_dns_gethostbyname3_r (const char *name, int af, struct hostent *result,\n\t\t\t char *buffer, size_t buflen, int *errnop,\n\t\t\t int *h_errnop, int32_t *ttlp, char **canonp)\n{\n union\n {\n querybuf *buf;\n u_char *ptr;\n } host_buffer;\n querybuf *orig_host_buffer;\n char tmp[NS_MAXDNAME];\n int size, type, n;\n const char *cp;\n int map = 0;\n int olderr = errno;\n enum nss_status status;\n\n if (__res_maybe_init (&_res, 0) == -1)\n return NSS_STATUS_UNAVAIL;\n\n switch (af) {\n case AF_INET:\n size = INADDRSZ;\n type = T_A;\n break;\n case AF_INET6:\n size = IN6ADDRSZ;\n type = T_AAAA;\n break;\n default:\n *h_errnop = NO_DATA;\n *errnop = EAFNOSUPPORT;\n return NSS_STATUS_UNAVAIL;\n }\n\n result->h_addrtype = af;\n result->h_length = size;\n\n /*\n * if there aren't any dots, it could be a user-level alias.\n * this is also done in res_query() since we are not the only\n * function that looks up host names.\n */\n if (strchr (name, '.') == NULL\n && (cp = res_hostalias (&_res, name, tmp, sizeof (tmp))) != NULL)\n name = cp;\n\n host_buffer.buf = orig_host_buffer = (querybuf *) alloca (1024);\n\n n = __libc_res_nsearch (&_res, name, C_IN, type, host_buffer.buf->buf,\n\t\t\t 1024, &host_buffer.ptr, NULL, NULL, NULL);\n if (n < 0)\n {\n switch (errno)\n\t{\n\tcase ESRCH:\n\t status = NSS_STATUS_TRYAGAIN;\n\t h_errno = TRY_AGAIN;\n\t break;\n\t/* System has run out of file descriptors. */\n\tcase EMFILE:\n\tcase ENFILE:\n\t h_errno = NETDB_INTERNAL;\n\t /* Fall through. */\n\tcase ECONNREFUSED:\n\tcase ETIMEDOUT:\n\t status = NSS_STATUS_UNAVAIL;\n\t break;\n\tdefault:\n\t status = NSS_STATUS_NOTFOUND;\n\t break;\n\t}\n *h_errnop = h_errno;\n if (h_errno == T\n/* ... truncated ... */\n```\n\n### resolv/nss_dns/dns-network.c\n\n#### _nss_dns_getnetbyname_r() [lines 106-152]\n```c\n\n\nenum nss_status\n_nss_dns_getnetbyname_r (const char *name, struct netent *result,\n\t\t\t char *buffer, size_t buflen, int *errnop,\n\t\t\t int *herrnop)\n{\n /* Return entry for network with NAME. */\n union\n {\n querybuf *buf;\n u_char *ptr;\n } net_buffer;\n querybuf *orig_net_buffer;\n int anslen;\n char *qbuf;\n enum nss_status status;\n\n if (__res_maybe_init (&_res, 0) == -1)\n return NSS_STATUS_UNAVAIL;\n\n qbuf = strdupa (name);\n\n net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);\n\n anslen = __libc_res_nsearch (&_res, qbuf, C_IN, T_PTR, net_buffer.buf->buf,\n\t\t\t 1024, &net_buffer.ptr, NULL, NULL, NULL);\n if (anslen < 0)\n {\n /* Nothing found. */\n *errnop = errno;\n if (net_buffer.buf != orig_net_buffer)\n\tfree (net_buffer.buf);\n return (errno == ECONNREFUSED\n\t || errno == EPFNOSUPPORT\n\t || errno == EAFNOSUPPORT)\n\t? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND;\n }\n\n status = getanswer_r (net_buffer.buf, anslen, result, buffer, buflen,\n\t\t\terrnop, herrnop, BYNAME);\n if (net_buffer.buf != orig_net_buffer)\n free (net_buffer.buf);\n return status;\n}\n\n\n```\n\n#### _nss_dns_getnetbyaddr_r() [lines 151-239]\n```c\n\n\nenum nss_status\n_nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result,\n\t\t\t char *buffer, size_t buflen, int *errnop,\n\t\t\t int *herrnop)\n{\n /* Return entry for network with NAME. */\n enum nss_status status;\n union\n {\n querybuf *buf;\n u_char *ptr;\n } net_buffer;\n querybuf *orig_net_buffer;\n unsigned int net_bytes[4];\n char qbuf[MAXDNAME];\n int cnt, anslen;\n u_int32_t net2;\n int olderr = errno;\n\n /* No net address lookup for IPv6 yet. */\n if (type != AF_INET)\n return NSS_STATUS_UNAVAIL;\n\n if (__res_maybe_init (&_res, 0) == -1)\n retu\n/* ... truncated ... */\n```\n\n### resolv/res_query.c\n\n#### region() [lines 59-146]\n```c\n * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE\n * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL\n * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR\n * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\n * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\n * SOFTWARE.\n */\n\n#if defined(LIBC_SCCS) && !defined(lint)\nstatic const char sccsid[] = \"@(#)res_query.c\t8.1 (Berkeley) 6/4/93\";\nstatic const char rcsid[] = \"$BINDId: res_query.c,v 8.20 2000/02/29 05:39:12 vixie Exp $\";\n#endif /* LIBC_SCCS and not lint */\n\n#include <assert.h>\n#include <sys/types.h>\n#include <sys/param.h>\n#include <netinet/in.h>\n#include <arpa/inet.h>\n#include <arpa/nameser.h>\n#include <ctype.h>\n#include <errno.h>\n#include <netdb.h>\n#include <resolv.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n/* Options. Leave them on. */\n/* #undef DEBUG */\n\n#if PACKETSZ > 65536\n#define MAXPACKET\tPACKETSZ\n#else\n#define MAXPACKET\t65536\n#endif\n\n#define QUERYSIZE\t(HFIXEDSZ + QFIXEDSZ + MAXCDNAME + 1)\n\nstatic int\n__libc_res_nquerydomain(res_state statp, const char *name, const char *domain,\n\t\t\tint class, int type, u_char *answer, int anslen,\n\t\t\tu_char **answerp, u_char **answerp2, int *nanswerp2,\n\t\t\tint *resplen2);\n\n/*\n * Formulate a normal query, send, and await answer.\n * Returned answer is placed in supplied buffer \"answer\".\n * Perform preliminary check of answer, returning success only\n * if no error is indicated and the answer count is nonzero.\n * Return the size of the response on success, -1 on error.\n * Error number is left in H_ERRNO.\n *\n * Caller must parse answer and determine whether it answers the question.\n */\nint\n__libc_res_nquery(res_state statp,\n\t\t co\n/* ... truncated ... */\n```\n\n### resolv/res_send.c\n\n#### evNowTime() [lines 165-177]\n```c\n}\n\nstatic void\nevNowTime(struct timespec *res) {\n\tstruct timeval now;\n\n\tif (gettimeofday(&now, NULL) < 0)\n\t\tevConsTime(res, 0, 0);\n\telse\n\t\tTIMEVAL_TO_TIMESPEC (&now, res);\n}\n\n\n```\n\n#### region() [lines 304-391]\n```c\n\n\t/*\n\t * Only header section present in replies to\n\t * dynamic update packets.\n\t */\n\tif ((((HEADER *)buf1)->opcode == ns_o_update) &&\n\t (((HEADER *)buf2)->opcode == ns_o_update))\n\t\treturn (1);\n\n\t/* Note that we initially do not convert QDCOUNT to the host byte\n\t order. We can compare it with the second buffer's QDCOUNT\n\t value without doing this. */\n\tint qdcount = ((HEADER*)buf1)->qdcount;\n\tif (qdcount != ((HEADER*)buf2)->qdcount)\n\t\treturn (0);\n\n\tqdcount = htons (qdcount);\n\tconst u_char *cp = buf1 + HFIXEDSZ;\n\n\twhile (qdcount-- > 0) {\n\t\tchar tname[MAXDNAME+1];\n\t\tint n, ttype, tclass;\n\n\t\tn = dn_expand(buf1, eom1, cp, tname, sizeof tname);\n\t\tif (n < 0)\n\t\t\treturn (-1);\n\t\tcp += n;\n\t\tif (cp + 2 * INT16SZ > eom1)\n\t\t\treturn (-1);\n\t\tNS_GET16(ttype, cp);\n\t\tNS_GET16(tclass, cp);\n\t\tif (!res_nameinquery(tname, ttype, tclass, buf2, eom2))\n\t\t\treturn (0);\n\t}\n\treturn (1);\n}\nlibresolv_hidden_def (res_queriesmatch)\n\nint\n__libc_res_nsend(res_state statp, const u_char *buf, int buflen,\n\t\t const u_char *buf2, int buflen2,\n\t\t u_char *ans, int anssiz, u_char **ansp, u_char **ansp2,\n\t\t int *nansp2, int *resplen2)\n{\n int gotsomewhere, terrno, try, v_circuit, resplen, ns, n;\n\n\tif (statp->nscount == 0) {\n\t\t__set_errno (ESRCH);\n\t\treturn (-1);\n\t}\n\n\tif (anssiz < (buf2 == NULL ? 1 : 2) * HFIXEDSZ) {\n\t\t__set_errno (EINVAL);\n\t\treturn (-1);\n\t}\n\n#ifdef USE_HOOKS\n\tif (__builtin_expect (statp->qhook || statp->rhook, 0)) {\n\t\tif (anssiz < MAXPACKET && ansp) {\n\t\t\tu_char *buf = malloc (MAXPACKET);\n\t\t\tif (buf == NULL)\n\t\t\t\treturn (-1);\n\t\t\tmemcpy (buf, ans, HFIXEDSZ);\n\n/* ... truncated ... */\n```\n\n\n## Upstream Fix\n```diff\n2014-02-18 Andreas Schwab <schwab@suse.de>\n\n\t[BZ #16574]\n\t* resolv/res_send.c (send_vc): Add parameter ansp2_malloced.\n\tStore non-zero if the second buffer was newly allocated.\n\t(send_dg): Likewise.\n\t(__libc_res_nsend): Add parameter ansp2_malloced and pass it down\n\tto send_vc and send_dg.\n\t(res_nsend): Pass NULL for ansp2_malloced.\n\t* resolv/res_query.c (__libc_res_nquery): Add parameter\n\tanswerp2_malloced and pass it down to __libc_res_nsend.\n\t(res_nquery): Pass additional NULL to __libc_res_nquery.\n\t(__libc_res_nsearch): Add parameter answerp2_malloced and pass it\n\tdown to __libc_res_nquery and __libc_res_nquerydomain. Deallocate\n\tsecond answer buffer if answerp2_malloced was set.\n\t(res_nsearch): Pass additional NULL to __libc_res_nsearch.\n\t(__libc_res_nquerydomain): Add parameter\n\tanswerp2_malloced and pass it down to __libc_res_nquery.\n\t(res_nquerydomain): Pass additional NULL to\n\t__libc_res_nquerydomain.\n\t* resolv/nss_dns/dns-network.c (_nss_dns_getnetbyname_r): Pass\n\tadditional NULL to __libc_res_nsend and __libc_res_nquery.\n\t* resolv/nss_dns/dns-host.c (_nss_dns_gethostbyname3_r): Pass\n\tadditional NULL to __libc_res_nsearch.\n\t(_nss_dns_gethostbyname4_r): Revert last change. Use new\n\tparameter of __libc_res_nsearch to check for separately allocated\n\tsecond buffer.\n\t(_nss_dns_gethostbyaddr2_r): Pass additional NULL to\n\t__libc_res_nquery.\n\t* resolv/nss_dns/dns-canon.c (_nss_dns_getcanonname_r): Pass\n\tadditional NULL to __libc_res_nquery.\n\t* resolv/gethnamaddr.c (gethostbyname2): Pass additional NULL to\n\t__libc_res_nsearch.\n\t(gethostbyaddr): Pass additional NULL to __libc_res_nquery.\n\t* include/resolv.h: Update prototypes of __libc_res_nquery,\n\t__libc_res_nsearch, __libc_res_nsend.\n\n2014-02-13 Andreas Schwab <schwab@suse.de>\n\n\t[BZ #16574]\n\t* resolv/nss_dns/dns-host.c (_nss_dns_gethostbyname4_r): Free the\n\tsecond answer buffer if it was separately allocated.\n\nIndex: glibc-2.19/include/resolv.h\n===================================================================\n--- glibc-2.19.orig/include/resolv.h\n+++ glibc-2.19/include/resolv.h\n@@ -48,11 +48,11 @@ libc_hidden_proto (__res_randomid)\n libc_hidden_proto (__res_state)\n \n int __libc_res_nquery (res_state, const char *, int, int, u_char *, int,\n-\t\t u_char **, u_char **, int *, int *);\n+\t\t u_char **, u_char **, int *, int *, int *);\n int __libc_res_nsearch (res_state, const char *, int, int, u_char *, int,\n-\t\t\tu_char **, u_char **, int *, int *);\n+\t\t\tu_char **, u_char **, int *, int *, int *);\n int __libc_res_nsend (res_state, const u_char *, int, const u_char *, int,\n-\t\t u_char *, int, u_char **, u_char **, int *, int *)\n+\t\t u_char *, int, u_char **, u_char **, int *, int *, int *)\n attribute_hidden;\n \n libresolv_hidden_proto (_sethtent)\nIndex: glibc-2.19/resolv/gethnamaddr.c\n===================================================================\n--- glibc-2.19.orig/resolv/gethnamaddr.c\n+++ glibc-2.19/resolv/gethnamaddr.c\n@@ -621,7 +621,7 @@ gethostbyname2(name, af)\n \tbuf.buf = origbuf = (querybuf *) alloca (1024);\n \n \tif ((n = __libc_res_nsearch(&_res, name, C_IN, type, buf.buf->buf, 1024,\n-\t\t\t\t &buf.ptr, NULL, NULL, NULL)) < 0) {\n+\t\t\t\t &buf.ptr, NULL, NULL, NULL, NULL)) < 0) {\n \t\tif (buf.buf != origbuf)\n \t\t\tfree (buf.buf);\n \t\tDprintf(\"res_nsearch failed (%d)\\n\", n);\n@@ -716,12 +716,12 @@ gethostbyaddr(addr, len, af)\n \tbuf.buf = orig_buf = (querybuf *) alloca (1024);\n \n \tn = __libc_res_nquery(&_res, qbuf, C_IN, T_PTR, buf.buf->buf, 1024,\n-\t\t\t &buf.ptr, NULL, NULL, NULL);\n+\t\t\t &buf.ptr, NULL, NULL, NULL, NULL);\n \tif (n < 0 && af == AF_INET6 && (_res.options & RES_NOIP6DOTINT) == 0) {\n \t\tstrcpy(qp, \"ip6.int\");\n \t\tn = __libc_res_nquery(&_res, qbuf, C_IN, T_PTR, buf.buf->buf,\n \t\t\t\t buf.buf != orig_buf ? MAXPACKET : 1024,\n-\t\t\t\t &buf.ptr, NULL, NULL, NULL);\n+\t\t\t\t &buf.ptr, NULL, NULL, NULL, NULL);\n \t}\n \tif (n < 0) {\n \t\tif (buf.buf != orig_buf)\nIndex: glibc-2.19/resolv/nss_dns/dns-canon.c\n===================================================================\n--- glibc-2.19.orig/resolv/nss_dns/dns-canon.c\n+++ glibc-2.19/resolv/nss_dns/dns-canon.c\n@@ -62,7 +62,7 @@ _nss_dns_getcanonname_r (const char *nam\n {\n int r = __libc_res_nquery (&_res, name, ns_c_in, qtypes[i],\n \t\t\t\t buf, sizeof (buf), &ansp.ptr, NULL, NULL,\n-\t\t\t\t NULL);\n+\t\t\t\t NULL, NULL);\n if (r > 0)\n \t{\n \t /* We need to decode the response. Just one question record.\nIndex: glibc-2.19/resolv/nss_dns/dns-host.c\n===================================================================\n--- glibc-2.19.orig/resolv/nss_dns/dns-host.c\n+++ glibc-2.19/resolv/nss_dns/dns-host.c\n@@ -190,7 +190,7 @@ _nss_dns_gethostbyname3_r (const char *n\n host_buffer.buf = orig_host_buffer = (querybuf *) alloca (1024);\n \n n = __libc_res_nsearch (&_res, name, C_IN, type, host_buffer.buf->buf,\n-\t\t\t 1024, &host_buffer.ptr, NULL, NULL, NULL);\n+\t\t\t 1024, &host_buffer.ptr, NULL, NULL, NULL, NULL);\n if (n < 0)\n {\n switch (errno)\n@@ -225,7 +225,7 @@ _nss_dns_gethostbyname3_r (const char *n\n \tn = __libc_res_nsearch (&_res, name, C_IN, T_A, host_buffer.buf->buf,\n \t\t\t\thost_buffer.buf != orig_host_buffer\n \t\t\t\t? MAXPACKET : 1024, &host_buffer.ptr,\n-\t\t\t\tNULL, NULL, NULL);\n+\t\t\t\tNULL, NULL, NULL, NULL);\n \n if (n < 0)\n \t{\n@@ -308,12 +308,13 @@ _nss_dns_gethostbyname4_r (const char *n\n u_char *ans2p = NULL;\n int nans2p = 0;\n int resplen2 = 0;\n+ int ans2p_malloced = 0;\n \n int olderr = errno;\n enum nss_status status;\n int n = __libc_res_nsearch (&_res, name, C_IN, T_UNSPEC,\n \t\t\t host_buffer.buf->buf, 2048, &host_buffer.ptr,\n-\t\t\t &ans2p, &nans2p, &resplen2);\n+\t\t\t &ans2p, &nans2p, &resplen2, &ans2p_malloced);\n if (n < 0)\n {\n switch (errno)\n@@ -352,6 +353,10 @@ _nss_dns_gethostbyname4_r (const char *n\n \t\t\t resplen2, name, pat, buffer, buflen,\n \t\t\t errnop, herrnop, ttlp);\n \n+ /* Check whether ans2p was separately allocated. */\n+ if (ans2p_malloced)\n+ free (ans2p);\n+\n if (host_buffer.buf != orig_host_buffer)\n free (host_buffer.buf);\n \n@@ -460,7 +465,7 @@ _nss_dns_gethostbyaddr2_r (const void *a\n \t strcpy (qp, \"].ip6.arpa\");\n \t n = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR,\n \t\t\t\t host_buffer.buf->buf, 1024, &host_buffer.ptr,\n-\t\t\t\t NULL, NULL, NULL);\n+\t\t\t\t NULL, NULL, NULL, NULL);\n \t if (n >= 0)\n \t goto got_it_already;\n \t}\n@@ -481,14 +486,14 @@ _nss_dns_gethostbyaddr2_r (const void *a\n }\n \n n = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, host_buffer.buf->buf,\n-\t\t\t 1024, &host_buffer.ptr, NULL, NULL, NULL);\n+\t\t\t 1024, &host_buffer.ptr, NULL, NULL, NULL, NULL);\n if (n < 0 && af == AF_INET6 && (_res.options & RES_NOIP6DOTINT) == 0)\n {\n strcpy (qp, \"ip6.int\");\n n = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, host_buffer.buf->buf,\n \t\t\t host_buffer.buf != orig_host_buffer\n \t\t\t ? MAXPACKET : 1024, &host_buffer.ptr,\n-\t\t\t NULL, NULL, NULL);\n+\t\t\t NULL, NULL, NULL, NULL);\n }\n if (n < 0)\n {\nIndex: glibc-2.19/resolv/nss_dns/dns-network.c\n===================================================================\n--- glibc-2.19.orig/resolv/nss_dns/dns-network.c\n+++ glibc-2.19/resolv/nss_dns/dns-network.c\n@@ -129,7 +129,7 @@ _nss_dns_getnetbyname_r (const char *nam\n net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);\n \n anslen = __libc_res_nsearch (&_res, qbuf, C_IN, T_PTR, net_buffer.buf->buf,\n-\t\t\t 1024, &net_buffer.ptr, NULL, NULL, NULL);\n+\t\t\t 1024, &net_buffer.ptr, NULL, NULL, NULL, NULL);\n if (anslen < 0)\n {\n /* Nothing found. */\n@@ -205,7 +205,7 @@ _nss_dns_getnetbyaddr_r (uint32_t net, i\n net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);\n \n anslen = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, net_buffer.buf->buf,\n-\t\t\t 1024, &net_buffer.ptr, NULL, NULL, NULL);\n+\t\t\t 1024, &net_buffer.ptr, NULL, NULL, NULL, NULL);\n if (anslen < 0)\n {\n /* Nothing found. */\nIndex: glibc-2.19/resolv/res_query.c\n=====================================================\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "2014-02-18 Andreas Schwab <schwab@suse.de>\n\n\t[BZ #16574]\n\t* resolv/res_send.c (send_vc): Add parameter ansp2_malloced.\n\tStore non-zero if the second buffer was newly allocated.\n\t(send_dg): Likewise.\n\t(__libc_res_nsend): Add parameter ansp2_malloced and pass it down\n\tto send_vc and send_dg.\n\t(res_nsend): Pass NULL for ansp2_malloced.\n\t* resolv/res_query.c (__libc_res_nquery): Add parameter\n\tanswerp2_malloced and pass it down to __libc_res_nsend.\n\t(res_nquery): Pass additional NULL to __libc_res_nquery.\n\t(__libc_res_nsearch): Add parameter answerp2_malloced and pass it\n\tdown to __libc_res_nquery and __libc_res_nquerydomain. Deallocate\n\tsecond answer buffer if answerp2_malloced was set.\n\t(res_nsearch): Pass additional NULL to __libc_res_nsearch.\n\t(__libc_res_nquerydomain): Add parameter\n\tanswerp2_malloced and pass it down to __libc_res_nquery.\n\t(res_nquerydomain): Pass additional NULL to\n\t__libc_res_nquerydomain.\n\t* resolv/nss_dns/dns-network.c (_nss_dns_getnetbyname_r): Pass\n\tadditional NULL to __libc_res_nsend and __libc_res_nquery.\n\t* resolv/nss_dns/dns-host.c (_nss_dns_gethostbyname3_r): Pass\n\tadditional NULL to __libc_res_nsearch.\n\t(_nss_dns_gethostbyname4_r): Revert last change. Use new\n\tparameter of __libc_res_nsearch to check for separately allocated\n\tsecond buffer.\n\t(_nss_dns_gethostbyaddr2_r): Pass additional NULL to\n\t__libc_res_nquery.\n\t* resolv/nss_dns/dns-canon.c (_nss_dns_getcanonname_r): Pass\n\tadditional NULL to __libc_res_nquery.\n\t* resolv/gethnamaddr.c (gethostbyname2): Pass additional NULL to\n\t__libc_res_nsearch.\n\t(gethostbyaddr): Pass additional NULL to __libc_res_nquery.\n\t* include/resolv.h: Update prototypes of __libc_res_nquery,\n\t__libc_res_nsearch, __libc_res_nsend.\n\n2014-02-13 Andreas Schwab <schwab@suse.de>\n\n\t[BZ #16574]\n\t* resolv/nss_dns/dns-host.c (_nss_dns_gethostbyname4_r): Free the\n\tsecond answer buffer if it was separately allocated.\n\nIndex: glibc-2.19/include/resolv.h\n===================================================================\n--- glibc-2.19.orig/include/resolv.h\n+++ glibc-2.19/include/resolv.h\n@@ -48,11 +48,11 @@ libc_hidden_proto (__res_randomid)\n libc_hidden_proto (__res_state)\n \n int __libc_res_nquery (res_state, const char *, int, int, u_char *, int,\n-\t\t u_char **, u_char **, int *, int *);\n+\t\t u_char **, u_char **, int *, int *, int *);\n int __libc_res_nsearch (res_state, const char *, int, int, u_char *, int,\n-\t\t\tu_char **, u_char **, int *, int *);\n+\t\t\tu_char **, u_char **, int *, int *, int *);\n int __libc_res_nsend (res_state, const u_char *, int, const u_char *, int,\n-\t\t u_char *, int, u_char **, u_char **, int *, int *)\n+\t\t u_char *, int, u_char **, u_char **, int *, int *, int *)\n attribute_hidden;\n \n libresolv_hidden_proto (_sethtent)\nIndex: glibc-2.19/resolv/gethnamaddr.c\n===================================================================\n--- glibc-2.19.orig/resolv/gethnamaddr.c\n+++ glibc-2.19/resolv/gethnamaddr.c\n@@ -621,7 +621,7 @@ gethostbyname2(name, af)\n \tbuf.buf = origbuf = (querybuf *) alloca (1024);\n \n \tif ((n = __libc_res_nsearch(&_res, name, C_IN, type, buf.buf->buf, 1024,\n-\t\t\t\t &buf.ptr, NULL, NULL, NULL)) < 0) {\n+\t\t\t\t &buf.ptr, NULL, NULL, NULL, NULL)) < 0) {\n \t\tif (buf.buf != origbuf)\n \t\t\tfree (buf.buf);\n \t\tDprintf(\"res_nsearch failed (%d)\\n\", n);\n@@ -716,12 +716,12 @@ gethostbyaddr(addr, len, af)\n \tbuf.buf = orig_buf = (querybuf *) alloca (1024);\n \n \tn = __libc_res_nquery(&_res, qbuf, C_IN, T_PTR, buf.buf->buf, 1024,\n-\t\t\t &buf.ptr, NULL, NULL, NULL);\n+\t\t\t &buf.ptr, NULL, NULL, NULL, NULL);\n \tif (n < 0 && af == AF_INET6 && (_res.options & RES_NOIP6DOTINT) == 0) {\n \t\tstrcpy(qp, \"ip6.int\");\n \t\tn = __libc_res_nquery(&_res, qbuf, C_IN, T_PTR, buf.buf->buf,\n \t\t\t\t buf.buf != orig_buf ? MAXPACKET : 1024,\n-\t\t\t\t &buf.ptr, NULL, NULL, NULL);\n+\t\t\t\t &buf.ptr, NULL, NULL, NULL, NULL);\n \t}\n \tif (n < 0) {\n \t\tif (buf.buf != orig_buf)\nIndex: glibc-2.19/resolv/nss_dns/dns-canon.c\n===================================================================\n--- glibc-2.19.orig/resolv/nss_dns/dns-canon.c\n+++ glibc-2.19/resolv/nss_dns/dns-canon.c\n@@ -62,7 +62,7 @@ _nss_dns_getcanonname_r (const char *nam\n {\n int r = __libc_res_nquery (&_res, name, ns_c_in, qtypes[i],\n \t\t\t\t buf, sizeof (buf), &ansp.ptr, NULL, NULL,\n-\t\t\t\t NULL);\n+\t\t\t\t NULL, NULL);\n if (r > 0)\n \t{\n \t /* We need to decode the response. Just one question record.\nIndex: glibc-2.19/resolv/nss_dns/dns-host.c\n===================================================================\n--- glibc-2.19.orig/resolv/nss_dns/dns-host.c\n+++ glibc-2.19/resolv/nss_dns/dns-host.c\n@@ -190,7 +190,7 @@ _nss_dns_gethostbyname3_r (const char *n\n host_buffer.buf = orig_host_buffer = (querybuf *) alloca (1024);\n \n n = __libc_res_nsearch (&_res, name, C_IN, type, host_buffer.buf->buf,\n-\t\t\t 1024, &host_buffer.ptr, NULL, NULL, NULL);\n+\t\t\t 1024, &host_buffer.ptr, NULL, NULL, NULL, NULL);\n if (n < 0)\n {\n switch (errno)\n@@ -225,7 +225,7 @@ _nss_dns_gethostbyname3_r (const char *n\n \tn = __libc_res_nsearch (&_res, name, C_IN, T_A, host_buffer.buf->buf,\n \t\t\t\thost_buffer.buf != orig_host_buffer\n \t\t\t\t? MAXPACKET : 1024, &host_buffer.ptr,\n-\t\t\t\tNULL, NULL, NULL);\n+\t\t\t\tNULL, NULL, NULL, NULL);\n \n if (n < 0)\n \t{\n@@ -308,12 +308,13 @@ _nss_dns_gethostbyname4_r (const char *n\n u_char *ans2p = NULL;\n int nans2p = 0;\n int resplen2 = 0;\n+ int ans2p_malloced = 0;\n \n int olderr = errno;\n enum nss_status status;\n int n = __libc_res_nsearch (&_res, name, C_IN, T_UNSPEC,\n \t\t\t host_buffer.buf->buf, 2048, &host_buffer.ptr,\n-\t\t\t &ans2p, &nans2p, &resplen2);\n+\t\t\t &ans2p, &nans2p, &resplen2, &ans2p_malloced);\n if (n < 0)\n {\n switch (errno)\n@@ -352,6 +353,10 @@ _nss_dns_gethostbyname4_r (const char *n\n \t\t\t resplen2, name, pat, buffer, buflen,\n \t\t\t errnop, herrnop, ttlp);\n \n+ /* Check whether ans2p was separately allocated. */\n+ if (ans2p_malloced)\n+ free (ans2p);\n+\n if (host_buffer.buf != orig_host_buffer)\n free (host_buffer.buf);\n \n@@ -460,7 +465,7 @@ _nss_dns_gethostbyaddr2_r (const void *a\n \t strcpy (qp, \"].ip6.arpa\");\n \t n = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR,\n \t\t\t\t host_buffer.buf->buf, 1024, &host_buffer.ptr,\n-\t\t\t\t NULL, NULL, NULL);\n+\t\t\t\t NULL, NULL, NULL, NULL);\n \t if (n >= 0)\n \t goto got_it_already;\n \t}\n@@ -481,14 +486,14 @@ _nss_dns_gethostbyaddr2_r (const void *a\n }\n \n n = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, host_buffer.buf->buf,\n-\t\t\t 1024, &host_buffer.ptr, NULL, NULL, NULL);\n+\t\t\t 1024, &host_buffer.ptr, NULL, NULL, NULL, NULL);\n if (n < 0 && af == AF_INET6 && (_res.options & RES_NOIP6DOTINT) == 0)\n {\n strcpy (qp, \"ip6.int\");\n n = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, host_buffer.buf->buf,\n \t\t\t host_buffer.buf != orig_host_buffer\n \t\t\t ? MAXPACKET : 1024, &host_buffer.ptr,\n-\t\t\t NULL, NULL, NULL);\n+\t\t\t NULL, NULL, NULL, NULL);\n }\n if (n < 0)\n {\nIndex: glibc-2.19/resolv/nss_dns/dns-network.c\n===================================================================\n--- glibc-2.19.orig/resolv/nss_dns/dns-network.c\n+++ glibc-2.19/resolv/nss_dns/dns-network.c\n@@ -129,7 +129,7 @@ _nss_dns_getnetbyname_r (const char *nam\n net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);\n \n anslen = __libc_res_nsearch (&_res, qbuf, C_IN, T_PTR, net_buffer.buf->buf,\n-\t\t\t 1024, &net_buffer.ptr, NULL, NULL, NULL);\n+\t\t\t 1024, &net_buffer.ptr, NULL, NULL, NULL, NULL);\n if (anslen < 0)\n {\n /* Nothing found. */\n@@ -205,7 +205,7 @@ _nss_dns_getnetbyaddr_r (uint32_t net, i\n net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);\n \n anslen = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, net_buffer.buf->buf,\n-\t\t\t 1024, &net_buffer.ptr, NULL, NULL, NULL);\n+\t\t\t 1024, &net_buffer.ptr, NULL, NULL, NULL, NULL);\n if (anslen < 0)\n {\n /* Nothing found. */\nIndex: glibc-2.19/resolv/res_query.c\n===================================================================\n--- glibc-2.19.orig/resolv/res_query.c\n+++ glibc-2.19/resolv/res_query.c\n@@ -98,7 +98,7 @@ static int\n __libc_res_nquerydomain(res_state statp, const char *name, const char *domain,\n \t\t\tint class, int type, u_char *answer, int anslen,\n \t\t\tu_char **answerp, u_char **answerp2, int *nanswerp2,\n-\t\t\tint *resplen2);\n+\t\t\tint *resplen2, int *answerp2_malloced);\n \n /*\n * Formulate a normal query, send, and await answer.\n@@ -119,7 +119,8 @@ __libc_res_nquery(res_state statp,\n \t\t u_char **answerp,\t/* if buffer needs to be enlarged */\n \t\t u_char **answerp2,\n \t\t int *nanswerp2,\n-\t\t int *resplen2)\n+\t\t int *resplen2,\n+\t\t int *answerp2_malloced)\n {\n \tHEADER *hp = (HEADER *) answer;\n \tHEADER *hp2;\n@@ -224,7 +225,8 @@ __libc_res_nquery(res_state statp,\n \t}\n \tassert (answerp == NULL || (void *) *answerp == (void *) answer);\n \tn = __libc_res_nsend(statp, query1, nquery1, query2, nquery2, answer,\n-\t\t\t anslen, answerp, answerp2, nanswerp2, resplen2);\n+\t\t\t anslen, answerp, answerp2, nanswerp2, resplen2,\n+\t\t\t answerp2_malloced);\n \tif (use_malloc)\n \t\tfree (buf);\n \tif (n < 0) {\n@@ -316,7 +318,7 @@ res_nquery(res_state statp,\n \t int anslen)\t\t/* size of answer buffer */\n {\n \treturn __libc_res_nquery(statp, name, class, type, answer, anslen,\n-\t\t\t\t NULL, NULL, NULL, NULL);\n+\t\t\t\t NULL, NULL, NULL, NULL, NULL);\n }\n libresolv_hidden_def (res_nquery)\n \n@@ -335,7 +337,8 @@ __libc_res_nsearch(res_state statp,\n \t\t u_char **answerp,\n \t\t u_char **answerp2,\n \t\t int *nanswerp2,\n-\t\t int *resplen2)\n+\t\t int *resplen2,\n+\t\t int *answerp2_malloced)\n {\n \tconst char *cp, * const *domain;\n \tHEADER *hp = (HEADER *) answer;\n@@ -360,7 +363,7 @@ __libc_res_nsearch(res_state statp,\n \tif (!dots && (cp = res_hostalias(statp, name, tmp, sizeof tmp))!= NULL)\n \t\treturn (__libc_res_nquery(statp, cp, class, type, answer,\n \t\t\t\t\t anslen, answerp, answerp2,\n-\t\t\t\t\t nanswerp2, resplen2));\n+\t\t\t\t\t nanswerp2, resplen2, answerp2_malloced));\n \n #ifdef DEBUG\n \tif (statp->options & RES_DEBUG)\n@@ -377,7 +380,8 @@ __libc_res_nsearch(res_state statp,\n \tif (dots >= statp->ndots || trailing_dot) {\n \t\tret = __libc_res_nquerydomain(statp, name, NULL, class, type,\n \t\t\t\t\t answer, anslen, answerp,\n-\t\t\t\t\t answerp2, nanswerp2, resplen2);\n+\t\t\t\t\t answerp2, nanswerp2, resplen2,\n+\t\t\t\t\t answerp2_malloced);\n \t\tif (ret > 0 || trailing_dot)\n \t\t\treturn (ret);\n \t\tsaved_herrno = h_errno;\n@@ -386,11 +390,11 @@ __libc_res_nsearch(res_state statp,\n \t\t\tanswer = *answerp;\n \t\t\tanslen = MAXPACKET;\n \t\t}\n-\t\tif (answerp2\n-\t\t && (*answerp2 < answer || *answerp2 >= answer + anslen))\n+\t\tif (answerp2 && *answerp2_malloced)\n \t\t {\n \t\t free (*answerp2);\n \t\t *answerp2 = NULL;\n+\t\t *answerp2_malloced = 0;\n \t\t }\n \t}\n \n@@ -417,7 +421,7 @@ __libc_res_nsearch(res_state statp,\n \t\t\t\t\t\t class, type,\n \t\t\t\t\t\t answer, anslen, answerp,\n \t\t\t\t\t\t answerp2, nanswerp2,\n-\t\t\t\t\t\t resplen2);\n+\t\t\t\t\t\t resplen2, answerp2_malloced);\n \t\t\tif (ret > 0)\n \t\t\t\treturn (ret);\n \n@@ -425,12 +429,11 @@ __libc_res_nsearch(res_state statp,\n \t\t\t\tanswer = *answerp;\n \t\t\t\tanslen = MAXPACKET;\n \t\t\t}\n-\t\t\tif (answerp2\n-\t\t\t && (*answerp2 < answer\n-\t\t\t\t|| *answerp2 >= answer + anslen))\n+\t\t\tif (answerp2 && *answerp2_malloced)\n \t\t\t {\n \t\t\t free (*answerp2);\n \t\t\t *answerp2 = NULL;\n+\t\t\t *answerp2_malloced = 0;\n \t\t\t }\n \n \t\t\t/*\n@@ -486,7 +489,8 @@ __libc_res_nsearch(res_state statp,\n \t && !(tried_as_is || root_on_list)) {\n \t\tret = __libc_res_nquerydomain(statp, name, NULL, class, type,\n \t\t\t\t\t answer, anslen, answerp,\n-\t\t\t\t\t answerp2, nanswerp2, resplen2);\n+\t\t\t\t\t answerp2, nanswerp2, resplen2,\n+\t\t\t\t\t answerp2_malloced);\n \t\tif (ret > 0)\n \t\t\treturn (ret);\n \t}\n@@ -498,10 +502,11 @@ __libc_res_nsearch(res_state statp,\n \t * else send back meaningless H_ERRNO, that being the one from\n \t * the last DNSRCH we did.\n \t */\n-\tif (answerp2 && (*answerp2 < answer || *answerp2 >= answer + anslen))\n+\tif (answerp2 && *answerp2_malloced)\n \t {\n \t free (*answerp2);\n \t *answerp2 = NULL;\n+\t *answerp2_malloced = 0;\n \t }\n \tif (saved_herrno != -1)\n \t\tRES_SET_H_ERRNO(statp, saved_herrno);\n@@ -521,7 +526,7 @@ res_nsearch(res_state statp,\n \t int anslen)\t\t/* size of answer */\n {\n \treturn __libc_res_nsearch(statp, name, class, type, answer,\n-\t\t\t\t anslen, NULL, NULL, NULL, NULL);\n+\t\t\t\t anslen, NULL, NULL, NULL, NULL, NULL);\n }\n libresolv_hidden_def (res_nsearch)\n \n@@ -539,7 +544,8 @@ __libc_res_nquerydomain(res_state statp,\n \t\t\tu_char **answerp,\n \t\t\tu_char **answerp2,\n \t\t\tint *nanswerp2,\n-\t\t\tint *resplen2)\n+\t\t\tint *resplen2,\n+\t\t\tint *answerp2_malloced)\n {\n \tchar nbuf[MAXDNAME];\n \tconst char *longname = nbuf;\n@@ -581,7 +587,7 @@ __libc_res_nquerydomain(res_state statp,\n \t}\n \treturn (__libc_res_nquery(statp, longname, class, type, answer,\n \t\t\t\t anslen, answerp, answerp2, nanswerp2,\n-\t\t\t\t resplen2));\n+\t\t\t\t resplen2, answerp2_malloced));\n }\n \n int\n@@ -593,7 +599,8 @@ res_nquerydomain(res_state statp,\n \t int anslen)\t\t/* size of answer */\n {\n \treturn __libc_res_nquerydomain(statp, name, domain, class, type,\n-\t\t\t\t answer, anslen, NULL, NULL, NULL, NULL);\n+\t\t\t\t answer, anslen, NULL, NULL, NULL, NULL,\n+\t\t\t\t NULL);\n }\n libresolv_hidden_def (res_nquerydomain)\n \nIndex: glibc-2.19/resolv/res_send.c\n===================================================================\n--- glibc-2.19.orig/resolv/res_send.c\n+++ glibc-2.19/resolv/res_send.c\n@@ -186,12 +186,12 @@ evNowTime(struct timespec *res) {\n static int\t\tsend_vc(res_state, const u_char *, int,\n \t\t\t\tconst u_char *, int,\n \t\t\t\tu_char **, int *, int *, int, u_char **,\n-\t\t\t\tu_char **, int *, int *);\n+\t\t\t\tu_char **, int *, int *, int *);\n static int\t\tsend_dg(res_state, const u_char *, int,\n \t\t\t\tconst u_char *, int,\n \t\t\t\tu_char **, int *, int *, int,\n \t\t\t\tint *, int *, u_char **,\n-\t\t\t\tu_char **, int *, int *);\n+\t\t\t\tu_char **, int *, int *, int *);\n #ifdef DEBUG\n static void\t\tAerror(const res_state, FILE *, const char *, int,\n \t\t\t const struct sockaddr *);\n@@ -343,7 +343,7 @@ int\n __libc_res_nsend(res_state statp, const u_char *buf, int buflen,\n \t\t const u_char *buf2, int buflen2,\n \t\t u_char *ans, int anssiz, u_char **ansp, u_char **ansp2,\n-\t\t int *nansp2, int *resplen2)\n+\t\t int *nansp2, int *resplen2, int *ansp2_malloced)\n {\n int gotsomewhere, terrno, try, v_circuit, resplen, ns, n;\n \n@@ -546,7 +546,8 @@ __libc_res_nsend(res_state statp, const\n \t\t\ttry = statp->retry;\n \t\t\tn = send_vc(statp, buf, buflen, buf2, buflen2,\n \t\t\t\t &ans, &anssiz, &terrno,\n-\t\t\t\t ns, ansp, ansp2, nansp2, resplen2);\n+\t\t\t\t ns, ansp, ansp2, nansp2, resplen2,\n+\t\t\t\t ansp2_malloced);\n \t\t\tif (n < 0)\n \t\t\t\treturn (-1);\n \t\t\tif (n == 0 && (buf2 == NULL || *resplen2 == 0))\n@@ -556,7 +557,7 @@ __libc_res_nsend(res_state statp, const\n \t\t\tn = send_dg(statp, buf, buflen, buf2, buflen2,\n \t\t\t\t &ans, &anssiz, &terrno,\n \t\t\t\t ns, &v_circuit, &gotsomewhere, ansp,\n-\t\t\t\t ansp2, nansp2, resplen2);\n+\t\t\t\t ansp2, nansp2, resplen2, ansp2_malloced);\n \t\t\tif (n < 0)\n \t\t\t\treturn (-1);\n \t\t\tif (n == 0 && (buf2 == NULL || *resplen2 == 0))\n@@ -646,7 +647,7 @@ res_nsend(res_state statp,\n \t const u_char *buf, int buflen, u_char *ans, int anssiz)\n {\n return __libc_res_nsend(statp, buf, buflen, NULL, 0, ans, anssiz,\n-\t\t\t NULL, NULL, NULL, NULL);\n+\t\t\t NULL, NULL, NULL, NULL, NULL);\n }\n libresolv_hidden_def (res_nsend)\n \n@@ -657,7 +658,7 @@ send_vc(res_state statp,\n \tconst u_char *buf, int buflen, const u_char *buf2, int buflen2,\n \tu_char **ansp, int *anssizp,\n \tint *terrno, int ns, u_char **anscp, u_char **ansp2, int *anssizp2,\n-\tint *resplen2)\n+\tint *resplen2, int *ansp2_malloced)\n {\n \tconst HEADER *hp = (HEADER *) buf;\n \tconst HEADER *hp2 = (HEADER *) buf2;\n@@ -823,6 +824,8 @@ send_vc(res_state statp,\n \t\t\t}\n \t\t\t*thisanssizp = MAXPACKET;\n \t\t\t*thisansp = newp;\n+\t\t\tif (thisansp == ansp2)\n+\t\t\t *ansp2_malloced = 1;\n \t\t\tanhp = (HEADER *) newp;\n \t\t\tlen = rlen;\n \t\t} else {\n@@ -992,7 +995,7 @@ send_dg(res_state statp,\n \tconst u_char *buf, int buflen, const u_char *buf2, int buflen2,\n \tu_char **ansp, int *anssizp,\n \tint *terrno, int ns, int *v_circuit, int *gotsomewhere, u_char **anscp,\n-\tu_char **ansp2, int *anssizp2, int *resplen2)\n+\tu_char **ansp2, int *anssizp2, int *resplen2, int *ansp2_malloced)\n {\n \tconst HEADER *hp = (HEADER *) buf;\n \tconst HEADER *hp2 = (HEADER *) buf2;\n@@ -1238,6 +1241,8 @@ send_dg(res_state statp,\n \t\t\tif (newp != NULL) {\n \t\t\t\t*anssizp = MAXPACKET;\n \t\t\t\t*thisansp = ans = newp;\n+\t\t\t\tif (thisansp == ansp2)\n+\t\t\t\t *ansp2_malloced = 1;\n \t\t\t}\n \t\t}\n \t\tHEADER *anhp = (HEADER *) *thisansp;" } ]
{ "id": "glibc-5640-nss-dns-memleak.patch", "cve_id": "CVE-2016-6323", "package": "glibc", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 3275, "context_files": 7 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-3120\n\nThe validate_as_request function in kdc_util.c in the Key Distribution Center (KDC) in MIT Kerberos 5 (aka krb5) before 1.13.6 and 1.4.x before 1.14.3, when restrict_anonymous_to_tgt is enabled, uses an incorrect client data structure, which allows remote authenticated users to cause a denial of service (NULL pointer dereference and daemon crash) via an S4U2Self request.\n\n## Package\nkrb5\n\n## Files to modify\n- src/lib/krb5/krb/bld_princ.c\n\n## Upstream Fix\n```diff\nFrom f0c094a1b745d91ef2f9a4eae2149aac026a5789 Mon Sep 17 00:00:00 2001\nFrom: Greg Hudson <ghudson@mit.edu>\nDate: Fri, 25 Sep 2015 12:51:47 -0400\nSubject: [PATCH] Fix build_principal memory bug [CVE-2015-2697]\n\nIn build_principal_va(), use k5memdup0() instead of strdup() to make a\ncopy of the realm, to ensure that we allocate the correct number of\nbytes and do not read past the end of the input string. This bug\naffects krb5_build_principal(), krb5_build_principal_va(), and\nkrb5_build_principal_alloc_va(). krb5_build_principal_ext() is not\naffected.\n\nCVE-2015-2697:\n\nIn MIT krb5 1.7 and later, an authenticated attacker may be able to\ncause a KDC to crash using a TGS request with a large realm field\nbeginning with a null byte. If the KDC attempts to find a referral to\nanswer the request, it constructs a principal name for lookup using\nkrb5_build_principal() with the requested realm. Due to a bug in this\nfunction, the null byte causes only one byte be allocated for the\nrealm field of the constructed principal, far less than its length.\nSubsequent operations on the lookup principal may cause a read beyond\nthe end of the mapped memory region, causing the KDC process to crash.\n\nCVSSv2: AV:N/AC:L/Au:S/C:N/I:N/A:C/E:POC/RL:OF/RC:C\n\nticket: 8252 (new)\ntarget_version: 1.14\ntags: pullup\n---\n src/lib/krb5/krb/bld_princ.c | 6 ++----\n 1 file changed, 2 insertions(+), 4 deletions(-)\n\ndiff --git a/src/lib/krb5/krb/bld_princ.c b/src/lib/krb5/krb/bld_princ.c\nindex ab6fed897f1..8604268ceb8 100644\n--- a/src/lib/krb5/krb/bld_princ.c\n+++ b/src/lib/krb5/krb/bld_princ.c\n@@ -40,10 +40,8 @@ build_principal_va(krb5_context context, krb5_principal princ,\n data = malloc(size * sizeof(krb5_data));\n if (!data) { retval = ENOMEM; }\n \n- if (!retval) {\n- r = strdup(realm);\n- if (!r) { retval = ENOMEM; }\n- }\n+ if (!retval)\n+ r = k5memdup0(realm, rlen, &retval);\n \n while (!retval && (component = va_arg(ap, char *))) {\n if (count == size) {\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From f0c094a1b745d91ef2f9a4eae2149aac026a5789 Mon Sep 17 00:00:00 2001\nFrom: Greg Hudson <ghudson@mit.edu>\nDate: Fri, 25 Sep 2015 12:51:47 -0400\nSubject: [PATCH] Fix build_principal memory bug [CVE-2015-2697]\n\nIn build_principal_va(), use k5memdup0() instead of strdup() to make a\ncopy of the realm, to ensure that we allocate the correct number of\nbytes and do not read past the end of the input string. This bug\naffects krb5_build_principal(), krb5_build_principal_va(), and\nkrb5_build_principal_alloc_va(). krb5_build_principal_ext() is not\naffected.\n\nCVE-2015-2697:\n\nIn MIT krb5 1.7 and later, an authenticated attacker may be able to\ncause a KDC to crash using a TGS request with a large realm field\nbeginning with a null byte. If the KDC attempts to find a referral to\nanswer the request, it constructs a principal name for lookup using\nkrb5_build_principal() with the requested realm. Due to a bug in this\nfunction, the null byte causes only one byte be allocated for the\nrealm field of the constructed principal, far less than its length.\nSubsequent operations on the lookup principal may cause a read beyond\nthe end of the mapped memory region, causing the KDC process to crash.\n\nCVSSv2: AV:N/AC:L/Au:S/C:N/I:N/A:C/E:POC/RL:OF/RC:C\n\nticket: 8252 (new)\ntarget_version: 1.14\ntags: pullup\n\ndiff --git a/src/lib/krb5/krb/bld_princ.c b/src/lib/krb5/krb/bld_princ.c\nindex ab6fed8..8604268 100644\n--- a/src/lib/krb5/krb/bld_princ.c\n+++ b/src/lib/krb5/krb/bld_princ.c\n@@ -40,10 +40,8 @@ build_principal_va(krb5_context context, krb5_principal princ,\n data = malloc(size * sizeof(krb5_data));\n if (!data) { retval = ENOMEM; }\n \n- if (!retval) {\n- r = strdup(realm);\n- if (!r) { retval = ENOMEM; }\n- }\n+ if (!retval)\n+ r = k5memdup0(realm, rlen, &retval);\n \n while (!retval && (component = va_arg(ap, char *))) {\n if (count == size) {\n-- \n2.6.2" } ]
{ "id": "krb5-5535-0100-Fix-build_principal-memor", "cve_id": "CVE-2016-3120", "package": "krb5", "upstream_enriched": true, "upstream_commit": "f0c094a1b745d91ef2f9a4eae2149aac026a5789", "upstream_repo": "krb5/krb5", "tier": "adapted", "has_source_context": false, "license": "MIT", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-2698\n\nThe iakerb_gss_export_sec_context function in lib/gssapi/krb5/iakerb.c in MIT Kerberos 5 (aka krb5) 1.14 pre-release 2015-09-14 improperly accesses a certain pointer, which allows remote authenticated users to cause a denial of service (memory corruption) or possibly have unspecified other impact by interacting with an application that calls the gss_export_sec_context function. NOTE: this vulnerability exists because of an incorrect fix for CVE-2015-2696.\n\n## Package\nkrb5\n\n## Files to modify\n- src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c\n\n## Upstream Fix\n```diff\nFrom 04038bf3633c4b909b5ded3072dc88c8c419bf16 Mon Sep 17 00:00:00 2001\nFrom: Ben Kaduk <kaduk@mit.edu>\nDate: Wed, 19 Nov 2014 12:04:46 -0500\nSubject: [PATCH] Support keyless principals in LDAP [CVE-2014-5354]\n\nOperations like \"kadmin -q 'addprinc -nokey foo'\" or\n\"kadmin -q 'purgekeys -all foo'\" result in principal entries with\nno keys present, so krb5_encode_krbsecretkey() would just return\nNULL, which then got unconditionally dereferenced in\nkrb5_add_ber_mem_ldap_mod().\n\nApply some fixes to krb5_encode_krbsecretkey() to handle zero-key\nprincipals better, correct the test for an allocation failure, and\nslightly restructure the cleanup handler to be shorter and more\nappropriate for the usage. Once it no longer short-circuits when\nn_key_data is zero, it will produce an array of length two with both\nentries NULL, which is treated as an empty list by the LDAP library,\nthe correct behavior for a keyless principal.\n\nHowever, attributes with empty values are only handled by the LDAP\nlibrary for Modify operations, not Add operations (which only get\na sequence of Attribute, with no operation field). Therefore, only\nadd an empty krbprincipalkey to the modlist when we will be performing a\nModify, and not when we will be performing an Add, which is conditional\non the (misspelled) create_standalone_prinicipal boolean.\n\nCVE-2014-5354:\n\nIn MIT krb5, when kadmind is configured to use LDAP for the KDC\ndatabase, an authenticated remote attacker can cause a NULL\ndereference by inserting into the database a principal entry which\ncontains no long-term keys.\n\nIn order for the LDAP KDC backend to translate a principal entry\nfrom the database abstraction layer into the form expected by the\nLDAP schema, the principal's keys are encoded into a\nNULL-terminated array of length-value entries to be stored in the\nLDAP database. However, the subroutine which produced this array\ndid not correctly handle the case where no keys were present,\nreturning NULL instead of an empty array, and the array was\nunconditionally dereferenced while adding to the list of LDAP\noperations to perform.\n\nVersions of MIT krb5 prior to 1.12 did not expose a way for\nprincipal entries to have no long-term key material, and\ntherefore are not vulnerable.\n\n CVSSv2 Vector: AV:N/AC:M/Au:S/C:N/I:N/A:P/E:H/RL:OF/RC:C\n\nticket: 8041 (new)\ntags: pullup\ntarget_version: 1.13.1\nsubject: kadmind with ldap backend crashes when putting keyless entries\n---\n .../kdb/ldap/libkdb_ldap/ldap_principal2.c | 25 +++++++++++++------\n 1 file changed, 17 insertions(+), 8 deletions(-)\n\ndiff --git a/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c b/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c\nindex 3e560d997ac..10b5982f164 100644\n--- a/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c\n+++ b/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c\n@@ -406,14 +406,14 @@ krb5_encode_krbsecretkey(krb5_key_data *key_data_in, int n_key_data,\n int num_versions = 1;\n int i, j, last;\n krb5_error_code err = 0;\n- krb5_key_data *key_data;\n+ krb5_key_data *key_data = NULL;\n \n- if (n_key_data <= 0)\n+ if (n_key_data < 0)\n return NULL;\n \n /* Make a shallow copy of the key data so we can alter it. */\n key_data = k5calloc(n_key_data, sizeof(*key_data), &err);\n- if (key_data_in == NULL)\n+ if (key_data == NULL)\n goto cleanup;\n memcpy(key_data, key_data_in, n_key_data * sizeof(*key_data));\n \n@@ -467,9 +467,8 @@ krb5_encode_krbsecretkey(krb5_key_data *key_data_in, int n_key_data,\n free(key_data);\n if (err != 0) {\n if (ret != NULL) {\n- for (i = 0; i <= num_versions; i++)\n- if (ret[i] != NULL)\n- free (ret[i]);\n+ for (i = 0; ret[i] != NULL; i++)\n+ free (ret[i]);\n free (ret);\n ret = NULL;\n }\n@@ -1036,9 +1035,19 @@ krb5_ldap_put_principal(krb5_context context, krb5_db_entry *entry,\n bersecretkey = krb5_encode_krbsecretkey (entry->key_data,\n entry->n_key_data, mkvno);\n \n- if ((st=krb5_add_ber_mem_ldap_mod(&mods, \"krbprincipalkey\",\n- LDAP_MOD_REPLACE | LDAP_MOD_BVALUES, bersecretkey)) != 0)\n+ if (bersecretkey == NULL) {\n+ st = ENOMEM;\n goto cleanup;\n+ }\n+ /* An empty list of bervals is only accepted for modify operations,\n+ * not add operations. */\n+ if (bersecretkey[0] != NULL || !create_standalone_prinicipal) {\n+ st = krb5_add_ber_mem_ldap_mod(&mods, \"krbprincipalkey\",\n+ LDAP_MOD_REPLACE | LDAP_MOD_BVALUES,\n+ bersecretkey);\n+ if (st != 0)\n+ goto cleanup;\n+ }\n \n if (!(entry->mask & KADM5_PRINCIPAL)) {\n memset(strval, 0, sizeof(strval));\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 04038bf3633c4b909b5ded3072dc88c8c419bf16 Mon Sep 17 00:00:00 2001\nFrom: Ben Kaduk <kaduk@mit.edu>\nDate: Wed, 19 Nov 2014 12:04:46 -0500\nSubject: [PATCH] Support keyless principals in LDAP [CVE-2014-5354]\n\nOperations like \"kadmin -q 'addprinc -nokey foo'\" or\n\"kadmin -q 'purgekeys -all foo'\" result in principal entries with\nno keys present, so krb5_encode_krbsecretkey() would just return\nNULL, which then got unconditionally dereferenced in\nkrb5_add_ber_mem_ldap_mod().\n\nApply some fixes to krb5_encode_krbsecretkey() to handle zero-key\nprincipals better, correct the test for an allocation failure, and\nslightly restructure the cleanup handler to be shorter and more\nappropriate for the usage. Once it no longer short-circuits when\nn_key_data is zero, it will produce an array of length two with both\nentries NULL, which is treated as an empty list by the LDAP library,\nthe correct behavior for a keyless principal.\n\nHowever, attributes with empty values are only handled by the LDAP\nlibrary for Modify operations, not Add operations (which only get\na sequence of Attribute, with no operation field). Therefore, only\nadd an empty krbprincipalkey to the modlist when we will be performing a\nModify, and not when we will be performing an Add, which is conditional\non the (misspelled) create_standalone_prinicipal boolean.\n\nCVE-2014-5354:\n\nIn MIT krb5, when kadmind is configured to use LDAP for the KDC\ndatabase, an authenticated remote attacker can cause a NULL\ndereference by inserting into the database a principal entry which\ncontains no long-term keys.\n\nIn order for the LDAP KDC backend to translate a principal entry\nfrom the database abstraction layer into the form expected by the\nLDAP schema, the principal's keys are encoded into a\nNULL-terminated array of length-value entries to be stored in the\nLDAP database. However, the subroutine which produced this array\ndid not correctly handle the case where no keys were present,\nreturning NULL instead of an empty array, and the array was\nunconditionally dereferenced while adding to the list of LDAP\noperations to perform.\n\nVersions of MIT krb5 prior to 1.12 did not expose a way for\nprincipal entries to have no long-term key material, and\ntherefore are not vulnerable.\n\n CVSSv2 Vector: AV:N/AC:M/Au:S/C:N/I:N/A:P/E:H/RL:OF/RC:C\n\nticket: 8041 (new)\ntags: pullup\ntarget_version: 1.13.1\nsubject: kadmind with ldap backend crashes when putting keyless entries\n---\n src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c | 25 +++++++++++++++-------\n 1 file changed, 17 insertions(+), 8 deletions(-)\n\ndiff --git a/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c b/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c\nindex 3e560d9..10b5982 100644\n--- a/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c\n+++ b/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c\n@@ -1036,9 +1035,19 @@ krb5_ldap_put_principal(krb5_context context, krb5_db_entry *entry,\n bersecretkey = krb5_encode_krbsecretkey (entry->key_data,\n entry->n_key_data, mkvno);\n \n- if ((st=krb5_add_ber_mem_ldap_mod(&mods, \"krbprincipalkey\",\n- LDAP_MOD_REPLACE | LDAP_MOD_BVALUES, bersecretkey)) != 0)\n+ if (bersecretkey == NULL) {\n+ st = ENOMEM;\n goto cleanup;\n+ }\n+ /* An empty list of bervals is only accepted for modify operations,\n+ * not add operations. */\n+ if (bersecretkey[0] != NULL || !create_standalone_prinicipal) {\n+ st = krb5_add_ber_mem_ldap_mod(&mods, \"krbprincipalkey\",\n+ LDAP_MOD_REPLACE | LDAP_MOD_BVALUES,\n+ bersecretkey);\n+ if (st != 0)\n+ goto cleanup;\n+ }\n \n if (!(entry->mask & KADM5_PRINCIPAL)) {\n memset(strval, 0, sizeof(strval));" } ]
{ "id": "krb5-4431-krb5-1.12.2-CVE-2014-5354.patc", "cve_id": "CVE-2015-2698", "package": "krb5", "upstream_enriched": true, "upstream_commit": "04038bf3633c4b909b5ded3072dc88c8c419bf16", "upstream_repo": "krb5/krb5", "tier": "adapted", "has_source_context": false, "license": "MIT", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-5358\n\nepan/dissectors/packet-pktap.c in the Ethernet dissector in Wireshark 2.x before 2.0.4 mishandles the packet-header data type, which allows remote attackers to cause a denial of service (application crash) via a crafted packet.\n\n## Package\nwireshark\n\n## Files to modify\n- epan/geoip_db.c\n- wireshark-1.12.0.orig/epan/geoip_db.c\n\n## Upstream Fix\n```diff\n---\n epan/geoip_db.c | 3 +++\n 1 file changed, 3 insertions(+)\n\nIndex: wireshark-1.12.0/epan/geoip_db.c\n===================================================================\n--- wireshark-1.12.0.orig/epan/geoip_db.c\t2014-07-31 20:22:47.000000000 +0100\n+++ wireshark-1.12.0/epan/geoip_db.c\t2014-08-04 23:44:43.000000000 +0100\n@@ -175,6 +175,9 @@ static void geoip_db_post_update_cb(void\n geoip_dat_scan_dir(geoip_db_paths[i].path);\n }\n }\n+ if (num_geoip_db_paths < 1) {\n+ geoip_dat_scan_dir(\"/var/lib/GeoIP\");\n+ }\n \n /* add fake databases for latitude and longitude\n * (using \"City\" in reality) */\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "---\n epan/geoip_db.c | 3 +++\n 1 file changed, 3 insertions(+)\n\nIndex: wireshark-1.12.0/epan/geoip_db.c\n===================================================================\n--- wireshark-1.12.0.orig/epan/geoip_db.c\t2014-07-31 20:22:47.000000000 +0100\n+++ wireshark-1.12.0/epan/geoip_db.c\t2014-08-04 23:44:43.000000000 +0100\n@@ -175,6 +175,9 @@ static void geoip_db_post_update_cb(void\n geoip_dat_scan_dir(geoip_db_paths[i].path);\n }\n }\n+ if (num_geoip_db_paths < 1) {\n+ geoip_dat_scan_dir(\"/var/lib/GeoIP\");\n+ }\n \n /* add fake databases for latitude and longitude\n * (using \"City\" in reality) */" } ]
{ "id": "wireshark-5208-wireshark-1.2.0-geoip.patch", "cve_id": "CVE-2016-5358", "package": "wireshark", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": false, "license": "GPL-2.0-or-later AND GPL-3.0-or-later", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-2105\n\nInteger overflow in the EVP_EncodeUpdate function in crypto/evp/encode.c in OpenSSL before 1.0.1t and 1.0.2 before 1.0.2h allows remote attackers to cause a denial of service (heap memory corruption) via a large amount of binary data.\n\n## Package\nopenssl\n\n## Files to modify\n- ssl/s3_srvr.c\n\n## Target Source Code\n\n### ssl/s3_srvr.c\n\n#### ssl3_get_client_key_exchange() [lines 2126-2912]\n```c\n\treturn(-1);\n\t}\n\nint ssl3_get_client_key_exchange(SSL *s)\n\t{\n\tint i,al,ok;\n\tlong n;\n\tunsigned long alg_k;\n\tunsigned char *p;\n#ifndef OPENSSL_NO_RSA\n\tRSA *rsa=NULL;\n\tEVP_PKEY *pkey=NULL;\n#endif\n#ifndef OPENSSL_NO_DH\n\tBIGNUM *pub=NULL;\n\tDH *dh_srvr;\n#endif\n#ifndef OPENSSL_NO_KRB5\n\tKSSL_ERR kssl_err;\n#endif /* OPENSSL_NO_KRB5 */\n\n#ifndef OPENSSL_NO_ECDH\n\tEC_KEY *srvr_ecdh = NULL;\n\tEVP_PKEY *clnt_pub_pkey = NULL;\n\tEC_POINT *clnt_ecpoint = NULL;\n\tBN_CTX *bn_ctx = NULL; \n#endif\n\n\tn=s->method->ssl_get_message(s,\n\t\tSSL3_ST_SR_KEY_EXCH_A,\n\t\tSSL3_ST_SR_KEY_EXCH_B,\n\t\tSSL3_MT_CLIENT_KEY_EXCHANGE,\n\t\t2048, /* ??? */\n\t\t&ok);\n\n\tif (!ok) return((int)n);\n\tp=(unsigned char *)s->init_msg;\n\n\talg_k=s->s3->tmp.new_cipher->algorithm_mkey;\n\n#ifndef OPENSSL_NO_RSA\n\tif (alg_k & SSL_kRSA)\n\t\t{\n\t\t/* FIX THIS UP EAY EAY EAY EAY */\n\t\tif (s->s3->tmp.use_rsa_tmp)\n\t\t\t{\n\t\t\tif ((s->cert != NULL) && (s->cert->rsa_tmp != NULL))\n\t\t\t\trsa=s->cert->rsa_tmp;\n\t\t\t/* Don't do a callback because rsa_tmp should\n\t\t\t * be sent already */\n\t\t\tif (rsa == NULL)\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_PKEY);\n\t\t\t\tgoto f_err;\n\n\t\t\t\t}\n\t\t\t}\n/* ... 709 lines omitted ... */\n\t\tgoto f_err;\n\t\t}\n\n\treturn(1);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\n#if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_SRP)\nerr:\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tEVP_PKEY_free(clnt_pub_pkey);\n\tEC_POINT_free(clnt_ecpoint);\n\tif (srvr_ecdh != NULL) \n\t\tEC_KEY_free(srvr_ecdh);\n\tBN_CTX_free(bn_ctx);\n#endif\n\treturn(-1);\n\t}\n\nint ssl3_get_cert_verify(SSL *s)\n```\n\n\n## Upstream Fix\n```diff\nFrom adb46dbc6dd7347750df2468c93e8c34bcb93a4b Mon Sep 17 00:00:00 2001\nFrom: Adam Langley <agl@chromium.org>\nDate: Wed, 24 Apr 2013 14:45:44 -0400\nSubject: [PATCH] This change alters the processing of invalid, RSA pre-master\n secrets so that bad encryptions are treated like random session keys in\n constant time.\n\n---\n ssl/s3_srvr.c | 134 +++++++++++++++++++++++++++++++++-----------------\n 1 file changed, 89 insertions(+), 45 deletions(-)\n\ndiff --git a/ssl/s3_srvr.c b/ssl/s3_srvr.c\nindex ea4e132d979ca..28d5bed483f85 100644\n--- a/ssl/s3_srvr.c\n+++ b/ssl/s3_srvr.c\n@@ -2195,6 +2195,10 @@ int ssl3_get_client_key_exchange(SSL *s)\n #ifndef OPENSSL_NO_RSA\n \tif (alg_k & SSL_kRSA)\n \t\t{\n+\t\tunsigned char rand_premaster_secret[SSL_MAX_MASTER_KEY_LENGTH];\n+\t\tint decrypt_len, decrypt_good_mask;\n+\t\tunsigned char version_good;\n+\n \t\t/* FIX THIS UP EAY EAY EAY EAY */\n \t\tif (s->s3->tmp.use_rsa_tmp)\n \t\t\t{\n@@ -2242,54 +2246,94 @@ int ssl3_get_client_key_exchange(SSL *s)\n \t\t\t\tn=i;\n \t\t\t}\n \n-\t\ti=RSA_private_decrypt((int)n,p,p,rsa,RSA_PKCS1_PADDING);\n-\n-\t\tal = -1;\n-\t\t\n-\t\tif (i != SSL_MAX_MASTER_KEY_LENGTH)\n-\t\t\t{\n-\t\t\tal=SSL_AD_DECODE_ERROR;\n-\t\t\t/* SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT); */\n-\t\t\t}\n-\n-\t\tif ((al == -1) && !((p[0] == (s->client_version>>8)) && (p[1] == (s->client_version & 0xff))))\n-\t\t\t{\n-\t\t\t/* The premaster secret must contain the same version number as the\n-\t\t\t * ClientHello to detect version rollback attacks (strangely, the\n-\t\t\t * protocol does not offer such protection for DH ciphersuites).\n-\t\t\t * However, buggy clients exist that send the negotiated protocol\n-\t\t\t * version instead if the server does not support the requested\n-\t\t\t * protocol version.\n-\t\t\t * If SSL_OP_TLS_ROLLBACK_BUG is set, tolerate such clients. */\n-\t\t\tif (!((s->options & SSL_OP_TLS_ROLLBACK_BUG) &&\n-\t\t\t\t(p[0] == (s->version>>8)) && (p[1] == (s->version & 0xff))))\n-\t\t\t\t{\n-\t\t\t\tal=SSL_AD_DECODE_ERROR;\n-\t\t\t\t/* SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_PROTOCOL_VERSION_NUMBER); */\n+\t\t/* We must not leak whether a decryption failure occurs because\n+\t\t * of Bleichenbacher's attack on PKCS #1 v1.5 RSA padding (see\n+\t\t * RFC 2246, section 7.4.7.1). The code follows that advice of\n+\t\t * the TLS RFC and generates a random premaster secret for the\n+\t\t * case that the decrypt fails. See\n+\t\t * https://tools.ietf.org/html/rfc5246#section-7.4.7.1 */\n \n-\t\t\t\t/* The Klima-Pokorny-Rosa extension of Bleichenbacher's attack\n-\t\t\t\t * (http://eprint.iacr.org/2003/052/) exploits the version\n-\t\t\t\t * number check as a \"bad version oracle\" -- an alert would\n-\t\t\t\t * reveal that the plaintext corresponding to some ciphertext\n-\t\t\t\t * made up by the adversary is properly formatted except\n-\t\t\t\t * that the version number is wrong. To avoid such attacks,\n-\t\t\t\t * we should treat this just like any other decryption error. */\n-\t\t\t\t}\n+\t\t/* should be RAND_bytes, but we cannot work around a failure. */\n+\t\tif (RAND_pseudo_bytes(rand_premaster_secret,\n+\t\t\t\t sizeof(rand_premaster_secret)) <= 0)\n+\t\t\tgoto err;\n+\t\tdecrypt_len = RSA_private_decrypt((int)n,p,p,rsa,RSA_PKCS1_PADDING);\n+\t\tERR_clear_error();\n+\n+\t\t/* decrypt_len should be SSL_MAX_MASTER_KEY_LENGTH.\n+\t\t * decrypt_good_mask will be zero if so and non-zero otherwise. */\n+\t\tdecrypt_good_mask = decrypt_len ^ SSL_MAX_MASTER_KEY_LENGTH;\n+\n+\t\t/* If the version in the decrypted pre-master secret is correct\n+\t\t * then version_good will be zero. The Klima-Pokorny-Rosa\n+\t\t * extension of Bleichenbacher's attack\n+\t\t * (http://eprint.iacr.org/2003/052/) exploits the version\n+\t\t * number check as a \"bad version oracle\". Thus version checks\n+\t\t * are done in constant time and are treated like any other\n+\t\t * decryption error. */\n+\t\tversion_good = p[0] ^ (s->client_version>>8);\n+\t\tversion_good |= p[1] ^ (s->client_version&0xff);\n+\n+\t\t/* The premaster secret must contain the same version number as\n+\t\t * the ClientHello to detect version rollback attacks\n+\t\t * (strangely, the protocol does not offer such protection for\n+\t\t * DH ciphersuites). However, buggy clients exist that send the\n+\t\t * negotiated protocol version instead if the server does not\n+\t\t * support the requested protocol version. If\n+\t\t * SSL_OP_TLS_ROLLBACK_BUG is set, tolerate such clients. */\n+\t\tif (s->options & SSL_OP_TLS_ROLLBACK_BUG)\n+\t\t\t{\n+\t\t\tunsigned char workaround_mask = version_good;\n+\t\t\tunsigned char workaround;\n+\n+\t\t\t/* workaround_mask will be 0xff if version_good is\n+\t\t\t * non-zero (i.e. the version match failed). Otherwise\n+\t\t\t * it'll be 0x00. */\n+\t\t\tworkaround_mask |= workaround_mask >> 4;\n+\t\t\tworkaround_mask |= workaround_mask >> 2;\n+\t\t\tworkaround_mask |= workaround_mask >> 1;\n+\t\t\tworkaround_mask = ~((workaround_mask & 1) - 1);\n+\n+\t\t\tworkaround = p[0] ^ (s->version>>8);\n+\t\t\tworkaround |= p[1] ^ (s->version&0xff);\n+\n+\t\t\t/* If workaround_mask is 0xff (i.e. there was a version\n+\t\t\t * mismatch) then we copy the value of workaround over\n+\t\t\t * version_good. */\n+\t\t\tversion_good = (workaround & workaround_mask) |\n+\t\t\t\t (version_good & ~workaround_mask);\n+\t\t\t}\n+\n+\t\t/* If any bits in version_good are set then they'll poision\n+\t\t * decrypt_good_mask and cause rand_premaster_secret to be\n+\t\t * used. */\n+\t\tdecrypt_good_mask |= version_good;\n+\n+\t\t/* decrypt_good_mask will be zero iff decrypt_len ==\n+\t\t * SSL_MAX_MASTER_KEY_LENGTH and the version check passed. We\n+\t\t * fold the bottom 32 bits of it with an OR so that the LSB\n+\t\t * will be zero iff everything is good. This assumes that we'll\n+\t\t * never decrypt a value > 2**31 bytes, which seems safe. */\n+\t\tdecrypt_good_mask |= decrypt_good_mask >> 16;\n+\t\tdecrypt_good_mask |= decrypt_good_mask >> 8;\n+\t\tdecrypt_good_mask |= decrypt_good_mask >> 4;\n+\t\tdecrypt_good_mask |= decrypt_good_mask >> 2;\n+\t\tdecrypt_good_mask |= decrypt_good_mask >> 1;\n+\t\t/* Now select only the LSB and subtract one. If decrypt_len ==\n+\t\t * SSL_MAX_MASTER_KEY_LENGTH and the version check passed then\n+\t\t * decrypt_good_mask will be all ones. Otherwise it'll be all\n+\t\t * zeros. */\n+\t\tdecrypt_good_mask &= 1;\n+\t\tdecrypt_good_mask--;\n+\n+\t\t/* Now copy rand_premaster_secret over p using\n+\t\t * decrypt_good_mask. */\n+\t\tfor (i = 0; i < (int) sizeof(rand_premaster_secret); i++)\n+\t\t\t{\n+\t\t\tp[i] = (p[i] & decrypt_good_mask) |\n+\t\t\t (rand_premaster_secret[i] & ~decrypt_good_mask);\n \t\t\t}\n \n-\t\tif (al != -1)\n-\t\t\t{\n-\t\t\t/* Some decryption failure -- use random value instead as countermeasure\n-\t\t\t * against Bleichenbacher's attack on PKCS #1 v1.5 RSA padding\n-\t\t\t * (see RFC 2246, section 7.4.7.1). */\n-\t\t\tERR_clear_error();\n-\t\t\ti = SSL_MAX_MASTER_KEY_LENGTH;\n-\t\t\tp[0] = s->client_version >> 8;\n-\t\t\tp[1] = s->client_version & 0xff;\n-\t\t\tif (RAND_pseudo_bytes(p+2, i-2) <= 0) /* should be RAND_bytes, but we cannot work around a failure */\n-\t\t\t\tgoto err;\n-\t\t\t}\n-\t\n \t\ts->session->master_key_length=\n \t\t\ts->method->ssl3_enc->generate_master_secret(s,\n \t\t\t\ts->session->master_key,\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "commit 133145686e054a28f78b94e8a996ef7ae13d30b7\nAuthor: Adam Langley <agl@chromium.org>\nDate: Wed Apr 24 14:45:44 2013 -0400\n\n This change alters the processing of invalid, RSA pre-master secrets so\n that bad encryptions are treated like random session keys in constant\n time.\n \n (cherry picked from commit adb46dbc6dd7347750df2468c93e8c34bcb93a4b)\n \n Reviewed-by: Rich Salz <rsalz@openssl.org>\n\ndiff --git a/ssl/s3_srvr.c b/ssl/s3_srvr.c\nindex c907f2b..127185a 100644\n--- a/ssl/s3_srvr.c\n+++ b/ssl/s3_srvr.c\n@@ -2167,6 +2167,10 @@ int ssl3_get_client_key_exchange(SSL *s)\n #ifndef OPENSSL_NO_RSA\n \tif (alg_k & SSL_kRSA)\n \t\t{\n+\t\tunsigned char rand_premaster_secret[SSL_MAX_MASTER_KEY_LENGTH];\n+\t\tint decrypt_len, decrypt_good_mask;\n+\t\tunsigned char version_good;\n+\n \t\t/* FIX THIS UP EAY EAY EAY EAY */\n \t\tif (s->s3->tmp.use_rsa_tmp)\n \t\t\t{\n@@ -2214,54 +2218,94 @@ int ssl3_get_client_key_exchange(SSL *s)\n \t\t\t\tn=i;\n \t\t\t}\n \n-\t\ti=RSA_private_decrypt((int)n,p,p,rsa,RSA_PKCS1_PADDING);\n-\n-\t\tal = -1;\n-\t\t\n-\t\tif (i != SSL_MAX_MASTER_KEY_LENGTH)\n-\t\t\t{\n-\t\t\tal=SSL_AD_DECODE_ERROR;\n-\t\t\t/* SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT); */\n-\t\t\t}\n-\n-\t\tif ((al == -1) && !((p[0] == (s->client_version>>8)) && (p[1] == (s->client_version & 0xff))))\n-\t\t\t{\n-\t\t\t/* The premaster secret must contain the same version number as the\n-\t\t\t * ClientHello to detect version rollback attacks (strangely, the\n-\t\t\t * protocol does not offer such protection for DH ciphersuites).\n-\t\t\t * However, buggy clients exist that send the negotiated protocol\n-\t\t\t * version instead if the server does not support the requested\n-\t\t\t * protocol version.\n-\t\t\t * If SSL_OP_TLS_ROLLBACK_BUG is set, tolerate such clients. */\n-\t\t\tif (!((s->options & SSL_OP_TLS_ROLLBACK_BUG) &&\n-\t\t\t\t(p[0] == (s->version>>8)) && (p[1] == (s->version & 0xff))))\n-\t\t\t\t{\n-\t\t\t\tal=SSL_AD_DECODE_ERROR;\n-\t\t\t\t/* SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_PROTOCOL_VERSION_NUMBER); */\n+\t\t/* We must not leak whether a decryption failure occurs because\n+\t\t * of Bleichenbacher's attack on PKCS #1 v1.5 RSA padding (see\n+\t\t * RFC 2246, section 7.4.7.1). The code follows that advice of\n+\t\t * the TLS RFC and generates a random premaster secret for the\n+\t\t * case that the decrypt fails. See\n+\t\t * https://tools.ietf.org/html/rfc5246#section-7.4.7.1 */\n \n-\t\t\t\t/* The Klima-Pokorny-Rosa extension of Bleichenbacher's attack\n-\t\t\t\t * (http://eprint.iacr.org/2003/052/) exploits the version\n-\t\t\t\t * number check as a \"bad version oracle\" -- an alert would\n-\t\t\t\t * reveal that the plaintext corresponding to some ciphertext\n-\t\t\t\t * made up by the adversary is properly formatted except\n-\t\t\t\t * that the version number is wrong. To avoid such attacks,\n-\t\t\t\t * we should treat this just like any other decryption error. */\n-\t\t\t\t}\n+\t\t/* should be RAND_bytes, but we cannot work around a failure. */\n+\t\tif (RAND_pseudo_bytes(rand_premaster_secret,\n+\t\t\t\t sizeof(rand_premaster_secret)) <= 0)\n+\t\t\tgoto err;\n+\t\tdecrypt_len = RSA_private_decrypt((int)n,p,p,rsa,RSA_PKCS1_PADDING);\n+\t\tERR_clear_error();\n+\n+\t\t/* decrypt_len should be SSL_MAX_MASTER_KEY_LENGTH.\n+\t\t * decrypt_good_mask will be zero if so and non-zero otherwise. */\n+\t\tdecrypt_good_mask = decrypt_len ^ SSL_MAX_MASTER_KEY_LENGTH;\n+\n+\t\t/* If the version in the decrypted pre-master secret is correct\n+\t\t * then version_good will be zero. The Klima-Pokorny-Rosa\n+\t\t * extension of Bleichenbacher's attack\n+\t\t * (http://eprint.iacr.org/2003/052/) exploits the version\n+\t\t * number check as a \"bad version oracle\". Thus version checks\n+\t\t * are done in constant time and are treated like any other\n+\t\t * decryption error. */\n+\t\tversion_good = p[0] ^ (s->client_version>>8);\n+\t\tversion_good |= p[1] ^ (s->client_version&0xff);\n+\n+\t\t/* The premaster secret must contain the same version number as\n+\t\t * the ClientHello to detect version rollback attacks\n+\t\t * (strangely, the protocol does not offer such protection for\n+\t\t * DH ciphersuites). However, buggy clients exist that send the\n+\t\t * negotiated protocol version instead if the server does not\n+\t\t * support the requested protocol version. If\n+\t\t * SSL_OP_TLS_ROLLBACK_BUG is set, tolerate such clients. */\n+\t\tif (s->options & SSL_OP_TLS_ROLLBACK_BUG)\n+\t\t\t{\n+\t\t\tunsigned char workaround_mask = version_good;\n+\t\t\tunsigned char workaround;\n+\n+\t\t\t/* workaround_mask will be 0xff if version_good is\n+\t\t\t * non-zero (i.e. the version match failed). Otherwise\n+\t\t\t * it'll be 0x00. */\n+\t\t\tworkaround_mask |= workaround_mask >> 4;\n+\t\t\tworkaround_mask |= workaround_mask >> 2;\n+\t\t\tworkaround_mask |= workaround_mask >> 1;\n+\t\t\tworkaround_mask = ~((workaround_mask & 1) - 1);\n+\n+\t\t\tworkaround = p[0] ^ (s->version>>8);\n+\t\t\tworkaround |= p[1] ^ (s->version&0xff);\n+\n+\t\t\t/* If workaround_mask is 0xff (i.e. there was a version\n+\t\t\t * mismatch) then we copy the value of workaround over\n+\t\t\t * version_good. */\n+\t\t\tversion_good = (workaround & workaround_mask) |\n+\t\t\t\t (version_good & ~workaround_mask);\n+\t\t\t}\n+\n+\t\t/* If any bits in version_good are set then they'll poision\n+\t\t * decrypt_good_mask and cause rand_premaster_secret to be\n+\t\t * used. */\n+\t\tdecrypt_good_mask |= version_good;\n+\n+\t\t/* decrypt_good_mask will be zero iff decrypt_len ==\n+\t\t * SSL_MAX_MASTER_KEY_LENGTH and the version check passed. We\n+\t\t * fold the bottom 32 bits of it with an OR so that the LSB\n+\t\t * will be zero iff everything is good. This assumes that we'll\n+\t\t * never decrypt a value > 2**31 bytes, which seems safe. */\n+\t\tdecrypt_good_mask |= decrypt_good_mask >> 16;\n+\t\tdecrypt_good_mask |= decrypt_good_mask >> 8;\n+\t\tdecrypt_good_mask |= decrypt_good_mask >> 4;\n+\t\tdecrypt_good_mask |= decrypt_good_mask >> 2;\n+\t\tdecrypt_good_mask |= decrypt_good_mask >> 1;\n+\t\t/* Now select only the LSB and subtract one. If decrypt_len ==\n+\t\t * SSL_MAX_MASTER_KEY_LENGTH and the version check passed then\n+\t\t * decrypt_good_mask will be all ones. Otherwise it'll be all\n+\t\t * zeros. */\n+\t\tdecrypt_good_mask &= 1;\n+\t\tdecrypt_good_mask--;\n+\n+\t\t/* Now copy rand_premaster_secret over p using\n+\t\t * decrypt_good_mask. */\n+\t\tfor (i = 0; i < (int) sizeof(rand_premaster_secret); i++)\n+\t\t\t{\n+\t\t\tp[i] = (p[i] & decrypt_good_mask) |\n+\t\t\t (rand_premaster_secret[i] & ~decrypt_good_mask);\n \t\t\t}\n \n-\t\tif (al != -1)\n-\t\t\t{\n-\t\t\t/* Some decryption failure -- use random value instead as countermeasure\n-\t\t\t * against Bleichenbacher's attack on PKCS #1 v1.5 RSA padding\n-\t\t\t * (see RFC 2246, section 7.4.7.1). */\n-\t\t\tERR_clear_error();\n-\t\t\ti = SSL_MAX_MASTER_KEY_LENGTH;\n-\t\t\tp[0] = s->client_version >> 8;\n-\t\t\tp[1] = s->client_version & 0xff;\n-\t\t\tif (RAND_pseudo_bytes(p+2, i-2) <= 0) /* should be RAND_bytes, but we cannot work around a failure */\n-\t\t\t\tgoto err;\n-\t\t\t}\n-\t\n \t\ts->session->master_key_length=\n \t\t\ts->method->ssl3_enc->generate_master_secret(s,\n \t\t\t\ts->session->master_key," } ]
{ "id": "openssl-5050-openssl-RSA_premaster_secret_i", "cve_id": "CVE-2016-2105", "package": "openssl", "upstream_enriched": true, "upstream_commit": "adb46dbc6dd7347750df2468c93e8c34bcb93a4b", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "license": "OpenSSL", "context_tokens_est": 423, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-6354\n\nHeap-based buffer overflow in the yy_get_next_buffer function in Flex before 2.6.1 might allow context-dependent attackers to cause a denial of service or possibly execute arbitrary code via vectors involving num_to_read.\n\n## Package\nmozilla-nss\n\n## Files to modify\n- lib/jar/jarfile.c\n\n## Upstream Fix\n```diff\ndiff --git a/lib/jar/jarfile.c b/lib/jar/jarfile.c\n--- a/lib/jar/jarfile.c\n+++ b/lib/jar/jarfile.c\n@@ -652,17 +652,17 @@ jar_gen_index(JAR *jar, jarArch format, \n * List the physical contents of a Phil Katz\n * style .ZIP file into the JAR linked list.\n *\n */\n static int\n jar_listzip(JAR *jar, JAR_FILE fp)\n {\n ZZLink *ent;\n- JAR_Item *it;\n+ JAR_Item *it = NULL;\n JAR_Physical *phy = NULL;\n struct ZipLocal *Local = PORT_ZNew(struct ZipLocal);\n struct ZipCentral *Central = PORT_ZNew(struct ZipCentral);\n struct ZipEnd *End = PORT_ZNew(struct ZipEnd);\n \n int err = 0;\n long pos = 0L;\n unsigned int compression;\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "diff --git a/lib/jar/jarfile.c b/lib/jar/jarfile.c\n--- a/lib/jar/jarfile.c\n+++ b/lib/jar/jarfile.c\n@@ -652,17 +652,17 @@ jar_gen_index(JAR *jar, jarArch format, \n * List the physical contents of a Phil Katz\n * style .ZIP file into the JAR linked list.\n *\n */\n static int\n jar_listzip(JAR *jar, JAR_FILE fp)\n {\n ZZLink *ent;\n- JAR_Item *it;\n+ JAR_Item *it = NULL;\n JAR_Physical *phy = NULL;\n struct ZipLocal *Local = PORT_ZNew(struct ZipLocal);\n struct ZipCentral *Central = PORT_ZNew(struct ZipCentral);\n struct ZipEnd *End = PORT_ZNew(struct ZipEnd);\n \n int err = 0;\n long pos = 0L;\n unsigned int compression;" } ]
{ "id": "mozilla-nss-5531-nss-uninitialized.patch", "cve_id": "CVE-2016-6354", "package": "mozilla-nss", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": false, "license": "MPL-2.0", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2013-4288\n\nRace condition in PolicyKit (aka polkit) allows local users to bypass intended PolicyKit restrictions and gain privileges by starting a setuid or pkexec process before the authorization check is performed, related to (1) the polkit_unix_process_new API function, (2) the dbus API, or (3) the --process (unix-process) option for authorization to pkcheck.\n\n## Package\nsystemd\n\n## Files to modify\n- systemd-195.orig/src/login/logind-dbus.c\n- src/login/logind-dbus.c\n\n## Target Source Code\n\n### src/login/logind-dbus.c\n\n#### bus_manager_create_session() [lines 296-691]\n```c\n return 0;\n}\n\nstatic int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMessage **_reply) {\n Session *session = NULL;\n User *user = NULL;\n const char *type, *class, *seat, *tty, *display, *remote_user, *remote_host, *service;\n uint32_t uid, leader, audit_id = 0;\n dbus_bool_t remote, kill_processes, exists;\n char **controllers = NULL, **reset_controllers = NULL;\n SessionType t;\n SessionClass c;\n Seat *s;\n DBusMessageIter iter;\n int r;\n char *id = NULL, *p;\n uint32_t vtnr = 0;\n int fifo_fd = -1;\n DBusMessage *reply = NULL;\n bool b;\n\n assert(m);\n assert(message);\n assert(_reply);\n\n if (!dbus_message_iter_init(message, &iter) ||\n dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32)\n return -EINVAL;\n\n dbus_message_iter_get_basic(&iter, &uid);\n\n if (!dbus_message_iter_next(&iter) ||\n dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32)\n return -EINVAL;\n\n dbus_message_iter_get_basic(&iter, &leader);\n\n if (leader <= 0 ||\n !dbus_message_iter_next(&iter) ||\n dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)\n/* ... 64 lines omitted ... */\n else if (vtnr != (uint32_t) v)\n return -EINVAL;\n } else if (tty_is_console(tty)) {\n\n if (!s)\n s = m->vtconsole;\n else if (s != m->vtconsole)\n return -EINVAL;\n\n if (vtnr != 0)\n return -EINVAL;\n\n } else if (!isempty(tty) && s && seat_is_vtconsole(s))\n return -EINVAL;\n\n if (s) {\n if (seat_can_multi_session(s)) {\n if (vtnr > 63)\n return -EINVAL;\n } else {\n if (vtnr != 0)\n return -EINVAL;\n }\n }\n\n if (!dbus_message_iter_next(&iter) ||\n dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)\n return -EINVAL;\n/* ... 244 lines omitted ... */\nfail:\n strv_free(controllers);\n strv_free(reset_controllers);\n\n if (session)\n session_add_to_gc_queue(session);\n\n if (user)\n user_add_to_gc_queue(user);\n\n if (fifo_fd >= 0)\n close_nointr_nofail(fifo_fd);\n\n if (reply)\n dbus_message_unref(reply);\n\n return r;\n}\n\nstatic int bus_manager_inhibit(Manager *m, DBusConnection *connection, DBusMessage *message, DBusError *error, DBusMessage **_reply) {\n```\n\n\n## Upstream Fix\n```diff\nFrom 978cf3c75fbd94fd0e046206ada6169b35edd919 Mon Sep 17 00:00:00 2001\nFrom: Lennart Poettering <lennart@poettering.net>\nDate: Sun, 28 Oct 2012 17:37:16 +0100\nSubject: [PATCH] logind: it's OK if a process on an pty requests a session for\n seat0\n\nAfter all, if a sudo/su inside an X terminal should get added to the\nsame session as the X session itself.\n---\n src/login/logind-dbus.c | 3 +--\n 1 file changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c\nindex 4326e5b87cf3c..8b6021d35f667 100644\n--- a/src/login/logind-dbus.c\n+++ b/src/login/logind-dbus.c\n@@ -415,8 +415,7 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess\n if (vtnr != 0)\n return -EINVAL;\n \n- } else if (!isempty(tty) && s && seat_is_vtconsole(s))\n- return -EINVAL;\n+ }\n \n if (s) {\n if (seat_can_multi_session(s)) {\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 978cf3c75fbd94fd0e046206ada6169b35edd919 Mon Sep 17 00:00:00 2001\nFrom: Lennart Poettering <lennart@poettering.net>\nDate: Sun, 28 Oct 2012 17:37:16 +0100\nSubject: [PATCH] logind: it's OK if a process on an pty requests a session\n for seat0\n\nAfter all, if a sudo/su inside an X terminal should get added to the\nsame session as the X session itself.\n---\n src/login/logind-dbus.c | 3 +--\n 1 file changed, 1 insertion(+), 2 deletions(-)\n\nIndex: systemd-195/src/login/logind-dbus.c\n===================================================================\n--- systemd-195.orig/src/login/logind-dbus.c\n+++ systemd-195/src/login/logind-dbus.c\n@@ -409,8 +409,7 @@ static int bus_manager_create_session(Ma\n if (vtnr != 0)\n return -EINVAL;\n \n- } else if (!isempty(tty) && s && seat_is_vtconsole(s))\n- return -EINVAL;\n+ }\n \n if (s) {\n if (seat_can_multi_session(s)) {" } ]
{ "id": "systemd-2025-fix-logind-pty-seat.patch", "cve_id": "CVE-2013-4288", "package": "systemd", "upstream_enriched": true, "upstream_commit": "978cf3c75fbd94fd0e046206ada6169b35edd919", "upstream_repo": "systemd/systemd", "tier": "adapted", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 712, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-2698\n\nThe iakerb_gss_export_sec_context function in lib/gssapi/krb5/iakerb.c in MIT Kerberos 5 (aka krb5) 1.14 pre-release 2015-09-14 improperly accesses a certain pointer, which allows remote authenticated users to cause a denial of service (memory corruption) or possibly have unspecified other impact by interacting with an application that calls the gss_export_sec_context function. NOTE: this vulnerability exists because of an incorrect fix for CVE-2015-2696.\n\n## Package\nkrb5\n\n## Files to modify\n- src/lib/gssapi/spnego/spnego_mech.c\n\n## Upstream Fix\n```diff\nFrom f18ddf5d82de0ab7591a36e465bc24225776940f Mon Sep 17 00:00:00 2001\nFrom: David Woodhouse <David.Woodhouse@intel.com>\nDate: Tue, 15 Jul 2014 12:54:15 -0400\nSubject: [PATCH] Fix double-free in SPNEGO [CVE-2014-4343]\n\nIn commit cd7d6b08 (\"Verify acceptor's mech in SPNEGO initiator\") the\npointer sc->internal_mech became an alias into sc->mech_set->elements,\nwhich should be considered constant for the duration of the SPNEGO\ncontext. So don't free it.\n\nCVE-2014-4343:\n\nIn MIT krb5 releases 1.10 and newer, an unauthenticated remote\nattacker with the ability to spoof packets appearing to be from a\nGSSAPI acceptor can cause a double-free condition in GSSAPI initiators\n(clients) which are using the SPNEGO mechanism, by returning a\ndifferent underlying mechanism than was proposed by the initiator. At\nthis stage of the negotiation, the acceptor is unauthenticated, and\nthe acceptor's response could be spoofed by an attacker with the\nability to inject traffic to the initiator.\n\nHistorically, some double-free vulnerabilities can be translated into\nremote code execution, though the necessary exploits must be tailored\nto the individual application and are usually quite\ncomplicated. Double-frees can also be exploited to cause an\napplication crash, for a denial of service. However, most GSSAPI\nclient applications are not vulnerable, as the SPNEGO mechanism is not\nused by default (when GSS_C_NO_OID is passed as the mech_type argument\nto gss_init_sec_context()). The most common use of SPNEGO is for\nHTTP-Negotiate, used in web browsers and other web clients. Most such\nclients are believed to not offer HTTP-Negotiate by default, instead\nrequiring a whitelist of sites for which it may be used to be\nconfigured. If the whitelist is configured to only allow\nHTTP-Negotiate over TLS connections (\"https://\"), a successful\nattacker must also spoof the web server's SSL certificate, due to the\nway the WWW-Authenticate header is sent in a 401 (Unauthorized)\nresponse message. Unfortunately, many instructions for enabling\nHTTP-Negotiate in common web browsers do not include a TLS\nrequirement.\n\n CVSSv2 Vector: AV:N/AC:H/Au:N/C:C/I:C/A:C/E:POC/RL:OF/RC:C\n\n[kaduk@mit.edu: CVE summary and CVSSv2 vector]\n\nticket: 7969 (new)\ntarget_version: 1.12.2\ntags: pullup\n---\n src/lib/gssapi/spnego/spnego_mech.c | 1 -\n 1 file changed, 1 deletion(-)\n\ndiff --git a/src/lib/gssapi/spnego/spnego_mech.c b/src/lib/gssapi/spnego/spnego_mech.c\nindex 173c6d2939a..8f829d8c592 100644\n--- a/src/lib/gssapi/spnego/spnego_mech.c\n+++ b/src/lib/gssapi/spnego/spnego_mech.c\n@@ -818,7 +818,6 @@ init_ctx_reselect(OM_uint32 *minor_status, spnego_gss_ctx_id_t sc,\n \tOM_uint32 tmpmin;\n \tsize_t i;\n \n-\tgeneric_gss_release_oid(&tmpmin, &sc->internal_mech);\n \tgss_delete_sec_context(&tmpmin, &sc->ctx_handle,\n \t\t\t GSS_C_NO_BUFFER);\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From f18ddf5d82de0ab7591a36e465bc24225776940f Mon Sep 17 00:00:00 2001\nFrom: David Woodhouse <David.Woodhouse@intel.com>\nDate: Tue, 15 Jul 2014 12:54:15 -0400\nSubject: [PATCH] Fix double-free in SPNEGO [CVE-2014-4343]\n\nIn commit cd7d6b08 (\"Verify acceptor's mech in SPNEGO initiator\") the\npointer sc->internal_mech became an alias into sc->mech_set->elements,\nwhich should be considered constant for the duration of the SPNEGO\ncontext. So don't free it.\n\nCVE-2014-4343:\n\nIn MIT krb5 releases 1.10 and newer, an unauthenticated remote\nattacker with the ability to spoof packets appearing to be from a\nGSSAPI acceptor can cause a double-free condition in GSSAPI initiators\n(clients) which are using the SPNEGO mechanism, by returning a\ndifferent underlying mechanism than was proposed by the initiator. At\nthis stage of the negotiation, the acceptor is unauthenticated, and\nthe acceptor's response could be spoofed by an attacker with the\nability to inject traffic to the initiator.\n\nHistorically, some double-free vulnerabilities can be translated into\nremote code execution, though the necessary exploits must be tailored\nto the individual application and are usually quite\ncomplicated. Double-frees can also be exploited to cause an\napplication crash, for a denial of service. However, most GSSAPI\nclient applications are not vulnerable, as the SPNEGO mechanism is not\nused by default (when GSS_C_NO_OID is passed as the mech_type argument\nto gss_init_sec_context()). The most common use of SPNEGO is for\nHTTP-Negotiate, used in web browsers and other web clients. Most such\nclients are believed to not offer HTTP-Negotiate by default, instead\nrequiring a whitelist of sites for which it may be used to be\nconfigured. If the whitelist is configured to only allow\nHTTP-Negotiate over TLS connections (\"https://\"), a successful\nattacker must also spoof the web server's SSL certificate, due to the\nway the WWW-Authenticate header is sent in a 401 (Unauthorized)\nresponse message. Unfortunately, many instructions for enabling\nHTTP-Negotiate in common web browsers do not include a TLS\nrequirement.\n\n CVSSv2 Vector: AV:N/AC:H/Au:N/C:C/I:C/A:C/E:POC/RL:OF/RC:C\n\n[kaduk@mit.edu: CVE summary and CVSSv2 vector]\n\nticket: 7969 (new)\ntarget_version: 1.12.2\ntags: pullup\n---\n src/lib/gssapi/spnego/spnego_mech.c | 1 -\n 1 file changed, 1 deletion(-)\n\ndiff --git a/src/lib/gssapi/spnego/spnego_mech.c b/src/lib/gssapi/spnego/spnego_mech.c\nindex 173c6d2..8f829d8 100644\n--- a/src/lib/gssapi/spnego/spnego_mech.c\n+++ b/src/lib/gssapi/spnego/spnego_mech.c\n@@ -818,7 +818,6 @@ init_ctx_reselect(OM_uint32 *minor_status, spnego_gss_ctx_id_t sc,\n \tOM_uint32 tmpmin;\n \tsize_t i;\n \n-\tgeneric_gss_release_oid(&tmpmin, &sc->internal_mech);\n \tgss_delete_sec_context(&tmpmin, &sc->ctx_handle,\n \t\t\t GSS_C_NO_BUFFER);\n \n-- \n1.9.3" } ]
{ "id": "krb5-4431-krb5-1.12-CVE-2014-4343-Fix-do", "cve_id": "CVE-2015-2698", "package": "krb5", "upstream_enriched": true, "upstream_commit": "f18ddf5d82de0ab7591a36e465bc24225776940f", "upstream_repo": "krb5/krb5", "tier": "adapted", "has_source_context": false, "license": "MIT", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-3194\n\ncrypto/rsa/rsa_ameth.c in OpenSSL 1.0.1 before 1.0.1q and 1.0.2 before 1.0.2e allows remote attackers to cause a denial of service (NULL pointer dereference and application crash) via an RSA PSS ASN.1 signature that lacks a mask generation function parameter.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i.orig/apps/gendh.c\n- openssl-1.0.1i/apps/gendh.c\n- openssl-1.0.1i/apps/dhparam.c\n- openssl-1.0.1i.orig/apps/dhparam.c\n- apps/dhparam.c\n\n## Target Source Code\n\n### apps/dhparam.c\n\n#### region() [lines 91-178]\n```c\n *\n * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR\n * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n * OF THE POSSIBILITY OF SUCH DAMAGE.\n * ====================================================================\n *\n * This product includes cryptographic software written by Eric Young\n * (eay@cryptsoft.com). This product includes software written by Tim\n * Hudson (tjh@cryptsoft.com).\n *\n */\n\n#include <openssl/opensslconf.h>\t/* for OPENSSL_NO_DH */\n#ifndef OPENSSL_NO_DH\n#include <stdio.h>\n#include <stdlib.h>\n#include <time.h>\n#include <string.h>\n#include \"apps.h\"\n#include <openssl/bio.h>\n#include <openssl/err.h>\n#include <openssl/bn.h>\n#include <openssl/dh.h>\n#include <openssl/x509.h>\n#include <openssl/pem.h>\n\n#ifndef OPENSSL_NO_DSA\n#include <openssl/dsa.h>\n#endif\n\n#undef PROG\n#define PROG\tdhparam_main\n\n#define DEFBITS\t512\n\n/* -inform arg\t- input format - default PEM (DER or PEM)\n * -outform arg - output format - default PEM\n * -in arg\t- input file - default stdin\n * -out arg\t- output file - default stdout\n * -dsaparam - read or generate DSA parameters, convert to DH\n * -check\t- check the parameters are ok\n * -noout\n * -text\n * -C\n */\n\nstatic int MS_CALLBACK dh_cb(int p, int n, BN_GENCB *cb);\n\nint MAIN(int, char **);\n\nint MAIN(int argc, char **argv)\n\t{\n\tDH *dh=NULL;\n\tint i,badops=0,text=0;\n#ifndef OPENSSL_NO_DSA\n\tint dsaparam=0;\n#endif\n\tBIO *in=NULL,*out=NULL;\n\tint informat,outformat,check=0,noout=0,C=0,ret=1;\n\tchar *infile,*outfile,*prog;\n\tchar *inrand=NULL;\n#ifndef OPENSSL_NO_ENGINE\n\tchar *engine=NULL;\n#endif\n\tint num = 0, g = 0;\n\n\tapps_startup();\n\n\tif (bio_err == NULL)\n\t\tif ((bio_err=BIO_new(BIO_s_file())) != NULL)\n\t\t\tBIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);\n\n\tif (!load_config(bio_err, NULL))\n\t\tgoto end;\n\n\tinfile=NULL;\n\toutfile=NULL;\n\tinformat=FORMAT_PEM;\n\toutformat=FORMAT_PEM;\n```\n\n#### region() [lines 147-536]\n```c\n\nint MAIN(int, char **);\n\nint MAIN(int argc, char **argv)\n\t{\n\tDH *dh=NULL;\n\tint i,badops=0,text=0;\n#ifndef OPENSSL_NO_DSA\n\tint dsaparam=0;\n#endif\n\tBIO *in=NULL,*out=NULL;\n\tint informat,outformat,check=0,noout=0,C=0,ret=1;\n\tchar *infile,*outfile,*prog;\n\tchar *inrand=NULL;\n#ifndef OPENSSL_NO_ENGINE\n\tchar *engine=NULL;\n#endif\n\tint num = 0, g = 0;\n\n\tapps_startup();\n\n\tif (bio_err == NULL)\n\t\tif ((bio_err=BIO_new(BIO_s_file())) != NULL)\n\t\t\tBIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);\n\n\tif (!load_config(bio_err, NULL))\n\t\tgoto end;\n\n\tinfile=NULL;\n\toutfile=NULL;\n\tinformat=FORMAT_PEM;\n\toutformat=FORMAT_PEM;\n\n\tprog=argv[0];\n\targc--;\n\targv++;\n\twhile (argc >= 1)\n\t\t{\n\t\tif \t(strcmp(*argv,\"-inform\") == 0)\n\t\t\t{\n/* ... 57 lines omitted ... */\n\t\tBIO_printf(bio_err,\" -inform arg input format - one of DER PEM\\n\");\n\t\tBIO_printf(bio_err,\" -outform arg output format - one of DER PEM\\n\");\n\t\tBIO_printf(bio_err,\" -in arg input file\\n\");\n\t\tBIO_printf(bio_err,\" -out arg output file\\n\");\n#ifndef OPENSSL_NO_DSA\n\t\tBIO_printf(bio_err,\" -dsaparam read or generate DSA parameters, convert to DH\\n\");\n#endif\n\t\tBIO_printf(bio_err,\" -check check the DH parameters\\n\");\n\t\tBIO_printf(bio_err,\" -text print a text form of the DH parameters\\n\");\n\t\tBIO_printf(bio_err,\" -C Output C code\\n\");\n\t\tBIO_printf(bio_err,\" -2 generate parameters using 2 as the generator value\\n\");\n\t\tBIO_printf(bio_err,\" -5 generate parameters using 5 as the generator value\\n\");\n\t\tBIO_printf(bio_err,\" numbits number of bits in to generate (default 512)\\n\");\n#ifndef OPENSSL_NO_ENGINE\n\t\tBIO_printf(bio_err,\" -engine e use engine e, possibly a hardware device.\\n\");\n#endif\n\t\tBIO_printf(bio_err,\" -rand file%cfile%c...\\n\", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR);\n\t\tBIO_printf(bio_err,\" - load the file (or the files in the directory) into\\n\");\n\t\tBIO_printf(bio_err,\" the random number generator\\n\");\n\t\tBIO_printf(bio_err,\" -noout no output\\n\");\n\t\tgoto end;\n\t\t}\n\n\tERR_load_crypto_strings();\n\n#ifndef OPENSSL_NO_ENGINE\n setup_engine(bio_err, engine, 0);\n/* ... 246 lines omitted ... */\n\t\t\tBIO_printf(bio_err,\"bad output format specified for outfile\\n\");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (!i)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,\"unable to write DH parameters\\n\");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tret=0;\nend:\n\tif (in != NULL) BIO_free(in);\n\tif (out != NULL) BIO_free_all(out);\n\tif (dh != NULL) DH_free(dh);\n\tapps_shutdown();\n\tOPENSSL_EXIT(ret);\n\t}\n\n/* dh_cb is identical to dsa_cb in apps/dsaparam.c */\n```\n\n### apps/gendh.c\n\n#### region() [lines 39-126]\n```c\n * the apps directory (application code) you must include an acknowledgement:\n * \"This product includes software written by Tim Hudson (tjh@cryptsoft.com)\"\n * \n * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n * SUCH DAMAGE.\n * \n * The licence and distribution terms for any publically available version or\n * derivative of this code cannot be changed. i.e. this code cannot simply be\n * copied and put under another distribution licence\n * [including the GNU Public Licence.]\n */\n\n#include <openssl/opensslconf.h>\n/* Until the key-gen callbacks are modified to use newer prototypes, we allow\n * deprecated functions for openssl-internal code */\n#ifdef OPENSSL_NO_DEPRECATED\n#undef OPENSSL_NO_DEPRECATED\n#endif\n\n#ifndef OPENSSL_NO_DH\n#include <stdio.h>\n#include <string.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include \"apps.h\"\n#include <openssl/bio.h>\n#include <openssl/rand.h>\n#include <openssl/err.h>\n#include <openssl/bn.h>\n#include <openssl/dh.h>\n#include <openssl/x509.h>\n#include <openssl/pem.h>\n\n#define DEFBITS\t512\n#undef PROG\n#define PROG gendh_main\n\nstatic int MS_CALLBACK dh_cb(int p, int n, BN_GENCB *cb);\n\nint MAIN(int, char **);\n\nint MAIN(int argc, char **argv)\n\t{\n\tBN_GENCB cb;\n\tDH *dh=NULL;\n\tint ret=1,num=DEFBITS;\n\tint g=2;\n\tchar *outfile=NULL;\n\tchar *inrand=NULL;\n#ifndef OPENSSL_NO_ENGINE\n\tchar *engine=NULL;\n#endif\n\tBIO *out=NULL;\n\n\tapps_startup();\n\n\tBN_GENCB_set(&cb, dh_cb, bio_err);\n\tif (bio_err == NULL)\n\t\tif ((bio_err=BIO_new(BIO_s_file())) != NULL)\n\t\t\tBIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);\n\n\tif (!load_config(bio_err, NULL))\n\t\tgoto end;\n\n\targv++;\n\targc--;\n\tfor (;;)\n\t\t{\n\t\tif (argc <= 0) break;\n\t\tif (strcmp(*argv,\"-out\") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\toutfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,\"-2\") == 0)\n\t\t\tg=2;\n\t/*\telse if (strcmp(*argv,\"-3\") == 0)\n\t\t\tg=3; */\n\t\telse if (strcmp(*argv,\"-5\") == 0)\n```\n\n\n## Upstream Fix\n```diff\nFrom 8568170d774f02880eec6cad5512f555d0c83f65 Mon Sep 17 00:00:00 2001\nFrom: Emilia Kasper <emilia@openssl.org>\nDate: Wed, 13 May 2015 11:57:55 +0200\nSubject: [PATCH] dhparam: set the default to 2048 bits\n\nReviewed-by: Matt Caswell <matt@openssl.org>\nReviewed-by: Kurt Roeckx <kurt@openssl.org>\n---\n apps/dhparam.c | 4 ++--\n apps/gendh.c | 2 +-\n 2 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/apps/dhparam.c b/apps/dhparam.c\nindex f86311c28fd36..d3b6d58ad2e5a 100644\n--- a/apps/dhparam.c\n+++ b/apps/dhparam.c\n@@ -130,7 +130,7 @@\n # undef PROG\n # define PROG dhparam_main\n \n-# define DEFBITS 512\n+# define DEFBITS 2048\n \n /*-\n * -inform arg - input format - default PEM (DER or PEM)\n@@ -254,7 +254,7 @@ int MAIN(int argc, char **argv)\n BIO_printf(bio_err,\n \" -5 generate parameters using 5 as the generator value\\n\");\n BIO_printf(bio_err,\n- \" numbits number of bits in to generate (default 512)\\n\");\n+ \" numbits number of bits in to generate (default 2048)\\n\");\n # ifndef OPENSSL_NO_ENGINE\n BIO_printf(bio_err,\n \" -engine e use engine e, possibly a hardware device.\\n\");\ndiff --git a/apps/gendh.c b/apps/gendh.c\nindex adaa101783dfd..fef6f1b1774d1 100644\n--- a/apps/gendh.c\n+++ b/apps/gendh.c\n@@ -80,7 +80,7 @@\n # include <openssl/x509.h>\n # include <openssl/pem.h>\n \n-# define DEFBITS 512\n+# define DEFBITS 2048\n # undef PROG\n # define PROG gendh_main\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 8568170d774f02880eec6cad5512f555d0c83f65 Mon Sep 17 00:00:00 2001\nFrom: Emilia Kasper <emilia@openssl.org>\nDate: Wed, 13 May 2015 11:57:55 +0200\nSubject: [PATCH 2/5] dhparam: set the default to 2048 bits\n\nReviewed-by: Matt Caswell <matt@openssl.org>\nReviewed-by: Kurt Roeckx <kurt@openssl.org>\n---\n apps/dhparam.c | 4 ++--\n apps/gendh.c | 2 +-\n 2 files changed, 3 insertions(+), 3 deletions(-)\n\nIndex: openssl-1.0.1i/apps/dhparam.c\n===================================================================\n--- openssl-1.0.1i.orig/apps/dhparam.c\t2015-06-12 13:16:47.628625800 +0200\n+++ openssl-1.0.1i/apps/dhparam.c\t2015-06-12 13:17:23.851068922 +0200\n@@ -130,7 +130,7 @@\n #undef PROG\n #define PROG\tdhparam_main\n \n-#define DEFBITS\t512\n+#define DEFBITS\t2048\n \n /* -inform arg\t- input format - default PEM (DER or PEM)\n * -outform arg - output format - default PEM\n@@ -253,7 +253,7 @@ bad:\n \t\tBIO_printf(bio_err,\" -C Output C code\\n\");\n \t\tBIO_printf(bio_err,\" -2 generate parameters using 2 as the generator value\\n\");\n \t\tBIO_printf(bio_err,\" -5 generate parameters using 5 as the generator value\\n\");\n-\t\tBIO_printf(bio_err,\" numbits number of bits in to generate (default 512)\\n\");\n+\t\tBIO_printf(bio_err,\" numbits number of bits in to generate (default 2048)\\n\");\n #ifndef OPENSSL_NO_ENGINE\n \t\tBIO_printf(bio_err,\" -engine e use engine e, possibly a hardware device.\\n\");\n #endif\nIndex: openssl-1.0.1i/apps/gendh.c\n===================================================================\n--- openssl-1.0.1i.orig/apps/gendh.c\t2015-06-12 13:16:47.629625812 +0200\n+++ openssl-1.0.1i/apps/gendh.c\t2015-06-12 13:17:54.615474034 +0200\n@@ -78,7 +78,7 @@\n #include <openssl/x509.h>\n #include <openssl/pem.h>\n \n-#define DEFBITS\t512\n+#define DEFBITS\t2048\n #undef PROG\n #define PROG gendh_main" } ]
{ "id": "openssl-4352-0002-dhparam-set-the-default-t", "cve_id": "CVE-2015-3194", "package": "openssl", "upstream_enriched": true, "upstream_commit": "8568170d774f02880eec6cad5512f555d0c83f65", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "license": "OpenSSL", "context_tokens_est": 1941, "context_files": 2 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-3706\n\nStack-based buffer overflow in the getaddrinfo function in sysdeps/posix/getaddrinfo.c in the GNU C Library (aka glibc or libc6) allows remote attackers to cause a denial of service (crash) via vectors involving hostent conversion. NOTE: this vulnerability exists because of an incomplete fix for CVE-2013-4458.\n\n## Package\nglibc-utils\n\n## Files to modify\n- glibc-2.19.orig/malloc/arena.c\n- malloc/arena.c\n- malloc/tst-malloc-thread-exit.c\n\n## Target Source Code\n\n### malloc/Makefile\n\n#### region() [lines 1-76]\n```c\n# Copyright (C) 1991-2014 Free Software Foundation, Inc.\n# This file is part of the GNU C Library.\n\n# The GNU C Library is free software; you can redistribute it and/or\n# modify it under the terms of the GNU Lesser General Public\n# License as published by the Free Software Foundation; either\n# version 2.1 of the License, or (at your option) any later version.\n\n# The GNU C Library is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n# Lesser General Public License for more details.\n\n# You should have received a copy of the GNU Lesser General Public\n# License along with the GNU C Library; if not, see\n# <http://www.gnu.org/licenses/>.\n\n#\n#\tMakefile for malloc routines\n#\nsubdir\t:= malloc\n\nall:\n\ndist-headers := malloc.h\nheaders := $(dist-headers) obstack.h mcheck.h\ntests := mallocbug tst-malloc tst-valloc tst-calloc tst-obstack \\\n\t tst-mallocstate tst-mcheck tst-mallocfork tst-trim1 \\\n\t tst-malloc-usable tst-realloc tst-posix_memalign \\\n\t tst-pvalloc tst-memalign\ntest-srcs = tst-mtrace\n\nroutines = malloc morecore mcheck mtrace obstack\n\ninstall-lib := libmcheck.a\nnon-lib.a := libmcheck.a\n\n# Additional library.\nextra-libs = libmemusage\nextra-libs-others = $(extra-libs)\n\nlibmemusage-routines = memusage\nlibmemusage-inhibit-o = $(filter-out .os,$(object-suffixes))\n\n# These should be removed by `make clean'.\nextra-objs = mcheck-init.o libmcheck.a\n\n# Include the cleanup handler.\naux := set-freeres thread-freeres\n\ninclude ../Makeconfig\n\nCPPFLAGS-memusagestat = -DNOT_IN_libc\n\n# The Perl script to analyze the output of the mtrace functions.\nifneq ($(PERL),no)\ninstall-bin-script = mtrace\ngenerated = mtrace\n\n# The Perl script will print addresses and to do this nicely we must know\n# whether we are on a 32 or 64 bit machine.\nifneq ($(findstring wordsize-32,$(config-sysdirs)),)\naddress-width=10\nelse\naddress-width=18\nendif\nendif\n\n# Unless we get a test for the availability of libgd which also works\n# for cross-compiling we disable the memusagestat generation in this\n# situation.\nifneq ($(cross-compiling),yes)\n# If the gd library is available we build the `memusagestat' program.\nifneq ($(LIBGD),no)\nothers: $(objpfx)memusage\ninstall-bin = memusagestat\n```\n\n#### region() [lines 6-92]\n```c\n# License as published by the Free Software Foundation; either\n# version 2.1 of the License, or (at your option) any later version.\n\n# The GNU C Library is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n# Lesser General Public License for more details.\n\n# You should have received a copy of the GNU Lesser General Public\n# License along with the GNU C Library; if not, see\n# <http://www.gnu.org/licenses/>.\n\n#\n#\tMakefile for malloc routines\n#\nsubdir\t:= malloc\n\nall:\n\ndist-headers := malloc.h\nheaders := $(dist-headers) obstack.h mcheck.h\ntests := mallocbug tst-malloc tst-valloc tst-calloc tst-obstack \\\n\t tst-mallocstate tst-mcheck tst-mallocfork tst-trim1 \\\n\t tst-malloc-usable tst-realloc tst-posix_memalign \\\n\t tst-pvalloc tst-memalign\ntest-srcs = tst-mtrace\n\nroutines = malloc morecore mcheck mtrace obstack\n\ninstall-lib := libmcheck.a\nnon-lib.a := libmcheck.a\n\n# Additional library.\nextra-libs = libmemusage\nextra-libs-others = $(extra-libs)\n\nlibmemusage-routines = memusage\nlibmemusage-inhibit-o = $(filter-out .os,$(object-suffixes))\n\n# These should be removed by `make clean'.\nextra-objs = mcheck-init.o libmcheck.a\n\n# Include the cleanup handler.\naux := set-freeres thread-freeres\n\ninclude ../Makeconfig\n\nCPPFLAGS-memusagestat = -DNOT_IN_libc\n\n# The Perl script to analyze the output of the mtrace functions.\nifneq ($(PERL),no)\ninstall-bin-script = mtrace\ngenerated = mtrace\n\n# The Perl script will print addresses and to do this nicely we must know\n# whether we are on a 32 or 64 bit machine.\nifneq ($(findstring wordsize-32,$(config-sysdirs)),)\naddress-width=10\nelse\naddress-width=18\nendif\nendif\n\n# Unless we get a test for the availability of libgd which also works\n# for cross-compiling we disable the memusagestat generation in this\n# s\n/* ... truncated ... */\n```\n\n### malloc/arena.c\n\n#### _int_new_arena() [lines 731-785]\n```c\n/* Create a new arena with initial size \"size\". */\n\nstatic mstate\n_int_new_arena (size_t size)\n{\n mstate a;\n heap_info *h;\n char *ptr;\n unsigned long misalign;\n\n h = new_heap (size + (sizeof (*h) + sizeof (*a) + MALLOC_ALIGNMENT),\n mp_.top_pad);\n if (!h)\n {\n /* Maybe size is too large to fit in a single heap. So, just try\n to create a minimally-sized arena and let _int_malloc() attempt\n to deal with the large request via mmap_chunk(). */\n h = new_heap (sizeof (*h) + sizeof (*a) + MALLOC_ALIGNMENT, mp_.top_pad);\n if (!h)\n return 0;\n }\n a = h->ar_ptr = (mstate) (h + 1);\n malloc_init_state (a);\n /*a->next = NULL;*/\n a->system_mem = a->max_system_mem = h->size;\n arena_mem += h->size;\n\n /* Set up the top chunk, with proper alignment. */\n ptr = (char *) (a + 1);\n misalign = (unsigned long) chunk2mem (ptr) & MALLOC_ALIGN_MASK;\n if (misalign > 0)\n ptr += MALLOC_ALIGNMENT - misalign;\n top (a) = (mchunkptr) ptr;\n set_head (top (a), (((char *) h + h->size) - ptr) | PREV_INUSE);\n\n LIBC_PROBE (memory_arena_new, 2, a, size);\n tsd_setspecific (arena_key, (void *) a);\n mutex_init (&a->mutex);\n (void) mutex_lock (&a->mutex);\n\n (void) mutex_lock (&list_lock);\n\n /* Add the new arena to the global list. */\n a->next = main_arena.next;\n atomic_write_barrier ();\n main_arena.next = a;\n\n (void) mutex_unlock (&list_lock);\n\n THREAD_STAT (++(a->stat_lock_loop));\n\n return a;\n}\n\n\n```\n\n#### get_free_list() [lines 784-810]\n```c\n\n\nstatic mstate\nget_free_list (void)\n{\n mstate result = free_list;\n if (result != NULL)\n {\n (void) mutex_lock (&list_lock);\n result = free_list;\n if (result != NULL)\n free_list = result->next_free;\n (void) mutex_unlock (&list_lock);\n\n if (result != NULL)\n {\n LIBC_PROBE (memory_arena_reuse_free_list, 1, result);\n (void) mutex_lock (&result->mutex);\n tsd_setspecific (arena_key, (void *) result);\n THREAD_STAT (++(result->stat_lock_loop));\n }\n }\n\n return result;\n}\n\n/* Lock and return an arena that can be reused for memory allocation.\n```\n\n#### reused_arena() [lines 811-849]\n```c\n Avoid AVOID_ARENA as we have already failed to allocate memory in\n it and it is currently locked. */\nstatic mstate\nreused_arena (mstate avoid_arena)\n{\n mstate result;\n static mstate next_to_use;\n if (next_to_use == NULL)\n next_to_use = &main_arena;\n\n result = next_to_use;\n do\n {\n if (!mutex_trylock (&result->mutex))\n goto out;\n\n result = result->next;\n }\n while (result != next_to_use);\n\n /* Avoid AVOID_ARENA as we have already failed to allocate memory\n in that arena and it is currently locked. */\n if (result == avoid_arena)\n result = result->next;\n\n /* No arena available. Wait for the next in line. */\n LIBC_PROBE (memory_arena_reuse_wait, 3, &result->mutex, result, avoid_arena);\n (void) mutex_lock (&result->mutex);\n\nout:\n LIBC_PROBE (memory_arena_reuse, 2, result, avoid_arena);\n tsd_setspecific (arena_key, (void *) result);\n THREAD_STAT (++(result->stat_lock_loop));\n next_to_use = result->next;\n\n return result;\n}\n\nstatic mstate\n```\n\n\n## Upstream Fix\n```diff\n2015-12-16 Florian Weimer <fweimer@redhat.com>\n\n\t[BZ #19243]\n\t* malloc/arena.c (get_free_list): Remove assert and adjust\n\treference count handling. Add comment about reused_arena\n\tinteraction.\n\t(reused_arena): Add comments abount get_free_list interaction.\n\t* malloc/tst-malloc-thread-exit.c: New file.\n\t* malloc/Makefile (tests): Add tst-malloc-thread-exit.\n\t(tst-malloc-thread-exit): Link against libpthread.\n\nIndex: glibc-2.19/malloc/Makefile\n===================================================================\n--- glibc-2.19.orig/malloc/Makefile\n+++ glibc-2.19/malloc/Makefile\n@@ -28,7 +28,7 @@ tests := mallocbug tst-malloc tst-valloc\n \t tst-mallocstate tst-mcheck tst-mallocfork tst-trim1 \\\n \t tst-malloc-usable tst-realloc tst-posix_memalign \\\n \t tst-pvalloc tst-memalign \\\n-\t tst-malloc-backtrace\n+\t tst-malloc-backtrace tst-malloc-thread-exit\n test-srcs = tst-mtrace\n \n routines = malloc morecore mcheck mtrace obstack\n@@ -45,6 +45,8 @@ libmemusage-inhibit-o = $(filter-out .os\n \n $(objpfx)tst-malloc-backtrace: $(common-objpfx)nptl/libpthread.so \\\n \t\t\t $(common-objpfx)nptl/libpthread_nonshared.a\n+$(objpfx)tst-malloc-thread-exit: $(common-objpfx)nptl/libpthread.so \\\n+\t\t\t $(common-objpfx)nptl/libpthread_nonshared.a\n \n # These should be removed by `make clean'.\n extra-objs = mcheck-init.o libmcheck.a\nIndex: glibc-2.19/malloc/arena.c\n===================================================================\n--- glibc-2.19.orig/malloc/arena.c\n+++ glibc-2.19/malloc/arena.c\n@@ -824,6 +824,8 @@ _int_new_arena (size_t size)\n }\n \n \n+/* Remove an arena from free_list. The arena may be in use because it\n+ was attached concurrently to a thread by reused_arena below. */\n static mstate\n get_free_list (void)\n {\n@@ -838,10 +840,8 @@ get_free_list (void)\n \t{\n \t free_list = result->next_free;\n \n-\t /* Arenas on the free list are not attached to any thread. */\n-\t assert (result->attached_threads == 0);\n-\t /* But the arena will now be attached to this thread. */\n-\t result->attached_threads = 1;\n+\t /* The arena will be attached to this thread. */\n+\t ++result->attached_threads;\n \n \t detach_arena (replaced_arena);\n \t}\n@@ -870,6 +870,8 @@ reused_arena (mstate avoid_arena)\n if (next_to_use == NULL)\n next_to_use = &main_arena;\n \n+ /* Iterate over all arenas (including those linked from\n+ free_list). */\n result = next_to_use;\n do\n {\n@@ -904,6 +906,8 @@ reused_arena (mstate avoid_arena)\n (void) mutex_lock (&result->mutex);\n \n out:\n+ /* Attach the arena to the current thread. Note that we may have\n+ selected an arena which was on free_list. */\n {\n mstate replaced_arena;\n arena_lookup (replaced_arena);\nIndex: glibc-2.19/malloc/tst-malloc-thread-exit.c\n===================================================================\n--- /dev/null\n+++ glibc-2.19/malloc/tst-malloc-thread-exit.c\n@@ -0,0 +1,217 @@\n+/* Test malloc with concurrent thread termination.\n+ Copyright (C) 2015 Free Software Foundation, Inc.\n+ This file is part of the GNU C Library.\n+\n+ The GNU C Library is free software; you can redistribute it and/or\n+ modify it under the terms of the GNU Lesser General Public\n+ License as published by the Free Software Foundation; either\n+ version 2.1 of the License, or (at your option) any later version.\n+\n+ The GNU C Library is distributed in the hope that it will be useful,\n+ but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ Lesser General Public License for more details.\n+\n+ You should have received a copy of the GNU Lesser General Public\n+ License along with the GNU C Library; if not, see\n+ <http://www.gnu.org/licenses/>. */\n+\n+/* This thread spawns a number of outer threads, equal to the arena\n+ limit. The outer threads run a loop which start and join two\n+ different kinds of threads: the first kind allocates (attaching an\n+ arena to the thread; malloc_first_thread) and waits, the second\n+ kind waits and allocates (wait_first_threads). Both kinds of\n+ threads exit immediately after waiting. The hope is that this will\n+ exhibit races in thread termination and arena management,\n+ particularly related to the arena free list. */\n+\n+#include <errno.h>\n+#include <pthread.h>\n+#include <stdbool.h>\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <unistd.h>\n+\n+#define TIMEOUT 7\n+\n+static bool termination_requested;\n+static int inner_thread_count = 4;\n+static size_t malloc_size = 32;\n+\n+static void\n+__attribute__ ((noinline, noclone))\n+unoptimized_free (void *ptr)\n+{\n+ free (ptr);\n+}\n+\n+static void *\n+malloc_first_thread (void * closure)\n+{\n+ pthread_barrier_t *barrier = closure;\n+ void *ptr = malloc (malloc_size);\n+ if (ptr == NULL)\n+ {\n+ printf (\"error: malloc: %m\\n\");\n+ abort ();\n+ }\n+ int ret = pthread_barrier_wait (barrier);\n+ if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD)\n+ {\n+ errno = ret;\n+ printf (\"error: pthread_barrier_wait: %m\\n\");\n+ abort ();\n+ }\n+ unoptimized_free (ptr);\n+ return NULL;\n+}\n+\n+static void *\n+wait_first_thread (void * closure)\n+{\n+ pthread_barrier_t *barrier = closure;\n+ int ret = pthread_barrier_wait (barrier);\n+ if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD)\n+ {\n+ errno = ret;\n+ printf (\"error: pthread_barrier_wait: %m\\n\");\n+ abort ();\n+ }\n+ void *ptr = malloc (malloc_size);\n+ if (ptr == NULL)\n+ {\n+ printf (\"error: malloc: %m\\n\");\n+ abort ();\n+ }\n+ unoptimized_free (ptr);\n+ return NULL;\n+}\n+\n+static void *\n+outer_thread (void *closure)\n+{\n+ pthread_t *threads = calloc (sizeof (*threads), inner_thread_count);\n+ if (threads == NULL)\n+ {\n+ printf (\"error: calloc: %m\\n\");\n+ abort ();\n+ }\n+\n+ while (!__atomic_load_n (&termination_requested, __ATOMIC_RELAXED))\n+ {\n+ pthread_barrier_t barrier;\n+ int ret = pthread_barrier_init (&barrier, NULL, inner_thread_count + 1);\n+ if (ret != 0)\n+ {\n+ errno = ret;\n+ printf (\"pthread_barrier_init: %m\\n\");\n+ abort ();\n+ }\n+ for (int i = 0; i < inner_thread_count; ++i)\n+ {\n+ void *(*func) (void *);\n+ if ((i % 2) == 0)\n+ func = malloc_first_thread;\n+ else\n+ func = wait_first_thread;\n+ ret = pthread_create (threads + i, NULL, func, &barrier);\n+ if (ret != 0)\n+ {\n+ errno = ret;\n+ printf (\"error: pthread_create: %m\\n\");\n+ abort ();\n+ }\n+ }\n+ ret = pthread_barrier_wait (&barrier);\n+ if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD)\n+ {\n+ errno = ret;\n+ printf (\"pthread_wait: %m\\n\");\n+ abort ();\n+ }\n+ for (int i = 0; i < inner_thread_count; ++i)\n+ {\n+ ret = pthread_join (threads[i], NULL);\n+ if (ret != 0)\n+ {\n+ ret = errno;\n+ printf (\"error: pthread_join: %m\\n\");\n+ abort ();\n+ }\n+ }\n+ ret = pthread_barrier_destroy (&barrier);\n+ if (ret != 0)\n+ {\n+ ret = errno;\n+ printf (\"pthread_barrier_destroy: %m\\n\");\n+ abort ();\n+ }\n+ }\n+\n+ free (threads);\n+\n+ return NULL;\n+}\n+\n+static int\n+do_test (void)\n+{\n+ /* The number of top-level threads should be equal to the number of\n+ arenas. See arena_get2. */\n+ long outer_thread_count = sysconf (_SC_NPROCESSORS_ONLN);\n+ if (outer_thread_count >= 1)\n+ {\n+ /* See NARENAS_FROM_NCORES in malloc.c. */\n+ if (sizeof (long) == 4)\n+ outer_thread_count *= 2;\n+ else\n+ outer_thread_count *= 8;\n+ }\n+\n+ /* Leave some room for shutting down all threads gracefully. */\n+ int timeout = TIMEOUT - 2;\n+\n+ pthread_t *threads = calloc (sizeof (*threads), outer_thread_count);\n+ if (threads == NULL)\n+ {\n+ printf (\"error: calloc: %m\\n\");\n+ abort ();\n+ }\n+\n+ \n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "2015-12-16 Florian Weimer <fweimer@redhat.com>\n\n\t[BZ #19243]\n\t* malloc/arena.c (get_free_list): Remove assert and adjust\n\treference count handling. Add comment about reused_arena\n\tinteraction.\n\t(reused_arena): Add comments abount get_free_list interaction.\n\t* malloc/tst-malloc-thread-exit.c: New file.\n\t* malloc/Makefile (tests): Add tst-malloc-thread-exit.\n\t(tst-malloc-thread-exit): Link against libpthread.\n\nIndex: glibc-2.19/malloc/Makefile\n===================================================================\n--- glibc-2.19.orig/malloc/Makefile\n+++ glibc-2.19/malloc/Makefile\n@@ -28,7 +28,7 @@ tests := mallocbug tst-malloc tst-valloc\n \t tst-mallocstate tst-mcheck tst-mallocfork tst-trim1 \\\n \t tst-malloc-usable tst-realloc tst-posix_memalign \\\n \t tst-pvalloc tst-memalign \\\n-\t tst-malloc-backtrace\n+\t tst-malloc-backtrace tst-malloc-thread-exit\n test-srcs = tst-mtrace\n \n routines = malloc morecore mcheck mtrace obstack\n@@ -45,6 +45,8 @@ libmemusage-inhibit-o = $(filter-out .os\n \n $(objpfx)tst-malloc-backtrace: $(common-objpfx)nptl/libpthread.so \\\n \t\t\t $(common-objpfx)nptl/libpthread_nonshared.a\n+$(objpfx)tst-malloc-thread-exit: $(common-objpfx)nptl/libpthread.so \\\n+\t\t\t $(common-objpfx)nptl/libpthread_nonshared.a\n \n # These should be removed by `make clean'.\n extra-objs = mcheck-init.o libmcheck.a\nIndex: glibc-2.19/malloc/arena.c\n===================================================================\n--- glibc-2.19.orig/malloc/arena.c\n+++ glibc-2.19/malloc/arena.c\n@@ -824,6 +824,8 @@ _int_new_arena (size_t size)\n }\n \n \n+/* Remove an arena from free_list. The arena may be in use because it\n+ was attached concurrently to a thread by reused_arena below. */\n static mstate\n get_free_list (void)\n {\n@@ -838,10 +840,8 @@ get_free_list (void)\n \t{\n \t free_list = result->next_free;\n \n-\t /* Arenas on the free list are not attached to any thread. */\n-\t assert (result->attached_threads == 0);\n-\t /* But the arena will now be attached to this thread. */\n-\t result->attached_threads = 1;\n+\t /* The arena will be attached to this thread. */\n+\t ++result->attached_threads;\n \n \t detach_arena (replaced_arena);\n \t}\n@@ -870,6 +870,8 @@ reused_arena (mstate avoid_arena)\n if (next_to_use == NULL)\n next_to_use = &main_arena;\n \n+ /* Iterate over all arenas (including those linked from\n+ free_list). */\n result = next_to_use;\n do\n {\n@@ -904,6 +906,8 @@ reused_arena (mstate avoid_arena)\n (void) mutex_lock (&result->mutex);\n \n out:\n+ /* Attach the arena to the current thread. Note that we may have\n+ selected an arena which was on free_list. */\n {\n mstate replaced_arena;\n arena_lookup (replaced_arena);\nIndex: glibc-2.19/malloc/tst-malloc-thread-exit.c\n===================================================================\n--- /dev/null\n+++ glibc-2.19/malloc/tst-malloc-thread-exit.c\n@@ -0,0 +1,217 @@\n+/* Test malloc with concurrent thread termination.\n+ Copyright (C) 2015 Free Software Foundation, Inc.\n+ This file is part of the GNU C Library.\n+\n+ The GNU C Library is free software; you can redistribute it and/or\n+ modify it under the terms of the GNU Lesser General Public\n+ License as published by the Free Software Foundation; either\n+ version 2.1 of the License, or (at your option) any later version.\n+\n+ The GNU C Library is distributed in the hope that it will be useful,\n+ but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ Lesser General Public License for more details.\n+\n+ You should have received a copy of the GNU Lesser General Public\n+ License along with the GNU C Library; if not, see\n+ <http://www.gnu.org/licenses/>. */\n+\n+/* This thread spawns a number of outer threads, equal to the arena\n+ limit. The outer threads run a loop which start and join two\n+ different kinds of threads: the first kind allocates (attaching an\n+ arena to the thread; malloc_first_thread) and waits, the second\n+ kind waits and allocates (wait_first_threads). Both kinds of\n+ threads exit immediately after waiting. The hope is that this will\n+ exhibit races in thread termination and arena management,\n+ particularly related to the arena free list. */\n+\n+#include <errno.h>\n+#include <pthread.h>\n+#include <stdbool.h>\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <unistd.h>\n+\n+#define TIMEOUT 7\n+\n+static bool termination_requested;\n+static int inner_thread_count = 4;\n+static size_t malloc_size = 32;\n+\n+static void\n+__attribute__ ((noinline, noclone))\n+unoptimized_free (void *ptr)\n+{\n+ free (ptr);\n+}\n+\n+static void *\n+malloc_first_thread (void * closure)\n+{\n+ pthread_barrier_t *barrier = closure;\n+ void *ptr = malloc (malloc_size);\n+ if (ptr == NULL)\n+ {\n+ printf (\"error: malloc: %m\\n\");\n+ abort ();\n+ }\n+ int ret = pthread_barrier_wait (barrier);\n+ if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD)\n+ {\n+ errno = ret;\n+ printf (\"error: pthread_barrier_wait: %m\\n\");\n+ abort ();\n+ }\n+ unoptimized_free (ptr);\n+ return NULL;\n+}\n+\n+static void *\n+wait_first_thread (void * closure)\n+{\n+ pthread_barrier_t *barrier = closure;\n+ int ret = pthread_barrier_wait (barrier);\n+ if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD)\n+ {\n+ errno = ret;\n+ printf (\"error: pthread_barrier_wait: %m\\n\");\n+ abort ();\n+ }\n+ void *ptr = malloc (malloc_size);\n+ if (ptr == NULL)\n+ {\n+ printf (\"error: malloc: %m\\n\");\n+ abort ();\n+ }\n+ unoptimized_free (ptr);\n+ return NULL;\n+}\n+\n+static void *\n+outer_thread (void *closure)\n+{\n+ pthread_t *threads = calloc (sizeof (*threads), inner_thread_count);\n+ if (threads == NULL)\n+ {\n+ printf (\"error: calloc: %m\\n\");\n+ abort ();\n+ }\n+\n+ while (!__atomic_load_n (&termination_requested, __ATOMIC_RELAXED))\n+ {\n+ pthread_barrier_t barrier;\n+ int ret = pthread_barrier_init (&barrier, NULL, inner_thread_count + 1);\n+ if (ret != 0)\n+ {\n+ errno = ret;\n+ printf (\"pthread_barrier_init: %m\\n\");\n+ abort ();\n+ }\n+ for (int i = 0; i < inner_thread_count; ++i)\n+ {\n+ void *(*func) (void *);\n+ if ((i % 2) == 0)\n+ func = malloc_first_thread;\n+ else\n+ func = wait_first_thread;\n+ ret = pthread_create (threads + i, NULL, func, &barrier);\n+ if (ret != 0)\n+ {\n+ errno = ret;\n+ printf (\"error: pthread_create: %m\\n\");\n+ abort ();\n+ }\n+ }\n+ ret = pthread_barrier_wait (&barrier);\n+ if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD)\n+ {\n+ errno = ret;\n+ printf (\"pthread_wait: %m\\n\");\n+ abort ();\n+ }\n+ for (int i = 0; i < inner_thread_count; ++i)\n+ {\n+ ret = pthread_join (threads[i], NULL);\n+ if (ret != 0)\n+ {\n+ ret = errno;\n+ printf (\"error: pthread_join: %m\\n\");\n+ abort ();\n+ }\n+ }\n+ ret = pthread_barrier_destroy (&barrier);\n+ if (ret != 0)\n+ {\n+ ret = errno;\n+ printf (\"pthread_barrier_destroy: %m\\n\");\n+ abort ();\n+ }\n+ }\n+\n+ free (threads);\n+\n+ return NULL;\n+}\n+\n+static int\n+do_test (void)\n+{\n+ /* The number of top-level threads should be equal to the number of\n+ arenas. See arena_get2. */\n+ long outer_thread_count = sysconf (_SC_NPROCESSORS_ONLN);\n+ if (outer_thread_count >= 1)\n+ {\n+ /* See NARENAS_FROM_NCORES in malloc.c. */\n+ if (sizeof (long) == 4)\n+ outer_thread_count *= 2;\n+ else\n+ outer_thread_count *= 8;\n+ }\n+\n+ /* Leave some room for shutting down all threads gracefully. */\n+ int timeout = TIMEOUT - 2;\n+\n+ pthread_t *threads = calloc (sizeof (*threads), outer_thread_count);\n+ if (threads == NULL)\n+ {\n+ printf (\"error: calloc: %m\\n\");\n+ abort ();\n+ }\n+\n+ for (long i = 0; i < outer_thread_count; ++i)\n+ {\n+ int ret = pthread_create (threads + i, NULL, outer_thread, NULL);\n+ if (ret != 0)\n+ {\n+ errno = ret;\n+ printf (\"error: pthread_create: %m\\n\");\n+ abort ();\n+ }\n+ }\n+\n+ struct timespec ts = {timeout, 0};\n+ if (nanosleep (&ts, NULL))\n+ {\n+ printf (\"error: error: nanosleep: %m\\n\");\n+ abort ();\n+ }\n+\n+ __atomic_store_n (&termination_requested, true, __ATOMIC_RELAXED);\n+\n+ for (long i = 0; i < outer_thread_count; ++i)\n+ {\n+ int ret = pthread_join (threads[i], NULL);\n+ if (ret != 0)\n+ {\n+ errno = ret;\n+ printf (\"error: pthread_join: %m\\n\");\n+ abort ();\n+ }\n+ }\n+ free (threads);\n+\n+ return 0;\n+}\n+\n+#define TEST_FUNCTION do_test ()\n+#include \"../test-skeleton.c\"" } ]
{ "id": "glibc-utils-5322-malloc-Fix-attached-thread-ref", "cve_id": "CVE-2016-3706", "package": "glibc-utils", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 1890, "context_files": 2 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-6210\n\nsshd in OpenSSH before 7.3, when SHA256 or SHA512 are used for user password hashing, uses BLOWFISH hashing on a static password when the username does not exist, which allows remote attackers to enumerate users by leveraging the timing difference between responses when a large password is provided.\n\n## Package\nopenssh-askpass-gnome\n\n## Files to modify\n- openssh-6.6p1/sandbox-seccomp-filter.c\n\n## Upstream Fix\n```diff\n# HG changeset patch\n# Parent 8c8249d4e830ade9dfa1d2294c6218bbe439cb4a\nAllow the stat() syscall for OpenSSL re-seed patch\n(which causes OpenSSL use stat() on some file)\n\nbnc#912436\n\ndiff --git a/openssh-6.6p1/sandbox-seccomp-filter.c b/openssh-6.6p1/sandbox-seccomp-filter.c\n--- a/openssh-6.6p1/sandbox-seccomp-filter.c\n+++ b/openssh-6.6p1/sandbox-seccomp-filter.c\n@@ -97,16 +97,17 @@ static const struct sock_filter preauth_\n \tSC_ALLOW(gettimeofday),\n \tSC_ALLOW(clock_gettime),\n #ifdef __NR_time /* not defined on EABI ARM */\n \tSC_ALLOW(time),\n #endif\n \tSC_ALLOW(read),\n \tSC_ALLOW(write),\n \tSC_ALLOW(close),\n+\tSC_ALLOW(stat),\n #ifdef __NR_shutdown /* not defined on archs that go via socketcall(2) */\n \tSC_ALLOW(shutdown),\n #endif\n \tSC_ALLOW(brk),\n \tSC_ALLOW(poll),\n #ifdef __NR__newselect\n \tSC_ALLOW(_newselect),\n #else\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "# HG changeset patch\n# Parent 8c8249d4e830ade9dfa1d2294c6218bbe439cb4a\nAllow the stat() syscall for OpenSSL re-seed patch\n(which causes OpenSSL use stat() on some file)\n\nbnc#912436\n\ndiff --git a/openssh-6.6p1/sandbox-seccomp-filter.c b/openssh-6.6p1/sandbox-seccomp-filter.c\n--- a/openssh-6.6p1/sandbox-seccomp-filter.c\n+++ b/openssh-6.6p1/sandbox-seccomp-filter.c\n@@ -97,16 +97,17 @@ static const struct sock_filter preauth_\n \tSC_ALLOW(gettimeofday),\n \tSC_ALLOW(clock_gettime),\n #ifdef __NR_time /* not defined on EABI ARM */\n \tSC_ALLOW(time),\n #endif\n \tSC_ALLOW(read),\n \tSC_ALLOW(write),\n \tSC_ALLOW(close),\n+\tSC_ALLOW(stat),\n #ifdef __NR_shutdown /* not defined on archs that go via socketcall(2) */\n \tSC_ALLOW(shutdown),\n #endif\n \tSC_ALLOW(brk),\n \tSC_ALLOW(poll),\n #ifdef __NR__newselect\n \tSC_ALLOW(_newselect),\n #else" } ]
{ "id": "openssh-askpass-gnome-5597-openssh-6.6p1-seccomp_stat.pat", "cve_id": "CVE-2016-6210", "package": "openssh-askpass-gnome", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": false, "license": "BSD-2-Clause", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-8618\n\nThe libcurl API function called `curl_maprintf()` before version 7.51.0 can be tricked into doing a double-free due to an unsafe `size_t` multiplication, on systems using 32 bit `size_t` variables.\n\n## Package\ncurl\n\n## Files to modify\n- lib/cookie.c\n\n## Upstream Fix\n```diff\nFrom eac573ea9c368f5e3c07de4d5ec5c5d0f84a021a Mon Sep 17 00:00:00 2001\nFrom: Tim Ruehsen <tim.ruehsen@gmx.de>\nDate: Tue, 19 Aug 2014 21:01:28 +0200\nSubject: [PATCH 1/2] cookies: only use full host matches for hosts used as IP\n address\n\nBy not detecting and rejecting domain names for partial literal IP\naddresses properly when parsing received HTTP cookies, libcurl can be\nfooled to both send cookies to wrong sites and to allow arbitrary sites\nto set cookies for others.\n\nBug: http://curl.haxx.se/docs/adv_20140910.html\n---\n lib/cookie.c | 50 ++++++++++++++++++++++++++++++++++++++----------\n tests/data/test1105 | 3 +--\n tests/data/test31 | 55 +++++++++++++++++++++++++++--------------------------\n tests/data/test8 | 3 ++-\n 4 files changed, 71 insertions(+), 40 deletions(-)\n\ndiff --git a/lib/cookie.c b/lib/cookie.c\nindex 0590643..46904ac 100644\n--- a/lib/cookie.c\n+++ b/lib/cookie.c\n@@ -93,10 +93,11 @@ Example set of cookies:\n #include \"curl_memory.h\"\n #include \"share.h\"\n #include \"strtoofft.h\"\n #include \"rawstr.h\"\n #include \"curl_memrchr.h\"\n+#include \"inet_pton.h\"\n \n /* The last #include file should be: */\n #include \"memdebug.h\"\n \n static void freecookie(struct Cookie *co)\n@@ -317,10 +318,32 @@ static void remove_expired(struct CookieInfo *cookies)\n }\n co = nx;\n }\n }\n \n+/*\n+ * Return true if the given string is an IP(v4|v6) address.\n+ */\n+static bool isip(const char *domain)\n+{\n+ struct in_addr addr;\n+#ifdef ENABLE_IPV6\n+ struct in6_addr addr6;\n+#endif\n+\n+ if(Curl_inet_pton(AF_INET, domain, &addr)\n+#ifdef ENABLE_IPV6\n+ || Curl_inet_pton(AF_INET6, domain, &addr6)\n+#endif\n+ ) {\n+ /* domain name given as IP address */\n+ return TRUE;\n+ }\n+\n+ return FALSE;\n+}\n+\n /****************************************************************************\n *\n * Curl_cookie_add()\n *\n * Add a single cookie line to the cookie keeping object.\n@@ -437,28 +460,31 @@ Curl_cookie_add(struct SessionHandle *data,\n badcookie = TRUE; /* out of memory bad */\n break;\n }\n }\n else if(Curl_raw_equal(\"domain\", name)) {\n+ bool is_ip;\n+\n /* Now, we make sure that our host is within the given domain,\n or the given domain is not valid and thus cannot be set. */\n \n if('.' == whatptr[0])\n whatptr++; /* ignore preceding dot */\n \n- if(!domain || tailmatch(whatptr, domain)) {\n- const char *tailptr=whatptr;\n- if(tailptr[0] == '.')\n- tailptr++;\n- strstore(&co->domain, tailptr); /* don't prefix w/dots\n- internally */\n+ is_ip = isip(domain ? domain : whatptr);\n+\n+ if(!domain\n+ || (is_ip && !strcmp(whatptr, domain))\n+ || (!is_ip && tailmatch(whatptr, domain))) {\n+ strstore(&co->domain, whatptr);\n if(!co->domain) {\n badcookie = TRUE;\n break;\n }\n- co->tailmatch=TRUE; /* we always do that if the domain name was\n- given */\n+ if(!is_ip)\n+ co->tailmatch=TRUE; /* we always do that if the domain name was\n+ given */\n }\n else {\n /* we did not get a tailmatch and then the attempted set domain\n is not a domain to which the current host belongs. Mark as\n bad. */\n@@ -966,17 +992,21 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,\n struct Cookie *newco;\n struct Cookie *co;\n time_t now = time(NULL);\n struct Cookie *mainco=NULL;\n size_t matches = 0;\n+ bool is_ip;\n \n if(!c || !c->cookies)\n return NULL; /* no cookie struct or no cookies in the struct */\n \n /* at first, remove expired cookies */\n remove_expired(c);\n \n+ /* check if host is an IP(v4|v6) address */\n+ is_ip = isip(host);\n+\n co = c->cookies;\n \n while(co) {\n /* only process this cookie if it is not expired or had no expire\n date AND that if the cookie requires we're secure we must only\n@@ -984,12 +1014,12 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,\n if((!co->expires || (co->expires > now)) &&\n (co->secure?secure:TRUE)) {\n \n /* now check if the domain is correct */\n if(!co->domain ||\n- (co->tailmatch && tailmatch(co->domain, host)) ||\n- (!co->tailmatch && Curl_raw_equal(host, co->domain)) ) {\n+ (co->tailmatch && !is_ip && tailmatch(co->domain, host)) ||\n+ ((!co->tailmatch || is_ip) && Curl_raw_equal(host, co->domain)) ) {\n /* the right part of the host matches the domain stuff in the\n cookie data */\n \n /* now check the left part of the path with the cookies path\n requirement */\ndiff --git a/tests/data/test1105 b/tests/data/test1105\nindex 25f194c..9564775 100644\n--- a/tests/data/test1105\n+++ b/tests/data/test1105\n@@ -57,10 +57,9 @@ userid=myname&password=mypassword\n # Netscape HTTP Cookie File\n # http://curl.haxx.se/docs/http-cookies.html\n # This file was generated by libcurl! Edit at your own risk.\n \n 127.0.0.1\tFALSE\t/we/want/\tFALSE\t0\tfoobar\tname\n-.127.0.0.1\tTRUE\t\"/silly/\"\tFALSE\t0\tmismatch\tthis\n-.0.0.1\tTRUE\t/\tFALSE\t0\tpartmatch\tpresent\n+127.0.0.1\tFALSE\t\"/silly/\"\tFALSE\t0\tmismatch\tthis\n </file>\n </verify>\n </testcase>\ndiff --git a/tests/data/test31 b/tests/data/test31\nindex 38af83b..dfcac04 100644\n--- a/tests/data/test31\n+++ b/tests/data/test31\n@@ -49,11 +49,12 @@ Set-Cookie: nodomainnovalue\n Set-Cookie: nodomain=value; expires=Fri Feb 2 11:56:27 GMT 2035\n Set-Cookie: novalue; domain=reallysilly\n Set-Cookie: test=yes; domain=foo.com; expires=Sat Feb 2 11:56:27 GMT 2030\n Set-Cookie: test2=yes; domain=se; expires=Sat Feb 2 11:56:27 GMT 2030\n Set-Cookie: magic=yessir; path=/silly/; HttpOnly\n-Set-Cookie: blexp=yesyes; domain=.0.0.1; domain=.0.0.1; expiry=totally bad;\n+Set-Cookie: blexp=yesyes; domain=127.0.0.1; domain=127.0.0.1; expiry=totally bad;\n+Set-Cookie: partialip=nono; domain=.0.0.1;\n \n boo\n </data>\n </reply>\n \n@@ -93,36 +94,36 @@ Accept: */*\n <file name=\"log/jar31.txt\" mode=\"text\">\n # Netscape HTTP Cookie File\n # http://curl.haxx.se/docs/http-cookies.html\n # This file was generated by libcurl! Edit at your own risk.\n \n-.127.0.0.1\tTRUE\t/silly/\tFALSE\t0\tismatch\tthis\n-.127.0.0.1\tTRUE\t/overwrite\tFALSE\t0\toverwrite\tthis2\n-.127.0.0.1\tTRUE\t/secure1/\tTRUE\t0\tsec1value\tsecure1\n-.127.0.0.1\tTRUE\t/secure2/\tTRUE\t0\tsec2value\tsecure2\n-.127.0.0.1\tTRUE\t/secure3/\tTRUE\t0\tsec3value\tsecure3\n-.127.0.0.1\tTRUE\t/secure4/\tTRUE\t0\tsec4value\tsecure4\n-.127.0.0.1\tTRUE\t/secure5/\tTRUE\t0\tsec5value\tsecure5\n-.127.0.0.1\tTRUE\t/secure6/\tTRUE\t0\tsec6value\tsecure6\n-.127.0.0.1\tTRUE\t/secure7/\tTRUE\t0\tsec7value\tsecure7\n-.127.0.0.1\tTRUE\t/secure8/\tTRUE\t0\tsec8value\tsecure8\n-.127.0.0.1\tTRUE\t/secure9/\tTRUE\t0\tsecure\tvery1\n-#HttpOnly_.127.0.0.1\tTRUE\t/p1/\tFALSE\t0\thttpo1\tvalue1\n-#HttpOnly_.127.0.0.1\tTRUE\t/p2/\tFALSE\t0\thttpo2\tvalue2\n-#HttpOnly_.127.0.0.1\tTRUE\t/p3/\tFALSE\t0\thttpo3\tvalue3\n-#HttpOnly_.127.0.0.1\tTRUE\t/p4/\tFALSE\t0\thttpo4\tvalue4\n-#HttpOnly_.127.0.0.1\tTRUE\t/p4/\tFALSE\t0\thttponly\tmyvalue1\n-#HttpOnly_.127.0.0.1\tTRUE\t/p4/\tTRUE\t0\thttpandsec\tmyvalue2\n-#HttpOnly_.127.0.0.1\tTRUE\t/p4/\tTRUE\t0\thttpandsec2\tmyvalue3\n-#HttpOnly_.127.0.0.1\tTRUE\t/p4/\tTRUE\t0\thttpandsec3\tmyvalue4\n-#HttpOnly_.127.0.0.1\tTRUE\t/p4/\tTRUE\t0\thttpandsec4\tmyvalue5\n-#HttpOnly_.127.0.0.1\tTRUE\t/p4/\tTRUE\t0\thttpandsec5\tmyvalue6\n-#HttpOnly_.127.0.0.1\tTRUE\t/p4/\tTRUE\t0\thttpandsec6\tmyvalue7\n-#HttpOnly_.127.0.0.1\tTRUE\t/p4/\tTRUE\t0\thttpandsec7\tmyvalue8\n-#HttpOnly_.127.0.0.1\tTRUE\t/p4/\tTRUE\t0\thttpandsec8\tmyvalue9\n-.127.0.0.1\tTRUE\t/\tFALSE\t0\tpartmatch\tpresent\n+127.0.0.1\tFALSE\t/silly/\tFALSE\t0\tismatch\tthis\n+127.0.0.1\tFALSE\t/overwrite\tFALSE\t0\toverwrite\tthis2\n+127.0.0.1\tFALSE\t/secure1/\tTRUE\t0\tsec1value\tsecure1\n+127.0.0.1\tFALSE\t/secure2/\tTRUE\t0\tsec2value\tsecure2\n+127.0.0.1\tFALSE\t/secure3/\tTRUE\t0\tsec3value\tsecure3\n+127.0.0.1\tFALSE\t/secure4/\tTRUE\t0\tsec4value\tsecure4\n+127.0.0.1\tFALSE\t/secure5/\tTRUE\t0\tsec5value\tse\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From eac573ea9c368f5e3c07de4d5ec5c5d0f84a021a Mon Sep 17 00:00:00 2001\nFrom: Tim Ruehsen <tim.ruehsen@gmx.de>\nDate: Tue, 19 Aug 2014 21:01:28 +0200\nSubject: [PATCH 1/2] cookies: only use full host matches for hosts used as IP\n address\n\nBy not detecting and rejecting domain names for partial literal IP\naddresses properly when parsing received HTTP cookies, libcurl can be\nfooled to both send cookies to wrong sites and to allow arbitrary sites\nto set cookies for others.\n\nBug: http://curl.haxx.se/docs/adv_20140910.html\n---\n lib/cookie.c | 50 ++++++++++++++++++++++++++++++++++++++----------\n tests/data/test1105 | 3 +--\n tests/data/test31 | 55 +++++++++++++++++++++++++++--------------------------\n tests/data/test8 | 3 ++-\n 4 files changed, 71 insertions(+), 40 deletions(-)\n\ndiff --git a/lib/cookie.c b/lib/cookie.c\nindex 0590643..46904ac 100644\n--- a/lib/cookie.c\n+++ b/lib/cookie.c\n@@ -93,10 +93,11 @@ Example set of cookies:\n #include \"curl_memory.h\"\n #include \"share.h\"\n #include \"strtoofft.h\"\n #include \"rawstr.h\"\n #include \"curl_memrchr.h\"\n+#include \"inet_pton.h\"\n \n /* The last #include file should be: */\n #include \"memdebug.h\"\n \n static void freecookie(struct Cookie *co)\n@@ -317,10 +318,32 @@ static void remove_expired(struct CookieInfo *cookies)\n }\n co = nx;\n }\n }\n \n+/*\n+ * Return true if the given string is an IP(v4|v6) address.\n+ */\n+static bool isip(const char *domain)\n+{\n+ struct in_addr addr;\n+#ifdef ENABLE_IPV6\n+ struct in6_addr addr6;\n+#endif\n+\n+ if(Curl_inet_pton(AF_INET, domain, &addr)\n+#ifdef ENABLE_IPV6\n+ || Curl_inet_pton(AF_INET6, domain, &addr6)\n+#endif\n+ ) {\n+ /* domain name given as IP address */\n+ return TRUE;\n+ }\n+\n+ return FALSE;\n+}\n+\n /****************************************************************************\n *\n * Curl_cookie_add()\n *\n * Add a single cookie line to the cookie keeping object.\n@@ -437,28 +460,31 @@ Curl_cookie_add(struct SessionHandle *data,\n badcookie = TRUE; /* out of memory bad */\n break;\n }\n }\n else if(Curl_raw_equal(\"domain\", name)) {\n+ bool is_ip;\n+\n /* Now, we make sure that our host is within the given domain,\n or the given domain is not valid and thus cannot be set. */\n \n if('.' == whatptr[0])\n whatptr++; /* ignore preceding dot */\n \n- if(!domain || tailmatch(whatptr, domain)) {\n- const char *tailptr=whatptr;\n- if(tailptr[0] == '.')\n- tailptr++;\n- strstore(&co->domain, tailptr); /* don't prefix w/dots\n- internally */\n+ is_ip = isip(domain ? domain : whatptr);\n+\n+ if(!domain\n+ || (is_ip && !strcmp(whatptr, domain))\n+ || (!is_ip && tailmatch(whatptr, domain))) {\n+ strstore(&co->domain, whatptr);\n if(!co->domain) {\n badcookie = TRUE;\n break;\n }\n- co->tailmatch=TRUE; /* we always do that if the domain name was\n- given */\n+ if(!is_ip)\n+ co->tailmatch=TRUE; /* we always do that if the domain name was\n+ given */\n }\n else {\n /* we did not get a tailmatch and then the attempted set domain\n is not a domain to which the current host belongs. Mark as\n bad. */\n@@ -966,17 +992,21 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,\n struct Cookie *newco;\n struct Cookie *co;\n time_t now = time(NULL);\n struct Cookie *mainco=NULL;\n size_t matches = 0;\n+ bool is_ip;\n \n if(!c || !c->cookies)\n return NULL; /* no cookie struct or no cookies in the struct */\n \n /* at first, remove expired cookies */\n remove_expired(c);\n \n+ /* check if host is an IP(v4|v6) address */\n+ is_ip = isip(host);\n+\n co = c->cookies;\n \n while(co) {\n /* only process this cookie if it is not expired or had no expire\n date AND that if the cookie requires we're secure we must only\n@@ -984,12 +1014,12 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,\n if((!co->expires || (co->expires > now)) &&\n (co->secure?secure:TRUE)) {\n \n /* now check if the domain is correct */\n if(!co->domain ||\n- (co->tailmatch && tailmatch(co->domain, host)) ||\n- (!co->tailmatch && Curl_raw_equal(host, co->domain)) ) {\n+ (co->tailmatch && !is_ip && tailmatch(co->domain, host)) ||\n+ ((!co->tailmatch || is_ip) && Curl_raw_equal(host, co->domain)) ) {\n /* the right part of the host matches the domain stuff in the\n cookie data */\n \n /* now check the left part of the path with the cookies path\n requirement */\ndiff --git a/tests/data/test1105 b/tests/data/test1105\nindex 25f194c..9564775 100644\n--- a/tests/data/test1105\n+++ b/tests/data/test1105\n@@ -57,10 +57,9 @@ userid=myname&password=mypassword\n # Netscape HTTP Cookie File\n # http://curl.haxx.se/docs/http-cookies.html\n # This file was generated by libcurl! Edit at your own risk.\n \n 127.0.0.1\tFALSE\t/we/want/\tFALSE\t0\tfoobar\tname\n-.127.0.0.1\tTRUE\t\"/silly/\"\tFALSE\t0\tmismatch\tthis\n-.0.0.1\tTRUE\t/\tFALSE\t0\tpartmatch\tpresent\n+127.0.0.1\tFALSE\t\"/silly/\"\tFALSE\t0\tmismatch\tthis\n </file>\n </verify>\n </testcase>\ndiff --git a/tests/data/test31 b/tests/data/test31\nindex 38af83b..dfcac04 100644\n--- a/tests/data/test31\n+++ b/tests/data/test31\n@@ -49,11 +49,12 @@ Set-Cookie: nodomainnovalue\n Set-Cookie: nodomain=value; expires=Fri Feb 2 11:56:27 GMT 2035\n Set-Cookie: novalue; domain=reallysilly\n Set-Cookie: test=yes; domain=foo.com; expires=Sat Feb 2 11:56:27 GMT 2030\n Set-Cookie: test2=yes; domain=se; expires=Sat Feb 2 11:56:27 GMT 2030\n Set-Cookie: magic=yessir; path=/silly/; HttpOnly\n-Set-Cookie: blexp=yesyes; domain=.0.0.1; domain=.0.0.1; expiry=totally bad;\n+Set-Cookie: blexp=yesyes; domain=127.0.0.1; domain=127.0.0.1; expiry=totally bad;\n+Set-Cookie: partialip=nono; domain=.0.0.1;\n \n boo\n </data>\n </reply>\n \n@@ -93,36 +94,36 @@ Accept: */*\n <file name=\"log/jar31.txt\" mode=\"text\">\n # Netscape HTTP Cookie File\n # http://curl.haxx.se/docs/http-cookies.html\n # This file was generated by libcurl! Edit at your own risk.\n \n-.127.0.0.1\tTRUE\t/silly/\tFALSE\t0\tismatch\tthis\n-.127.0.0.1\tTRUE\t/overwrite\tFALSE\t0\toverwrite\tthis2\n-.127.0.0.1\tTRUE\t/secure1/\tTRUE\t0\tsec1value\tsecure1\n-.127.0.0.1\tTRUE\t/secure2/\tTRUE\t0\tsec2value\tsecure2\n-.127.0.0.1\tTRUE\t/secure3/\tTRUE\t0\tsec3value\tsecure3\n-.127.0.0.1\tTRUE\t/secure4/\tTRUE\t0\tsec4value\tsecure4\n-.127.0.0.1\tTRUE\t/secure5/\tTRUE\t0\tsec5value\tsecure5\n-.127.0.0.1\tTRUE\t/secure6/\tTRUE\t0\tsec6value\tsecure6\n-.127.0.0.1\tTRUE\t/secure7/\tTRUE\t0\tsec7value\tsecure7\n-.127.0.0.1\tTRUE\t/secure8/\tTRUE\t0\tsec8value\tsecure8\n-.127.0.0.1\tTRUE\t/secure9/\tTRUE\t0\tsecure\tvery1\n-#HttpOnly_.127.0.0.1\tTRUE\t/p1/\tFALSE\t0\thttpo1\tvalue1\n-#HttpOnly_.127.0.0.1\tTRUE\t/p2/\tFALSE\t0\thttpo2\tvalue2\n-#HttpOnly_.127.0.0.1\tTRUE\t/p3/\tFALSE\t0\thttpo3\tvalue3\n-#HttpOnly_.127.0.0.1\tTRUE\t/p4/\tFALSE\t0\thttpo4\tvalue4\n-#HttpOnly_.127.0.0.1\tTRUE\t/p4/\tFALSE\t0\thttponly\tmyvalue1\n-#HttpOnly_.127.0.0.1\tTRUE\t/p4/\tTRUE\t0\thttpandsec\tmyvalue2\n-#HttpOnly_.127.0.0.1\tTRUE\t/p4/\tTRUE\t0\thttpandsec2\tmyvalue3\n-#HttpOnly_.127.0.0.1\tTRUE\t/p4/\tTRUE\t0\thttpandsec3\tmyvalue4\n-#HttpOnly_.127.0.0.1\tTRUE\t/p4/\tTRUE\t0\thttpandsec4\tmyvalue5\n-#HttpOnly_.127.0.0.1\tTRUE\t/p4/\tTRUE\t0\thttpandsec5\tmyvalue6\n-#HttpOnly_.127.0.0.1\tTRUE\t/p4/\tTRUE\t0\thttpandsec6\tmyvalue7\n-#HttpOnly_.127.0.0.1\tTRUE\t/p4/\tTRUE\t0\thttpandsec7\tmyvalue8\n-#HttpOnly_.127.0.0.1\tTRUE\t/p4/\tTRUE\t0\thttpandsec8\tmyvalue9\n-.127.0.0.1\tTRUE\t/\tFALSE\t0\tpartmatch\tpresent\n+127.0.0.1\tFALSE\t/silly/\tFALSE\t0\tismatch\tthis\n+127.0.0.1\tFALSE\t/overwrite\tFALSE\t0\toverwrite\tthis2\n+127.0.0.1\tFALSE\t/secure1/\tTRUE\t0\tsec1value\tsecure1\n+127.0.0.1\tFALSE\t/secure2/\tTRUE\t0\tsec2value\tsecure2\n+127.0.0.1\tFALSE\t/secure3/\tTRUE\t0\tsec3value\tsecure3\n+127.0.0.1\tFALSE\t/secure4/\tTRUE\t0\tsec4value\tsecure4\n+127.0.0.1\tFALSE\t/secure5/\tTRUE\t0\tsec5value\tsecure5\n+127.0.0.1\tFALSE\t/secure6/\tTRUE\t0\tsec6value\tsecure6\n+127.0.0.1\tFALSE\t/secure7/\tTRUE\t0\tsec7value\tsecure7\n+127.0.0.1\tFALSE\t/secure8/\tTRUE\t0\tsec8value\tsecure8\n+127.0.0.1\tFALSE\t/secure9/\tTRUE\t0\tsecure\tvery1\n+#HttpOnly_127.0.0.1\tFALSE\t/p1/\tFALSE\t0\thttpo1\tvalue1\n+#HttpOnly_127.0.0.1\tFALSE\t/p2/\tFALSE\t0\thttpo2\tvalue2\n+#HttpOnly_127.0.0.1\tFALSE\t/p3/\tFALSE\t0\thttpo3\tvalue3\n+#HttpOnly_127.0.0.1\tFALSE\t/p4/\tFALSE\t0\thttpo4\tvalue4\n+#HttpOnly_127.0.0.1\tFALSE\t/p4/\tFALSE\t0\thttponly\tmyvalue1\n+#HttpOnly_127.0.0.1\tFALSE\t/p4/\tTRUE\t0\thttpandsec\tmyvalue2\n+#HttpOnly_127.0.0.1\tFALSE\t/p4/\tTRUE\t0\thttpandsec2\tmyvalue3\n+#HttpOnly_127.0.0.1\tFALSE\t/p4/\tTRUE\t0\thttpandsec3\tmyvalue4\n+#HttpOnly_127.0.0.1\tFALSE\t/p4/\tTRUE\t0\thttpandsec4\tmyvalue5\n+#HttpOnly_127.0.0.1\tFALSE\t/p4/\tTRUE\t0\thttpandsec5\tmyvalue6\n+#HttpOnly_127.0.0.1\tFALSE\t/p4/\tTRUE\t0\thttpandsec6\tmyvalue7\n+#HttpOnly_127.0.0.1\tFALSE\t/p4/\tTRUE\t0\thttpandsec7\tmyvalue8\n+#HttpOnly_127.0.0.1\tFALSE\t/p4/\tTRUE\t0\thttpandsec8\tmyvalue9\n+127.0.0.1\tFALSE\t/\tFALSE\t0\tpartmatch\tpresent\n 127.0.0.1\tFALSE\t/we/want/\tFALSE\t2054030187\tnodomain\tvalue\n #HttpOnly_127.0.0.1\tFALSE\t/silly/\tFALSE\t0\tmagic\tyessir\n-.0.0.1\tTRUE\t/we/want/\tFALSE\t0\tblexp\tyesyes\n+127.0.0.1\tFALSE\t/we/want/\tFALSE\t0\tblexp\tyesyes\n </file>\n </verify>\n </testcase>\ndiff --git a/tests/data/test8 b/tests/data/test8\nindex 4d54541..030fd55 100644\n--- a/tests/data/test8\n+++ b/tests/data/test8\n@@ -40,11 +40,12 @@ Set-Cookie: mismatch=this; domain=%HOSTIP; path=\"/silly/\";\n Set-Cookie: partmatch=present; domain=.0.0.1; path=/w;\n Set-Cookie: duplicate=test; domain=.0.0.1; domain=.0.0.1; path=/donkey;\n Set-Cookie: cookie=yes; path=/we;\n Set-Cookie: cookie=perhaps; path=/we/want;\n Set-Cookie: nocookie=yes; path=/WE;\n-Set-Cookie: blexp=yesyes; domain=.0.0.1; domain=.0.0.1; expiry=totally bad;\n+Set-Cookie: blexp=yesyes; domain=%HOSTIP; domain=%HOSTIP; expiry=totally bad;\n+Set-Cookie: partialip=nono; domain=.0.0.1;\n \n </file>\n <precheck>\n perl -e 'if (\"%HOSTIP\" !~ /\\.0\\.0\\.1$/) {print \"Test only works for HOSTIPs ending with .0.0.1\"; exit(1)}'\n </precheck>\n-- \n2.1.0" } ]
{ "id": "curl-5786-curl-CVE-2014-3613.patch", "cve_id": "CVE-2016-8618", "package": "curl", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": false, "license": "MIT", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2013-4288\n\nRace condition in PolicyKit (aka polkit) allows local users to bypass intended PolicyKit restrictions and gain privileges by starting a setuid or pkexec process before the authorization check is performed, related to (1) the polkit_unix_process_new API function, (2) the dbus API, or (3) the --process (unix-process) option for authorization to pkcheck.\n\n## Package\nsystemd-mini\n\n## Files to modify\n- systemd-195.orig/src/locale/localectl.c\n- src/locale/localectl.c\n\n## Target Source Code\n\n### src/locale/localectl.c\n\n#### region() [lines 220-268]\n```c\n return 0;\n}\n\nstatic int set_locale(DBusConnection *bus, char **args, unsigned n) {\n _cleanup_dbus_message_unref_ DBusMessage *m = NULL, *reply = NULL;\n dbus_bool_t interactive = true;\n DBusError error;\n DBusMessageIter iter;\n int r;\n\n assert(bus);\n assert(args);\n\n dbus_error_init(&error);\n\n polkit_agent_open_if_enabled();\n\n m = dbus_message_new_method_call(\n \"org.freedesktop.locale1\",\n \"/org/freedesktop/locale1\",\n \"org.freedesktop.locale1\",\n \"SetLocale\");\n if (!m)\n return log_oom();\n\n dbus_message_iter_init_append(m, &iter);\n\n r = bus_append_strv_iter(&iter, args + 1);\n if (r < 0)\n return log_oom();\n\n if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &interactive))\n return log_oom();\n\n reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error);\n if (!reply) {\n log_error(\"Failed to issue method call: %s\", bus_error_message(&error));\n r = -EIO;\n goto finish;\n }\n\n r = 0;\n\nfinish:\n dbus_error_free(&error);\n return r;\n}\n\nstatic int list_locales(DBusConnection *bus, char **args, unsigned n) {\n```\n\n#### list_locales() [lines 265-408]\n```c\n return r;\n}\n\nstatic int list_locales(DBusConnection *bus, char **args, unsigned n) {\n /* Stolen from glibc... */\n\n struct locarhead {\n uint32_t magic;\n /* Serial number. */\n uint32_t serial;\n /* Name hash table. */\n uint32_t namehash_offset;\n uint32_t namehash_used;\n uint32_t namehash_size;\n /* String table. */\n uint32_t string_offset;\n uint32_t string_used;\n uint32_t string_size;\n /* Table with locale records. */\n uint32_t locrectab_offset;\n uint32_t locrectab_used;\n uint32_t locrectab_size;\n /* MD5 sum hash table. */\n uint32_t sumhash_offset;\n uint32_t sumhash_used;\n uint32_t sumhash_size;\n };\n\n struct namehashent {\n /* Hash value of the name. */\n uint32_t hashval;\n /* Offset of the name in the string table. */\n uint32_t name_offset;\n /* Offset of the locale record. */\n uint32_t locrec_offset;\n };\n\n const struct locarhead *h;\n const struct namehashent *e;\n const void *p = MAP_FAILED;\n _cleanup_close_ int fd = -1;\n _cleanup_strv_free_ char **l = NULL;\n char **j;\n Set *locales;\n size_t sz = 0;\n struct stat st;\n unsigned i;\n int r;\n\n locales = set_new(string_hash_func, string_compare_func);\n if (!locales)\n return log_oom();\n\n fd = open(\"/usr/lib/locale/locale-archive\", O_RDONLY|O_NOCTTY|O_CLOEXEC);\n if (fd < 0) {\n log_error(\"Failed to open locale archive: %m\");\n r = -errno;\n goto finish;\n }\n\n if (fstat(fd, &st) < 0) {\n log_error(\"fstat() failed: %m\");\n r = -errno;\n goto finish;\n }\n\n if (!S_ISREG(st.st_mode)) {\n log_error(\"Archive file is not regular\");\n r = -EBADMSG;\n goto finish;\n/* ... 54 lines omitted ... */\n\n strv_sort(l);\n\n pager_open_if_enabled();\n\n STRV_FOREACH(j, l)\n puts(*j);\n\n r = 0;\n\nfinish:\n if (p != MAP_FAILED)\n munmap((void*) p, sz);\n\n set_free_free(locales);\n\n return r;\n}\n\nstatic int set_vconsole_keymap(DBusConnection *bus, char **args, unsigned n) {\n```\n\n\n## Upstream Fix\n```diff\nFrom 17d33cecaa762f7e43200307328af5e9135e2091 Mon Sep 17 00:00:00 2001\nFrom: Giovanni Campagna <scampa.giovanni@gmail.com>\nDate: Sat, 5 Jan 2013 01:29:53 +0100\nSubject: [PATCH] localectl: support systems without locale-archive\n\nNot all systems ships with locales inside /usr/lib/locale-archive, some\nprefer to have locale data as individual subdirectories of /usr/lib/locale.\n(A notable example of this is OpenEmbeddded, and OSes deriving from it\nlike gnome-ostree).\nGiven that glibc supports both ways, localectl should too.\n---\n src/locale/localectl.c | 101 ++++++++++++++++++++++++++++++++++-------\n 1 file changed, 85 insertions(+), 16 deletions(-)\n\ndiff --git a/src/locale/localectl.c b/src/locale/localectl.c\nindex 5d35f9cdae4db..b3acb3ec456f4 100644\n--- a/src/locale/localectl.c\n+++ b/src/locale/localectl.c\n@@ -266,7 +266,7 @@ static int set_locale(DBusConnection *bus, char **args, unsigned n) {\n return r;\n }\n \n-static int list_locales(DBusConnection *bus, char **args, unsigned n) {\n+static int add_locales_from_archive(Set *locales) {\n /* Stolen from glibc... */\n \n struct locarhead {\n@@ -304,21 +304,15 @@ static int list_locales(DBusConnection *bus, char **args, unsigned n) {\n const struct namehashent *e;\n const void *p = MAP_FAILED;\n _cleanup_close_ int fd = -1;\n- _cleanup_strv_free_ char **l = NULL;\n- char **j;\n- Set *locales;\n size_t sz = 0;\n struct stat st;\n unsigned i;\n int r;\n \n- locales = set_new(string_hash_func, string_compare_func);\n- if (!locales)\n- return log_oom();\n-\n fd = open(\"/usr/lib/locale/locale-archive\", O_RDONLY|O_NOCTTY|O_CLOEXEC);\n if (fd < 0) {\n- log_error(\"Failed to open locale archive: %m\");\n+ if (errno != ENOENT)\n+ log_error(\"Failed to open locale archive: %m\");\n r = -errno;\n goto finish;\n }\n@@ -380,15 +374,93 @@ static int list_locales(DBusConnection *bus, char **args, unsigned n) {\n }\n }\n \n+ r = 0;\n+\n+ finish:\n+ if (p != MAP_FAILED)\n+ munmap((void*) p, sz);\n+\n+ return r;\n+}\n+\n+static int add_locales_from_libdir (Set *locales) {\n+ DIR *dir;\n+ struct dirent *entry;\n+ int r;\n+\n+ dir = opendir(\"/usr/lib/locale\");\n+ if (!dir) {\n+ log_error(\"Failed to open locale directory: %m\");\n+ r = -errno;\n+ goto finish;\n+ }\n+\n+ errno = 0;\n+ while ((entry = readdir(dir))) {\n+ char *z;\n+\n+ if (entry->d_type != DT_DIR)\n+ continue;\n+\n+ if (ignore_file(entry->d_name))\n+ continue;\n+\n+ z = strdup(entry->d_name);\n+ if (!z) {\n+ r = log_oom();\n+ goto finish;\n+ }\n+\n+ r = set_put(locales, z);\n+ if (r < 0) {\n+ free(z);\n+\n+ if (r != -EEXIST) {\n+ log_error(\"Failed to add locale: %s\", strerror(-r));\n+ goto finish;\n+ }\n+ }\n+\n+ errno = 0;\n+ }\n+\n+ if (errno != 0) {\n+ log_error(\"Failed to read locale directory: %m\");\n+ r = -errno;\n+ goto finish;\n+ }\n+\n+ r = 0;\n+\n+ finish:\n+ closedir(dir);\n+ return r;\n+}\n+\n+static int list_locales(DBusConnection *bus, char **args, unsigned n) {\n+ Set *locales;\n+ _cleanup_strv_free_ char **l = NULL;\n+ char **j;\n+ int r;\n+\n+ locales = set_new(string_hash_func, string_compare_func);\n+ if (!locales)\n+ return log_oom();\n+\n+ r = add_locales_from_archive(locales);\n+ if (r < 0 && r != -ENOENT)\n+ goto finish;\n+\n+ r = add_locales_from_libdir(locales);\n+ if (r < 0)\n+ goto finish;\n+\n l = set_get_strv(locales);\n if (!l) {\n r = log_oom();\n goto finish;\n }\n \n- set_free(locales);\n- locales = NULL;\n-\n strv_sort(l);\n \n pager_open_if_enabled();\n@@ -399,10 +471,7 @@ static int list_locales(DBusConnection *bus, char **args, unsigned n) {\n r = 0;\n \n finish:\n- if (p != MAP_FAILED)\n- munmap((void*) p, sz);\n-\n- set_free_free(locales);\n+ set_free(locales);\n \n return r;\n }\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 17d33cecaa762f7e43200307328af5e9135e2091 Mon Sep 17 00:00:00 2001\nFrom: Giovanni Campagna <scampa.giovanni@gmail.com>\nDate: Sat, 5 Jan 2013 01:29:53 +0100\nSubject: [PATCH] localectl: support systems without locale-archive\n\nNot all systems ships with locales inside /usr/lib/locale-archive, some\nprefer to have locale data as individual subdirectories of /usr/lib/locale.\n(A notable example of this is OpenEmbeddded, and OSes deriving from it\nlike gnome-ostree).\nGiven that glibc supports both ways, localectl should too.\n---\n src/locale/localectl.c | 101 ++++++++++++++++++++++++++++++++++++++++--------\n 1 file changed, 85 insertions(+), 16 deletions(-)\n\nIndex: systemd-195/src/locale/localectl.c\n===================================================================\n--- systemd-195.orig/src/locale/localectl.c\n+++ systemd-195/src/locale/localectl.c\n@@ -265,7 +265,7 @@ finish:\n return r;\n }\n \n-static int list_locales(DBusConnection *bus, char **args, unsigned n) {\n+static int add_locales_from_archive(Set *locales) {\n /* Stolen from glibc... */\n \n struct locarhead {\n@@ -303,21 +303,15 @@ static int list_locales(DBusConnection *\n const struct namehashent *e;\n const void *p = MAP_FAILED;\n _cleanup_close_ int fd = -1;\n- _cleanup_strv_free_ char **l = NULL;\n- char **j;\n- Set *locales;\n size_t sz = 0;\n struct stat st;\n unsigned i;\n int r;\n \n- locales = set_new(string_hash_func, string_compare_func);\n- if (!locales)\n- return log_oom();\n-\n fd = open(\"/usr/lib/locale/locale-archive\", O_RDONLY|O_NOCTTY|O_CLOEXEC);\n if (fd < 0) {\n- log_error(\"Failed to open locale archive: %m\");\n+ if (errno != ENOENT)\n+ log_error(\"Failed to open locale archive: %m\");\n r = -errno;\n goto finish;\n }\n@@ -378,15 +372,93 @@ static int list_locales(DBusConnection *\n }\n }\n \n+ r = 0;\n+\n+ finish:\n+ if (p != MAP_FAILED)\n+ munmap((void*) p, sz);\n+\n+ return r;\n+}\n+\n+static int add_locales_from_libdir (Set *locales) {\n+ DIR *dir;\n+ struct dirent *entry;\n+ int r;\n+\n+ dir = opendir(\"/usr/lib/locale\");\n+ if (!dir) {\n+ log_error(\"Failed to open locale directory: %m\");\n+ r = -errno;\n+ goto finish;\n+ }\n+\n+ errno = 0;\n+ while ((entry = readdir(dir))) {\n+ char *z;\n+\n+ if (entry->d_type != DT_DIR)\n+ continue;\n+\n+ if (ignore_file(entry->d_name))\n+ continue;\n+\n+ z = strdup(entry->d_name);\n+ if (!z) {\n+ r = log_oom();\n+ goto finish;\n+ }\n+\n+ r = set_put(locales, z);\n+ if (r < 0) {\n+ free(z);\n+\n+ if (r != -EEXIST) {\n+ log_error(\"Failed to add locale: %s\", strerror(-r));\n+ goto finish;\n+ }\n+ }\n+\n+ errno = 0;\n+ }\n+\n+ if (errno != 0) {\n+ log_error(\"Failed to read locale directory: %m\");\n+ r = -errno;\n+ goto finish;\n+ }\n+\n+ r = 0;\n+\n+ finish:\n+ closedir(dir);\n+ return r;\n+}\n+\n+static int list_locales(DBusConnection *bus, char **args, unsigned n) {\n+ Set *locales;\n+ _cleanup_strv_free_ char **l = NULL;\n+ char **j;\n+ int r;\n+\n+ locales = set_new(string_hash_func, string_compare_func);\n+ if (!locales)\n+ return log_oom();\n+\n+ r = add_locales_from_archive(locales);\n+ if (r < 0 && r != -ENOENT)\n+ goto finish;\n+\n+ r = add_locales_from_libdir(locales);\n+ if (r < 0)\n+ goto finish;\n+\n l = set_get_strv(locales);\n if (!l) {\n r = log_oom();\n goto finish;\n }\n \n- set_free(locales);\n- locales = NULL;\n-\n strv_sort(l);\n \n pager_open_if_enabled();\n@@ -397,10 +469,7 @@ static int list_locales(DBusConnection *\n r = 0;\n \n finish:\n- if (p != MAP_FAILED)\n- munmap((void*) p, sz);\n-\n- set_free_free(locales);\n+ set_free(locales);\n \n return r;\n }" } ]
{ "id": "systemd-mini-2025-localectl-support-systems-with", "cve_id": "CVE-2013-4288", "package": "systemd-mini", "upstream_enriched": true, "upstream_commit": "17d33cecaa762f7e43200307328af5e9135e2091", "upstream_repo": "systemd/systemd", "tier": "adapted", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 1014, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-8629\n\nThe xdr_nullstring function in lib/kadm5/kadm_rpc_xdr.c in kadmind in MIT Kerberos 5 (aka krb5) before 1.13.4 and 1.14.x before 1.14.1 does not verify whether '\\0' characters exist as expected, which allows remote authenticated users to obtain sensitive information or cause a denial of service (out-of-bounds read) via a crafted string.\n\n## Package\nkrb5-mini\n\n## Files to modify\n- src/lib/krb5/rcache/rc_io.c\n\n## Upstream Fix\n```diff\nFrom c61e8c0c6ad5fda8d23dd896c4aed0ac5b470020 Mon Sep 17 00:00:00 2001\nFrom: Greg Hudson <ghudson@mit.edu>\nDate: Wed, 17 Sep 2014 10:45:28 -0400\nSubject: [PATCH] Work around replay cache creation race\n\nIf two processes try to initialize the same replay cache at the same\ntime, krb5_rc_io_creat can race between unlink and open, leading to a\nKRB5_RC_IO_PERM error. When this happens, make the losing process\nretry so that it can continue.\n\nThis does not solve the replay cache creation race, nor is that the\nonly replay cache race issue. It simply prevents the race from\ncausing a spurious failure.\n\nticket: 3498\ntarget_version: 1.13\ntags: pullup\n---\n src/lib/krb5/rcache/rc_io.c | 12 ++++++++----\n 1 file changed, 8 insertions(+), 4 deletions(-)\n\ndiff --git a/src/lib/krb5/rcache/rc_io.c b/src/lib/krb5/rcache/rc_io.c\nindex 7e3b7e951a4..b9859fe9f65 100644\n--- a/src/lib/krb5/rcache/rc_io.c\n+++ b/src/lib/krb5/rcache/rc_io.c\n@@ -158,7 +158,7 @@ krb5_rc_io_creat(krb5_context context, krb5_rc_iostuff *d, char **fn)\n {\n krb5_int16 rc_vno = htons(KRB5_RC_VNO);\n krb5_error_code retval = 0;\n- int do_not_unlink = 0;\n+ int flags, do_not_unlink = 0;\n char *dir;\n size_t dirlen;\n \n@@ -166,9 +166,13 @@ krb5_rc_io_creat(krb5_context context, krb5_rc_iostuff *d, char **fn)\n if (fn && *fn) {\n if (asprintf(&d->fn, \"%s%s%s\", dir, PATH_SEPARATOR, *fn) < 0)\n return KRB5_RC_IO_MALLOC;\n- unlink(d->fn);\n- d->fd = THREEPARAMOPEN(d->fn, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL |\n- O_BINARY, 0600);\n+ d->fd = -1;\n+ do {\n+ if (unlink(d->fn) == -1 && errno != ENOENT)\n+ break;\n+ flags = O_WRONLY | O_CREAT | O_TRUNC | O_EXCL | O_BINARY;\n+ d->fd = THREEPARAMOPEN(d->fn, flags, 0600);\n+ } while (d->fd == -1 && errno == EEXIST);\n } else {\n retval = krb5_rc_io_mkstemp(context, d, dir);\n if (retval)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 99e08376c14240e2141c6fa9289fafab8245c754 Mon Sep 17 00:00:00 2001\nFrom: Greg Hudson <ghudson@mit.edu>\nDate: Wed, 17 Sep 2014 10:45:28 -0400\nSubject: [PATCH] Work around replay cache creation race\n\nIf two processes try to initialize the same replay cache at the same\ntime, krb5_rc_io_creat can race between unlink and open, leading to a\nKRB5_RC_IO_PERM error. When this happens, make the losing process\nretry so that it can continue.\n\nThis does not solve the replay cache creation race, nor is that the\nonly replay cache race issue. It simply prevents the race from\ncausing a spurious failure.\n\n(cherry picked from commit c61e8c0c6ad5fda8d23dd896c4aed0ac5b470020)\n\nticket: 3498\nversion_fixed: 1.13\nstatus: resolved\n---\n src/lib/krb5/rcache/rc_io.c | 12 ++++++++----\n 1 file changed, 8 insertions(+), 4 deletions(-)\n\ndiff --git a/src/lib/krb5/rcache/rc_io.c b/src/lib/krb5/rcache/rc_io.c\nindex 7e3b7e9..b9859fe 100644\n--- a/src/lib/krb5/rcache/rc_io.c\n+++ b/src/lib/krb5/rcache/rc_io.c\n@@ -158,7 +158,7 @@ krb5_rc_io_creat(krb5_context context, krb5_rc_iostuff *d, char **fn)\n {\n krb5_int16 rc_vno = htons(KRB5_RC_VNO);\n krb5_error_code retval = 0;\n- int do_not_unlink = 0;\n+ int flags, do_not_unlink = 0;\n char *dir;\n size_t dirlen;\n \n@@ -166,9 +166,13 @@ krb5_rc_io_creat(krb5_context context, krb5_rc_iostuff *d, char **fn)\n if (fn && *fn) {\n if (asprintf(&d->fn, \"%s%s%s\", dir, PATH_SEPARATOR, *fn) < 0)\n return KRB5_RC_IO_MALLOC;\n- unlink(d->fn);\n- d->fd = THREEPARAMOPEN(d->fn, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL |\n- O_BINARY, 0600);\n+ d->fd = -1;\n+ do {\n+ if (unlink(d->fn) == -1 && errno != ENOENT)\n+ break;\n+ flags = O_WRONLY | O_CREAT | O_TRUNC | O_EXCL | O_BINARY;\n+ d->fd = THREEPARAMOPEN(d->fn, flags, 0600);\n+ } while (d->fd == -1 && errno == EEXIST);\n } else {\n retval = krb5_rc_io_mkstemp(context, d, dir);\n if (retval)\n-- \n1.8.4.5" } ]
{ "id": "krb5-mini-4619-krb5-1.13-work-around-replay-c", "cve_id": "CVE-2015-8629", "package": "krb5-mini", "upstream_enriched": true, "upstream_commit": "c61e8c0c6ad5fda8d23dd896c4aed0ac5b470020", "upstream_repo": "krb5/krb5", "tier": "adapted", "has_source_context": false, "license": "MIT", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2012-4405\n\nMultiple integer underflows in the icmLut_allocate function in International Color Consortium (ICC) Format library (icclib), as used in Ghostscript 9.06 and Argyll Color Management System, allow remote attackers to cause a denial of service (crash) and possibly execute arbitrary code via a crafted (1) PostScript or (2) PDF file with embedded images, which triggers a heap-based buffer overflow. NOTE: this issue is also described as an array index error.\n\n## Package\nghostscript-library\n\n## Files to modify\n- base/echogs.c\n\n## Upstream Fix\n```diff\nrom: Hauke Klein <klein@math.uni-kiel.de>\nTo: gs-devel@ghostscript.com\n\nHi, while building ghostscript 8.62 with non-standard settings for\nGLGENDIR, GLOBJDIR, ...\nI noticed a few small inconsistencies in ghostscripts makefiles. The\nattached patch should\nfix these. I'm also building with a separate build directory.\nUnfortunately, the resulting path\nstrings overflow a static buffer in echogs.c. The patch also changes\nthe size of these\nbuffers. I'm just including limits.h, I should probably guard this\nwith an HAVE_LIMITS_H\nor something like this.\n\nPS. I hope this message is appropriate for this list (or should gs-\ncode-review be\nused for such things?)\n\n--- base/echogs.c\n+++ base/echogs.c\t2010-09-28 12:56:09.159926344 +0000\n@@ -31,6 +31,7 @@ extern int fputc(int, FILE *), fputs(con\n #include <ctype.h>\n #include <string.h>\n #include <time.h>\t\t/* for ctime */\n+#include <limits.h>\n \n /*\n * This program exists solely to get around omissions, problems, and\n@@ -91,14 +92,14 @@ main(int argc, char *argv[])\n FILE *in = 0;\n const char *extn = \"\";\n char fmode[4];\n-#define FNSIZE 1000\n+#define FNSIZE PATH_MAX\n char *fnparam = NULL; /* Initialisation to shut up compilers */\n char fname[FNSIZE];\n int newline = 1;\n int interact = 0;\n int (*eputc)(int, FILE *) = fputc;\n int (*eputs)(const char *, FILE *) = fputs;\n-#define LINESIZE 1000+FNSIZE\n+#define LINESIZE 1000+PATH_MAX\n char line[LINESIZE];\n char sw = 0, sp = 0, hexx = 0;\n char **argp = argv + 1;\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "rom: Hauke Klein <klein@math.uni-kiel.de>\nTo: gs-devel@ghostscript.com\n\nHi, while building ghostscript 8.62 with non-standard settings for\nGLGENDIR, GLOBJDIR, ...\nI noticed a few small inconsistencies in ghostscripts makefiles. The\nattached patch should\nfix these. I'm also building with a separate build directory.\nUnfortunately, the resulting path\nstrings overflow a static buffer in echogs.c. The patch also changes\nthe size of these\nbuffers. I'm just including limits.h, I should probably guard this\nwith an HAVE_LIMITS_H\nor something like this.\n\nPS. I hope this message is appropriate for this list (or should gs-\ncode-review be\nused for such things?)\n\n--- base/echogs.c\n+++ base/echogs.c\t2010-09-28 12:56:09.159926344 +0000\n@@ -31,6 +31,7 @@ extern int fputc(int, FILE *), fputs(con\n #include <ctype.h>\n #include <string.h>\n #include <time.h>\t\t/* for ctime */\n+#include <limits.h>\n \n /*\n * This program exists solely to get around omissions, problems, and\n@@ -91,14 +92,14 @@ main(int argc, char *argv[])\n FILE *in = 0;\n const char *extn = \"\";\n char fmode[4];\n-#define FNSIZE 1000\n+#define FNSIZE PATH_MAX\n char *fnparam = NULL; /* Initialisation to shut up compilers */\n char fname[FNSIZE];\n int newline = 1;\n int interact = 0;\n int (*eputc)(int, FILE *) = fputc;\n int (*eputs)(const char *, FILE *) = fputs;\n-#define LINESIZE 1000+FNSIZE\n+#define LINESIZE 1000+PATH_MAX\n char line[LINESIZE];\n char sw = 0, sp = 0, hexx = 0;\n char **argp = argv + 1;" } ]
{ "id": "ghostscript-library-883-ghostscript-9.00-echogs.patch", "cve_id": "CVE-2012-4405", "package": "ghostscript-library", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": false, "license": "AGPL-3.0-only", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2012-4561\n\nThe (1) publickey_make_dss, (2) publickey_make_rsa, (3) signature_from_string, (4) ssh_do_sign, and (5) ssh_sign_session_id functions in keys.c in libssh before 0.5.3 free \"an invalid pointer on an error path,\" which might allow remote attackers to cause a denial of service (crash) via unspecified vectors.\n\n## Package\nlibssh\n\n## Files to modify\n- libssh-0.5.2.orig/src/channels.c\n- src/channels.c\n\n## Upstream Fix\n```diff\nFrom 6236001ff4f9017c9f842d6548baba9760c95f5c Mon Sep 17 00:00:00 2001\nFrom: Andreas Schneider <asn@cryptomilk.org>\nDate: Fri, 5 Oct 2012 14:39:51 +0200\nSubject: [PATCH] CVE-2012-4559: Ensure that we don't free req twice.\n\n---\n src/channels.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/src/channels.c b/src/channels.c\nindex ad989d78f..214485c98 100644\n--- a/src/channels.c\n+++ b/src/channels.c\n@@ -1417,6 +1417,7 @@ static int channel_request(ssh_channel channel, const char *request,\n buffer_add_ssh_string(session->out_buffer, req) < 0 ||\n buffer_add_u8(session->out_buffer, reply == 0 ? 0 : 1) < 0) {\n ssh_set_error_oom(session);\n+ ssh_string_free(req);\n goto error;\n }\n ssh_string_free(req);\n@@ -1476,7 +1477,6 @@ static int channel_request(ssh_channel channel, const char *request,\n return rc;\n error:\n buffer_reinit(session->out_buffer);\n- ssh_string_free(req);\n \n leave_function();\n return rc;\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 6236001ff4f9017c9f842d6548baba9760c95f5c Mon Sep 17 00:00:00 2001\nFrom: Andreas Schneider <asn@cryptomilk.org>\nDate: Fri, 5 Oct 2012 14:39:51 +0200\nSubject: [PATCH 08/13] CVE-2012-4559: Ensure that we don't free req twice.\n\n\nSigned-off-by: Andreas Schneider <asn@cryptomilk.org>\n---\n src/channels.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\nIndex: libssh-0.5.2/src/channels.c\n===================================================================\n--- libssh-0.5.2.orig/src/channels.c\n+++ libssh-0.5.2/src/channels.c\n@@ -1414,6 +1414,7 @@ static int channel_request(ssh_channel c\n buffer_add_ssh_string(session->out_buffer, req) < 0 ||\n buffer_add_u8(session->out_buffer, reply == 0 ? 0 : 1) < 0) {\n ssh_set_error_oom(session);\n+ ssh_string_free(req);\n goto error;\n }\n ssh_string_free(req);\n@@ -1473,7 +1474,6 @@ static int channel_request(ssh_channel c\n return rc;\n error:\n buffer_reinit(session->out_buffer);\n- ssh_string_free(req);\n \n leave_function();\n return rc;" } ]
{ "id": "libssh-1119-0008-CVE-2012-4559-Ensure-that", "cve_id": "CVE-2012-4561", "package": "libssh", "upstream_enriched": true, "upstream_commit": "6236001ff4f9017c9f842d6548baba9760c95f5c", "upstream_repo": "libssh/libssh-mirror", "tier": "adapted", "has_source_context": false, "license": "LGPL-2.1-or-later", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-7511\n\nLibgcrypt before 1.6.5 does not properly perform elliptic-point curve multiplication during decryption, which makes it easier for physically proximate attackers to extract ECDH keys by measuring electromagnetic emanations.\n\n## Package\nlibgcrypt\n\n## Files to modify\n- tests/gcrypt_rsagtest.c\n\n## Target Source Code\n\n### Makefile.am\n\n#### region() [lines 1-52]\n```c\n# Makefile for cipher modules\n# Copyright (C) 2008 Free Software Foundation, Inc.\n#\n# This file is part of Libgcrypt.\n#\n# Libgcrypt is free software; you can redistribute it and/or modify\n# it under the terms of the GNU Lesser General Public License as\n# published by the Free Software Foundation; either version 2.1 of\n# the License, or (at your option) any later version.\n#\n# Libgcrypt is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n# GNU Lesser General Public License for more details.\n#\n# You should have received a copy of the GNU Lesser General Public\n# License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n# Process this file with automake to produce Makefile.in\n\n# Need to include ../src in addition to top_srcdir because gcrypt.h is\n# a built header.\nAM_CPPFLAGS = -I../src -I$(top_srcdir)/src\nAM_CFLAGS = $(GPG_ERROR_CFLAGS)\n\nnoinst_LTLIBRARIES = librandom.la\n\nGCRYPT_MODULES = @GCRYPT_RANDOM@\n\nlibrandom_la_DEPENDENCIES = $(GCRYPT_MODULES)\nlibrandom_la_LIBADD = $(GCRYPT_MODULES)\n\nlibrandom_la_SOURCES = \\\nrandom.c random.h \\\nrand-internal.h \\\nrandom-csprng.c \\\nrandom-fips.c \\\nrandom-system.c \\\nrndhw.c\n\nif USE_RANDOM_DAEMON\nlibrandom_la_SOURCES += random-daemon.c\nendif USE_RANDOM_DAEMON\n\n\nEXTRA_librandom_la_SOURCES = \\\nrndlinux.c \\\nrndegd.c \\\nrndunix.c \\\nrndw32.c \\\nrndw32ce.c\n\n```\n\n\n## Upstream Fix\n```diff\nIndex: libgcrypt-1.6.1/Makefile.am\n===================================================================\n--- libgcrypt-1.6.1.orig/Makefile.am\t2015-02-02 17:15:29.429281092 +0100\n+++ libgcrypt-1.6.1/Makefile.am\t2015-02-02 17:18:07.098674810 +0100\n@@ -36,11 +36,14 @@ EXTRA_DIST = autogen.sh autogen.rc READM\n \n DISTCLEANFILES =\n \n-bin_PROGRAMS = fipsdrv drbg_test\n+bin_PROGRAMS = fipsdrv drbg_test gcrypt_rsagtest\n \n fipsdrv_SOURCES = tests/fipsdrv.c\n fipsdrv_LDADD = src/libgcrypt.la $(DL_LIBS) $(GPG_ERROR_LIBS)\n \n+gcrypt_rsagtest_SOURCES = tests/gcrypt_rsagtest.c\n+gcrypt_rsagtest_LDADD = src/libgcrypt.la $(DL_LIBS)\n+\n drbg_test_CPPFLAGS = -I../src -I$(top_srcdir)/src\n drbg_test_SOURCES = src/gcrypt.h tests/drbg_test.c\n drbg_test_LDADD = src/libgcrypt.la $(DL_LIBS) $(GPG_ERROR_LIBS)\nIndex: libgcrypt-1.6.1/tests/gcrypt_rsagtest.c\n===================================================================\n--- /dev/null\t1970-01-01 00:00:00.000000000 +0000\n+++ libgcrypt-1.6.1/tests/gcrypt_rsagtest.c\t2015-02-02 17:15:29.458281349 +0100\n@@ -0,0 +1,332 @@\n+/* fips_rsagtest.c */\n+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL\n+ * project 2005.\n+ */\n+/* ====================================================================\n+ * Copyright (c) 2005,2007 The OpenSSL Project. All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ *\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ *\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in\n+ * the documentation and/or other materials provided with the\n+ * distribution.\n+ *\n+ * 3. All advertising materials mentioning features or use of this\n+ * software must display the following acknowledgment:\n+ * \"This product includes software developed by the OpenSSL Project\n+ * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)\"\n+ *\n+ * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n+ * endorse or promote products derived from this software without\n+ * prior written permission. For written permission, please contact\n+ * licensing@OpenSSL.org.\n+ *\n+ * 5. Products derived from this software may not be called \"OpenSSL\"\n+ * nor may \"OpenSSL\" appear in their names without prior written\n+ * permission of the OpenSSL Project.\n+ *\n+ * 6. Redistributions of any form whatsoever must retain the following\n+ * acknowledgment:\n+ * \"This product includes software developed by the OpenSSL Project\n+ * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)\"\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR\n+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n+ * OF THE POSSIBILITY OF SUCH DAMAGE.\n+ * ====================================================================\n+ *\n+ * This product includes cryptographic software written by Eric Young\n+ * (eay@cryptsoft.com). This product includes software written by Tim\n+ * Hudson (tjh@cryptsoft.com).\n+ *\n+ */\n+\n+#include <stdio.h>\n+#include <ctype.h>\n+#include <string.h>\n+#include <stdlib.h>\n+#include <unistd.h>\n+\n+int rsa_PrimeKAT(FILE *out, FILE *in);\n+\n+int main(int argc, char **argv)\n+\t{\n+\tFILE *in = NULL, *out = NULL;\n+\tconst char *cmd = argv[1];\n+\n+\tint ret = 1;\n+\n+\tif (!cmd)\n+\t\t{\n+\t\tfprintf(stderr, \"gcrypt_rsagtest [KeyGen|PrimeKAT|PrimeGen]\\n\");\n+\t\tgoto end;\n+\t\t}\n+\n+\tif (argc == 2)\n+\t\tin = stdin;\n+\telse\n+\t\tin = fopen(argv[2], \"r\");\n+\n+\tif (argc <= 3)\n+\t\tout = stdout;\n+\telse\n+\t\tout = fopen(argv[3], \"w\");\n+\n+\tif (!in)\n+\t\t{\n+\t\tfprintf(stderr, \"FATAL input initialization error\\n\");\n+\t\tgoto end;\n+\t\t}\n+\n+\tif (!out)\n+\t\t{\n+\t\tfprintf(stderr, \"FATAL output initialization error\\n\");\n+\t\tgoto end;\n+\t\t}\n+\n+\tif (!strcmp(cmd, \"PrimeKAT\"))\n+\t\tret = rsa_PrimeKAT(out, in);\n+\telse\n+\t\t{\n+\t\tfprintf(stderr, \"Unknown command %s\\n\", cmd);\n+\t\tgoto end;\n+\t\t}\n+\n+\tif (!ret)\n+\t\t{\n+\t\tfprintf(stderr, \"FATAL RSAGTEST file processing error in %s\\n\", cmd);\n+\t\tgoto end;\n+\t\t}\n+\n+\tend:\n+\n+\tif (in && (in != stdin))\n+\t\tfclose(in);\n+\tif (out && (out != stdout))\n+\t\tfclose(out);\n+\n+\treturn ret;\n+\n+\t}\n+\n+#define RSA_TEST_MAXLINELEN\t10240\n+\n+int do_prime_test(int mod, char *e, char *prandom, char *qrandom)\n+{\n+\tchar sexp[8192];\n+\tchar answer[1024];\n+\tchar fipsdrv[] = \"/usr/lib/libgcrypt/cavs/fipsdrv\";\n+\tint to[2];\n+\tint from[2];\n+\n+\tif (!qrandom)\n+\t\t{\n+\t\tqrandom = strdup(\"01\");\n+\t\t}\n+\n+\tint written = snprintf(sexp, 8192, \"(genkey(rsa(nbits 4:%d)(test-parms(e #%s#)(p #%s#)(q #%s#))))\\0\",\n+\t\tmod, e, prandom, qrandom);\n+\n+\tif (pipe(from) || pipe(to))\n+\t\t{\n+\t\tfprintf(stderr, \"Can't create pipe\\n\");\n+\t\treturn -1;\n+\t\t}\n+\n+\t/* fipsdrv expects the data from its standard input\n+\t * and we need to read its stdout, so we need to perform\n+\t * some pipe trickery */\n+\tswitch(fork())\n+\t\t{\n+\t\tcase -1:\n+\t\t\tfprintf(stderr, \"Can't fork\\n\");\n+\t\t\treturn -1;\n+\t\tcase 0: /* fipsdrv process */\n+\t\t\tclose(to[1]);\n+\t\t\tclose(from[0]);\n+\t\t\t/* set stdin and stdout to the correct pipes */\n+\t\t\tdup2(to[0], 0);\n+\t\t\tdup2(from[1], 1);\n+\t\t\texeclp(fipsdrv, fipsdrv, \"rsa-keygen-kat\", (char *)NULL);\n+\t\tdefault: /* parent collecting output from fipsdrv */\n+\t\t\tclose(from[1]);\n+\t\t\tclose(to[0]);\n+\t\t\t/* write the sexp to fipsdrv's input */\n+\t\t\twrite(to[1], sexp, written);\n+\t\t\tclose(to[1]);\n+\t\t\t/* read the fipsdrv's result */\n+\t\t\tread(from[0], answer, 1024);\n+\t\t\tclose(from[0]);\n+\n+\t\t\treturn !strcmp(answer, \"P\\n\");\n+\t\t}\n+}\n+\n+\n+int rsa_PrimeKAT(FILE *out, FILE *in)\n+\t{\n+\tchar *linebuf, *olinebuf, *p, *q;\n+\tchar *keyword, *value;\n+\tchar *prandom = NULL, *qrandom = NULL;\n+\tchar *e = NULL;\n+\tint mod = 0;\n+\tint result = 0;\n+\tint ret = 0;\n+\tint lnum = 0;\n+\n+\tolinebuf = malloc(RSA_TEST_MAXLINELEN);\n+\tlinebuf = malloc(RSA_TEST_MAXLINELEN);\n+\n+\tif (!linebuf || !olinebuf)\n+\t\tgoto error;\n+\n+\twhile (fgets(olinebuf, RSA_TEST_MAXLINELEN, in))\n+\t\t{\n+\t\t/* Test tool emits a 0xff at the end of the file */\n+\t\tif (((unsigned char*)olinebuf)[0] == 0xff)\n+\t\t\tbreak;\n+\t\tlnum++;\n+\t\tstrcpy(linebuf, olinebuf);\n+\t\tkeyword = linebuf;\n+\t\t/* Skip leading space */\n+\t\twhile (isspace((unsigned char)*keyword))\n+\t\t\tkeyword++;\n+\n+\t\t/* Look for = sign */\n+\t\tp = strchr(linebuf, '=');\n+\n+\t\t/* If no =, just copy */\n+\t\tif (!p)\n+\t\t\t{\n+\t\t\tfputs(olinebuf, out);\n+\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\tif (*keyword == '[')\n+\t\t\tkeyword++;\n+\n+\t\tq = p - 1;\n+\n+\t\t/* Remove trailing space */\n+\t\twhile (isspace((unsigned char)*q))\n+\t\t\t*q-- = 0;\n+\n+\t\t*p = 0;\n+\t\tvalue = p + 1;\n+\n+\t\t/* Remove leading space from value */\n+\t\twhile (isspace((unsigned char)*value))\n+\t\t\tvalue++;\n+\n+\t\t/* Remove trailing space from value */\n+\t\tp = value + strlen(value) - 1;\n+\n+\t\twhile (*p == '\\n' || isspace((unsigned char)*p))\n+\t\t\t*p-- = 0;\n+\t\t/* For [things], remove trailing ] and whitespace */\n+\t\tif (*linebuf == '[')\n+\t\t\t{\n+\t\t\t\twhile (isspace((unsigned char)*p) || *p == ']')\n+\t\t\t\t\t*p-- = 0;\n+\t\t\t}\n+\n+\t\t/* collected e, prandom and next thing is not qrandom -> trigger test */\n+\t\tif (e && prandom && (qrandom || strcmp(keyword, \"qrandom\")))\n+\t\t\t{\n+\t\t\t\tresult = do_prime_test(mod, e, prandom, qrandom);\n+\t\t\t\tfree(prandom);\n+\t\t\t\tfree(qrandom);\n+\t\t\t\tfree(e);\n+\t\t\t\tprandom = NULL;\n+\t\t\t\tqrandom = NULL;\n+\t\t\t\te = NULL;\n+\t\t\t\tif (result == -1)\n+\t\t\t\t\tgoto error;\n+\t\t\t\tfpri\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "Index: libgcrypt-1.6.1/Makefile.am\n===================================================================\n--- libgcrypt-1.6.1.orig/Makefile.am\t2015-02-02 17:15:29.429281092 +0100\n+++ libgcrypt-1.6.1/Makefile.am\t2015-02-02 17:18:07.098674810 +0100\n@@ -36,11 +36,14 @@ EXTRA_DIST = autogen.sh autogen.rc READM\n \n DISTCLEANFILES =\n \n-bin_PROGRAMS = fipsdrv drbg_test\n+bin_PROGRAMS = fipsdrv drbg_test gcrypt_rsagtest\n \n fipsdrv_SOURCES = tests/fipsdrv.c\n fipsdrv_LDADD = src/libgcrypt.la $(DL_LIBS) $(GPG_ERROR_LIBS)\n \n+gcrypt_rsagtest_SOURCES = tests/gcrypt_rsagtest.c\n+gcrypt_rsagtest_LDADD = src/libgcrypt.la $(DL_LIBS)\n+\n drbg_test_CPPFLAGS = -I../src -I$(top_srcdir)/src\n drbg_test_SOURCES = src/gcrypt.h tests/drbg_test.c\n drbg_test_LDADD = src/libgcrypt.la $(DL_LIBS) $(GPG_ERROR_LIBS)\nIndex: libgcrypt-1.6.1/tests/gcrypt_rsagtest.c\n===================================================================\n--- /dev/null\t1970-01-01 00:00:00.000000000 +0000\n+++ libgcrypt-1.6.1/tests/gcrypt_rsagtest.c\t2015-02-02 17:15:29.458281349 +0100\n@@ -0,0 +1,332 @@\n+/* fips_rsagtest.c */\n+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL\n+ * project 2005.\n+ */\n+/* ====================================================================\n+ * Copyright (c) 2005,2007 The OpenSSL Project. All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ *\n+ * 1. Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ *\n+ * 2. Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in\n+ * the documentation and/or other materials provided with the\n+ * distribution.\n+ *\n+ * 3. All advertising materials mentioning features or use of this\n+ * software must display the following acknowledgment:\n+ * \"This product includes software developed by the OpenSSL Project\n+ * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)\"\n+ *\n+ * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n+ * endorse or promote products derived from this software without\n+ * prior written permission. For written permission, please contact\n+ * licensing@OpenSSL.org.\n+ *\n+ * 5. Products derived from this software may not be called \"OpenSSL\"\n+ * nor may \"OpenSSL\" appear in their names without prior written\n+ * permission of the OpenSSL Project.\n+ *\n+ * 6. Redistributions of any form whatsoever must retain the following\n+ * acknowledgment:\n+ * \"This product includes software developed by the OpenSSL Project\n+ * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)\"\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR\n+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n+ * OF THE POSSIBILITY OF SUCH DAMAGE.\n+ * ====================================================================\n+ *\n+ * This product includes cryptographic software written by Eric Young\n+ * (eay@cryptsoft.com). This product includes software written by Tim\n+ * Hudson (tjh@cryptsoft.com).\n+ *\n+ */\n+\n+#include <stdio.h>\n+#include <ctype.h>\n+#include <string.h>\n+#include <stdlib.h>\n+#include <unistd.h>\n+\n+int rsa_PrimeKAT(FILE *out, FILE *in);\n+\n+int main(int argc, char **argv)\n+\t{\n+\tFILE *in = NULL, *out = NULL;\n+\tconst char *cmd = argv[1];\n+\n+\tint ret = 1;\n+\n+\tif (!cmd)\n+\t\t{\n+\t\tfprintf(stderr, \"gcrypt_rsagtest [KeyGen|PrimeKAT|PrimeGen]\\n\");\n+\t\tgoto end;\n+\t\t}\n+\n+\tif (argc == 2)\n+\t\tin = stdin;\n+\telse\n+\t\tin = fopen(argv[2], \"r\");\n+\n+\tif (argc <= 3)\n+\t\tout = stdout;\n+\telse\n+\t\tout = fopen(argv[3], \"w\");\n+\n+\tif (!in)\n+\t\t{\n+\t\tfprintf(stderr, \"FATAL input initialization error\\n\");\n+\t\tgoto end;\n+\t\t}\n+\n+\tif (!out)\n+\t\t{\n+\t\tfprintf(stderr, \"FATAL output initialization error\\n\");\n+\t\tgoto end;\n+\t\t}\n+\n+\tif (!strcmp(cmd, \"PrimeKAT\"))\n+\t\tret = rsa_PrimeKAT(out, in);\n+\telse\n+\t\t{\n+\t\tfprintf(stderr, \"Unknown command %s\\n\", cmd);\n+\t\tgoto end;\n+\t\t}\n+\n+\tif (!ret)\n+\t\t{\n+\t\tfprintf(stderr, \"FATAL RSAGTEST file processing error in %s\\n\", cmd);\n+\t\tgoto end;\n+\t\t}\n+\n+\tend:\n+\n+\tif (in && (in != stdin))\n+\t\tfclose(in);\n+\tif (out && (out != stdout))\n+\t\tfclose(out);\n+\n+\treturn ret;\n+\n+\t}\n+\n+#define RSA_TEST_MAXLINELEN\t10240\n+\n+int do_prime_test(int mod, char *e, char *prandom, char *qrandom)\n+{\n+\tchar sexp[8192];\n+\tchar answer[1024];\n+\tchar fipsdrv[] = \"/usr/lib/libgcrypt/cavs/fipsdrv\";\n+\tint to[2];\n+\tint from[2];\n+\n+\tif (!qrandom)\n+\t\t{\n+\t\tqrandom = strdup(\"01\");\n+\t\t}\n+\n+\tint written = snprintf(sexp, 8192, \"(genkey(rsa(nbits 4:%d)(test-parms(e #%s#)(p #%s#)(q #%s#))))\\0\",\n+\t\tmod, e, prandom, qrandom);\n+\n+\tif (pipe(from) || pipe(to))\n+\t\t{\n+\t\tfprintf(stderr, \"Can't create pipe\\n\");\n+\t\treturn -1;\n+\t\t}\n+\n+\t/* fipsdrv expects the data from its standard input\n+\t * and we need to read its stdout, so we need to perform\n+\t * some pipe trickery */\n+\tswitch(fork())\n+\t\t{\n+\t\tcase -1:\n+\t\t\tfprintf(stderr, \"Can't fork\\n\");\n+\t\t\treturn -1;\n+\t\tcase 0: /* fipsdrv process */\n+\t\t\tclose(to[1]);\n+\t\t\tclose(from[0]);\n+\t\t\t/* set stdin and stdout to the correct pipes */\n+\t\t\tdup2(to[0], 0);\n+\t\t\tdup2(from[1], 1);\n+\t\t\texeclp(fipsdrv, fipsdrv, \"rsa-keygen-kat\", (char *)NULL);\n+\t\tdefault: /* parent collecting output from fipsdrv */\n+\t\t\tclose(from[1]);\n+\t\t\tclose(to[0]);\n+\t\t\t/* write the sexp to fipsdrv's input */\n+\t\t\twrite(to[1], sexp, written);\n+\t\t\tclose(to[1]);\n+\t\t\t/* read the fipsdrv's result */\n+\t\t\tread(from[0], answer, 1024);\n+\t\t\tclose(from[0]);\n+\n+\t\t\treturn !strcmp(answer, \"P\\n\");\n+\t\t}\n+}\n+\n+\n+int rsa_PrimeKAT(FILE *out, FILE *in)\n+\t{\n+\tchar *linebuf, *olinebuf, *p, *q;\n+\tchar *keyword, *value;\n+\tchar *prandom = NULL, *qrandom = NULL;\n+\tchar *e = NULL;\n+\tint mod = 0;\n+\tint result = 0;\n+\tint ret = 0;\n+\tint lnum = 0;\n+\n+\tolinebuf = malloc(RSA_TEST_MAXLINELEN);\n+\tlinebuf = malloc(RSA_TEST_MAXLINELEN);\n+\n+\tif (!linebuf || !olinebuf)\n+\t\tgoto error;\n+\n+\twhile (fgets(olinebuf, RSA_TEST_MAXLINELEN, in))\n+\t\t{\n+\t\t/* Test tool emits a 0xff at the end of the file */\n+\t\tif (((unsigned char*)olinebuf)[0] == 0xff)\n+\t\t\tbreak;\n+\t\tlnum++;\n+\t\tstrcpy(linebuf, olinebuf);\n+\t\tkeyword = linebuf;\n+\t\t/* Skip leading space */\n+\t\twhile (isspace((unsigned char)*keyword))\n+\t\t\tkeyword++;\n+\n+\t\t/* Look for = sign */\n+\t\tp = strchr(linebuf, '=');\n+\n+\t\t/* If no =, just copy */\n+\t\tif (!p)\n+\t\t\t{\n+\t\t\tfputs(olinebuf, out);\n+\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\tif (*keyword == '[')\n+\t\t\tkeyword++;\n+\n+\t\tq = p - 1;\n+\n+\t\t/* Remove trailing space */\n+\t\twhile (isspace((unsigned char)*q))\n+\t\t\t*q-- = 0;\n+\n+\t\t*p = 0;\n+\t\tvalue = p + 1;\n+\n+\t\t/* Remove leading space from value */\n+\t\twhile (isspace((unsigned char)*value))\n+\t\t\tvalue++;\n+\n+\t\t/* Remove trailing space from value */\n+\t\tp = value + strlen(value) - 1;\n+\n+\t\twhile (*p == '\\n' || isspace((unsigned char)*p))\n+\t\t\t*p-- = 0;\n+\t\t/* For [things], remove trailing ] and whitespace */\n+\t\tif (*linebuf == '[')\n+\t\t\t{\n+\t\t\t\twhile (isspace((unsigned char)*p) || *p == ']')\n+\t\t\t\t\t*p-- = 0;\n+\t\t\t}\n+\n+\t\t/* collected e, prandom and next thing is not qrandom -> trigger test */\n+\t\tif (e && prandom && (qrandom || strcmp(keyword, \"qrandom\")))\n+\t\t\t{\n+\t\t\t\tresult = do_prime_test(mod, e, prandom, qrandom);\n+\t\t\t\tfree(prandom);\n+\t\t\t\tfree(qrandom);\n+\t\t\t\tfree(e);\n+\t\t\t\tprandom = NULL;\n+\t\t\t\tqrandom = NULL;\n+\t\t\t\te = NULL;\n+\t\t\t\tif (result == -1)\n+\t\t\t\t\tgoto error;\n+\t\t\t\tfprintf(out, \"Result = %c\\n\\n\", result ? 'P' : 'F');\n+\t\t\t}\n+\n+\t\tif (!strcmp(keyword, \"mod\"))\n+\t\t\t{\n+\t\t\tmod = atoi(value);\n+\t\t\tif (!mod)\n+\t\t\t\tgoto parse_error;\n+\t\t\t}\n+\t\telse if (!strcmp(keyword, \"prandom\"))\n+\t\t\t{\n+\t\t\tif (prandom || !(prandom = strdup(value)))\n+\t\t\t\tgoto parse_error;\n+\t\t\t}\n+\t\telse if (!strcmp(keyword, \"qrandom\"))\n+\t\t\t{\n+\t\t\tif (qrandom || !(qrandom = strdup(value)))\n+\t\t\t\tgoto parse_error;\n+\t\t\t}\n+\t\telse if (!strcmp(keyword, \"e\"))\n+\t\t\t{\n+\t\t\tif (!(e = strdup(value)))\n+\t\t\t\tgoto parse_error;\n+\t\t\t}\n+\t\telse if (*linebuf == '[')\n+\t\t\t{\n+\t\t\t/* just copy */\n+\t\t\t}\n+\t\telse\n+\t\t\tgoto parse_error;\n+\n+\t\tfputs(olinebuf, out);\n+\n+\t\t}\n+\n+\t/* trigger last test -- the test should be abstracted out into a function */\n+\tif (e && prandom)\n+\t\t{\n+\t\t\tresult = do_prime_test(mod, e, prandom, qrandom);\n+\t\t\tfree(e);\n+\t\t\tprandom = NULL;\n+\t\t\tqrandom = NULL;\n+\t\t\te = NULL;\n+\t\t\tif (result == -1)\n+\t\t\t\tgoto error;\n+\t\t\tfprintf(out, \"Result = %c\\n\\n\", result ? 'P' : 'F');\n+\t\t}\n+\n+\tret = 1;\n+\n+\terror:\n+\n+\tif (olinebuf)\n+\t\tfree(olinebuf);\n+\tif (linebuf)\n+\t\tfree(linebuf);\n+\n+\tif (prandom)\n+\t\tfree(prandom);\n+\tif (qrandom)\n+\t\tfree(qrandom);\n+\tif (e)\n+\t\tfree(e);\n+\n+\treturn ret;\n+\n+\tparse_error:\n+\n+\tfprintf(stderr, \"FATAL parse error processing line %d\\n\", lnum);\n+\n+\tgoto error;\n+\n+\t}" } ]
{ "id": "libgcrypt-4975-libgcrypt-fips_KAT_keygen_test", "cve_id": "CVE-2015-7511", "package": "libgcrypt", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": true, "license": "GPL-2.0-or-later AND LGPL-2.1-or-later AND GPL-3.0-or-later", "context_tokens_est": 376, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2013-4288\n\nRace condition in PolicyKit (aka polkit) allows local users to bypass intended PolicyKit restrictions and gain privileges by starting a setuid or pkexec process before the authorization check is performed, related to (1) the polkit_unix_process_new API function, (2) the dbus API, or (3) the --process (unix-process) option for authorization to pkcheck.\n\n## Package\nsystemd-mini\n\n## Files to modify\n- systemd-195.orig/src/login/logind.c\n- src/login/logind.c\n\n## Target Source Code\n\n### src/login/71-seat.rules.in\n\n#### region() [lines 1-49]\n```c\n# This file is part of systemd.\n#\n# systemd is free software; you can redistribute it and/or modify it\n# under the terms of the GNU Lesser General Public License as published by\n# the Free Software Foundation; either version 2.1 of the License, or\n# (at your option) any later version.\n\nACTION==\"remove\", GOTO=\"seat_end\"\n\nTAG==\"uaccess\", SUBSYSTEM!=\"sound\", TAG+=\"seat\"\nSUBSYSTEM==\"sound\", KERNEL==\"card*\", TAG+=\"seat\"\nSUBSYSTEM==\"input\", KERNEL==\"input*\", TAG+=\"seat\"\nSUBSYSTEM==\"graphics\", KERNEL==\"fb[0-9]*\", TAG+=\"seat\"\nSUBSYSTEM==\"usb\", ATTR{bDeviceClass}==\"09\", TAG+=\"seat\"\n\n# 'Plugable' USB hub, sound, network, graphics adapter\nSUBSYSTEM==\"usb\", ATTR{idVendor}==\"2230\", ATTR{idProduct}==\"000[13]\", ENV{ID_AUTOSEAT}=\"1\"\n\n# Mimo 720, with integrated USB hub, displaylink graphics, and e2i\n# touchscreen. This device carries no proper VID/PID in the USB hub,\n# but it does carry good ID data in the graphics component, hence we\n# check it from the parent. There's a bit of a race here however,\n# given that the child devices might not exist yet at the time this\n# rule is executed. To work around this we'll trigger the parent from\n# the child if we notice that the parent wasn't recognized yet.\n\n# Match parent\nSUBSYSTEM==\"usb\", ATTR{idVendor}==\"058f\", ATTR{idProduct}==\"6254\", \\\n ATTR{%k.2/idVendor}==\"17e9\", ATTR{%k.2/idProduct}==\"401a\", ATTR{%k.2/product}==\"mimo inc\", \\\n ENV{ID_AUTOSEAT}=\"1\", ENV{ID_AVOID_LOOP}=\"1\"\n\n# Match child, look for parent's ID_AVOID_LOOP\nSUBSYSTEM==\"usb\", ATTR{idVendor}==\"17e9\", ATTR{idProduct}==\"401a\", ATTR{product}==\"mimo inc\", \\\n ATTR{../idVendor}==\"058f\", ATTR{../idProduct}==\"6254\", \\\n IMPORT{parent}=\"ID_AVOID_LOOP\"\n\n# Match child, retrigger parent\nSUBSYSTEM==\"usb\", ATTR{idVendor}==\"17e9\", ATTR{idProduct}==\"401a\", ATTR{product}==\"mimo inc\", \\\n ATTR{../idVendor}==\"058f\", ATTR{../idProduct}==\"6254\", \\\n ENV{ID_AVOID_LOOP}==\"\", \\\n RUN+=\"@bindir@/udevadm trigger --parent-match=%p/..\"\n\nTAG==\"seat\", ENV{ID_PATH}==\"\", IMPORT{builtin}=\"path_id\"\nTAG==\"seat\", ENV{ID_FOR_SEAT}==\"\", ENV{ID_PATH_TAG}!=\"\", ENV{ID_FOR_SEAT}=\"$env{SUBSYSTEM}-$env{ID_PATH_TAG}\"\n\nSUBSYSTEM==\"input\", ATTR{name}==\"Wiebetech LLC Wiebetech\", RUN+=\"@rootbindir@/loginctl lock-sessions\"\n\nLABEL=\"seat_end\"\n\n```\n\n### src/login/logind.c\n\n#### manager_enumerate_devices() [lines 434-490]\n```c\n return 0;\n}\n\nint manager_enumerate_devices(Manager *m) {\n struct udev_list_entry *item = NULL, *first = NULL;\n struct udev_enumerate *e;\n int r;\n\n assert(m);\n\n /* Loads devices from udev and creates seats for them as\n * necessary */\n\n e = udev_enumerate_new(m->udev);\n if (!e) {\n r = -ENOMEM;\n goto finish;\n }\n\n r = udev_enumerate_add_match_subsystem(e, \"graphics\");\n if (r < 0)\n goto finish;\n\n r = udev_enumerate_add_match_tag(e, \"seat\");\n if (r < 0)\n goto finish;\n\n r = udev_enumerate_scan_devices(e);\n if (r < 0)\n goto finish;\n\n first = udev_enumerate_get_list_entry(e);\n udev_list_entry_foreach(item, first) {\n struct udev_device *d;\n int k;\n\n d = udev_device_new_from_syspath(m->udev, udev_list_entry_get_name(item));\n if (!d) {\n r = -ENOMEM;\n goto finish;\n }\n\n k = manager_process_seat_device(m, d);\n udev_device_unref(d);\n\n if (k < 0)\n r = k;\n }\n\nfinish:\n if (e)\n udev_enumerate_unref(e);\n\n return r;\n}\n\nint manager_enumerate_buttons(Manager *m) {\n```\n\n#### manager_connect_udev() [lines 1273-1367]\n```c\n return 0;\n}\n\nstatic int manager_connect_udev(Manager *m) {\n struct epoll_event ev;\n int r;\n\n assert(m);\n assert(!m->udev_seat_monitor);\n assert(!m->udev_vcsa_monitor);\n assert(!m->udev_button_monitor);\n\n m->udev_seat_monitor = udev_monitor_new_from_netlink(m->udev, \"udev\");\n if (!m->udev_seat_monitor)\n return -ENOMEM;\n\n r = udev_monitor_filter_add_match_tag(m->udev_seat_monitor, \"seat\");\n if (r < 0)\n return r;\n\n r = udev_monitor_filter_add_match_subsystem_devtype(m->udev_seat_monitor, \"graphics\", NULL);\n if (r < 0)\n return r;\n\n r = udev_monitor_enable_receiving(m->udev_seat_monitor);\n if (r < 0)\n return r;\n\n m->udev_seat_fd = udev_monitor_get_fd(m->udev_seat_monitor);\n\n zero(ev);\n ev.events = EPOLLIN;\n ev.data.u32 = FD_SEAT_UDEV;\n if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->udev_seat_fd, &ev) < 0)\n return -errno;\n\n /* Don't watch keys if nobody cares */\n if (m->handle_power_key != HANDLE_IGNORE ||\n m->handle_suspend_key != HANDLE_IGNORE ||\n m->handle_hibernate_key != HANDLE_IGNORE ||\n m->handle_lid_switch != HANDLE_IGNORE) {\n\n m->udev_button_monitor = udev_monitor_new_from_netlink(m->udev, \"udev\");\n if (!m->udev_button_monitor)\n return -ENOMEM;\n\n r = udev_monitor_filter_add_match_tag(m->udev_button_monitor, \"power-switch\");\n if (r < 0)\n return r;\n\n r = udev_monitor_filter_add_match_subsystem_devtype(m->udev_button_monitor, \"input\", NULL);\n if (r < 0)\n return r;\n\n r = udev_monitor_enable_receiving(m->udev_button_monitor);\n if (r < 0)\n return r;\n\n m->udev_button_fd = udev_monitor_get_fd(m->udev_button_monitor);\n\n zero(ev);\n ev.events = EPOLLIN;\n ev.data.u32 = FD_BUTTON_UDEV;\n if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->udev_button_fd, &ev) < 0)\n return -errno;\n }\n\n /* Don't bother watching VCSA devices, if nobody cares */\n if (m->n_autovts > 0 && m->console_active_fd >= 0) {\n\n m->udev_vcsa_monitor = udev_monitor_new_from_netlink(m->udev, \"udev\");\n if (!m->udev_vcsa_monitor)\n return -ENOMEM;\n\n r = udev_monitor_filter_add_match_subsystem_devtype(m->udev_vcsa_monitor, \"vc\", NULL);\n if (r < 0)\n return r;\n\n r = udev_monitor_enable_receiving(m->udev_vcsa_monitor);\n if (r < 0)\n return r;\n\n m->udev_vcsa_fd = udev_monitor_get_fd(m->udev_vcsa_monitor);\n\n zero(ev);\n ev.events = EPOLLIN;\n ev.data.u32 = FD_VCSA_UDEV;\n if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->udev_vcsa_fd, &ev) < 0)\n return -errno;\n }\n\n return 0;\n}\n\nvoid manager_gc(Manager *m, bool drop_not_started) {\n```\n\n\n## Upstream Fix\n```diff\nFrom 955f9bde9ba6d9f0a7364d5cb7c0cee951d5caab Mon Sep 17 00:00:00 2001\nFrom: Oleg Samarin <osamarin68@gmail.com>\nDate: Sat, 5 Jan 2013 20:33:37 +0400\nSubject: [PATCH] logind: Capability of making seats without framebuffer\n devices\n\nfile logind.c: The seat is now activated by any device with udev tag \"seat-master\"\nfile 71-seat.rules.in: All framebuffer devices have this tag\n---\n src/login/71-seat.rules.in | 2 +-\n src/login/logind.c | 12 ++----------\n 2 files changed, 3 insertions(+), 11 deletions(-)\n\ndiff --git a/src/login/71-seat.rules.in b/src/login/71-seat.rules.in\nindex f554d7f6151b8..4f1a9a59a1fef 100644\n--- a/src/login/71-seat.rules.in\n+++ b/src/login/71-seat.rules.in\n@@ -10,7 +10,7 @@ ACTION==\"remove\", GOTO=\"seat_end\"\n TAG==\"uaccess\", SUBSYSTEM!=\"sound\", TAG+=\"seat\"\n SUBSYSTEM==\"sound\", KERNEL==\"card*\", TAG+=\"seat\"\n SUBSYSTEM==\"input\", KERNEL==\"input*\", TAG+=\"seat\"\n-SUBSYSTEM==\"graphics\", KERNEL==\"fb[0-9]*\", TAG+=\"seat\"\n+SUBSYSTEM==\"graphics\", KERNEL==\"fb[0-9]*\", TAG+=\"seat\", TAG+=\"seat-master\"\n SUBSYSTEM==\"usb\", ATTR{bDeviceClass}==\"09\", TAG+=\"seat\"\n \n # 'Plugable' USB hub, sound, network, graphics adapter\ndiff --git a/src/login/logind.c b/src/login/logind.c\nindex 6438631b594c1..6776229ee7b66 100644\n--- a/src/login/logind.c\n+++ b/src/login/logind.c\n@@ -459,11 +459,7 @@ int manager_enumerate_devices(Manager *m) {\n goto finish;\n }\n \n- r = udev_enumerate_add_match_subsystem(e, \"graphics\");\n- if (r < 0)\n- goto finish;\n-\n- r = udev_enumerate_add_match_tag(e, \"seat\");\n+ r = udev_enumerate_add_match_tag(e, \"seat-master\");\n if (r < 0)\n goto finish;\n \n@@ -1295,11 +1291,7 @@ static int manager_connect_udev(Manager *m) {\n if (!m->udev_seat_monitor)\n return -ENOMEM;\n \n- r = udev_monitor_filter_add_match_tag(m->udev_seat_monitor, \"seat\");\n- if (r < 0)\n- return r;\n-\n- r = udev_monitor_filter_add_match_subsystem_devtype(m->udev_seat_monitor, \"graphics\", NULL);\n+ r = udev_monitor_filter_add_match_tag(m->udev_seat_monitor, \"seat-master\");\n if (r < 0)\n return r;\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 955f9bde9ba6d9f0a7364d5cb7c0cee951d5caab Mon Sep 17 00:00:00 2001\nFrom: Oleg Samarin <osamarin68@gmail.com>\nDate: Sat, 5 Jan 2013 20:33:37 +0400\nSubject: [PATCH] logind: Capability of making seats without framebuffer\n devices\n\nfile logind.c: The seat is now activated by any device with udev tag \"seat-master\"\nfile 71-seat.rules.in: All framebuffer devices have this tag\n---\n src/login/71-seat.rules.in | 2 +-\n src/login/logind.c | 12 ++----------\n 2 files changed, 3 insertions(+), 11 deletions(-)\n\nIndex: systemd-195/src/login/71-seat.rules.in\n===================================================================\n--- systemd-195.orig/src/login/71-seat.rules.in\n+++ systemd-195/src/login/71-seat.rules.in\n@@ -10,7 +10,7 @@ ACTION==\"remove\", GOTO=\"seat_end\"\n TAG==\"uaccess\", SUBSYSTEM!=\"sound\", TAG+=\"seat\"\n SUBSYSTEM==\"sound\", KERNEL==\"card*\", TAG+=\"seat\"\n SUBSYSTEM==\"input\", KERNEL==\"input*\", TAG+=\"seat\"\n-SUBSYSTEM==\"graphics\", KERNEL==\"fb[0-9]*\", TAG+=\"seat\"\n+SUBSYSTEM==\"graphics\", KERNEL==\"fb[0-9]*\", TAG+=\"seat\", TAG+=\"seat-master\"\n SUBSYSTEM==\"usb\", ATTR{bDeviceClass}==\"09\", TAG+=\"seat\"\n \n # 'Plugable' USB hub, sound, network, graphics adapter\nIndex: systemd-195/src/login/logind.c\n===================================================================\n--- systemd-195.orig/src/login/logind.c\n+++ systemd-195/src/login/logind.c\n@@ -450,11 +450,7 @@ int manager_enumerate_devices(Manager *m\n goto finish;\n }\n \n- r = udev_enumerate_add_match_subsystem(e, \"graphics\");\n- if (r < 0)\n- goto finish;\n-\n- r = udev_enumerate_add_match_tag(e, \"seat\");\n+ r = udev_enumerate_add_match_tag(e, \"seat-master\");\n if (r < 0)\n goto finish;\n \n@@ -1286,11 +1282,7 @@ static int manager_connect_udev(Manager\n if (!m->udev_seat_monitor)\n return -ENOMEM;\n \n- r = udev_monitor_filter_add_match_tag(m->udev_seat_monitor, \"seat\");\n- if (r < 0)\n- return r;\n-\n- r = udev_monitor_filter_add_match_subsystem_devtype(m->udev_seat_monitor, \"graphics\", NULL);\n+ r = udev_monitor_filter_add_match_tag(m->udev_seat_monitor, \"seat-master\");\n if (r < 0)\n return r;" } ]
{ "id": "systemd-mini-2025-logind-capability-making-seats", "cve_id": "CVE-2013-4288", "package": "systemd-mini", "upstream_enriched": true, "upstream_commit": "955f9bde9ba6d9f0a7364d5cb7c0cee951d5caab", "upstream_repo": "systemd/systemd", "tier": "adapted", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 1799, "context_files": 2 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2013-0221\n\nThe SUSE coreutils-i18n.patch for GNU coreutils allows context-dependent attackers to cause a denial of service (segmentation fault and crash) via a long string to the sort command, when using the (1) -d or (2) -M switch, which triggers a stack-based buffer overflow in the alloca function.\n\n## Package\ncoreutils\n\n## Files to modify\n- gnulib-tests/test-getaddrinfo.c\n\n## Upstream Fix\n```diff\nIndex: gnulib-tests/test-getaddrinfo.c\n===================================================================\n--- gnulib-tests/test-getaddrinfo.c.orig\t2012-04-16 13:18:02.424819645 +0200\n+++ gnulib-tests/test-getaddrinfo.c\t2012-04-16 13:18:07.737692228 +0200\n@@ -86,11 +86,7 @@ simple (char const *host, char const *se\n the test merely because someone is down the country on their\n in-law's farm. */\n if (res == EAI_AGAIN)\n- {\n- skip++;\n- fprintf (stderr, \"skipping getaddrinfo test: no network?\\n\");\n- return 77;\n- }\n+ return 0;\n /* IRIX reports EAI_NONAME for \"https\". Don't fail the test\n merely because of this. */\n if (res == EAI_NONAME)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "Index: gnulib-tests/test-getaddrinfo.c\n===================================================================\n--- gnulib-tests/test-getaddrinfo.c.orig\t2012-04-16 13:18:02.424819645 +0200\n+++ gnulib-tests/test-getaddrinfo.c\t2012-04-16 13:18:07.737692228 +0200\n@@ -86,11 +86,7 @@ simple (char const *host, char const *se\n the test merely because someone is down the country on their\n in-law's farm. */\n if (res == EAI_AGAIN)\n- {\n- skip++;\n- fprintf (stderr, \"skipping getaddrinfo test: no network?\\n\");\n- return 77;\n- }\n+ return 0;\n /* IRIX reports EAI_NONAME for \"https\". Don't fail the test\n merely because of this. */\n if (res == EAI_NONAME)" } ]
{ "id": "coreutils-1251-coreutils-getaddrinfo.patch", "cve_id": "CVE-2013-0221", "package": "coreutils", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": false, "license": "GPL-3.0-or-later", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2013-5653\n\nThe getenv and filenameforall functions in Ghostscript 9.10 ignore the \"-dSAFER\" argument, which allows remote attackers to read data via a crafted postscript file.\n\n## Package\nghostscript\n\n## Files to modify\n- ghostscript-9.15.orig/psi/zfile.c\n\n## Upstream Fix\n```diff\nFrom ab109aaeb3ddba59518b036fb288402a65cf7ce8 Mon Sep 17 00:00:00 2001\nFrom: Chris Liddell <chris.liddell@artifex.com>\nDate: Sat, 5 Mar 2016 14:56:03 -0800\nSubject: [PATCH] Bug 694724: Have filenameforall and getenv honor SAFER\n\n---\n Resource/Init/gs_init.ps | Bin 78437 -> 78515 bytes\n psi/zfile.c | 36 ++++++++++++++++++++----------------\n 2 files changed, 20 insertions(+), 16 deletions(-)\n\ndiff --git a/Resource/Init/gs_init.ps b/Resource/Init/gs_init.ps\nindex fa33d886bff989ac9fe5a6c2b33b57e5677fa07b..99888acaa31e7d21494105121c96e58686fa1ee5 100644\nGIT binary patch\ndelta 103\nzcmaF*gk|$nmWC~iSA<oHD~n4~b5k;tOBD3eQ%h3w$`q;#@(UF7_0tk_ic@P93Q9}1\nUUle8(WhPo_D&uw!2}W5d063B*=Kufz\n\ndelta 29\njcmdn|l;!CYmWC~iSA@5lh%+WJZjTjZ+`tH8*GmHcxxETx\n\ndiff --git a/psi/zfile.c b/psi/zfile.c\nindex 320ecd500c..0b9f29949c 100644\n--- a/psi/zfile.c\n+++ b/psi/zfile.c\n@@ -371,22 +371,26 @@ file_continue(i_ctx_t *i_ctx_p)\n \n if (len < devlen)\n return_error(gs_error_rangecheck); /* not even room for device len */\n- memcpy((char *)pscratch->value.bytes, iodev->dname, devlen);\n- code = iodev->procs.enumerate_next(pfen, (char *)pscratch->value.bytes + devlen,\n- len - devlen);\n- if (code == ~(uint) 0) { /* all done */\n- esp -= 5; /* pop proc, pfen, devlen, iodev , mark */\n- return o_pop_estack;\n- } else if (code > len) /* overran string */\n- return_error(gs_error_rangecheck);\n- else {\n- push(1);\n- ref_assign(op, pscratch);\n- r_set_size(op, code + devlen);\n- push_op_estack(file_continue); /* come again */\n- *++esp = pscratch[2]; /* proc */\n- return o_push_estack;\n- }\n+\n+ do {\n+ memcpy((char *)pscratch->value.bytes, iodev->dname, devlen);\n+ code = iodev->procs.enumerate_next(pfen, (char *)pscratch->value.bytes + devlen,\n+ len - devlen);\n+ if (code == ~(uint) 0) { /* all done */\n+ esp -= 5; /* pop proc, pfen, devlen, iodev , mark */\n+ return o_pop_estack;\n+ } else if (code > len) /* overran string */\n+ return_error(gs_error_rangecheck);\n+ else if (iodev != iodev_default(imemory)\n+ || (check_file_permissions_reduced(i_ctx_p, (char *)pscratch->value.bytes, code + devlen, \"PermitFileReading\")) == 0) {\n+ push(1);\n+ ref_assign(op, pscratch);\n+ r_set_size(op, code + devlen);\n+ push_op_estack(file_continue); /* come again */\n+ *++esp = pscratch[2]; /* proc */\n+ return o_push_estack;\n+ }\n+ } while(1);\n }\n /* Cleanup procedure for enumerating files */\n static int\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From ab109aaeb3ddba59518b036fb288402a65cf7ce8 Mon Sep 17 00:00:00 2001\nFrom: Chris Liddell <chris.liddell@artifex.com>\nDate: Sat, 5 Mar 2016 14:56:03 -0800\nSubject: [PATCH] Bug 694724: Have filenameforall and getenv honor SAFER\n\nCVE-2013-5653\n---\n Resource/Init/gs_init.ps | 2 ++\n psi/zfile.c | 36 ++++++++++++++++++++----------------\n 2 files changed, 22 insertions(+), 16 deletions(-)\n--- ghostscript-9.15.orig/Resource/Init/gs_init.ps\t2016-10-08 21:27:33.159836244 +0200\n+++ ghostscript-9.15.orig/Resource/Init/gs_init.ps\t2016-10-08 21:27:34.755859833 +0200\n@@ -2021,6 +2021,7 @@ readonly def\n \n /.locksafe {\n .locksafe_userparams\n+ systemdict /getenv {pop //false} put\n % setpagedevice has the side effect of clearing the page, but\n % we will just document that. Using setpagedevice keeps the device\n % properties and pagedevice .LockSafetyParams in agreement even\n@@ -2039,6 +2040,7 @@ readonly def\n %%\n /.locksafeglobal {\n .locksafe_userparams\n+ systemdict /getenv {pop //false} put\n % setpagedevice has the side effect of clearing the page, but\n % we will just document that. Using setpagedevice keeps the device\n % properties and pagedevice .LockSafetyParams in agreement even\n--- ghostscript-9.15.orig/psi/zfile.c\t2016-10-08 21:27:34.759859892 +0200\n+++ ghostscript-9.15.orig/psi/zfile.c\t2016-10-08 21:28:59.229108366 +0200\n@@ -371,22 +371,26 @@ file_continue(i_ctx_t *i_ctx_p)\n \n if (len < devlen)\n return_error(e_rangecheck); /* not even room for device len */\n- memcpy((char *)pscratch->value.bytes, iodev->dname, devlen);\n- code = iodev->procs.enumerate_next(pfen, (char *)pscratch->value.bytes + devlen,\n- len - devlen);\n- if (code == ~(uint) 0) { /* all done */\n- esp -= 5; /* pop proc, pfen, devlen, iodev , mark */\n- return o_pop_estack;\n- } else if (code > len) /* overran string */\n- return_error(e_rangecheck);\n- else {\n- push(1);\n- ref_assign(op, pscratch);\n- r_set_size(op, code + devlen);\n- push_op_estack(file_continue); /* come again */\n- *++esp = pscratch[2]; /* proc */\n- return o_push_estack;\n- }\n+\n+ do {\n+ memcpy((char *)pscratch->value.bytes, iodev->dname, devlen);\n+ code = iodev->procs.enumerate_next(pfen, (char *)pscratch->value.bytes + devlen,\n+ len - devlen);\n+ if (code == ~(uint) 0) { /* all done */\n+ esp -= 5; /* pop proc, pfen, devlen, iodev , mark */\n+ return o_pop_estack;\n+ } else if (code > len) /* overran string */\n+ return_error(gs_error_rangecheck);\n+ else if (iodev != iodev_default(imemory)\n+ || (check_file_permissions_reduced(i_ctx_p, (char *)pscratch->value.bytes, code + devlen, \"PermitFileReading\")) == 0) {\n+ push(1);\n+ ref_assign(op, pscratch);\n+ r_set_size(op, code + devlen);\n+ push_op_estack(file_continue); /* come again */\n+ *++esp = pscratch[2]; /* proc */\n+ return o_push_estack;\n+ }\n+ } while(1);\n }\n /* Cleanup procedure for enumerating files */\n static int" } ]
{ "id": "ghostscript-5881-CVE-2013-5653.patch", "cve_id": "CVE-2013-5653", "package": "ghostscript", "upstream_enriched": true, "upstream_commit": "ab109aaeb3ddba59518b036fb288402a65cf7ce8", "upstream_repo": "ArtifexSoftware/ghostpdl", "tier": "adapted", "has_source_context": false, "license": "AGPL-3.0-only", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-7511\n\nLibgcrypt before 1.6.5 does not properly perform elliptic-point curve multiplication during decryption, which makes it easier for physically proximate attackers to extract ECDH keys by measuring electromagnetic emanations.\n\n## Package\nlibgcrypt\n\n## Files to modify\n- src/global.c\n- src/fips.c\n- libgcrypt-1.6.1.orig/src/global.c\n- libgcrypt-1.6.1.orig/src/fips.c\n\n## Target Source Code\n\n### src/global.c\n\n#### global_init() [lines 77-134]\n```c\n application to make sure that this has been called is by using\n gcry_check_version. */\nstatic void\nglobal_init (void)\n{\n gcry_error_t err = 0;\n\n if (any_init_done)\n return;\n any_init_done = 1;\n\n /* Tell the random module that we have seen an init call. */\n _gcry_set_preferred_rng_type (0);\n\n /* Initialize our portable thread/mutex wrapper. */\n err = ath_init ();\n if (err)\n {\n err = gpg_error_from_errno (err);\n goto fail;\n }\n\n /* See whether the system is in FIPS mode. This needs to come as\n early as possible but after ATH has been initialized. */\n _gcry_initialize_fips_mode (force_fips_mode);\n\n /* Before we do any other initialization we need to test available\n hardware features. */\n _gcry_detect_hw_features ();\n\n /* Initialize the modules - this is mainly allocating some memory and\n creating mutexes. */\n err = _gcry_cipher_init ();\n if (err)\n goto fail;\n err = _gcry_md_init ();\n if (err)\n goto fail;\n err = _gcry_pk_init ();\n if (err)\n goto fail;\n err = _gcry_primegen_init ();\n if (err)\n goto fail;\n err = _gcry_secmem_module_init ();\n if (err)\n goto fail;\n err = _gcry_mpi_init ();\n if (err)\n goto fail;\n\n return;\n\n fail:\n BUG ();\n}\n\n\n```\n\n### src/fips.c\n\n#### get_library_path() [lines 603-655]\n```c\n else\n {\n fname = gcry_malloc (strlen (info.dli_fname) + 1 + 5 + 1 );\n if (!fname)\n err = gpg_error_from_syserror ();\n else\n {\n FILE *fp;\n char *p;\n\n /* Prefix the basename with a dot. */\n strcpy (fname, info.dli_fname);\n p = strrchr (fname, '/');\n if (p)\n p++;\n else\n p = fname;\n memmove (p+1, p, strlen (p)+1);\n *p = '.';\n strcat (fname, \".hmac\");\n\n /* Open the file. */\n fp = fopen (fname, \"r\");\n if (!fp)\n err = gpg_error_from_syserror ();\n else\n {\n /* A buffer of 64 bytes plus one for a LF and one to\n detect garbage. */\n unsigned char buffer[64+1+1];\n const unsigned char *s;\n int n;\n\n /* The HMAC files consists of lowercase hex digits\n only with an optional trailing linefeed. Fail if\n there is any garbage. */\n err = gpg_error (GPG_ERR_SELFTEST_FAILED);\n n = fread (buffer, 1, sizeof buffer, fp);\n if (n == 64 || (n == 65 && buffer[64] == '\\n'))\n {\n buffer[64] = 0;\n for (n=0, s= buffer;\n n < 32 && loxdigit_p (s) && loxdigit_p (s+1);\n n++, s += 2)\n buffer[n] = loxtoi_2 (s);\n if ( n == 32 && !memcmp (digest, buffer, 32) )\n err = 0;\n }\n fclose (fp);\n }\n }\n }\n }\n```\n\n#### check_binary_integrity() [lines 580-670]\n```c\n\n/* Run an integrity check on the binary. Returns 0 on success. */\nstatic int\ncheck_binary_integrity (void)\n{\n#ifdef ENABLE_HMAC_BINARY_CHECK\n gpg_error_t err;\n Dl_info info;\n unsigned char digest[32];\n int dlen;\n char *fname = NULL;\n const char key[] = \"What am I, a doctor or a moonshuttle conductor?\";\n\n if (!dladdr (\"gcry_check_version\", &info))\n err = gpg_error_from_syserror ();\n else\n {\n dlen = _gcry_hmac256_file (digest, sizeof digest, info.dli_fname,\n key, strlen (key));\n if (dlen < 0)\n err = gpg_error_from_syserror ();\n else if (dlen != 32)\n err = gpg_error (GPG_ERR_INTERNAL);\n else\n {\n fname = gcry_malloc (strlen (info.dli_fname) + 1 + 5 + 1 );\n if (!fname)\n err = gpg_error_from_syserror ();\n else\n {\n FILE *fp;\n char *p;\n\n /* Prefix the basename with a dot. */\n strcpy (fname, info.dli_fname);\n p = strrchr (fname, '/');\n if (p)\n p++;\n else\n p = fname;\n memmove (p+1, p, strlen (p)+1);\n *p = '.';\n strcat (fname, \".hmac\");\n\n /* Open the file. */\n fp = fopen (fname, \"r\");\n if (!fp)\n err = gpg_error_from_syserror ();\n else\n {\n /* A buffer of 64 bytes plus one for a LF and one to\n detect garbage. */\n unsigned char buffer[64+1+1];\n const unsigned char *s;\n int n;\n\n /* The HMAC files consists of lowercase hex digits\n only with an optional trailing linefeed. Fail if\n there is any garbage. */\n err = gpg_error (GPG_ERR_SELFTEST_FAILED);\n n = fread (buffer, 1, sizeof buffer, fp);\n if (n == 64 || (n == 65 && buffer[64] == '\\n'))\n {\n buffer[64] = 0;\n for (n=0, s= buffer;\n n < 32 && loxdigit_p (s) && loxdigit_p (s+1);\n n++, s += 2)\n buffer[n] = loxtoi_2 (s);\n if ( n == 32 && !memcmp (digest, buffer, 32) )\n err = 0;\n }\n fclose (fp);\n }\n }\n }\n }\n reporter (\"binary\", 0, fname, err? gpg_strerror (err):NULL);\n#ifdef HAVE_SYSLOG\n if (err)\n syslog (LOG_USER|LOG_ERR, \"Libgcrypt error: \"\n \"integrity check using `%s' failed: %s\",\n fname? fname:\"[?]\", gpg_strerror (err));\n#endif /*HAVE_SYSLOG*/\n xfree (fname);\n return !!err;\n#else\n return 0;\n#endif\n}\n\n\n```\n\n#### _gcry_fips_run_selftests() [lines 671-715]\n```c\n/* Run the self-tests. If EXTENDED is true, extended versions of the\n selftest are run, that is more tests than required by FIPS. */\ngpg_err_code_t\n_gcry_fips_run_selftests (int extended)\n{\n enum module_states result = STATE_ERROR;\n gcry_err_code_t ec = GPG_ERR_SELFTEST_FAILED;\n\n if (fips_mode ())\n fips_new_state (STATE_SELFTEST);\n\n if (run_cipher_selftests (extended))\n goto leave;\n\n if (run_digest_selftests (extended))\n goto leave;\n\n if (run_hmac_selftests (extended))\n goto leave;\n\n /* Run random tests before the pubkey tests because the latter\n require random. */\n if (run_random_selftests ())\n goto leave;\n\n if (run_pubkey_selftests (extended))\n goto leave;\n\n /* Now check the integrity of the binary. We do this this after\n having checked the HMAC code. */\n if (check_binary_integrity ())\n goto leave;\n\n /* All selftests passed. */\n result = STATE_OPERATIONAL;\n ec = 0;\n\n leave:\n if (fips_mode ())\n fips_new_state (result);\n\n return ec;\n}\n\n\n```\n\n\n## Upstream Fix\n```diff\nIndex: libgcrypt-1.6.1/src/global.c\n===================================================================\n--- libgcrypt-1.6.1.orig/src/global.c\t2015-04-21 17:40:23.784433223 +0200\n+++ libgcrypt-1.6.1/src/global.c\t2015-04-27 18:13:25.310922681 +0200\n@@ -124,6 +124,9 @@ global_init (void)\n err = _gcry_mpi_init ();\n if (err)\n goto fail;\n+ err = _gcry_fips_run_selftests (0);\n+ if (err)\n+ goto fail;\n \n return;\n \nIndex: libgcrypt-1.6.1/src/fips.c\n===================================================================\n--- libgcrypt-1.6.1.orig/src/fips.c\t2015-04-21 17:40:23.806433562 +0200\n+++ libgcrypt-1.6.1/src/fips.c\t2015-04-27 18:25:01.617583930 +0200\n@@ -607,6 +607,39 @@ get_library_path(const char *symbolname,\n return rv;\n }\n \n+static gpg_error_t\n+get_hmac_path(char **fname)\n+{\n+ char libpath[4096];\n+ gpg_error_t err;\n+\n+ if (get_library_path (\"gcry_check_version\", libpath, sizeof(libpath)))\n+ err = gpg_error_from_syserror ();\n+ else\n+ {\n+ *fname = _gcry_malloc (strlen (libpath) + 1 + 5 + 1 );\n+ if (!*fname)\n+ err = gpg_error_from_syserror ();\n+ else\n+ {\n+ char *p;\n+\n+ /* Prefix the basename with a dot. */\n+ strcpy (*fname, libpath);\n+ p = strrchr (*fname, '/');\n+ if (p)\n+ p++;\n+ else\n+ p = *fname;\n+ memmove (p+1, p, strlen (p)+1);\n+ *p = '.';\n+ strcat (*fname, \".hmac\");\n+ err = 0;\n+ }\n+ }\n+ return err;\n+}\n+\n /* Run an integrity check on the binary. Returns 0 on success. */\n static int\n check_binary_integrity (void)\n@@ -631,25 +664,9 @@ check_binary_integrity (void)\n err = gpg_error (GPG_ERR_INTERNAL);\n else\n {\n- fname = _gcry_malloc (strlen (libpath) + 1 + 5 + 1 );\n- if (!fname)\n- err = gpg_error_from_syserror ();\n- else\n- {\n- FILE *fp;\n- char *p;\n-\n- /* Prefix the basename with a dot. */\n- strcpy (fname, libpath);\n- p = strrchr (fname, '/');\n- if (p)\n- p++;\n- else\n- p = fname;\n- memmove (p+1, p, strlen (p)+1);\n- *p = '.';\n- strcat (fname, \".hmac\");\n-\n+ FILE *fp;\n+ err = get_hmac_path(&fname);\n+ if (!err) {\n /* Open the file. */\n fp = fopen (fname, \"r\");\n if (!fp)\n@@ -696,6 +713,33 @@ check_binary_integrity (void)\n #endif\n }\n \n+int\n+can_skip_selftests(void)\n+{\n+ char *fname = NULL;\n+ int ret = 0;\n+\n+ if (fips_mode())\n+ return 0;\n+\n+ if (get_hmac_path(&fname))\n+ return 0;\n+\n+ /* check the hmac presence */\n+ if (access(fname, F_OK))\n+ /* no hmac file is present, don't run the tests */\n+ if (errno == ENOENT)\n+ ret = 1;\n+ /* otherwise one of these events happened:\n+ access() returned 0\n+ -> run the tests\n+ some error other than ENOENT occurred\n+ -> run the tests anyway and let them fail\n+ */\n+\n+ xfree(fname);\n+ return ret;\n+}\n \n /* Run the self-tests. If EXTENDED is true, extended versions of the\n selftest are run, that is more tests than required by FIPS. */\n@@ -705,6 +749,9 @@ _gcry_fips_run_selftests (int extended)\n enum module_states result = STATE_ERROR;\n gcry_err_code_t ec = GPG_ERR_SELFTEST_FAILED;\n \n+ if (can_skip_selftests())\n+ return 0;\n+\n if (fips_mode ())\n fips_new_state (STATE_SELFTEST);\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "Index: libgcrypt-1.6.1/src/global.c\n===================================================================\n--- libgcrypt-1.6.1.orig/src/global.c\t2015-04-21 17:40:23.784433223 +0200\n+++ libgcrypt-1.6.1/src/global.c\t2015-04-27 18:13:25.310922681 +0200\n@@ -124,6 +124,9 @@ global_init (void)\n err = _gcry_mpi_init ();\n if (err)\n goto fail;\n+ err = _gcry_fips_run_selftests (0);\n+ if (err)\n+ goto fail;\n \n return;\n \nIndex: libgcrypt-1.6.1/src/fips.c\n===================================================================\n--- libgcrypt-1.6.1.orig/src/fips.c\t2015-04-21 17:40:23.806433562 +0200\n+++ libgcrypt-1.6.1/src/fips.c\t2015-04-27 18:25:01.617583930 +0200\n@@ -607,6 +607,39 @@ get_library_path(const char *symbolname,\n return rv;\n }\n \n+static gpg_error_t\n+get_hmac_path(char **fname)\n+{\n+ char libpath[4096];\n+ gpg_error_t err;\n+\n+ if (get_library_path (\"gcry_check_version\", libpath, sizeof(libpath)))\n+ err = gpg_error_from_syserror ();\n+ else\n+ {\n+ *fname = _gcry_malloc (strlen (libpath) + 1 + 5 + 1 );\n+ if (!*fname)\n+ err = gpg_error_from_syserror ();\n+ else\n+ {\n+ char *p;\n+\n+ /* Prefix the basename with a dot. */\n+ strcpy (*fname, libpath);\n+ p = strrchr (*fname, '/');\n+ if (p)\n+ p++;\n+ else\n+ p = *fname;\n+ memmove (p+1, p, strlen (p)+1);\n+ *p = '.';\n+ strcat (*fname, \".hmac\");\n+ err = 0;\n+ }\n+ }\n+ return err;\n+}\n+\n /* Run an integrity check on the binary. Returns 0 on success. */\n static int\n check_binary_integrity (void)\n@@ -631,25 +664,9 @@ check_binary_integrity (void)\n err = gpg_error (GPG_ERR_INTERNAL);\n else\n {\n- fname = _gcry_malloc (strlen (libpath) + 1 + 5 + 1 );\n- if (!fname)\n- err = gpg_error_from_syserror ();\n- else\n- {\n- FILE *fp;\n- char *p;\n-\n- /* Prefix the basename with a dot. */\n- strcpy (fname, libpath);\n- p = strrchr (fname, '/');\n- if (p)\n- p++;\n- else\n- p = fname;\n- memmove (p+1, p, strlen (p)+1);\n- *p = '.';\n- strcat (fname, \".hmac\");\n-\n+ FILE *fp;\n+ err = get_hmac_path(&fname);\n+ if (!err) {\n /* Open the file. */\n fp = fopen (fname, \"r\");\n if (!fp)\n@@ -696,6 +713,33 @@ check_binary_integrity (void)\n #endif\n }\n \n+int\n+can_skip_selftests(void)\n+{\n+ char *fname = NULL;\n+ int ret = 0;\n+\n+ if (fips_mode())\n+ return 0;\n+\n+ if (get_hmac_path(&fname))\n+ return 0;\n+\n+ /* check the hmac presence */\n+ if (access(fname, F_OK))\n+ /* no hmac file is present, don't run the tests */\n+ if (errno == ENOENT)\n+ ret = 1;\n+ /* otherwise one of these events happened:\n+ access() returned 0\n+ -> run the tests\n+ some error other than ENOENT occurred\n+ -> run the tests anyway and let them fail\n+ */\n+\n+ xfree(fname);\n+ return ret;\n+}\n \n /* Run the self-tests. If EXTENDED is true, extended versions of the\n selftest are run, that is more tests than required by FIPS. */\n@@ -705,6 +749,9 @@ _gcry_fips_run_selftests (int extended)\n enum module_states result = STATE_ERROR;\n gcry_err_code_t ec = GPG_ERR_SELFTEST_FAILED;\n \n+ if (can_skip_selftests())\n+ return 0;\n+\n if (fips_mode ())\n fips_new_state (STATE_SELFTEST);" } ]
{ "id": "libgcrypt-4975-libgcrypt-fips_run_selftest_at", "cve_id": "CVE-2015-7511", "package": "libgcrypt", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": true, "license": "GPL-2.0-or-later AND LGPL-2.1-or-later AND GPL-3.0-or-later", "context_tokens_est": 1786, "context_files": 2 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-2105\n\nInteger overflow in the EVP_EncodeUpdate function in crypto/evp/encode.c in OpenSSL before 1.0.1t and 1.0.2 before 1.0.2h allows remote attackers to cause a denial of service (heap memory corruption) via a large amount of binary data.\n\n## Package\nopenssl\n\n## Files to modify\n- crypto/evp/e_aes.c\n\n## Upstream Fix\n```diff\nFrom 800e34eef64fc2d1ef301cc9195d1059f49884d7 Mon Sep 17 00:00:00 2001\nFrom: \"Leonidas S. Barbosa\" <leosilva@linux.vnet.ibm.com>\nDate: Tue, 1 Sep 2015 17:28:38 -0400\nSubject: [PATCH 1/4] Taking only the struct-change of 'ks' to 'ks->ks'\n\nFrom c5f6da54fc64fb544028a547c9f6835f3f392428\n---\n crypto/evp/e_aes.c | 52 ++++++++++++++++++++++++++--------------------------\n 1 file changed, 26 insertions(+), 26 deletions(-)\n\ndiff --git a/crypto/evp/e_aes.c b/crypto/evp/e_aes.c\nindex a4b00c9..f3ac729 100644\n--- a/crypto/evp/e_aes.c\n+++ b/crypto/evp/e_aes.c\n@@ -62,7 +62,7 @@\n \n typedef struct\n \t{\n-\tAES_KEY ks;\n+\tunion { double align; AES_KEY ks; } ks;\n \tblock128_f block;\n \tunion {\n \t\tcbc128_f cbc;\n@@ -72,7 +72,7 @@ typedef struct\n \n typedef struct\n \t{\n-\tAES_KEY ks;\t\t/* AES key schedule to use */\n+\tunion { double align; AES_KEY ks; } ks;\t/* AES key schedule to use */\n \tint key_set;\t\t/* Set if key initialised */\n \tint iv_set;\t\t/* Set if an iv is set */\n \tGCM128_CONTEXT gcm;\n@@ -86,7 +86,7 @@ typedef struct\n \n typedef struct\n \t{\n-\tAES_KEY ks1, ks2;\t/* AES key schedules to use */\n+\tunion { double align; AES_KEY ks; } ks1, ks2;\t/* AES key schedules to use */\n \tXTS128_CONTEXT xts;\n \tvoid (*stream)(const unsigned char *in,\n \t\t\tunsigned char *out, size_t length,\n@@ -96,7 +96,7 @@ typedef struct\n \n typedef struct\n \t{\n-\tAES_KEY ks;\t\t/* AES key schedule to use */\n+\tunion { double align; AES_KEY ks; } ks;\t/* AES key schedule to use */\n \tint key_set;\t\t/* Set if key initialised */\n \tint iv_set;\t\t/* Set if an iv is set */\n \tint tag_set;\t\t/* Set if tag is valid */\n@@ -324,7 +324,7 @@ static int aesni_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t\treturn 1;\n \tif (key)\n \t\t{\n-\t\taesni_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks);\n+\t\taesni_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks.ks);\n \t\tCRYPTO_gcm128_init(&gctx->gcm, &gctx->ks,\n \t\t\t\t(block128_f)aesni_encrypt);\n \t\tgctx->ctr = (ctr128_f)aesni_ctr32_encrypt_blocks;\n@@ -369,19 +369,19 @@ static int aesni_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t\t/* key_len is two AES keys */\n \t\tif (enc)\n \t\t\t{\n-\t\t\taesni_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\taesni_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)aesni_encrypt;\n \t\t\txctx->stream = aesni_xts_encrypt;\n \t\t\t}\n \t\telse\n \t\t\t{\n-\t\t\taesni_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\taesni_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)aesni_decrypt;\n \t\t\txctx->stream = aesni_xts_decrypt;\n \t\t\t}\n \n \t\taesni_set_encrypt_key(key + ctx->key_len/2,\n-\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2);\n+\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2.ks);\n \t\txctx->xts.block2 = (block128_f)aesni_encrypt;\n \n \t\txctx->xts.key1 = &xctx->ks1;\n@@ -408,7 +408,7 @@ static int aesni_ccm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t\treturn 1;\n \tif (key)\n \t\t{\n-\t\taesni_set_encrypt_key(key, ctx->key_len * 8, &cctx->ks);\n+\t\taesni_set_encrypt_key(key, ctx->key_len * 8, &cctx->ks.ks);\n \t\tCRYPTO_ccm128_init(&cctx->ccm, cctx->M, cctx->L,\n \t\t\t\t\t&cctx->ks, (block128_f)aesni_encrypt);\n \t\tcctx->str = enc?(ccm128_f)aesni_ccm64_encrypt_blocks :\n@@ -519,7 +519,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef BSAES_CAPABLE\n \t if (BSAES_CAPABLE && mode==EVP_CIPH_CBC_MODE)\n \t\t{\n-\t\tret = AES_set_decrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = AES_set_decrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)AES_decrypt;\n \t\tdat->stream.cbc\t= (cbc128_f)bsaes_cbc_encrypt;\n \t\t}\n@@ -528,7 +528,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef VPAES_CAPABLE\n \t if (VPAES_CAPABLE)\n \t\t{\n-\t\tret = vpaes_set_decrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = vpaes_set_decrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)vpaes_decrypt;\n \t\tdat->stream.cbc\t= mode==EVP_CIPH_CBC_MODE ?\n \t\t\t\t\t(cbc128_f)vpaes_cbc_encrypt :\n@@ -537,7 +537,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t else\n #endif\n \t\t{\n-\t\tret = AES_set_decrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = AES_set_decrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)AES_decrypt;\n \t\tdat->stream.cbc\t= mode==EVP_CIPH_CBC_MODE ?\n \t\t\t\t\t(cbc128_f)AES_cbc_encrypt :\n@@ -547,7 +547,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef BSAES_CAPABLE\n \t if (BSAES_CAPABLE && mode==EVP_CIPH_CTR_MODE)\n \t\t{\n-\t\tret = AES_set_encrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = AES_set_encrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)AES_encrypt;\n \t\tdat->stream.ctr\t= (ctr128_f)bsaes_ctr32_encrypt_blocks;\n \t\t}\n@@ -556,7 +556,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef VPAES_CAPABLE\n \t if (VPAES_CAPABLE)\n \t\t{\n-\t\tret = vpaes_set_encrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = vpaes_set_encrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)vpaes_encrypt;\n \t\tdat->stream.cbc\t= mode==EVP_CIPH_CBC_MODE ?\n \t\t\t\t\t(cbc128_f)vpaes_cbc_encrypt :\n@@ -565,7 +565,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t else\n #endif\n \t\t{\n-\t\tret = AES_set_encrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = AES_set_encrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)AES_encrypt;\n \t\tdat->stream.cbc\t= mode==EVP_CIPH_CBC_MODE ?\n \t\t\t\t\t(cbc128_f)AES_cbc_encrypt :\n@@ -861,7 +861,7 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef BSAES_CAPABLE\n \t\tif (BSAES_CAPABLE)\n \t\t\t{\n-\t\t\tAES_set_encrypt_key(key,ctx->key_len*8,&gctx->ks);\n+\t\t\tAES_set_encrypt_key(key,ctx->key_len*8,&gctx->ks.ks);\n \t\t\tCRYPTO_gcm128_init(&gctx->gcm,&gctx->ks,\n \t\t\t\t\t(block128_f)AES_encrypt);\n \t\t\tgctx->ctr = (ctr128_f)bsaes_ctr32_encrypt_blocks;\n@@ -872,7 +872,7 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef VPAES_CAPABLE\n \t\tif (VPAES_CAPABLE)\n \t\t\t{\n-\t\t\tvpaes_set_encrypt_key(key,ctx->key_len*8,&gctx->ks);\n+\t\t\tvpaes_set_encrypt_key(key,ctx->key_len*8,&gctx->ks.ks);\n \t\t\tCRYPTO_gcm128_init(&gctx->gcm,&gctx->ks,\n \t\t\t\t\t(block128_f)vpaes_encrypt);\n \t\t\tgctx->ctr = NULL;\n@@ -882,7 +882,7 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #endif\n \t\t(void)0;\t/* terminate potentially open 'else' */\n \n-\t\tAES_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks);\n+\t\tAES_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks.ks);\n \t\tCRYPTO_gcm128_init(&gctx->gcm, &gctx->ks, (block128_f)AES_encrypt);\n #ifdef AES_CTR_ASM\n \t\tgctx->ctr = (ctr128_f)AES_ctr32_encrypt;\n@@ -1132,17 +1132,17 @@ static int aes_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t\t {\n \t\t if (enc)\n \t\t\t{\n-\t\t\tvpaes_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\tvpaes_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)vpaes_encrypt;\n \t\t\t}\n \t\t else\n \t\t\t{\n-\t\t\tvpaes_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\tvpaes_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)vpaes_decrypt;\n \t\t\t}\n \n \t\t vpaes_set_encrypt_key(key + ctx->key_len/2,\n-\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2);\n+\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2.ks);\n \t\t xctx->xts.block2 = (block128_f)vpaes_encrypt;\n \n \t\t xctx->xts.key1 = &xctx->ks1;\n@@ -1154,17 +1154,17 @@ static int aes_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \n \t\tif (enc)\n \t\t\t{\n-\t\t\tAES_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\tAES_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)AES_encrypt;\n \t\t\t}\n \t\telse\n \t\t\t{\n-\t\t\tAES_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\tAES_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)AES_decrypt;\n \t\t\t}\n \n \t\tAES_set_encrypt_key(key + ctx->key_len/2,\n-\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2);\n+\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2.ks);\n \t\txctx->xts.block2 = (block128_f\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 800e34eef64fc2d1ef301cc9195d1059f49884d7 Mon Sep 17 00:00:00 2001\nFrom: \"Leonidas S. Barbosa\" <leosilva@linux.vnet.ibm.com>\nDate: Tue, 1 Sep 2015 17:28:38 -0400\nSubject: [PATCH 1/4] Taking only the struct-change of 'ks' to 'ks->ks'\n\nFrom c5f6da54fc64fb544028a547c9f6835f3f392428\n---\n crypto/evp/e_aes.c | 52 ++++++++++++++++++++++++++--------------------------\n 1 file changed, 26 insertions(+), 26 deletions(-)\n\ndiff --git a/crypto/evp/e_aes.c b/crypto/evp/e_aes.c\nindex a4b00c9..f3ac729 100644\n--- a/crypto/evp/e_aes.c\n+++ b/crypto/evp/e_aes.c\n@@ -62,7 +62,7 @@\n \n typedef struct\n \t{\n-\tAES_KEY ks;\n+\tunion { double align; AES_KEY ks; } ks;\n \tblock128_f block;\n \tunion {\n \t\tcbc128_f cbc;\n@@ -72,7 +72,7 @@ typedef struct\n \n typedef struct\n \t{\n-\tAES_KEY ks;\t\t/* AES key schedule to use */\n+\tunion { double align; AES_KEY ks; } ks;\t/* AES key schedule to use */\n \tint key_set;\t\t/* Set if key initialised */\n \tint iv_set;\t\t/* Set if an iv is set */\n \tGCM128_CONTEXT gcm;\n@@ -86,7 +86,7 @@ typedef struct\n \n typedef struct\n \t{\n-\tAES_KEY ks1, ks2;\t/* AES key schedules to use */\n+\tunion { double align; AES_KEY ks; } ks1, ks2;\t/* AES key schedules to use */\n \tXTS128_CONTEXT xts;\n \tvoid (*stream)(const unsigned char *in,\n \t\t\tunsigned char *out, size_t length,\n@@ -96,7 +96,7 @@ typedef struct\n \n typedef struct\n \t{\n-\tAES_KEY ks;\t\t/* AES key schedule to use */\n+\tunion { double align; AES_KEY ks; } ks;\t/* AES key schedule to use */\n \tint key_set;\t\t/* Set if key initialised */\n \tint iv_set;\t\t/* Set if an iv is set */\n \tint tag_set;\t\t/* Set if tag is valid */\n@@ -324,7 +324,7 @@ static int aesni_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t\treturn 1;\n \tif (key)\n \t\t{\n-\t\taesni_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks);\n+\t\taesni_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks.ks);\n \t\tCRYPTO_gcm128_init(&gctx->gcm, &gctx->ks,\n \t\t\t\t(block128_f)aesni_encrypt);\n \t\tgctx->ctr = (ctr128_f)aesni_ctr32_encrypt_blocks;\n@@ -369,19 +369,19 @@ static int aesni_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t\t/* key_len is two AES keys */\n \t\tif (enc)\n \t\t\t{\n-\t\t\taesni_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\taesni_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)aesni_encrypt;\n \t\t\txctx->stream = aesni_xts_encrypt;\n \t\t\t}\n \t\telse\n \t\t\t{\n-\t\t\taesni_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\taesni_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)aesni_decrypt;\n \t\t\txctx->stream = aesni_xts_decrypt;\n \t\t\t}\n \n \t\taesni_set_encrypt_key(key + ctx->key_len/2,\n-\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2);\n+\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2.ks);\n \t\txctx->xts.block2 = (block128_f)aesni_encrypt;\n \n \t\txctx->xts.key1 = &xctx->ks1;\n@@ -408,7 +408,7 @@ static int aesni_ccm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t\treturn 1;\n \tif (key)\n \t\t{\n-\t\taesni_set_encrypt_key(key, ctx->key_len * 8, &cctx->ks);\n+\t\taesni_set_encrypt_key(key, ctx->key_len * 8, &cctx->ks.ks);\n \t\tCRYPTO_ccm128_init(&cctx->ccm, cctx->M, cctx->L,\n \t\t\t\t\t&cctx->ks, (block128_f)aesni_encrypt);\n \t\tcctx->str = enc?(ccm128_f)aesni_ccm64_encrypt_blocks :\n@@ -519,7 +519,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef BSAES_CAPABLE\n \t if (BSAES_CAPABLE && mode==EVP_CIPH_CBC_MODE)\n \t\t{\n-\t\tret = AES_set_decrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = AES_set_decrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)AES_decrypt;\n \t\tdat->stream.cbc\t= (cbc128_f)bsaes_cbc_encrypt;\n \t\t}\n@@ -528,7 +528,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef VPAES_CAPABLE\n \t if (VPAES_CAPABLE)\n \t\t{\n-\t\tret = vpaes_set_decrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = vpaes_set_decrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)vpaes_decrypt;\n \t\tdat->stream.cbc\t= mode==EVP_CIPH_CBC_MODE ?\n \t\t\t\t\t(cbc128_f)vpaes_cbc_encrypt :\n@@ -537,7 +537,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t else\n #endif\n \t\t{\n-\t\tret = AES_set_decrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = AES_set_decrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)AES_decrypt;\n \t\tdat->stream.cbc\t= mode==EVP_CIPH_CBC_MODE ?\n \t\t\t\t\t(cbc128_f)AES_cbc_encrypt :\n@@ -547,7 +547,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef BSAES_CAPABLE\n \t if (BSAES_CAPABLE && mode==EVP_CIPH_CTR_MODE)\n \t\t{\n-\t\tret = AES_set_encrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = AES_set_encrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)AES_encrypt;\n \t\tdat->stream.ctr\t= (ctr128_f)bsaes_ctr32_encrypt_blocks;\n \t\t}\n@@ -556,7 +556,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef VPAES_CAPABLE\n \t if (VPAES_CAPABLE)\n \t\t{\n-\t\tret = vpaes_set_encrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = vpaes_set_encrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)vpaes_encrypt;\n \t\tdat->stream.cbc\t= mode==EVP_CIPH_CBC_MODE ?\n \t\t\t\t\t(cbc128_f)vpaes_cbc_encrypt :\n@@ -565,7 +565,7 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t else\n #endif\n \t\t{\n-\t\tret = AES_set_encrypt_key(key,ctx->key_len*8,&dat->ks);\n+\t\tret = AES_set_encrypt_key(key,ctx->key_len*8,&dat->ks.ks);\n \t\tdat->block\t= (block128_f)AES_encrypt;\n \t\tdat->stream.cbc\t= mode==EVP_CIPH_CBC_MODE ?\n \t\t\t\t\t(cbc128_f)AES_cbc_encrypt :\n@@ -861,7 +861,7 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef BSAES_CAPABLE\n \t\tif (BSAES_CAPABLE)\n \t\t\t{\n-\t\t\tAES_set_encrypt_key(key,ctx->key_len*8,&gctx->ks);\n+\t\t\tAES_set_encrypt_key(key,ctx->key_len*8,&gctx->ks.ks);\n \t\t\tCRYPTO_gcm128_init(&gctx->gcm,&gctx->ks,\n \t\t\t\t\t(block128_f)AES_encrypt);\n \t\t\tgctx->ctr = (ctr128_f)bsaes_ctr32_encrypt_blocks;\n@@ -872,7 +872,7 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef VPAES_CAPABLE\n \t\tif (VPAES_CAPABLE)\n \t\t\t{\n-\t\t\tvpaes_set_encrypt_key(key,ctx->key_len*8,&gctx->ks);\n+\t\t\tvpaes_set_encrypt_key(key,ctx->key_len*8,&gctx->ks.ks);\n \t\t\tCRYPTO_gcm128_init(&gctx->gcm,&gctx->ks,\n \t\t\t\t\t(block128_f)vpaes_encrypt);\n \t\t\tgctx->ctr = NULL;\n@@ -882,7 +882,7 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #endif\n \t\t(void)0;\t/* terminate potentially open 'else' */\n \n-\t\tAES_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks);\n+\t\tAES_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks.ks);\n \t\tCRYPTO_gcm128_init(&gctx->gcm, &gctx->ks, (block128_f)AES_encrypt);\n #ifdef AES_CTR_ASM\n \t\tgctx->ctr = (ctr128_f)AES_ctr32_encrypt;\n@@ -1132,17 +1132,17 @@ static int aes_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t\t {\n \t\t if (enc)\n \t\t\t{\n-\t\t\tvpaes_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\tvpaes_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)vpaes_encrypt;\n \t\t\t}\n \t\t else\n \t\t\t{\n-\t\t\tvpaes_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\tvpaes_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)vpaes_decrypt;\n \t\t\t}\n \n \t\t vpaes_set_encrypt_key(key + ctx->key_len/2,\n-\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2);\n+\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2.ks);\n \t\t xctx->xts.block2 = (block128_f)vpaes_encrypt;\n \n \t\t xctx->xts.key1 = &xctx->ks1;\n@@ -1154,17 +1154,17 @@ static int aes_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \n \t\tif (enc)\n \t\t\t{\n-\t\t\tAES_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\tAES_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)AES_encrypt;\n \t\t\t}\n \t\telse\n \t\t\t{\n-\t\t\tAES_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1);\n+\t\t\tAES_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1.ks);\n \t\t\txctx->xts.block1 = (block128_f)AES_decrypt;\n \t\t\t}\n \n \t\tAES_set_encrypt_key(key + ctx->key_len/2,\n-\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2);\n+\t\t\t\t\t\tctx->key_len * 4, &xctx->ks2.ks);\n \t\txctx->xts.block2 = (block128_f)AES_encrypt;\n \n \t\txctx->xts.key1 = &xctx->ks1;\n@@ -1289,7 +1289,7 @@ static int aes_ccm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n #ifdef VPAES_CAPABLE\n \t\tif (VPAES_CAPABLE)\n \t\t\t{\n-\t\t\tvpaes_set_encrypt_key(key, ctx->key_len*8, &cctx->ks);\n+\t\t\tvpaes_set_encrypt_key(key, ctx->key_len*8, &cctx->ks.ks);\n \t\t\tCRYPTO_ccm128_init(&cctx->ccm, cctx->M, cctx->L,\n \t\t\t\t\t&cctx->ks, (block128_f)vpaes_encrypt);\n \t\t\tcctx->str = NULL;\n@@ -1297,7 +1297,7 @@ static int aes_ccm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,\n \t\t\tbreak;\n \t\t\t}\n #endif\n-\t\tAES_set_encrypt_key(key, ctx->key_len * 8, &cctx->ks);\n+\t\tAES_set_encrypt_key(key, ctx->key_len * 8, &cctx->ks.ks);\n \t\tCRYPTO_ccm128_init(&cctx->ccm, cctx->M, cctx->L,\n \t\t\t\t\t&cctx->ks, (block128_f)AES_encrypt);\n \t\tcctx->str = NULL;\n-- \n1.8.5.6" } ]
{ "id": "openssl-5050-0001-Taking-only-the-struct-ch", "cve_id": "CVE-2016-2105", "package": "openssl", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": false, "license": "OpenSSL", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2011-4362\n\nInteger signedness error in the base64_decode function in the HTTP authentication functionality (http_auth.c) in lighttpd 1.4 before 1.4.30 and 1.5 before SVN revision 2806 allows remote attackers to cause a denial of service (segmentation fault) via crafted base64 input that triggers an out-of-bounds read with a negative index.\n\n## Package\nlighttpd\n\n## Files to modify\n- src/server.c\n- src/fdevent_libev.c\n- src/network.c\n- src/fdevent.h\n- src/fdevent_solaris_devpoll.c\n\n## Target Source Code\n\n### src/network.c\n\n#### region() [lines 1-72]\n```c\n#include \"network.h\"\n#include \"fdevent.h\"\n#include \"log.h\"\n#include \"connections.h\"\n#include \"plugin.h\"\n#include \"joblist.h\"\n#include \"configfile.h\"\n\n#include \"network_backends.h\"\n#include \"sys-mmap.h\"\n#include \"sys-socket.h\"\n\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <sys/time.h>\n\n#include <errno.h>\n#include <fcntl.h>\n#include <unistd.h>\n#include <string.h>\n#include <stdlib.h>\n#include <assert.h>\n\n#ifdef USE_OPENSSL\n# include <openssl/ssl.h>\n# include <openssl/err.h>\n# include <openssl/rand.h>\n# include <openssl/dh.h>\n# include <openssl/bn.h>\n\n# if OPENSSL_VERSION_NUMBER >= 0x0090800fL\n# ifndef OPENSSL_NO_ECDH\n# include <openssl/ecdh.h>\n# endif\n# endif\n#endif\n\n#ifdef USE_OPENSSL\nstatic void ssl_info_callback(const SSL *ssl, int where, int ret) {\n\tUNUSED(ret);\n\n\tif (0 != (where & SSL_CB_HANDSHAKE_START)) {\n\t\tconnection *con = SSL_get_app_data(ssl);\n\t\t++con->renegotiations;\n\t} else if (0 != (where & SSL_CB_HANDSHAKE_DONE)) {\n\t\tssl->s3->flags |= SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS;\n\t}\n}\n#endif\n\nstatic handler_t network_server_handle_fdevent(server *srv, void *context, int revents) {\n\tserver_socket *srv_socket = (server_socket *)context;\n\tconnection *con;\n\tint loops = 0;\n\n\tUNUSED(context);\n\n\tif (0 == (revents & FDEVENT_IN)) {\n\t\tlog_error_write(srv, __FILE__, __LINE__, \"sdd\",\n\t\t\t\t\"strange event for server socket\",\n\t\t\t\tsrv_socket->fd,\n\t\t\t\trevents)\n/* ... truncated ... */\n```\n\n### src/server.c\n\n#### show_features() [lines 366-514]\n```c\n\twrite(STDOUT_FILENO, b, strlen(b));\n}\n\nstatic void show_features (void) {\n const char features[] = \"\"\n#ifdef USE_SELECT\n \"\\t+ select (generic)\\n\"\n#else\n \"\\t- select (generic)\\n\"\n#endif\n#ifdef USE_POLL\n \"\\t+ poll (Unix)\\n\"\n#else\n \"\\t- poll (Unix)\\n\"\n#endif\n#ifdef USE_LINUX_SIGIO\n \"\\t+ rt-signals (Linux 2.4+)\\n\"\n#else\n \"\\t- rt-signals (Linux 2.4+)\\n\"\n#endif\n#ifdef USE_LINUX_EPOLL\n \"\\t+ epoll (Linux 2.6)\\n\"\n#else\n \"\\t- epoll (Linux 2.6)\\n\"\n#endif\n#ifdef USE_SOLARIS_DEVPOLL\n \"\\t+ /dev/poll (Solaris)\\n\"\n#else\n \"\\t- /dev/poll (Solaris)\\n\"\n#endif\n#ifdef USE_SOLARIS_PORT\n \"\\t+ eventports (Solaris)\\n\"\n#else\n \"\\t- eventports (Solaris)\\n\"\n#endif\n#ifdef USE_FREEBSD_KQUEUE\n \"\\t+ kqueue (FreeBSD)\\n\"\n#else\n \"\\t- kqueue (FreeBSD)\\n\"\n#endif\n#ifdef USE_LIBEV\n \"\\t+ libev (generic)\\n\"\n#else\n \"\\t- libev (generic)\\n\"\n#endif\n \"\\nNetwork handler:\\n\\n\"\n#if defined USE_LINUX_SENDFILE\n \"\\t+ linux-sendfile\\n\"\n#else\n \"\\t- linux-sendfile\\n\"\n#endif\n#if defined USE_FREEBSD_SENDFILE\n \"\\t+ freebsd-sendfile\\n\"\n#else\n \"\\t- freebsd-sendfile\\n\"\n#endif\n#if defined USE_SOLARIS_SENDFILEV\n \"\\t+ solaris-sendfilev\\n\"\n#else\n \"\\t- solaris-sendfilev\\n\"\n#endif\n#if defined USE_WRITEV\n \"\\t+ writev\\n\"\n#else\n \"\\t- writev\\n\"\n#endif\n \"\\t+ write\\n\"\n#ifdef USE_MMAP\n \n/* ... truncated ... */\n```\n\n\n## Upstream Fix\n```diff\ncommit 35875cd515e06b3ab7e8afd1190a2fec83112ae4\nAuthor: Stefan Bühler <stbuehler@web.de>\nDate: Tue Dec 27 13:45:36 2011 +0000\n\n [ssl] include more headers explicitly\n \n git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2825 152afb58-edef-0310-8abb-c4023f1b3aa9\n\ndiff --git a/src/network.c b/src/network.c\nindex ba36654..bd30e2d 100644\n--- a/src/network.c\n+++ b/src/network.c\n@@ -25,6 +25,14 @@\n # include <openssl/ssl.h>\n # include <openssl/err.h>\n # include <openssl/rand.h>\n+# include <openssl/dh.h>\n+# include <openssl/bn.h>\n+\n+# if OPENSSL_VERSION_NUMBER >= 0x0090800fL\n+# ifndef OPENSSL_NO_ECDH\n+# include <openssl/ecdh.h>\n+# endif\n+# endif\n #endif\n \n #ifdef USE_OPENSSL\n\ncommit 6f0752da380c8ae7c7dab12a902b4635d3676d0a\nAuthor: Stefan Bühler <stbuehler@web.de>\nDate: Tue Dec 27 12:14:23 2011 +0000\n\n list all network handlers in lighttpd -V (fixes #2376)\n \n git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2824 152afb58-edef-0310-8abb-c4023f1b3aa9\n\ndiff --git a/src/server.c b/src/server.c\nindex bad6c07..beeb368 100644\n--- a/src/server.c\n+++ b/src/server.c\n@@ -409,19 +409,31 @@ static void show_features (void) {\n \"\\t- libev (generic)\\n\"\n #endif\n \"\\nNetwork handler:\\n\\n\"\n-#if defined(USE_LINUX_SENDFILE) || defined(USE_FREEBSD_SENDFILE) || defined(USE_SOLARIS_SENDFILEV) || defined(USE_AIX_SENDFILE)\n- \"\\t+ sendfile\\n\"\n+#if defined USE_LINUX_SENDFILE\n+ \"\\t+ linux-sendfile\\n\"\n #else\n- #ifdef USE_WRITEV\n+ \"\\t- linux-sendfile\\n\"\n+#endif\n+#if defined USE_FREEBSD_SENDFILE\n+ \"\\t+ freebsd-sendfile\\n\"\n+#else\n+ \"\\t- freebsd-sendfile\\n\"\n+#endif\n+#if defined USE_SOLARIS_SENDFILEV\n+ \"\\t+ solaris-sendfilev\\n\"\n+#else\n+ \"\\t- solaris-sendfilev\\n\"\n+#endif\n+#if defined USE_WRITEV\n \"\\t+ writev\\n\"\n- #else\n+#else\n+ \"\\t- writev\\n\"\n+#endif\n \"\\t+ write\\n\"\n- #endif\n- #ifdef USE_MMAP\n+#ifdef USE_MMAP\n \"\\t+ mmap support\\n\"\n- #else\n+#else\n \"\\t- mmap support\\n\"\n- #endif\n #endif\n \"\\nFeatures:\\n\\n\"\n #ifdef HAVE_IPV6\n\ncommit 79bcfab083d8437aff5d03df10fd1e1d5b79ffc7\nAuthor: Stefan Bühler <stbuehler@web.de>\nDate: Sun Dec 25 15:35:01 2011 +0000\n\n Move fdevent subsystem includes to implementation files to reduce conflicts (fixes #2373)\n \n git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2823 152afb58-edef-0310-8abb-c4023f1b3aa9\n\ndiff --git a/src/fdevent.h b/src/fdevent.h\nindex bdc82b5..9dd9a6c 100644\n--- a/src/fdevent.h\n+++ b/src/fdevent.h\n@@ -20,18 +20,12 @@\n \n #if defined(HAVE_EPOLL_CTL) && defined(HAVE_SYS_EPOLL_H)\n # define USE_LINUX_EPOLL\n-# include <sys/epoll.h>\n #endif\n \n /* MacOS 10.3.x has poll.h under /usr/include/, all other unixes\n * under /usr/include/sys/ */\n #if defined HAVE_POLL && (defined(HAVE_SYS_POLL_H) || defined(HAVE_POLL_H))\n # define USE_POLL\n-# ifdef HAVE_POLL_H\n-# include <poll.h>\n-# else\n-# include <sys/poll.h>\n-# endif\n #endif\n \n #if defined HAVE_SELECT\n@@ -46,7 +40,6 @@\n \n #if defined HAVE_SYS_DEVPOLL_H && defined(__sun)\n # define USE_SOLARIS_DEVPOLL\n-# include <sys/devpoll.h>\n #endif\n \n #if defined HAVE_PORT_H && defined HAVE_PORT_CREATE && defined(__sun)\n@@ -56,12 +49,10 @@\n \n #if defined HAVE_SYS_EVENT_H && defined HAVE_KQUEUE\n # define USE_FREEBSD_KQUEUE\n-# include <sys/event.h>\n #endif\n \n #if defined HAVE_LIBEV\n # define USE_LIBEV\n-# include <ev.h>\n #endif\n \n struct server;\ndiff --git a/src/fdevent_freebsd_kqueue.c b/src/fdevent_freebsd_kqueue.c\nindex 0f53a2a..220e265 100644\n--- a/src/fdevent_freebsd_kqueue.c\n+++ b/src/fdevent_freebsd_kqueue.c\n@@ -13,8 +13,8 @@\n #include <fcntl.h>\n \n #ifdef USE_FREEBSD_KQUEUE\n-#include <sys/event.h>\n-#include <sys/time.h>\n+# include <sys/event.h>\n+# include <sys/time.h>\n \n static void fdevent_freebsd_kqueue_free(fdevents *ev) {\n \tclose(ev->kq_fd);\ndiff --git a/src/fdevent_libev.c b/src/fdevent_libev.c\nindex 543127a..de62676 100644\n--- a/src/fdevent_libev.c\n+++ b/src/fdevent_libev.c\n@@ -5,6 +5,9 @@\n #include <assert.h>\n \n #ifdef USE_LIBEV\n+\n+# include <ev.h>\n+\n static void io_watcher_cb(struct ev_loop *loop, ev_io *w, int revents) {\n \tfdevents *ev = w->data;\n \tfdnode *fdn = ev->fdarray[w->fd];\ndiff --git a/src/fdevent_linux_sysepoll.c b/src/fdevent_linux_sysepoll.c\nindex b311f45..f761ed6 100644\n--- a/src/fdevent_linux_sysepoll.c\n+++ b/src/fdevent_linux_sysepoll.c\n@@ -13,6 +13,9 @@\n #include <fcntl.h>\n \n #ifdef USE_LINUX_EPOLL\n+\n+# include <sys/epoll.h>\n+\n static void fdevent_linux_sysepoll_free(fdevents *ev) {\n \tclose(ev->epoll_fd);\n \tfree(ev->epoll_events);\ndiff --git a/src/fdevent_poll.c b/src/fdevent_poll.c\nindex 6d102e6..e8dc385 100644\n--- a/src/fdevent_poll.c\n+++ b/src/fdevent_poll.c\n@@ -13,6 +13,13 @@\n #include <fcntl.h>\n \n #ifdef USE_POLL\n+\n+# ifdef HAVE_POLL_H\n+# include <poll.h>\n+# else\n+# include <sys/poll.h>\n+# endif\n+\n static void fdevent_poll_free(fdevents *ev) {\n \tfree(ev->pollfds);\n \tif (ev->unused.ptr) free(ev->unused.ptr);\ndiff --git a/src/fdevent_solaris_devpoll.c b/src/fdevent_solaris_devpoll.c\nindex cfbc510..dd273e6 100644\n--- a/src/fdevent_solaris_devpoll.c\n+++ b/src/fdevent_solaris_devpoll.c\n@@ -14,6 +14,8 @@\n \n #ifdef USE_SOLARIS_DEVPOLL\n \n+# include <sys/devpoll.h>\n+\n static void fdevent_solaris_devpoll_free(fdevents *ev) {\n \tfree(ev->devpollfds);\n \tclose(ev->devpoll_fd);\n\ncommit d194c09da94e310a3ca6659367ffe468303135d5\nAuthor: Stefan Bühler <stbuehler@web.de>\nDate: Fri Dec 23 10:31:57 2011 +0000\n\n [ssl] fix segfault in counting renegotiations for openssl versions without TLSEXT/SNI\n \n git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2822 152afb58-edef-0310-8abb-c4023f1b3aa9\n\ndiff --git a/src/connections.c b/src/connections.c\nindex cde78e1..faec09f 100644\n--- a/src/connections.c\n+++ b/src/connections.c\n@@ -1360,9 +1360,7 @@ connection *connection_accept(server *srv, server_socket *srv_socket) {\n \t\t\t}\n \n \t\t\tcon->renegotiations = 0;\n-#ifndef OPENSSL_NO_TLSEXT\n \t\t\tSSL_set_app_data(con->ssl, con);\n-#endif\n \t\t\tSSL_set_accept_state(con->ssl);\n \t\t\tcon->conf.is_ssl=1;\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "commit 35875cd515e06b3ab7e8afd1190a2fec83112ae4\nAuthor: Stefan Bühler <stbuehler@web.de>\nDate: Tue Dec 27 13:45:36 2011 +0000\n\n [ssl] include more headers explicitly\n \n git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2825 152afb58-edef-0310-8abb-c4023f1b3aa9\n\ndiff --git a/src/network.c b/src/network.c\nindex ba36654..bd30e2d 100644\n--- a/src/network.c\n+++ b/src/network.c\n@@ -25,6 +25,14 @@\n # include <openssl/ssl.h>\n # include <openssl/err.h>\n # include <openssl/rand.h>\n+# include <openssl/dh.h>\n+# include <openssl/bn.h>\n+\n+# if OPENSSL_VERSION_NUMBER >= 0x0090800fL\n+# ifndef OPENSSL_NO_ECDH\n+# include <openssl/ecdh.h>\n+# endif\n+# endif\n #endif\n \n #ifdef USE_OPENSSL\n\ncommit 6f0752da380c8ae7c7dab12a902b4635d3676d0a\nAuthor: Stefan Bühler <stbuehler@web.de>\nDate: Tue Dec 27 12:14:23 2011 +0000\n\n list all network handlers in lighttpd -V (fixes #2376)\n \n git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2824 152afb58-edef-0310-8abb-c4023f1b3aa9\n\ndiff --git a/src/server.c b/src/server.c\nindex bad6c07..beeb368 100644\n--- a/src/server.c\n+++ b/src/server.c\n@@ -409,19 +409,31 @@ static void show_features (void) {\n \"\\t- libev (generic)\\n\"\n #endif\n \"\\nNetwork handler:\\n\\n\"\n-#if defined(USE_LINUX_SENDFILE) || defined(USE_FREEBSD_SENDFILE) || defined(USE_SOLARIS_SENDFILEV) || defined(USE_AIX_SENDFILE)\n- \"\\t+ sendfile\\n\"\n+#if defined USE_LINUX_SENDFILE\n+ \"\\t+ linux-sendfile\\n\"\n #else\n- #ifdef USE_WRITEV\n+ \"\\t- linux-sendfile\\n\"\n+#endif\n+#if defined USE_FREEBSD_SENDFILE\n+ \"\\t+ freebsd-sendfile\\n\"\n+#else\n+ \"\\t- freebsd-sendfile\\n\"\n+#endif\n+#if defined USE_SOLARIS_SENDFILEV\n+ \"\\t+ solaris-sendfilev\\n\"\n+#else\n+ \"\\t- solaris-sendfilev\\n\"\n+#endif\n+#if defined USE_WRITEV\n \"\\t+ writev\\n\"\n- #else\n+#else\n+ \"\\t- writev\\n\"\n+#endif\n \"\\t+ write\\n\"\n- #endif\n- #ifdef USE_MMAP\n+#ifdef USE_MMAP\n \"\\t+ mmap support\\n\"\n- #else\n+#else\n \"\\t- mmap support\\n\"\n- #endif\n #endif\n \"\\nFeatures:\\n\\n\"\n #ifdef HAVE_IPV6\n\ncommit 79bcfab083d8437aff5d03df10fd1e1d5b79ffc7\nAuthor: Stefan Bühler <stbuehler@web.de>\nDate: Sun Dec 25 15:35:01 2011 +0000\n\n Move fdevent subsystem includes to implementation files to reduce conflicts (fixes #2373)\n \n git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2823 152afb58-edef-0310-8abb-c4023f1b3aa9\n\ndiff --git a/src/fdevent.h b/src/fdevent.h\nindex bdc82b5..9dd9a6c 100644\n--- a/src/fdevent.h\n+++ b/src/fdevent.h\n@@ -20,18 +20,12 @@\n \n #if defined(HAVE_EPOLL_CTL) && defined(HAVE_SYS_EPOLL_H)\n # define USE_LINUX_EPOLL\n-# include <sys/epoll.h>\n #endif\n \n /* MacOS 10.3.x has poll.h under /usr/include/, all other unixes\n * under /usr/include/sys/ */\n #if defined HAVE_POLL && (defined(HAVE_SYS_POLL_H) || defined(HAVE_POLL_H))\n # define USE_POLL\n-# ifdef HAVE_POLL_H\n-# include <poll.h>\n-# else\n-# include <sys/poll.h>\n-# endif\n #endif\n \n #if defined HAVE_SELECT\n@@ -46,7 +40,6 @@\n \n #if defined HAVE_SYS_DEVPOLL_H && defined(__sun)\n # define USE_SOLARIS_DEVPOLL\n-# include <sys/devpoll.h>\n #endif\n \n #if defined HAVE_PORT_H && defined HAVE_PORT_CREATE && defined(__sun)\n@@ -56,12 +49,10 @@\n \n #if defined HAVE_SYS_EVENT_H && defined HAVE_KQUEUE\n # define USE_FREEBSD_KQUEUE\n-# include <sys/event.h>\n #endif\n \n #if defined HAVE_LIBEV\n # define USE_LIBEV\n-# include <ev.h>\n #endif\n \n struct server;\ndiff --git a/src/fdevent_freebsd_kqueue.c b/src/fdevent_freebsd_kqueue.c\nindex 0f53a2a..220e265 100644\n--- a/src/fdevent_freebsd_kqueue.c\n+++ b/src/fdevent_freebsd_kqueue.c\n@@ -13,8 +13,8 @@\n #include <fcntl.h>\n \n #ifdef USE_FREEBSD_KQUEUE\n-#include <sys/event.h>\n-#include <sys/time.h>\n+# include <sys/event.h>\n+# include <sys/time.h>\n \n static void fdevent_freebsd_kqueue_free(fdevents *ev) {\n \tclose(ev->kq_fd);\ndiff --git a/src/fdevent_libev.c b/src/fdevent_libev.c\nindex 543127a..de62676 100644\n--- a/src/fdevent_libev.c\n+++ b/src/fdevent_libev.c\n@@ -5,6 +5,9 @@\n #include <assert.h>\n \n #ifdef USE_LIBEV\n+\n+# include <ev.h>\n+\n static void io_watcher_cb(struct ev_loop *loop, ev_io *w, int revents) {\n \tfdevents *ev = w->data;\n \tfdnode *fdn = ev->fdarray[w->fd];\ndiff --git a/src/fdevent_linux_sysepoll.c b/src/fdevent_linux_sysepoll.c\nindex b311f45..f761ed6 100644\n--- a/src/fdevent_linux_sysepoll.c\n+++ b/src/fdevent_linux_sysepoll.c\n@@ -13,6 +13,9 @@\n #include <fcntl.h>\n \n #ifdef USE_LINUX_EPOLL\n+\n+# include <sys/epoll.h>\n+\n static void fdevent_linux_sysepoll_free(fdevents *ev) {\n \tclose(ev->epoll_fd);\n \tfree(ev->epoll_events);\ndiff --git a/src/fdevent_poll.c b/src/fdevent_poll.c\nindex 6d102e6..e8dc385 100644\n--- a/src/fdevent_poll.c\n+++ b/src/fdevent_poll.c\n@@ -13,6 +13,13 @@\n #include <fcntl.h>\n \n #ifdef USE_POLL\n+\n+# ifdef HAVE_POLL_H\n+# include <poll.h>\n+# else\n+# include <sys/poll.h>\n+# endif\n+\n static void fdevent_poll_free(fdevents *ev) {\n \tfree(ev->pollfds);\n \tif (ev->unused.ptr) free(ev->unused.ptr);\ndiff --git a/src/fdevent_solaris_devpoll.c b/src/fdevent_solaris_devpoll.c\nindex cfbc510..dd273e6 100644\n--- a/src/fdevent_solaris_devpoll.c\n+++ b/src/fdevent_solaris_devpoll.c\n@@ -14,6 +14,8 @@\n \n #ifdef USE_SOLARIS_DEVPOLL\n \n+# include <sys/devpoll.h>\n+\n static void fdevent_solaris_devpoll_free(fdevents *ev) {\n \tfree(ev->devpollfds);\n \tclose(ev->devpoll_fd);\n\ncommit d194c09da94e310a3ca6659367ffe468303135d5\nAuthor: Stefan Bühler <stbuehler@web.de>\nDate: Fri Dec 23 10:31:57 2011 +0000\n\n [ssl] fix segfault in counting renegotiations for openssl versions without TLSEXT/SNI\n \n git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2822 152afb58-edef-0310-8abb-c4023f1b3aa9\n\ndiff --git a/src/connections.c b/src/connections.c\nindex cde78e1..faec09f 100644\n--- a/src/connections.c\n+++ b/src/connections.c\n@@ -1360,9 +1360,7 @@ connection *connection_accept(server *srv, server_socket *srv_socket) {\n \t\t\t}\n \n \t\t\tcon->renegotiations = 0;\n-#ifndef OPENSSL_NO_TLSEXT\n \t\t\tSSL_set_app_data(con->ssl, con);\n-#endif\n \t\t\tSSL_set_accept_state(con->ssl);\n \t\t\tcon->conf.is_ssl=1;" } ]
{ "id": "lighttpd-255-lighttpd-1.4.30_head_fixes.pat", "cve_id": "CVE-2011-4362", "package": "lighttpd", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": true, "license": "BSD-3-Clause", "context_tokens_est": 728, "context_files": 2 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2013-5653\n\nThe getenv and filenameforall functions in Ghostscript 9.10 ignore the \"-dSAFER\" argument, which allows remote attackers to read data via a crafted postscript file.\n\n## Package\nghostscript-mini\n\n## Files to modify\n- ghostscript-9.15.orig/psi/zfile.c\n\n## Upstream Fix\n```diff\nFrom ab109aaeb3ddba59518b036fb288402a65cf7ce8 Mon Sep 17 00:00:00 2001\nFrom: Chris Liddell <chris.liddell@artifex.com>\nDate: Sat, 5 Mar 2016 14:56:03 -0800\nSubject: [PATCH] Bug 694724: Have filenameforall and getenv honor SAFER\n\n---\n Resource/Init/gs_init.ps | Bin 78437 -> 78515 bytes\n psi/zfile.c | 36 ++++++++++++++++++++----------------\n 2 files changed, 20 insertions(+), 16 deletions(-)\n\ndiff --git a/Resource/Init/gs_init.ps b/Resource/Init/gs_init.ps\nindex fa33d886bff989ac9fe5a6c2b33b57e5677fa07b..99888acaa31e7d21494105121c96e58686fa1ee5 100644\nGIT binary patch\ndelta 103\nzcmaF*gk|$nmWC~iSA<oHD~n4~b5k;tOBD3eQ%h3w$`q;#@(UF7_0tk_ic@P93Q9}1\nUUle8(WhPo_D&uw!2}W5d063B*=Kufz\n\ndelta 29\njcmdn|l;!CYmWC~iSA@5lh%+WJZjTjZ+`tH8*GmHcxxETx\n\ndiff --git a/psi/zfile.c b/psi/zfile.c\nindex 320ecd500c..0b9f29949c 100644\n--- a/psi/zfile.c\n+++ b/psi/zfile.c\n@@ -371,22 +371,26 @@ file_continue(i_ctx_t *i_ctx_p)\n \n if (len < devlen)\n return_error(gs_error_rangecheck); /* not even room for device len */\n- memcpy((char *)pscratch->value.bytes, iodev->dname, devlen);\n- code = iodev->procs.enumerate_next(pfen, (char *)pscratch->value.bytes + devlen,\n- len - devlen);\n- if (code == ~(uint) 0) { /* all done */\n- esp -= 5; /* pop proc, pfen, devlen, iodev , mark */\n- return o_pop_estack;\n- } else if (code > len) /* overran string */\n- return_error(gs_error_rangecheck);\n- else {\n- push(1);\n- ref_assign(op, pscratch);\n- r_set_size(op, code + devlen);\n- push_op_estack(file_continue); /* come again */\n- *++esp = pscratch[2]; /* proc */\n- return o_push_estack;\n- }\n+\n+ do {\n+ memcpy((char *)pscratch->value.bytes, iodev->dname, devlen);\n+ code = iodev->procs.enumerate_next(pfen, (char *)pscratch->value.bytes + devlen,\n+ len - devlen);\n+ if (code == ~(uint) 0) { /* all done */\n+ esp -= 5; /* pop proc, pfen, devlen, iodev , mark */\n+ return o_pop_estack;\n+ } else if (code > len) /* overran string */\n+ return_error(gs_error_rangecheck);\n+ else if (iodev != iodev_default(imemory)\n+ || (check_file_permissions_reduced(i_ctx_p, (char *)pscratch->value.bytes, code + devlen, \"PermitFileReading\")) == 0) {\n+ push(1);\n+ ref_assign(op, pscratch);\n+ r_set_size(op, code + devlen);\n+ push_op_estack(file_continue); /* come again */\n+ *++esp = pscratch[2]; /* proc */\n+ return o_push_estack;\n+ }\n+ } while(1);\n }\n /* Cleanup procedure for enumerating files */\n static int\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From ab109aaeb3ddba59518b036fb288402a65cf7ce8 Mon Sep 17 00:00:00 2001\nFrom: Chris Liddell <chris.liddell@artifex.com>\nDate: Sat, 5 Mar 2016 14:56:03 -0800\nSubject: [PATCH] Bug 694724: Have filenameforall and getenv honor SAFER\n\nCVE-2013-5653\n---\n Resource/Init/gs_init.ps | 2 ++\n psi/zfile.c | 36 ++++++++++++++++++++----------------\n 2 files changed, 22 insertions(+), 16 deletions(-)\n--- ghostscript-9.15.orig/Resource/Init/gs_init.ps\t2016-10-08 21:27:33.159836244 +0200\n+++ ghostscript-9.15.orig/Resource/Init/gs_init.ps\t2016-10-08 21:27:34.755859833 +0200\n@@ -2021,6 +2021,7 @@ readonly def\n \n /.locksafe {\n .locksafe_userparams\n+ systemdict /getenv {pop //false} put\n % setpagedevice has the side effect of clearing the page, but\n % we will just document that. Using setpagedevice keeps the device\n % properties and pagedevice .LockSafetyParams in agreement even\n@@ -2039,6 +2040,7 @@ readonly def\n %%\n /.locksafeglobal {\n .locksafe_userparams\n+ systemdict /getenv {pop //false} put\n % setpagedevice has the side effect of clearing the page, but\n % we will just document that. Using setpagedevice keeps the device\n % properties and pagedevice .LockSafetyParams in agreement even\n--- ghostscript-9.15.orig/psi/zfile.c\t2016-10-08 21:27:34.759859892 +0200\n+++ ghostscript-9.15.orig/psi/zfile.c\t2016-10-08 21:28:59.229108366 +0200\n@@ -371,22 +371,26 @@ file_continue(i_ctx_t *i_ctx_p)\n \n if (len < devlen)\n return_error(e_rangecheck); /* not even room for device len */\n- memcpy((char *)pscratch->value.bytes, iodev->dname, devlen);\n- code = iodev->procs.enumerate_next(pfen, (char *)pscratch->value.bytes + devlen,\n- len - devlen);\n- if (code == ~(uint) 0) { /* all done */\n- esp -= 5; /* pop proc, pfen, devlen, iodev , mark */\n- return o_pop_estack;\n- } else if (code > len) /* overran string */\n- return_error(e_rangecheck);\n- else {\n- push(1);\n- ref_assign(op, pscratch);\n- r_set_size(op, code + devlen);\n- push_op_estack(file_continue); /* come again */\n- *++esp = pscratch[2]; /* proc */\n- return o_push_estack;\n- }\n+\n+ do {\n+ memcpy((char *)pscratch->value.bytes, iodev->dname, devlen);\n+ code = iodev->procs.enumerate_next(pfen, (char *)pscratch->value.bytes + devlen,\n+ len - devlen);\n+ if (code == ~(uint) 0) { /* all done */\n+ esp -= 5; /* pop proc, pfen, devlen, iodev , mark */\n+ return o_pop_estack;\n+ } else if (code > len) /* overran string */\n+ return_error(gs_error_rangecheck);\n+ else if (iodev != iodev_default(imemory)\n+ || (check_file_permissions_reduced(i_ctx_p, (char *)pscratch->value.bytes, code + devlen, \"PermitFileReading\")) == 0) {\n+ push(1);\n+ ref_assign(op, pscratch);\n+ r_set_size(op, code + devlen);\n+ push_op_estack(file_continue); /* come again */\n+ *++esp = pscratch[2]; /* proc */\n+ return o_push_estack;\n+ }\n+ } while(1);\n }\n /* Cleanup procedure for enumerating files */\n static int" } ]
{ "id": "ghostscript-mini-5881-CVE-2013-5653.patch", "cve_id": "CVE-2013-5653", "package": "ghostscript-mini", "upstream_enriched": true, "upstream_commit": "ab109aaeb3ddba59518b036fb288402a65cf7ce8", "upstream_repo": "ArtifexSoftware/ghostpdl", "tier": "adapted", "has_source_context": false, "license": "AGPL-3.0-only", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2013-4288\n\nRace condition in PolicyKit (aka polkit) allows local users to bypass intended PolicyKit restrictions and gain privileges by starting a setuid or pkexec process before the authorization check is performed, related to (1) the polkit_unix_process_new API function, (2) the dbus API, or (3) the --process (unix-process) option for authorization to pkcheck.\n\n## Package\nsystemd\n\n## Files to modify\n- src/login/loginctl.c\n\n## Upstream Fix\n```diff\nFrom cc1368e3b3585ab822d76e00945ed4c064047530 Mon Sep 17 00:00:00 2001\nFrom: Lennart Poettering <lennart@poettering.net>\nDate: Sun, 22 Apr 2012 02:03:08 +0200\nSubject: [PATCH] loginctl: avoid segfault for kill-session and kill-user\n commands\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n\nAs reported by Mantas Mikulėnas.\n\nhttp://lists.freedesktop.org/archives/systemd-devel/2012-April/004993.html\n---\n src/login/loginctl.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/src/login/loginctl.c b/src/login/loginctl.c\nindex 3ec8057d3bdf3..18f56f0124a79 100644\n--- a/src/login/loginctl.c\n+++ b/src/login/loginctl.c\n@@ -1260,7 +1260,7 @@ static int kill_session(DBusConnection *bus, char **args, unsigned n) {\n if (!dbus_message_append_args(m,\n DBUS_TYPE_STRING, &args[i],\n DBUS_TYPE_STRING, &arg_kill_who,\n- DBUS_TYPE_INT32, arg_signal,\n+ DBUS_TYPE_INT32, &arg_signal,\n DBUS_TYPE_INVALID)) {\n log_error(\"Could not append arguments to message.\");\n ret = -ENOMEM;\n@@ -1464,7 +1464,7 @@ static int kill_user(DBusConnection *bus, char **args, unsigned n) {\n u = (uint32_t) uid;\n if (!dbus_message_append_args(m,\n DBUS_TYPE_UINT32, &u,\n- DBUS_TYPE_INT32, arg_signal,\n+ DBUS_TYPE_INT32, &arg_signal,\n DBUS_TYPE_INVALID)) {\n log_error(\"Could not append arguments to message.\");\n ret = -ENOMEM;\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 01c04b32cefc75aea65d3cea777a089584041492 Mon Sep 17 00:00:00 2001\nFrom: Lennart Poettering <lennart@poettering.net>\nDate: Sun, 22 Apr 2012 02:03:08 +0200\nSubject: [PATCH] loginctl: avoid segfault for kill-session and kill-user\n commands\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n\nAs reported by Mantas Mikulėnas.\n\nhttp://lists.freedesktop.org/archives/systemd-devel/2012-April/004993.html\n(cherry picked from commit cc1368e3b3585ab822d76e00945ed4c064047530)\n---\n src/login/loginctl.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/src/login/loginctl.c b/src/login/loginctl.c\nindex 172fb7f..a494447 100644\n--- a/src/login/loginctl.c\n+++ b/src/login/loginctl.c\n@@ -1260,7 +1260,7 @@ static int kill_session(DBusConnection *bus, char **args, unsigned n) {\n if (!dbus_message_append_args(m,\n DBUS_TYPE_STRING, &args[i],\n DBUS_TYPE_STRING, &arg_kill_who,\n- DBUS_TYPE_INT32, arg_signal,\n+ DBUS_TYPE_INT32, &arg_signal,\n DBUS_TYPE_INVALID)) {\n log_error(\"Could not append arguments to message.\");\n ret = -ENOMEM;\n@@ -1464,7 +1464,7 @@ static int kill_user(DBusConnection *bus, char **args, unsigned n) {\n u = (uint32_t) uid;\n if (!dbus_message_append_args(m,\n DBUS_TYPE_UINT32, &u,\n- DBUS_TYPE_INT32, arg_signal,\n+ DBUS_TYPE_INT32, &arg_signal,\n DBUS_TYPE_INVALID)) {\n log_error(\"Could not append arguments to message.\");\n ret = -ENOMEM;\n-- \n1.7.10.4" } ]
{ "id": "systemd-2026-fix-kill-session-crash.patch", "cve_id": "CVE-2013-4288", "package": "systemd", "upstream_enriched": true, "upstream_commit": "cc1368e3b3585ab822d76e00945ed4c064047530", "upstream_repo": "systemd/systemd", "tier": "adapted", "has_source_context": false, "license": "LGPL-2.1-or-later", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-6302\n\nThe tls_decrypt_ticket function in ssl/t1_lib.c in OpenSSL before 1.1.0 does not consider the HMAC size during validation of the ticket length, which allows remote attackers to cause a denial of service via a ticket that is too short.\n\n## Package\nopenssl\n\n## Files to modify\n- openssl-1.0.1i.orig/ssl/t1_lib.c\n- openssl-1.0.1i/ssl/t1_lib.c\n\n## Target Source Code\n\n### ssl/t1_lib.c\n\n#### tls_decrypt_ticket() [lines 2292-2396]\n```c\n * 3: a ticket was successfully decrypted and *psess was set.\n * 4: same as 3, but the ticket needs to be renewed.\n */\nstatic int tls_decrypt_ticket(SSL *s, const unsigned char *etick, int eticklen,\n\t\t\t\tconst unsigned char *sess_id, int sesslen,\n\t\t\t\tSSL_SESSION **psess)\n\t{\n\tSSL_SESSION *sess;\n\tunsigned char *sdec;\n\tconst unsigned char *p;\n\tint slen, mlen, renew_ticket = 0;\n\tunsigned char tick_hmac[EVP_MAX_MD_SIZE];\n\tHMAC_CTX hctx;\n\tEVP_CIPHER_CTX ctx;\n\tSSL_CTX *tctx = s->initial_ctx;\n\t/* Need at least keyname + iv + some encrypted data */\n\tif (eticklen < 48)\n\t\treturn 2;\n\t/* Initialize session ticket encryption and HMAC contexts */\n\tHMAC_CTX_init(&hctx);\n\tEVP_CIPHER_CTX_init(&ctx);\n\tif (tctx->tlsext_ticket_key_cb)\n\t\t{\n\t\tunsigned char *nctick = (unsigned char *)etick;\n\t\tint rv = tctx->tlsext_ticket_key_cb(s, nctick, nctick + 16,\n\t\t\t\t\t\t\t&ctx, &hctx, 0);\n\t\tif (rv < 0)\n\t\t\treturn -1;\n\t\tif (rv == 0)\n\t\t\treturn 2;\n\t\tif (rv == 2)\n\t\t\trenew_ticket = 1;\n\t\t}\n\telse\n\t\t{\n\t\t/* Check key name matches */\n\t\tif (memcmp(etick, tctx->tlsext_tick_key_name, 16))\n\t\t\treturn 2;\n\t\tHMAC_Init_ex(&hctx, tctx->tlsext_tick_hmac_key, 16,\n\t\t\t\t\ttlsext_tick_md(), NULL);\n\t\tEVP_DecryptInit_ex(&ctx, EVP_aes_128_cbc(), NULL,\n\t\t\t\ttctx->tlsext_tick_aes_key, etick + 16);\n\t\t}\n\t/* Attempt to process session ticket, first conduct sanity and\n\t * integrity checks on ticket.\n\t */\n\tmlen = HMAC_size(&hctx);\n\tif (mlen < 0)\n\t\t{\n\t\tEVP_CIPHER_CTX_cleanup(&ctx);\n\t\treturn -1;\n\t\t}\n\teticklen -= mlen;\n\t/* Check HMAC of encrypted ticket */\n\tHMAC_Update(&hctx, etick, eticklen);\n\tHMAC_Final(&hctx, tick_hmac, NULL);\n\tHMAC_CTX_cleanup(&hctx);\n\tif (CRYPTO_memcmp(tick_hmac, etick + eticklen, mlen))\n\t\treturn 2;\n\t/* Attempt to decrypt session data */\n\t/* Move p after IV to start of encrypted ticket, update length */\n\tp = etick + 16 + EVP_CIPHER_CTX_iv_length(&ctx);\n\teticklen -= 16 + EVP_CIPHER_CTX_iv_length(&ctx);\n\tsdec = OPENSSL_malloc(eticklen);\n\tif (!sdec)\n\t\t{\n\t\tEVP_CIPHER_CTX_cleanup(&ctx);\n\t\treturn -1;\n\t\t}\n\tEVP_DecryptUpdate(&ctx, sdec, &slen, p, eticklen);\n\tif (EVP_DecryptFinal(&ctx, sdec + slen, &mlen) <= 0)\n\t\t{\n\t\tEVP_CIPHER_CTX_cleanup(&ctx);\n\t\tOPENSSL_free(sdec);\n\t\treturn 2;\n\t\t}\n\tslen += mlen;\n\tEVP_CIPHER_CTX_cleanup(&ctx);\n\tp = sdec;\n\n\tsess = d2i_SSL_SESSION(NULL, &p, slen);\n\tOPENSSL_free(sdec);\n\tif (sess)\n\t\t{\n\t\t/* The session ID, if non-empty, is used by some clients to\n\t\t * detect that the ticket has been accepted. So we copy it to\n\t\t * the session structure. If it is empty set length to zero\n\t\t * as required by standard.\n\t\t */\n\t\tif (sesslen)\n\t\t\tmemcpy(sess->session_id, sess_id, sesslen);\n\t\tsess->session_id_length = sesslen;\n\t\t*psess = sess;\n\t\tif (renew_ticket)\n\t\t\treturn 4;\n\t\telse\n\t\t\treturn 3;\n\t\t}\n ERR_clear_error();\n\t/* For session parse failure, indicate that we need to send a new\n\t * ticket. */\n\treturn 2;\n\t}\n\n/* Tables to translate from NIDs to TLS v1.2 ids */\n```\n\n\n## Upstream Fix\n```diff\nFrom baaabfd8fdcec04a691695fad9a664bea43202b6 Mon Sep 17 00:00:00 2001\nFrom: \"Dr. Stephen Henson\" <steve@openssl.org>\nDate: Tue, 23 Aug 2016 18:14:54 +0100\nSubject: [PATCH] Sanity check ticket length.\n\nIf a ticket callback changes the HMAC digest to SHA512 the existing\nsanity checks are not sufficient and an attacker could perform a DoS\nattack with a malformed ticket. Add additional checks based on\nHMAC size.\n\nThanks to Shi Lei for reporting this bug.\n\nCVE-2016-6302\n\nReviewed-by: Rich Salz <rsalz@openssl.org>\n---\n ssl/t1_lib.c | 11 ++++++++---\n 1 file changed, 8 insertions(+), 3 deletions(-)\n\ndiff --git a/ssl/t1_lib.c b/ssl/t1_lib.c\nindex 7d322d0253387..fbcf2e663cb25 100644\n--- a/ssl/t1_lib.c\n+++ b/ssl/t1_lib.c\n@@ -3401,9 +3401,7 @@ static int tls_decrypt_ticket(SSL *s, const unsigned char *etick,\n HMAC_CTX hctx;\n EVP_CIPHER_CTX ctx;\n SSL_CTX *tctx = s->initial_ctx;\n- /* Need at least keyname + iv + some encrypted data */\n- if (eticklen < 48)\n- return 2;\n+\n /* Initialize session ticket encryption and HMAC contexts */\n HMAC_CTX_init(&hctx);\n EVP_CIPHER_CTX_init(&ctx);\n@@ -3437,6 +3435,13 @@ static int tls_decrypt_ticket(SSL *s, const unsigned char *etick,\n if (mlen < 0) {\n goto err;\n }\n+ /* Sanity check ticket length: must exceed keyname + IV + HMAC */\n+ if (eticklen <= 16 + EVP_CIPHER_CTX_iv_length(&ctx) + mlen) {\n+ HMAC_CTX_cleanup(&hctx);\n+ EVP_CIPHER_CTX_cleanup(&ctx);\n+ return 2;\n+ }\n+\n eticklen -= mlen;\n /* Check HMAC of encrypted ticket */\n if (HMAC_Update(&hctx, etick, eticklen) <= 0\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "commit 1bbe48ab149893a78bf99c8eb8895c928900a16f\nAuthor: Dr. Stephen Henson <steve@openssl.org>\nDate: Tue Aug 23 18:14:54 2016 +0100\n\n Sanity check ticket length.\n \n If a ticket callback changes the HMAC digest to SHA512 the existing\n sanity checks are not sufficient and an attacker could perform a DoS\n attack with a malformed ticket. Add additional checks based on\n HMAC size.\n \n Thanks to Shi Lei for reporting this bug.\n \n CVE-2016-6302\n \n Reviewed-by: Rich Salz <rsalz@openssl.org>\n (cherry picked from commit baaabfd8fdcec04a691695fad9a664bea43202b6)\n\nIndex: openssl-1.0.1i/ssl/t1_lib.c\n===================================================================\n--- openssl-1.0.1i.orig/ssl/t1_lib.c\t2016-09-22 14:54:08.914883013 +0200\n+++ openssl-1.0.1i/ssl/t1_lib.c\t2016-09-22 14:55:13.939900918 +0200\n@@ -2332,9 +2332,7 @@ static int tls_decrypt_ticket(SSL *s, co\n \tHMAC_CTX hctx;\n \tEVP_CIPHER_CTX ctx;\n \tSSL_CTX *tctx = s->initial_ctx;\n-\t/* Need at least keyname + iv + some encrypted data */\n-\tif (eticklen < 48)\n-\t\treturn 2;\n+\n \t/* Initialize session ticket encryption and HMAC contexts */\n \tHMAC_CTX_init(&hctx);\n \tEVP_CIPHER_CTX_init(&ctx);\n@@ -2369,6 +2367,14 @@ static int tls_decrypt_ticket(SSL *s, co\n \t\tEVP_CIPHER_CTX_cleanup(&ctx);\n \t\treturn -1;\n \t\t}\n+\n+ /* Sanity check ticket length: must exceed keyname + IV + HMAC */\n+ if (eticklen <= 16 + EVP_CIPHER_CTX_iv_length(&ctx) + mlen) {\n+ HMAC_CTX_cleanup(&hctx);\n+ EVP_CIPHER_CTX_cleanup(&ctx);\n+ return 2;\n+ }\n+\n \teticklen -= mlen;\n \t/* Check HMAC of encrypted ticket */\n \tHMAC_Update(&hctx, etick, eticklen);" } ]
{ "id": "openssl-5667-openssl-CVE-2016-6302.patch", "cve_id": "CVE-2016-6302", "package": "openssl", "upstream_enriched": true, "upstream_commit": "baaabfd8fdcec04a691695fad9a664bea43202b6", "upstream_repo": "openssl/openssl", "tier": "adapted", "has_source_context": true, "license": "OpenSSL", "context_tokens_est": 735, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2013-2877\n\nparser.c in libxml2 before 2.9.0, as used in Google Chrome before 28.0.1500.71 and other products, allows remote attackers to cause a denial of service (out-of-bounds read) via a document that ends abruptly, related to the lack of certain checks for the XML_PARSER_EOF state.\n\n## Package\nlibxml2\n\n## Files to modify\n- parser.c\n- libxml2-2.8.0.orig/parser.c\n\n## Target Source Code\n\n### parser.c\n\n#### xmlParseAttValueComplex() [lines 3892-3979]\n```c\n */\n\n htmlAutoCloseOnClose(ctxt, name);\n\n /*\n * Well formedness constraints, opening and closing must match.\n * With the exception that the autoclose may have popped stuff out\n * of the stack.\n */\n if (!xmlStrEqual(name, ctxt->name)) {\n if ((ctxt->name != NULL) && (!xmlStrEqual(ctxt->name, name))) {\n htmlParseErr(ctxt, XML_ERR_TAG_NAME_MISMATCH,\n\t \"Opening and ending tag mismatch: %s and %s\\n\",\n\t\t\t name, ctxt->name);\n }\n }\n\n /*\n * SAX: End of Tag\n */\n oldname = ctxt->name;\n if ((oldname != NULL) && (xmlStrEqual(oldname, name))) {\n if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))\n ctxt->sax->endElement(ctxt->userData, name);\n\thtmlNodeInfoPop(ctxt);\n htmlnamePop(ctxt);\n ret = 1;\n } else {\n ret = 0;\n }\n\n return (ret);\n}\n\n\n/**\n * htmlParseReference:\n * @ctxt: an HTML parser context\n *\n * parse and handle entity references in content,\n * this will end-up in a call to character() since this is either a\n * CharRef, or a predefined entity.\n */\nstatic void\nhtmlParseReference(htmlParserCtxtPtr ctxt) {\n const htmlEntityDesc * ent;\n xmlChar out[6];\n const xmlChar *name;\n if (CUR != '&') return;\n\n if (NXT(1) == '#') {\n\tunsigned int c;\n\tint bits, i = 0;\n\n\tc = htmlParseCharRef(ctxt);\n\tif (c == 0)\n\t return;\n\n if (c < 0x80) { out[i++]= c; bits= -6; }\n else if (c < 0x800) { out[i++]=((c >> 6) & 0x1F) | 0xC0; bits= 0; }\n else if (c < 0x10000) { out[i++]=((c >> 12) & 0x0F) | 0xE0; bits= 6; }\n else { out[i++]=((c >> 18) & 0x07) | 0xF0; bits= 12; }\n\n for ( ; bits >= 0; bits-= 6) {\n out[i++]= ((c >> bits) & 0x3F) | 0x80;\n }\n\tout[i] = 0;\n\n\thtmlCheckParagraph(ctxt);\n\tif ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL))\n\t ctxt->sax->characters(ctxt->userData, out, i);\n } else {\n\tent = htmlParseEntityRef(ctxt, &name);\n\tif (name == NULL) {\n\t htmlCheckParagraph(ctxt);\n\t if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL))\n\t ctxt->sax->characters(ctxt->userData, BAD_CAST \"&\", 1);\n\t return;\n\t}\n\tif ((ent == NULL) || !(ent->value > 0)) {\n\t htmlCheckParagraph(ctxt);\n\t if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL)) {\n\t\tctxt->sax->characters(ctxt->userData, BAD_CAST \"&\", 1);\n\t\tctxt->sax->characters(ctxt->userData, name, xmlStrlen(name));\n\t\t/* ctxt->sax->characters(ctxt->userData, BAD_CAST \";\", 1); */\n\t }\n\t} else {\n\t unsigned int c;\n```\n\n\n## Upstream Fix\n```diff\nFrom 6a36fbe3b3e001a8a840b5c1fdd81cefc9947f0d Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard <veillard@redhat.com>\nDate: Mon, 29 Oct 2012 10:39:55 +0800\nSubject: [PATCH] Fix potential out of bound access\n\n---\n parser.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/parser.c b/parser.c\nindex 0d8d7f2e65..bd634e9348 100644\n--- a/parser.c\n+++ b/parser.c\n@@ -4076,7 +4076,7 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) {\n goto error;\n \n if ((in_space) && (normalize)) {\n- while (buf[len - 1] == 0x20) len--;\n+ while ((len > 0) && (buf[len - 1] == 0x20)) len--;\n }\n buf[len] = 0;\n if (RAW == '<') {\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 6a36fbe3b3e001a8a840b5c1fdd81cefc9947f0d Mon Sep 17 00:00:00 2001\nFrom: Daniel Veillard <veillard@redhat.com>\nDate: Mon, 29 Oct 2012 02:39:55 +0000\nSubject: Fix potential out of bound access\n\n---\nIndex: libxml2-2.8.0/parser.c\n===================================================================\n--- libxml2-2.8.0.orig/parser.c\t2012-05-18 09:30:30.000000000 +0200\n+++ libxml2-2.8.0/parser.c\t2012-12-07 12:00:57.111732279 +0100\n@@ -3931,7 +3931,7 @@ xmlParseAttValueComplex(xmlParserCtxtPtr\n \tc = CUR_CHAR(l);\n }\n if ((in_space) && (normalize)) {\n- while (buf[len - 1] == 0x20) len--;\n+ while ((len > 0) && (buf[len - 1] == 0x20)) len--;\n }\n buf[len] = 0;\n if (RAW == '<') {" } ]
{ "id": "libxml2-1859-libxml2-CVE-2012-5134.patch", "cve_id": "CVE-2013-2877", "package": "libxml2", "upstream_enriched": true, "upstream_commit": "6a36fbe3b3e001a8a840b5c1fdd81cefc9947f0d", "upstream_repo": "GNOME/libxml2", "tier": "adapted", "has_source_context": true, "license": "MIT", "context_tokens_est": 659, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-3119\n\nThe process_db_args function in plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c in the LDAP KDB module in kadmind in MIT Kerberos 5 (aka krb5) through 1.13.4 and 1.14.x through 1.14.1 mishandles the DB argument, which allows remote authenticated users to cause a denial of service (NULL pointer dereference and daemon crash) via a crafted request to modify a principal.\n\n## Package\nkrb5\n\n## Files to modify\n- krb5-1.12.1/src/lib/gssapi/krb5/gssapiP_krb5.h\n- krb5-1.12.1/src/lib/gssapi/krb5/gssapi_krb5.c\n- krb5-1.12.1/src/lib/gssapi/krb5/iakerb.c\n\n## Upstream Fix\n```diff\nFrom 3db8dfec1ef50ddd78d6ba9503185995876a39fd Mon Sep 17 00:00:00 2001\nFrom: Greg Hudson <ghudson@mit.edu>\nDate: Sun, 1 Nov 2015 22:45:21 -0500\nSubject: [PATCH] Fix IAKERB context export/import [CVE-2015-2698]\n\nThe patches for CVE-2015-2696 contained a regression in the newly\nadded IAKERB iakerb_gss_export_sec_context() function, which could\ncause it to corrupt memory. Fix the regression by properly\ndereferencing the context_handle pointer before casting it.\n\nAlso, the patches did not implement an IAKERB gss_import_sec_context()\nfunction, under the erroneous belief that an exported IAKERB context\nwould be tagged as a krb5 context. Implement it now to allow IAKERB\ncontexts to be successfully exported and imported after establishment.\n\nCVE-2015-2698:\n\nIn any MIT krb5 release with the patches for CVE-2015-2696 applied, an\napplication which calls gss_export_sec_context() may experience memory\ncorruption if the context was established using the IAKERB mechanism.\nHistorically, some vulnerabilities of this nature can be translated\ninto remote code execution, though the necessary exploits must be\ntailored to the individual application and are usually quite\ncomplicated.\n\n CVSSv2 Vector: AV:N/AC:H/Au:S/C:C/I:C/A:C/E:POC/RL:OF/RC:C\n\nticket: 8273 (new)\ntarget_version: 1.14\ntags: pullup\n---\n src/lib/gssapi/krb5/gssapiP_krb5.h | 5 ++++\n src/lib/gssapi/krb5/gssapi_krb5.c | 2 +-\n src/lib/gssapi/krb5/iakerb.c | 42 +++++++++++++++++++++++++-----\n 3 files changed, 41 insertions(+), 8 deletions(-)\n\ndiff --git a/src/lib/gssapi/krb5/gssapiP_krb5.h b/src/lib/gssapi/krb5/gssapiP_krb5.h\nindex 97e090d099f..16635006db1 100644\n--- a/src/lib/gssapi/krb5/gssapiP_krb5.h\n+++ b/src/lib/gssapi/krb5/gssapiP_krb5.h\n@@ -1397,6 +1397,11 @@ OM_uint32 KRB5_CALLCONV\n iakerb_gss_export_sec_context(OM_uint32 *minor_status,\n gss_ctx_id_t *context_handle,\n gss_buffer_t interprocess_token);\n+\n+OM_uint32 KRB5_CALLCONV\n+iakerb_gss_import_sec_context(OM_uint32 *minor_status,\n+ const gss_buffer_t interprocess_token,\n+ gss_ctx_id_t *context_handle);\n #endif /* LEAN_CLIENT */\n \n OM_uint32 KRB5_CALLCONV\ndiff --git a/src/lib/gssapi/krb5/gssapi_krb5.c b/src/lib/gssapi/krb5/gssapi_krb5.c\nindex c4dfdd6fbd1..aea60dc09fd 100644\n--- a/src/lib/gssapi/krb5/gssapi_krb5.c\n+++ b/src/lib/gssapi/krb5/gssapi_krb5.c\n@@ -970,7 +970,7 @@ static struct gss_config iakerb_mechanism = {\n NULL,\n #else\n iakerb_gss_export_sec_context,\n- NULL,\n+ iakerb_gss_import_sec_context,\n #endif\n krb5_gss_inquire_cred_by_mech,\n krb5_gss_inquire_names_for_mech,\ndiff --git a/src/lib/gssapi/krb5/iakerb.c b/src/lib/gssapi/krb5/iakerb.c\nindex e25862df47d..32a341ec58d 100644\n--- a/src/lib/gssapi/krb5/iakerb.c\n+++ b/src/lib/gssapi/krb5/iakerb.c\n@@ -1057,7 +1057,7 @@ iakerb_gss_export_sec_context(OM_uint32 *minor_status,\n gss_buffer_t interprocess_token)\n {\n OM_uint32 maj;\n- iakerb_ctx_id_t ctx = (iakerb_ctx_id_t)context_handle;\n+ iakerb_ctx_id_t ctx = (iakerb_ctx_id_t)*context_handle;\n \n /* We don't currently support exporting partially established contexts. */\n if (!ctx->established)\n@@ -1072,13 +1072,41 @@ iakerb_gss_export_sec_context(OM_uint32 *minor_status,\n return maj;\n }\n \n-/*\n- * Until we implement partial context exports, there are no IAKERB exported\n- * context tokens, only tokens for the underlying krb5 context. So we do not\n- * need to implement an iakerb_gss_import_sec_context() yet; it would be\n- * unreachable except via a manually constructed token.\n- */\n+OM_uint32 KRB5_CALLCONV\n+iakerb_gss_import_sec_context(OM_uint32 *minor_status,\n+ gss_buffer_t interprocess_token,\n+ gss_ctx_id_t *context_handle)\n+{\n+ OM_uint32 maj, tmpmin;\n+ krb5_error_code code;\n+ gss_ctx_id_t gssc;\n+ krb5_gss_ctx_id_t kctx;\n+ iakerb_ctx_id_t ctx;\n+\n+ maj = krb5_gss_import_sec_context(minor_status, interprocess_token, &gssc);\n+ if (maj != GSS_S_COMPLETE)\n+ return maj;\n+ kctx = (krb5_gss_ctx_id_t)gssc;\n+\n+ if (!kctx->established) {\n+ /* We don't currently support importing partially established\n+ * contexts. */\n+ krb5_gss_delete_sec_context(&tmpmin, &gssc, GSS_C_NO_BUFFER);\n+ return GSS_S_FAILURE;\n+ }\n \n+ code = iakerb_alloc_context(&ctx, kctx->initiate);\n+ if (code != 0) {\n+ krb5_gss_delete_sec_context(&tmpmin, &gssc, GSS_C_NO_BUFFER);\n+ *minor_status = code;\n+ return GSS_S_FAILURE;\n+ }\n+\n+ ctx->gssc = gssc;\n+ ctx->established = 1;\n+ *context_handle = (gss_ctx_id_t)ctx;\n+ return GSS_S_COMPLETE;\n+}\n #endif /* LEAN_CLIENT */\n \n OM_uint32 KRB5_CALLCONV\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 3db8dfec1ef50ddd78d6ba9503185995876a39fd Mon Sep 17 00:00:00 2001\nFrom: Greg Hudson <ghudson@mit.edu>\nDate: Sun, 1 Nov 2015 22:45:21 -0500\nSubject: [PATCH] Fix IAKERB context export/import [CVE-2015-2698]\n\nThe patches for CVE-2015-2696 contained a regression in the newly\nadded IAKERB iakerb_gss_export_sec_context() function, which could\ncause it to corrupt memory. Fix the regression by properly\ndereferencing the context_handle pointer before casting it.\n\nAlso, the patches did not implement an IAKERB gss_import_sec_context()\nfunction, under the erroneous belief that an exported IAKERB context\nwould be tagged as a krb5 context. Implement it now to allow IAKERB\ncontexts to be successfully exported and imported after establishment.\n\nCVE-2015-2698:\n\nIn any MIT krb5 release with the patches for CVE-2015-2696 applied, an\napplication which calls gss_export_sec_context() may experience memory\ncorruption if the context was established using the IAKERB mechanism.\nHistorically, some vulnerabilities of this nature can be translated\ninto remote code execution, though the necessary exploits must be\ntailored to the individual application and are usually quite\ncomplicated.\n\n CVSSv2 Vector: AV:N/AC:H/Au:S/C:C/I:C/A:C/E:POC/RL:OF/RC:C\n\nticket: 8273 (new)\ntarget_version: 1.14\ntags: pullup\n\nLine numbers are adjusted by Howard Guo <hguo@suse.com> to fit into this older\nKerberos version distributed on SLE 12.\n\ndiff -rupN krb5-1.12.1/src/lib/gssapi/krb5/gssapi_krb5.c krb5-1.12.1-patched/src/lib/gssapi/krb5/gssapi_krb5.c\n--- krb5-1.12.1/src/lib/gssapi/krb5/gssapi_krb5.c\t2015-11-10 15:37:32.209657599 +0100\n+++ krb5-1.12.1-patched/src/lib/gssapi/krb5/gssapi_krb5.c\t2015-11-10 15:38:52.106323672 +0100\n@@ -945,7 +945,7 @@ static struct gss_config iakerb_mechanis\n NULL,\n #else\n iakerb_gss_export_sec_context,\n- NULL,\n+ iakerb_gss_import_sec_context,\n #endif\n krb5_gss_inquire_cred_by_mech,\n krb5_gss_inquire_names_for_mech,\ndiff -rupN krb5-1.12.1/src/lib/gssapi/krb5/gssapiP_krb5.h krb5-1.12.1-patched/src/lib/gssapi/krb5/gssapiP_krb5.h\n--- krb5-1.12.1/src/lib/gssapi/krb5/gssapiP_krb5.h\t2015-11-10 15:37:32.209657599 +0100\n+++ krb5-1.12.1-patched/src/lib/gssapi/krb5/gssapiP_krb5.h\t2015-11-10 15:38:52.106323672 +0100\n@@ -1393,6 +1393,11 @@ OM_uint32 KRB5_CALLCONV\n iakerb_gss_export_sec_context(OM_uint32 *minor_status,\n gss_ctx_id_t *context_handle,\n gss_buffer_t interprocess_token);\n+\n+OM_uint32 KRB5_CALLCONV\n+iakerb_gss_import_sec_context(OM_uint32 *minor_status,\n+ const gss_buffer_t interprocess_token,\n+ gss_ctx_id_t *context_handle);\n #endif /* LEAN_CLIENT */\n \n OM_uint32 KRB5_CALLCONV\ndiff -rupN krb5-1.12.1/src/lib/gssapi/krb5/iakerb.c krb5-1.12.1-patched/src/lib/gssapi/krb5/iakerb.c\n--- krb5-1.12.1/src/lib/gssapi/krb5/iakerb.c\t2015-11-10 15:37:32.209657599 +0100\n+++ krb5-1.12.1-patched/src/lib/gssapi/krb5/iakerb.c\t2015-11-10 15:41:43.431752632 +0100\n@@ -1061,7 +1061,7 @@ iakerb_gss_export_sec_context(OM_uint32\n gss_buffer_t interprocess_token)\n {\n OM_uint32 maj;\n- iakerb_ctx_id_t ctx = (iakerb_ctx_id_t)context_handle;\n+ iakerb_ctx_id_t ctx = (iakerb_ctx_id_t)*context_handle;\n \n /* We don't currently support exporting partially established contexts. */\n if (!ctx->established)\n@@ -1076,12 +1076,41 @@ iakerb_gss_export_sec_context(OM_uint32\n return maj;\n }\n \n-/*\n- * Until we implement partial context exports, there are no SPNEGO exported\n- * context tokens, only tokens for the underlying krb5 context. So we do not\n- * need to implement an iakerb_gss_import_sec_context() yet; it would be\n- * unreachable except via a manually constructed token.\n- */\n+OM_uint32 KRB5_CALLCONV\n+iakerb_gss_import_sec_context(OM_uint32 *minor_status,\n+ gss_buffer_t interprocess_token,\n+ gss_ctx_id_t *context_handle)\n+{\n+ OM_uint32 maj, tmpmin;\n+ krb5_error_code code;\n+ gss_ctx_id_t gssc;\n+ krb5_gss_ctx_id_t kctx;\n+ iakerb_ctx_id_t ctx;\n+\n+ maj = krb5_gss_import_sec_context(minor_status, interprocess_token, &gssc);\n+ if (maj != GSS_S_COMPLETE)\n+ return maj;\n+ kctx = (krb5_gss_ctx_id_t)gssc;\n+\n+ if (!kctx->established) {\n+ /* We don't currently support importing partially established\n+ * contexts. */\n+ krb5_gss_delete_sec_context(&tmpmin, &gssc, GSS_C_NO_BUFFER);\n+ return GSS_S_FAILURE;\n+ }\n+\n+ code = iakerb_alloc_context(&ctx, kctx->initiate);\n+ if (code != 0) {\n+ krb5_gss_delete_sec_context(&tmpmin, &gssc, GSS_C_NO_BUFFER);\n+ *minor_status = code;\n+ return GSS_S_FAILURE;\n+ }\n+\n+ ctx->gssc = gssc;\n+ ctx->established = 1;\n+ *context_handle = (gss_ctx_id_t)ctx;\n+ return GSS_S_COMPLETE;\n+}\n \n #endif /* LEAN_CLIENT */" } ]
{ "id": "krb5-4938-0103-Fix-IAKERB-context-export", "cve_id": "CVE-2016-3119", "package": "krb5", "upstream_enriched": true, "upstream_commit": "3db8dfec1ef50ddd78d6ba9503185995876a39fd", "upstream_repo": "krb5/krb5", "tier": "adapted", "has_source_context": false, "license": "MIT", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2015-8629\n\nThe xdr_nullstring function in lib/kadm5/kadm_rpc_xdr.c in kadmind in MIT Kerberos 5 (aka krb5) before 1.13.4 and 1.14.x before 1.14.1 does not verify whether '\\0' characters exist as expected, which allows remote authenticated users to obtain sensitive information or cause a denial of service (out-of-bounds read) via a crafted string.\n\n## Package\nkrb5\n\n## Files to modify\n- src/kadmin/server/server_stubs.c\n\n## Upstream Fix\n```diff\nFrom 83ed75feba32e46f736fcce0d96a0445f29b96c2 Mon Sep 17 00:00:00 2001\nFrom: Greg Hudson <ghudson@mit.edu>\nDate: Fri, 8 Jan 2016 13:16:54 -0500\nSubject: [PATCH] Fix leaks in kadmin server stubs [CVE-2015-8631]\n\nIn each kadmind server stub, initialize the client_name and\nserver_name variables, and release them in the cleanup handler. Many\nof the stubs will otherwise leak the client and server name if\nkrb5_unparse_name() fails. Also make sure to free the prime_arg\nvariables in rename_principal_2_svc(), or we can leak the first one if\nunparsing the second one fails. Discovered by Simo Sorce.\n\nCVE-2015-8631:\n\nIn all versions of MIT krb5, an authenticated attacker can cause\nkadmind to leak memory by supplying a null principal name in a request\nwhich uses one. Repeating these requests will eventually cause\nkadmind to exhaust all available memory.\n\n CVSSv2 Vector: AV:N/AC:L/Au:S/C:N/I:N/A:C/E:POC/RL:OF/RC:C\n\nticket: 8343 (new)\ntarget_version: 1.14-next\ntarget_version: 1.13-next\ntags: pullup\n\ndiff --git a/src/kadmin/server/server_stubs.c b/src/kadmin/server/server_stubs.c\nindex 1879dc6..6ac797e 100644\n--- a/src/kadmin/server/server_stubs.c\n+++ b/src/kadmin/server/server_stubs.c\n@@ -334,7 +334,8 @@ create_principal_2_svc(cprinc_arg *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name, service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n restriction_t *rp;\n@@ -382,10 +383,10 @@ create_principal_2_svc(cprinc_arg *arg, struct svc_req *rqstp)\n krb5_free_error_message(handle->context, errmsg);\n }\n free(prime_arg);\n- gss_release_buffer(&minor_stat, &client_name);\n- gss_release_buffer(&minor_stat, &service_name);\n \n exit_func:\n+ gss_release_buffer(&minor_stat, &client_name);\n+ gss_release_buffer(&minor_stat, &service_name);\n free_server_handle(handle);\n return &ret;\n }\n@@ -395,7 +396,8 @@ create_principal3_2_svc(cprinc3_arg *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name, service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n restriction_t *rp;\n@@ -444,10 +446,10 @@ create_principal3_2_svc(cprinc3_arg *arg, struct svc_req *rqstp)\n krb5_free_error_message(handle->context, errmsg);\n }\n free(prime_arg);\n- gss_release_buffer(&minor_stat, &client_name);\n- gss_release_buffer(&minor_stat, &service_name);\n \n exit_func:\n+ gss_release_buffer(&minor_stat, &client_name);\n+ gss_release_buffer(&minor_stat, &service_name);\n free_server_handle(handle);\n return &ret;\n }\n@@ -457,8 +459,8 @@ delete_principal_2_svc(dprinc_arg *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n const char *errmsg = NULL;\n@@ -501,10 +503,10 @@ delete_principal_2_svc(dprinc_arg *arg, struct svc_req *rqstp)\n \n }\n free(prime_arg);\n- gss_release_buffer(&minor_stat, &client_name);\n- gss_release_buffer(&minor_stat, &service_name);\n \n exit_func:\n+ gss_release_buffer(&minor_stat, &client_name);\n+ gss_release_buffer(&minor_stat, &service_name);\n free_server_handle(handle);\n return &ret;\n }\n@@ -514,8 +516,8 @@ modify_principal_2_svc(mprinc_arg *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n restriction_t *rp;\n@@ -559,9 +561,9 @@ modify_principal_2_svc(mprinc_arg *arg, struct svc_req *rqstp)\n krb5_free_error_message(handle->context, errmsg);\n }\n free(prime_arg);\n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -570,10 +572,9 @@ generic_ret *\n rename_principal_2_svc(rprinc_arg *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n- char *prime_arg1,\n- *prime_arg2;\n- gss_buffer_desc client_name,\n- service_name;\n+ char *prime_arg1 = NULL, *prime_arg2 = NULL;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n restriction_t *rp;\n@@ -655,11 +656,11 @@ rename_principal_2_svc(rprinc_arg *arg, struct svc_req *rqstp)\n krb5_free_error_message(handle->context, errmsg);\n \n }\n+exit_func:\n free(prime_arg1);\n free(prime_arg2);\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -669,8 +670,8 @@ get_principal_2_svc(gprinc_arg *arg, struct svc_req *rqstp)\n {\n static gprinc_ret ret;\n char *prime_arg, *funcname;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n const char *errmsg = NULL;\n@@ -719,9 +720,9 @@ get_principal_2_svc(gprinc_arg *arg, struct svc_req *rqstp)\n krb5_free_error_message(handle->context, errmsg);\n }\n free(prime_arg);\n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -731,8 +732,8 @@ get_princs_2_svc(gprincs_arg *arg, struct svc_req *rqstp)\n {\n static gprincs_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n const char *errmsg = NULL;\n@@ -777,9 +778,9 @@ get_princs_2_svc(gprincs_arg *arg, struct svc_req *rqstp)\n krb5_free_error_message(handle->context, errmsg);\n \n }\n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -789,8 +790,8 @@ chpass_principal_2_svc(chpass_arg *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ g\n... (truncated)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 83ed75feba32e46f736fcce0d96a0445f29b96c2 Mon Sep 17 00:00:00 2001\nFrom: Greg Hudson <ghudson@mit.edu>\nDate: Fri, 8 Jan 2016 13:16:54 -0500\nSubject: [PATCH] Fix leaks in kadmin server stubs [CVE-2015-8631]\n\nIn each kadmind server stub, initialize the client_name and\nserver_name variables, and release them in the cleanup handler. Many\nof the stubs will otherwise leak the client and server name if\nkrb5_unparse_name() fails. Also make sure to free the prime_arg\nvariables in rename_principal_2_svc(), or we can leak the first one if\nunparsing the second one fails. Discovered by Simo Sorce.\n\nCVE-2015-8631:\n\nIn all versions of MIT krb5, an authenticated attacker can cause\nkadmind to leak memory by supplying a null principal name in a request\nwhich uses one. Repeating these requests will eventually cause\nkadmind to exhaust all available memory.\n\n CVSSv2 Vector: AV:N/AC:L/Au:S/C:N/I:N/A:C/E:POC/RL:OF/RC:C\n\nticket: 8343 (new)\ntarget_version: 1.14-next\ntarget_version: 1.13-next\ntags: pullup\n\ndiff --git a/src/kadmin/server/server_stubs.c b/src/kadmin/server/server_stubs.c\nindex 1879dc6..6ac797e 100644\n--- a/src/kadmin/server/server_stubs.c\n+++ b/src/kadmin/server/server_stubs.c\n@@ -334,7 +334,8 @@ create_principal_2_svc(cprinc_arg *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name, service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n restriction_t *rp;\n@@ -382,10 +383,10 @@ create_principal_2_svc(cprinc_arg *arg, struct svc_req *rqstp)\n krb5_free_error_message(handle->context, errmsg);\n }\n free(prime_arg);\n- gss_release_buffer(&minor_stat, &client_name);\n- gss_release_buffer(&minor_stat, &service_name);\n \n exit_func:\n+ gss_release_buffer(&minor_stat, &client_name);\n+ gss_release_buffer(&minor_stat, &service_name);\n free_server_handle(handle);\n return &ret;\n }\n@@ -395,7 +396,8 @@ create_principal3_2_svc(cprinc3_arg *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name, service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n restriction_t *rp;\n@@ -444,10 +446,10 @@ create_principal3_2_svc(cprinc3_arg *arg, struct svc_req *rqstp)\n krb5_free_error_message(handle->context, errmsg);\n }\n free(prime_arg);\n- gss_release_buffer(&minor_stat, &client_name);\n- gss_release_buffer(&minor_stat, &service_name);\n \n exit_func:\n+ gss_release_buffer(&minor_stat, &client_name);\n+ gss_release_buffer(&minor_stat, &service_name);\n free_server_handle(handle);\n return &ret;\n }\n@@ -457,8 +459,8 @@ delete_principal_2_svc(dprinc_arg *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n const char *errmsg = NULL;\n@@ -501,10 +503,10 @@ delete_principal_2_svc(dprinc_arg *arg, struct svc_req *rqstp)\n \n }\n free(prime_arg);\n- gss_release_buffer(&minor_stat, &client_name);\n- gss_release_buffer(&minor_stat, &service_name);\n \n exit_func:\n+ gss_release_buffer(&minor_stat, &client_name);\n+ gss_release_buffer(&minor_stat, &service_name);\n free_server_handle(handle);\n return &ret;\n }\n@@ -514,8 +516,8 @@ modify_principal_2_svc(mprinc_arg *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n restriction_t *rp;\n@@ -559,9 +561,9 @@ modify_principal_2_svc(mprinc_arg *arg, struct svc_req *rqstp)\n krb5_free_error_message(handle->context, errmsg);\n }\n free(prime_arg);\n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -570,10 +572,9 @@ generic_ret *\n rename_principal_2_svc(rprinc_arg *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n- char *prime_arg1,\n- *prime_arg2;\n- gss_buffer_desc client_name,\n- service_name;\n+ char *prime_arg1 = NULL, *prime_arg2 = NULL;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n restriction_t *rp;\n@@ -655,11 +656,11 @@ rename_principal_2_svc(rprinc_arg *arg, struct svc_req *rqstp)\n krb5_free_error_message(handle->context, errmsg);\n \n }\n+exit_func:\n free(prime_arg1);\n free(prime_arg2);\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -669,8 +670,8 @@ get_principal_2_svc(gprinc_arg *arg, struct svc_req *rqstp)\n {\n static gprinc_ret ret;\n char *prime_arg, *funcname;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n const char *errmsg = NULL;\n@@ -719,9 +720,9 @@ get_principal_2_svc(gprinc_arg *arg, struct svc_req *rqstp)\n krb5_free_error_message(handle->context, errmsg);\n }\n free(prime_arg);\n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -731,8 +732,8 @@ get_princs_2_svc(gprincs_arg *arg, struct svc_req *rqstp)\n {\n static gprincs_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n const char *errmsg = NULL;\n@@ -777,9 +778,9 @@ get_princs_2_svc(gprincs_arg *arg, struct svc_req *rqstp)\n krb5_free_error_message(handle->context, errmsg);\n \n }\n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -789,8 +790,8 @@ chpass_principal_2_svc(chpass_arg *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n const char *errmsg = NULL;\n@@ -840,9 +841,9 @@ chpass_principal_2_svc(chpass_arg *arg, struct svc_req *rqstp)\n }\n \n free(prime_arg);\n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -852,8 +853,8 @@ chpass_principal3_2_svc(chpass3_arg *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n const char *errmsg = NULL;\n@@ -909,9 +910,9 @@ chpass_principal3_2_svc(chpass3_arg *arg, struct svc_req *rqstp)\n }\n \n free(prime_arg);\n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -921,8 +922,8 @@ setv4key_principal_2_svc(setv4key_arg *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n const char *errmsg = NULL;\n@@ -969,9 +970,9 @@ setv4key_principal_2_svc(setv4key_arg *arg, struct svc_req *rqstp)\n }\n \n free(prime_arg);\n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -981,8 +982,8 @@ setkey_principal_2_svc(setkey_arg *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n const char *errmsg = NULL;\n@@ -1029,9 +1030,9 @@ setkey_principal_2_svc(setkey_arg *arg, struct svc_req *rqstp)\n }\n \n free(prime_arg);\n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -1041,8 +1042,8 @@ setkey_principal3_2_svc(setkey3_arg *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n const char *errmsg = NULL;\n@@ -1092,9 +1093,9 @@ setkey_principal3_2_svc(setkey3_arg *arg, struct svc_req *rqstp)\n }\n \n free(prime_arg);\n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -1106,8 +1107,8 @@ chrand_principal_2_svc(chrand_arg *arg, struct svc_req *rqstp)\n krb5_keyblock *k;\n int nkeys;\n char *prime_arg, *funcname;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n const char *errmsg = NULL;\n@@ -1164,9 +1165,9 @@ chrand_principal_2_svc(chrand_arg *arg, struct svc_req *rqstp)\n krb5_free_error_message(handle->context, errmsg);\n }\n free(prime_arg);\n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -1178,8 +1179,8 @@ chrand_principal3_2_svc(chrand3_arg *arg, struct svc_req *rqstp)\n krb5_keyblock *k;\n int nkeys;\n char *prime_arg, *funcname;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n const char *errmsg = NULL;\n@@ -1241,9 +1242,9 @@ chrand_principal3_2_svc(chrand3_arg *arg, struct svc_req *rqstp)\n krb5_free_error_message(handle->context, errmsg);\n }\n free(prime_arg);\n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -1253,8 +1254,8 @@ create_policy_2_svc(cpol_arg *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n const char *errmsg = NULL;\n@@ -1295,9 +1296,9 @@ create_policy_2_svc(cpol_arg *arg, struct svc_req *rqstp)\n if (errmsg != NULL)\n krb5_free_error_message(handle->context, errmsg);\n }\n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -1307,8 +1308,8 @@ delete_policy_2_svc(dpol_arg *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n const char *errmsg = NULL;\n@@ -1347,9 +1348,9 @@ delete_policy_2_svc(dpol_arg *arg, struct svc_req *rqstp)\n if (errmsg != NULL)\n krb5_free_error_message(handle->context, errmsg);\n }\n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -1359,8 +1360,8 @@ modify_policy_2_svc(mpol_arg *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n const char *errmsg = NULL;\n@@ -1400,9 +1401,9 @@ modify_policy_2_svc(mpol_arg *arg, struct svc_req *rqstp)\n if (errmsg != NULL)\n krb5_free_error_message(handle->context, errmsg);\n }\n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -1413,8 +1414,8 @@ get_policy_2_svc(gpol_arg *arg, struct svc_req *rqstp)\n static gpol_ret ret;\n kadm5_ret_t ret2;\n char *prime_arg, *funcname;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_principal_ent_rec caller_ent;\n kadm5_server_handle_t handle;\n@@ -1475,9 +1476,9 @@ get_policy_2_svc(gpol_arg *arg, struct svc_req *rqstp)\n log_unauth(funcname, prime_arg,\n &client_name, &service_name, rqstp);\n }\n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n \n@@ -1488,8 +1489,8 @@ get_pols_2_svc(gpols_arg *arg, struct svc_req *rqstp)\n {\n static gpols_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n const char *errmsg = NULL;\n@@ -1531,9 +1532,9 @@ get_pols_2_svc(gpols_arg *arg, struct svc_req *rqstp)\n if (errmsg != NULL)\n krb5_free_error_message(handle->context, errmsg);\n }\n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -1541,7 +1542,8 @@ exit_func:\n getprivs_ret * get_privs_2_svc(krb5_ui_4 *arg, struct svc_req *rqstp)\n {\n static getprivs_ret ret;\n- gss_buffer_desc client_name, service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n const char *errmsg = NULL;\n@@ -1571,9 +1573,9 @@ getprivs_ret * get_privs_2_svc(krb5_ui_4 *arg, struct svc_req *rqstp)\n if (errmsg != NULL)\n krb5_free_error_message(handle->context, errmsg);\n \n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -1583,7 +1585,8 @@ purgekeys_2_svc(purgekeys_arg *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n char *prime_arg, *funcname;\n- gss_buffer_desc client_name, service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n \n@@ -1629,9 +1632,9 @@ purgekeys_2_svc(purgekeys_arg *arg, struct svc_req *rqstp)\n krb5_free_error_message(handle->context, errmsg);\n }\n free(prime_arg);\n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -1641,8 +1644,8 @@ get_strings_2_svc(gstrings_arg *arg, struct svc_req *rqstp)\n {\n static gstrings_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n const char *errmsg = NULL;\n@@ -1688,9 +1691,9 @@ get_strings_2_svc(gstrings_arg *arg, struct svc_req *rqstp)\n krb5_free_error_message(handle->context, errmsg);\n }\n free(prime_arg);\n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -1700,8 +1703,8 @@ set_string_2_svc(sstring_arg *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n char *prime_arg;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n OM_uint32 minor_stat;\n kadm5_server_handle_t handle;\n const char *errmsg = NULL;\n@@ -1744,9 +1747,9 @@ set_string_2_svc(sstring_arg *arg, struct svc_req *rqstp)\n krb5_free_error_message(handle->context, errmsg);\n }\n free(prime_arg);\n+exit_func:\n gss_release_buffer(&minor_stat, &client_name);\n gss_release_buffer(&minor_stat, &service_name);\n-exit_func:\n free_server_handle(handle);\n return &ret;\n }\n@@ -1754,8 +1757,8 @@ exit_func:\n generic_ret *init_2_svc(krb5_ui_4 *arg, struct svc_req *rqstp)\n {\n static generic_ret ret;\n- gss_buffer_desc client_name,\n- service_name;\n+ gss_buffer_desc client_name = GSS_C_EMPTY_BUFFER;\n+ gss_buffer_desc service_name = GSS_C_EMPTY_BUFFER;\n kadm5_server_handle_t handle;\n OM_uint32 minor_stat;\n const char *errmsg = NULL;\n@@ -1797,10 +1800,10 @@ generic_ret *init_2_svc(krb5_ui_4 *arg, struct svc_req *rqstp)\n rqstp->rq_cred.oa_flavor);\n if (errmsg != NULL)\n krb5_free_error_message(NULL, errmsg);\n- gss_release_buffer(&minor_stat, &client_name);\n- gss_release_buffer(&minor_stat, &service_name);\n \n exit_func:\n+ gss_release_buffer(&minor_stat, &client_name);\n+ gss_release_buffer(&minor_stat, &service_name);\n return(&ret);\n }\n \n-- \n2.7.0" } ]
{ "id": "krb5-4670-0105-Fix-leaks-in-kadmin-serve", "cve_id": "CVE-2015-8629", "package": "krb5", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "adapted", "has_source_context": false, "license": "MIT", "context_tokens_est": null, "context_files": null }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2012-5669\n\nThe _bdf_parse_glyphs function in FreeType before 2.4.11 allows context-dependent attackers to cause a denial of service (crash) and possibly execute arbitrary code via vectors related to BDF fonts and an incorrect calculation that triggers an out-of-bounds read.\n\n## Package\nfreetype2\n\n## Files to modify\n- src/base/ftcalc.c\n- freetype-2.4.7.orig/src/base/ftcalc.c\n\n## Target Source Code\n\n### src/base/ftcalc.c\n\n#### region() [lines 1-54]\n```c\n/***************************************************************************/\n/* */\n/* ftcalc.c */\n/* */\n/* Arithmetic computations (body). */\n/* */\n/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2008 by */\n/* David Turner, Robert Wilhelm, and Werner Lemberg. */\n/* */\n/* This file is part of the FreeType project, and may only be used, */\n/* modified, and distributed under the terms of the FreeType project */\n/* license, LICENSE.TXT. By continuing to use, modify, or distribute */\n/* this file you indicate that you have read the license and */\n/* understand and accept it fully. */\n/* */\n/***************************************************************************/\n\n /*************************************************************************/\n /* */\n /* Support for 1-complement arithmetic has been totally dropped in this */\n /* release. You can still write your own code if you need it. */\n /* */\n /*************************************************************************/\n\n /*************************************************************************/\n /* */\n /* Implementing basic computation routines. */\n /* */\n /* FT_MulDiv(), FT_MulFix(), FT_DivFix(), FT_RoundFix(), FT_CeilFix(), */\n /* and FT_FloorFix() are declared in freetype.h. */\n /* */\n /*************************************************************************/\n\n\n#include <ft2build.h>\n#include FT_GLYPH_H\n#include FT_INTERNAL_CALC_H\n#include FT_INTERNAL_DEBUG_H\n#include FT_INTERNAL_OBJECTS_H\n\n#ifdef FT_MULFIX_INLINED\n#undef FT_MulFix\n#endif\n\n/* we need to define a 64-bits data type here */\n\n#ifdef FT_LONG64\n\n typedef FT_INT64 FT_Int64;\n\n#else\n\n typedef struct FT_Int64_\n {\n```\n\n#### region() [lines 286-321]\n```c\n\n\n static FT_UInt32\n ft_div64by32( FT_UInt32 hi,\n FT_UInt32 lo,\n FT_UInt32 y )\n {\n FT_UInt32 r, q;\n FT_Int i;\n\n\n q = 0;\n r = hi;\n\n if ( r >= y )\n return (FT_UInt32)0x7FFFFFFFL;\n\n i = 32;\n do\n {\n r <<= 1;\n q <<= 1;\n r |= lo >> 31;\n\n if ( r >= (FT_UInt32)y )\n {\n r -= y;\n q |= 1;\n }\n lo <<= 1;\n } while ( --i );\n\n return q;\n }\n\n\n```\n\n#### region() [lines 355-394]\n```c\n /* */\n\n FT_EXPORT_DEF( FT_Long )\n FT_MulDiv( FT_Long a,\n FT_Long b,\n FT_Long c )\n {\n long s;\n\n\n /* XXX: this function does not allow 64-bit arguments */\n if ( a == 0 || b == c )\n return a;\n\n s = a; a = FT_ABS( a );\n s ^= b; b = FT_ABS( b );\n s ^= c; c = FT_ABS( c );\n\n if ( a <= 46340L && b <= 46340L && c <= 176095L && c > 0 )\n a = ( a * b + ( c >> 1 ) ) / c;\n\n else if ( c > 0 )\n {\n FT_Int64 temp, temp2;\n\n\n ft_multo64( (FT_Int32)a, (FT_Int32)b, &temp );\n\n temp2.hi = 0;\n temp2.lo = (FT_UInt32)(c >> 1);\n FT_Add64( &temp, &temp2, &temp );\n a = ft_div64by32( temp.hi, temp.lo, (FT_Int32)c );\n }\n else\n a = 0x7FFFFFFFL;\n\n return ( s < 0 ? -a : a );\n }\n\n\n```\n\n#### region() [lines 395-429]\n```c\n#ifdef TT_USE_BYTECODE_INTERPRETER\n\n FT_BASE_DEF( FT_Long )\n FT_MulDiv_No_Round( FT_Long a,\n FT_Long b,\n FT_Long c )\n {\n long s;\n\n\n if ( a == 0 || b == c )\n return a;\n\n s = a; a = FT_ABS( a );\n s ^= b; b = FT_ABS( b );\n s ^= c; c = FT_ABS( c );\n\n if ( a <= 46340L && b <= 46340L && c > 0 )\n a = a * b / c;\n\n else if ( c > 0 )\n {\n FT_Int64 temp;\n\n\n ft_multo64( (FT_Int32)a, (FT_Int32)b, &temp );\n a = ft_div64by32( temp.hi, temp.lo, (FT_Int32)c );\n }\n else\n a = 0x7FFFFFFFL;\n\n return ( s < 0 ? -a : a );\n }\n\n#endif /* TT_USE_BYTECODE_INTERPRETER */\n```\n\n#### region() [lines 533-573]\n```c\n /* documentation is in freetype.h */\n\n FT_EXPORT_DEF( FT_Long )\n FT_DivFix( FT_Long a,\n FT_Long b )\n {\n FT_Int32 s;\n FT_UInt32 q;\n\n\n /* XXX: this function does not allow 64-bit arguments */\n s = (FT_Int32)a; a = FT_ABS( a );\n s ^= (FT_Int32)b; b = FT_ABS( b );\n\n if ( b == 0 )\n {\n /* check for division by 0 */\n q = (FT_UInt32)0x7FFFFFFFL;\n }\n else if ( ( a >> 16 ) == 0 )\n {\n /* compute result directly */\n q = (FT_UInt32)( (a << 16) + (b >> 1) ) / (FT_UInt32)b;\n }\n else\n {\n /* we need more bits; we have to do it by hand */\n FT_Int64 temp, temp2;\n\n temp.hi = (FT_Int32) (a >> 16);\n temp.lo = (FT_UInt32)(a << 16);\n temp2.hi = 0;\n temp2.lo = (FT_UInt32)( b >> 1 );\n FT_Add64( &temp, &temp2, &temp );\n q = ft_div64by32( temp.hi, temp.lo, (FT_Int32)b );\n }\n\n return ( s < 0 ? -(FT_Int32)q : (FT_Int32)q );\n }\n\n\n```\n\n\n## Upstream Fix\n```diff\nFrom ba67957d5ead443f4b6b31805d6e780d54361ca4 Mon Sep 17 00:00:00 2001\nFrom: Werner Lemberg <wl@gnu.org>\nDate: Sat, 3 Mar 2012 12:27:18 +0100\nSubject: [PATCH] Fix Savannah bug #35660.\n\nFor some divisions, we use casts to 32bit entities. Always guard\nagainst division by zero with these casts also.\n\n* src/base/ftcalc.c (ft_div64by32): Remove redundant cast.\n(FT_MulDiv, FT_MulDiv_No_Round): Add 32bit cast.\n(FT_DivFix): Add 32bit cast (this omission triggered the bug).\n---\n ChangeLog | 11 +++++++++++\n src/base/ftcalc.c | 17 +++++++++--------\n 2 files changed, 20 insertions(+), 8 deletions(-)\n\ndiff --git a/ChangeLog b/ChangeLog\nindex 7e5814daf..f5840ca3f 100644\n--- a/ChangeLog\n+++ b/ChangeLog\n@@ -1,3 +1,14 @@\n+2012-03-03 Werner Lemberg <wl@gnu.org>\n+\n+\tFix Savannah bug #35660.\n+\n+\tFor some divisions, we use casts to 32bit entities. Always guard\n+\tagainst division by zero with these casts also.\n+\n+\t* src/base/ftcalc.c (ft_div64by32): Remove redundant cast.\n+\t(FT_MulDiv, FT_MulDiv_No_Round): Add 32bit cast.\n+\t(FT_DivFix): Add 32bit cast (this omission triggered the bug).\n+\n 2012-03-03 Werner Lemberg <wl@gnu.org>\n \n \t[psaux] Fix handling of track kerning.\ndiff --git a/src/base/ftcalc.c b/src/base/ftcalc.c\nindex 6ff01ee99..2aeea0459 100644\n--- a/src/base/ftcalc.c\n+++ b/src/base/ftcalc.c\n@@ -4,7 +4,7 @@\n /* */\n /* Arithmetic computations (body). */\n /* */\n-/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2008 by */\n+/* Copyright 1996-2006, 2008, 2012 by */\n /* David Turner, Robert Wilhelm, and Werner Lemberg. */\n /* */\n /* This file is part of the FreeType project, and may only be used, */\n@@ -307,7 +307,7 @@\n q <<= 1;\n r |= lo >> 31;\n \n- if ( r >= (FT_UInt32)y )\n+ if ( r >= y )\n {\n r -= y;\n q |= 1;\n@@ -373,7 +373,7 @@\n if ( a <= 46340L && b <= 46340L && c <= 176095L && c > 0 )\n a = ( a * b + ( c >> 1 ) ) / c;\n \n- else if ( c > 0 )\n+ else if ( (FT_Int32)c > 0 )\n {\n FT_Int64 temp, temp2;\n \n@@ -412,7 +412,7 @@\n if ( a <= 46340L && b <= 46340L && c > 0 )\n a = a * b / c;\n \n- else if ( c > 0 )\n+ else if ( (FT_Int32)c > 0 )\n {\n FT_Int64 temp;\n \n@@ -544,7 +544,7 @@\n s = (FT_Int32)a; a = FT_ABS( a );\n s ^= (FT_Int32)b; b = FT_ABS( b );\n \n- if ( b == 0 )\n+ if ( (FT_UInt32)b == 0 )\n {\n /* check for division by 0 */\n q = (FT_UInt32)0x7FFFFFFFL;\n@@ -552,15 +552,16 @@\n else if ( ( a >> 16 ) == 0 )\n {\n /* compute result directly */\n- q = (FT_UInt32)( (a << 16) + (b >> 1) ) / (FT_UInt32)b;\n+ q = (FT_UInt32)( ( a << 16 ) + ( b >> 1 ) ) / (FT_UInt32)b;\n }\n else\n {\n /* we need more bits; we have to do it by hand */\n FT_Int64 temp, temp2;\n \n- temp.hi = (FT_Int32) (a >> 16);\n- temp.lo = (FT_UInt32)(a << 16);\n+\n+ temp.hi = (FT_Int32) ( a >> 16 );\n+ temp.lo = (FT_UInt32)( a << 16 );\n temp2.hi = 0;\n temp2.lo = (FT_UInt32)( b >> 1 );\n FT_Add64( &temp, &temp2, &temp );\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From ba67957d5ead443f4b6b31805d6e780d54361ca4 Mon Sep 17 00:00:00 2001\nFrom: Werner Lemberg <wl@gnu.org>\nDate: Sat, 03 Mar 2012 11:27:18 +0000\nSubject: Fix Savannah bug #35660.\n\nFor some divisions, we use casts to 32bit entities. Always guard\nagainst division by zero with these casts also.\n\n* src/base/ftcalc.c (ft_div64by32): Remove redundant cast.\n(FT_MulDiv, FT_MulDiv_No_Round): Add 32bit cast.\n(FT_DivFix): Add 32bit cast (this omission triggered the bug).\n---\n---\n src/base/ftcalc.c | 17 +++++++++--------\n 1 file changed, 9 insertions(+), 8 deletions(-)\n\nIndex: freetype-2.4.7/src/base/ftcalc.c\n===================================================================\n--- freetype-2.4.7.orig/src/base/ftcalc.c\n+++ freetype-2.4.7/src/base/ftcalc.c\n@@ -2,11 +2,11 @@\n /* */\n /* ftcalc.c */\n /* */\n /* Arithmetic computations (body). */\n /* */\n-/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2008 by */\n+/* Copyright 1996-2006, 2008, 2012 by */\n /* David Turner, Robert Wilhelm, and Werner Lemberg. */\n /* */\n /* This file is part of the FreeType project, and may only be used, */\n /* modified, and distributed under the terms of the FreeType project */\n /* license, LICENSE.TXT. By continuing to use, modify, or distribute */\n@@ -305,11 +305,11 @@\n {\n r <<= 1;\n q <<= 1;\n r |= lo >> 31;\n \n- if ( r >= (FT_UInt32)y )\n+ if ( r >= y )\n {\n r -= y;\n q |= 1;\n }\n lo <<= 1;\n@@ -371,11 +371,11 @@\n s ^= c; c = FT_ABS( c );\n \n if ( a <= 46340L && b <= 46340L && c <= 176095L && c > 0 )\n a = ( a * b + ( c >> 1 ) ) / c;\n \n- else if ( c > 0 )\n+ else if ( (FT_Int32)c > 0 )\n {\n FT_Int64 temp, temp2;\n \n \n ft_multo64( (FT_Int32)a, (FT_Int32)b, &temp );\n@@ -410,11 +410,11 @@\n s ^= c; c = FT_ABS( c );\n \n if ( a <= 46340L && b <= 46340L && c > 0 )\n a = a * b / c;\n \n- else if ( c > 0 )\n+ else if ( (FT_Int32)c > 0 )\n {\n FT_Int64 temp;\n \n \n ft_multo64( (FT_Int32)a, (FT_Int32)b, &temp );\n@@ -542,27 +542,28 @@\n \n /* XXX: this function does not allow 64-bit arguments */\n s = (FT_Int32)a; a = FT_ABS( a );\n s ^= (FT_Int32)b; b = FT_ABS( b );\n \n- if ( b == 0 )\n+ if ( (FT_UInt32)b == 0 )\n {\n /* check for division by 0 */\n q = (FT_UInt32)0x7FFFFFFFL;\n }\n else if ( ( a >> 16 ) == 0 )\n {\n /* compute result directly */\n- q = (FT_UInt32)( (a << 16) + (b >> 1) ) / (FT_UInt32)b;\n+ q = (FT_UInt32)( ( a << 16 ) + ( b >> 1 ) ) / (FT_UInt32)b;\n }\n else\n {\n /* we need more bits; we have to do it by hand */\n FT_Int64 temp, temp2;\n \n- temp.hi = (FT_Int32) (a >> 16);\n- temp.lo = (FT_UInt32)(a << 16);\n+\n+ temp.hi = (FT_Int32) ( a >> 16 );\n+ temp.lo = (FT_UInt32)( a << 16 );\n temp2.hi = 0;\n temp2.lo = (FT_UInt32)( b >> 1 );\n FT_Add64( &temp, &temp2, &temp );\n q = ft_div64by32( temp.hi, temp.lo, (FT_Int32)b );\n }" } ]
{ "id": "freetype2-1225-CVE-2012-1143.patch", "cve_id": "CVE-2012-5669", "package": "freetype2", "upstream_enriched": true, "upstream_commit": "ba67957d5ead443f4b6b31805d6e780d54361ca4", "upstream_repo": "freetype/freetype", "tier": "adapted", "has_source_context": true, "license": "FTL AND GPL-2.0-only", "context_tokens_est": 1445, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2016-3706\n\nStack-based buffer overflow in the getaddrinfo function in sysdeps/posix/getaddrinfo.c in the GNU C Library (aka glibc or libc6) allows remote attackers to cause a denial of service (crash) via vectors involving hostent conversion. NOTE: this vulnerability exists because of an incomplete fix for CVE-2013-4458.\n\n## Package\nglibc-testsuite\n\n## Files to modify\n- nptl/sysdeps/unix/sysv/linux/fork.c\n- glibc-2.19.orig/nptl/sysdeps/unix/sysv/linux/fork.c\n\n## Target Source Code\n\n### nptl/sysdeps/unix/sysv/linux/fork.c\n\n#### __libc_fork() [lines 50-236]\n```c\n\n\npid_t\n__libc_fork (void)\n{\n pid_t pid;\n struct used_handler\n {\n struct fork_handler *handler;\n struct used_handler *next;\n } *allp = NULL;\n\n /* Run all the registered preparation handlers. In reverse order.\n While doing this we build up a list of all the entries. */\n struct fork_handler *runp;\n while ((runp = __fork_handlers) != NULL)\n {\n /* Make sure we read from the current RUNP pointer. */\n atomic_full_barrier ();\n\n unsigned int oldval = runp->refcntr;\n\n if (oldval == 0)\n\t/* This means some other thread removed the list just after\n\t the pointer has been loaded. Try again. Either the list\n\t is empty or we can retry it. */\n\tcontinue;\n\n /* Bump the reference counter. */\n if (atomic_compare_and_exchange_bool_acq (&__fork_handlers->refcntr,\n\t\t\t\t\t\toldval + 1, oldval))\n\t/* The value changed, try again. */\n\tcontinue;\n\n /* We bumped the reference counter for the first entry in the\n\t list. That means that none of the following entries will\n\t just go away. The unloading code works in the order of the\n\t list.\n\n\t While executing the registered handlers we are building a\n/* ... 80 lines omitted ... */\n if (__builtin_expect (__nptl_set_robust != NULL, 0))\n\t__nptl_set_robust (self);\n# endif\n#endif\n\n /* Reset the file list. These are recursive mutexes. */\n fresetlockfiles ();\n\n /* Reset locks in the I/O code. */\n _IO_list_resetlock ();\n\n /* Reset the lock the dynamic loader uses to protect its data. */\n __rtld_lock_initialize (GL(dl_load_lock));\n\n /* Run the handlers registered for the child. */\n while (allp != NULL)\n\t{\n\t if (allp->handler->child_handler != NULL)\n\t allp->handler->child_handler ();\n\n\t /* Note that we do not have to wake any possible waiter.\n\t This is the only thread in the new process. The count\n\t may have been bumped up by other threads doing a fork.\n\t We reset it to 1, to avoid waiting for non-existing\n\t thread(s) to release the count. */\n\t allp->handler->refcntr = 1;\n\n\t /* XXX We could at this point look through the object pool\n/* ... 19 lines omitted ... */\n _IO_list_unlock ();\n\n /* Run the handlers registered for the parent. */\n while (allp != NULL)\n\t{\n\t if (allp->handler->parent_handler != NULL)\n\t allp->handler->parent_handler ();\n\n\t if (atomic_decrement_and_test (&allp->handler->refcntr)\n\t && allp->handler->need_signal)\n\t lll_futex_wake (allp->handler->refcntr, 1, LLL_PRIVATE);\n\n\t allp = allp->next;\n\t}\n }\n\n return pid;\n}\nweak_alias (__libc_fork, __fork)\nlibc_hidden_def (__fork)\n```\n\n\n## Upstream Fix\n```diff\nIndex: glibc-2.19/nptl/sysdeps/unix/sysv/linux/fork.c\n===================================================================\n--- glibc-2.19.orig/nptl/sysdeps/unix/sysv/linux/fork.c\n+++ glibc-2.19/nptl/sysdeps/unix/sysv/linux/fork.c\n@@ -179,8 +179,9 @@ __libc_fork (void)\n /* Reset locks in the I/O code. */\n _IO_list_resetlock ();\n \n- /* Reset the lock the dynamic loader uses to protect its data. */\n+ /* Reset the locks the dynamic loader uses to protect its data. */\n __rtld_lock_initialize (GL(dl_load_lock));\n+ __rtld_lock_initialize (GL(dl_load_write_lock));\n \n /* Run the handlers registered for the child. */\n while (allp != NULL)\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "Index: glibc-2.19/nptl/sysdeps/unix/sysv/linux/fork.c\n===================================================================\n--- glibc-2.19.orig/nptl/sysdeps/unix/sysv/linux/fork.c\n+++ glibc-2.19/nptl/sysdeps/unix/sysv/linux/fork.c\n@@ -179,8 +179,9 @@ __libc_fork (void)\n /* Reset locks in the I/O code. */\n _IO_list_resetlock ();\n \n- /* Reset the lock the dynamic loader uses to protect its data. */\n+ /* Reset the locks the dynamic loader uses to protect its data. */\n __rtld_lock_initialize (GL(dl_load_lock));\n+ __rtld_lock_initialize (GL(dl_load_write_lock));\n \n /* Run the handlers registered for the child. */\n while (allp != NULL)" } ]
{ "id": "glibc-testsuite-5158-reinitialize-dl_load_write_loc", "cve_id": "CVE-2016-3706", "package": "glibc-testsuite", "upstream_enriched": null, "upstream_commit": null, "upstream_repo": null, "tier": "identical", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 673, "context_files": 1 }
[ { "role": "system", "content": "You are a security patch backporting assistant for SUSE/openSUSE.\n\nGiven a CVE description and an upstream fix, adapt the patch to work with\nthe target SUSE package version. Output the backported patch in unified\ndiff format. If the upstream fix applies directly, output it unchanged." }, { "role": "user", "content": "## CVE: CVE-2013-4288\n\nRace condition in PolicyKit (aka polkit) allows local users to bypass intended PolicyKit restrictions and gain privileges by starting a setuid or pkexec process before the authorization check is performed, related to (1) the polkit_unix_process_new API function, (2) the dbus API, or (3) the --process (unix-process) option for authorization to pkcheck.\n\n## Package\nsystemd-mini\n\n## Files to modify\n- src/core/dbus-manager.c\n- systemd-195.orig/src/core/dbus-manager.c\n\n## Target Source Code\n\n### src/core/dbus-manager.c\n\n#### region() [lines 1426-1439]\n```c\n goto oom;\n\n h = hashmap_new(string_hash_func, string_compare_func);\n if (!h)\n goto oom;\n\n r = unit_file_get_list(m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, NULL, h);\n if (r < 0) {\n unit_file_list_free(h);\n dbus_message_unref(reply);\n return bus_send_error_reply(connection, message, NULL, r);\n }\n\n dbus_message_iter_init_append(reply, &iter);\n```\n\n\n## Upstream Fix\n```diff\nFrom 645a9e5a2bbb06464a3fba1a3501e9d79e5bbad8 Mon Sep 17 00:00:00 2001\nFrom: Eelco Dolstra <eelco.dolstra@logicblox.com>\nDate: Wed, 31 Oct 2012 11:53:56 +0100\nSubject: [PATCH] dbus-manager: fix a fatal dbus abort in\n bus_manager_message_handler()\n\nIf ListUnitFiles fails, or an OOM occurs, then dbus_message_unref()\nwill be called twice on \"reply\", causing systemd to crash. So remove\nthe call to dbus_message_unref(); it is unnecessary because of\nthe cleanup attribute on \"reply\".\n\n[zj: modified to leave one dbus_message_unref() alone, per Colin\nWalters' comment.]\n---\n src/core/dbus-manager.c | 1 -\n 1 file changed, 1 deletion(-)\n\ndiff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c\nindex 2010241e6aca8..3cf3e90a3659d 100644\n--- a/src/core/dbus-manager.c\n+++ b/src/core/dbus-manager.c\n@@ -1436,7 +1436,6 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,\n r = unit_file_get_list(m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, NULL, h);\n if (r < 0) {\n unit_file_list_free(h);\n- dbus_message_unref(reply);\n return bus_send_error_reply(connection, message, NULL, r);\n }\n```\n\nGenerate a backported patch for the SUSE target version." }, { "role": "assistant", "content": "From 645a9e5a2bbb06464a3fba1a3501e9d79e5bbad8 Mon Sep 17 00:00:00 2001\nFrom: Eelco Dolstra <eelco.dolstra@logicblox.com>\nDate: Wed, 31 Oct 2012 11:53:56 +0100\nSubject: [PATCH] dbus-manager: fix a fatal dbus abort in\n bus_manager_message_handler()\n\nIf ListUnitFiles fails, or an OOM occurs, then dbus_message_unref()\nwill be called twice on \"reply\", causing systemd to crash. So remove\nthe call to dbus_message_unref(); it is unnecessary because of\nthe cleanup attribute on \"reply\".\n\n[zj: modified to leave one dbus_message_unref() alone, per Colin\nWalters' comment.]\n---\n src/core/dbus-manager.c | 1 -\n 1 file changed, 1 deletion(-)\n\nIndex: systemd-195/src/core/dbus-manager.c\n===================================================================\n--- systemd-195.orig/src/core/dbus-manager.c\n+++ systemd-195/src/core/dbus-manager.c\n@@ -1432,7 +1432,6 @@ static DBusHandlerResult bus_manager_mes\n r = unit_file_get_list(m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, NULL, h);\n if (r < 0) {\n unit_file_list_free(h);\n- dbus_message_unref(reply);\n return bus_send_error_reply(connection, message, NULL, r);\n }" } ]
{ "id": "systemd-mini-2025-fix-dbus-crash.patch", "cve_id": "CVE-2013-4288", "package": "systemd-mini", "upstream_enriched": true, "upstream_commit": "645a9e5a2bbb06464a3fba1a3501e9d79e5bbad8", "upstream_repo": "systemd/systemd", "tier": "adapted", "has_source_context": true, "license": "LGPL-2.1-or-later", "context_tokens_est": 161, "context_files": 1 }