Datasets:
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-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- pngset.c\n\n## Upstream Fix\n```diff\n--- pngset.c\n+++ pngset.c\n@@ -837,6 +837,15 @@\n (png_ptr->mode & PNG_WROTE_tIME))\n return;\n \n+ if (mod_time->month == 0 || mod_time->month > 12 ||\n+ mod_time->day == 0 || mod_time->day > 31 ||\n+ mod_time->hour > 23 || mod_time->minute > 59 ||\n+ mod_time->second > 60)\n+ {\n+ png_warning(png_ptr, \"Ignoring invalid time value\");\n+ return;\n+ }\n+\n png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time));\n info_ptr->valid |= PNG_INFO_tIME;\n }\n```\n\nGenerate a backported patch for the SUSE target version."
},
{
"role": "assistant",
"content": "--- pngset.c\n+++ pngset.c\n@@ -837,6 +837,15 @@\n (png_ptr->mode & PNG_WROTE_tIME))\n return;\n \n+ if (mod_time->month == 0 || mod_time->month > 12 ||\n+ mod_time->day == 0 || mod_time->day > 31 ||\n+ mod_time->hour > 23 || mod_time->minute > 59 ||\n+ mod_time->second > 60)\n+ {\n+ png_warning(png_ptr, \"Ignoring invalid time value\");\n+ return;\n+ }\n+\n png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time));\n info_ptr->valid |= PNG_INFO_tIME;\n }"
}
] |
{
"id": "libpng12-4248-libpng12-CVE-2015-7981.patch",
"cves": [],
"package": "libpng12",
"incident_id": 0,
"patch_name": "",
"tier": "identical",
"language": "c",
"patch_lines_changed": 9,
"patch_files_count": 0,
"total_tokens_est": 437,
"has_source_context": false,
"upstream_enriched": false,
"suse_license": "Zlib",
"upstream_license": "NOASSERTION",
"cve_id": null,
"upstream_commit": null,
"upstream_repo": 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-2019-11043\n\n===================================================================\n\n## Package\nphp7\n\n## Files to modify\n- ext/standard/info.c\n- sapi/cli/php_cli.c\n- sapi/cgi/cgi_main.c\n- configure.ac\n- sapi/fpm/fpm/fpm_main.c\n\n## Target Source Code\n\n### ext/standard/info.c\n\n#### php_print_info() [lines 786-1063]\n```c\n\n/* {{{ php_print_info\n */\nPHPAPI void php_print_info(int flag)\n{\n\tchar **env, *tmp1, *tmp2;\n\tzend_string *php_uname;\n\n\tif (!sapi_module.phpinfo_as_text) {\n\t\tphp_print_info_htmlhead();\n\t} else {\n\t\tphp_info_print(\"phpinfo()\\n\");\n\t}\n\n\tif (flag & PHP_INFO_GENERAL) {\n\t\tchar *zend_version = get_zend_version();\n\t\tchar temp_api[10];\n\n\t\tphp_uname = php_get_uname('a');\n\n\t\tif (!sapi_module.phpinfo_as_text) {\n\t\t\tphp_info_print_box_start(1);\n\t\t}\n\n\t\tif (!sapi_module.phpinfo_as_text) {\n\t time_t the_time;\n\t struct tm *ta, tmbuf;\n\n\t the_time = time(NULL);\n\t ta = php_localtime_r(&the_time, &tmbuf);\n\n php_info_print(\"<a href=\\\"http://www.php.net/\\\"><img border=\\\"0\\\" src=\\\"\");\n\t if (ta && (ta->tm_mon==3) && (ta->tm_mday==1)) {\n\t\t php_info_print(PHP_EGG_LOGO_DATA_URI \"\\\" alt=\\\"PHP logo\\\" /></a>\");\n\t } else {\n\t\t php_info_print(PHP_LOGO_DATA_URI \"\\\" alt=\\\"PHP logo\\\" /></a>\");\n\t\t\t}\n\t\t}\n\n\t\tif (!sapi_module.phpinfo_as_text) {\n\t\t\tphp_info_printf(\"<h1 class=\\\"p\\\">PHP Version %s</h1>\\n\", PHP_VERSION);\n\t\t} else {\n\t\t\tphp_info_print_table_row(2, \"PHP Version\", PHP_VERSION);\n\t\t}\n\t\tphp_info_print_box_end();\n\t\tphp_info_print_table_start();\n\t\tphp_info_print_table_row(2, \"System\", ZSTR_VAL(php_uname));\n\t\tphp_info_print_table_row(2, \"Build Date\", __DATE__ \" \" __TIME__);\n#ifdef COMPILER\n\t\tphp_info_print_table_row(2, \"Compiler\", COMPILER);\n#endif\n#ifdef ARCHITECTURE\n\t\tphp_info_print_table_row(2, \"Architecture\", ARCHITECTURE);\n#endif\n#ifdef CONFIGURE_COMMAND\n\t\tphp_info_print_table_row(2, \"Configure Command\", CONFIGURE_COMMAND );\n#endif\n\n\t\tif (sapi_module.pretty_name) {\n\t\t\tphp_info_print_table_row(2, \"Server API\", sapi_module.pretty_name );\n\t\t}\n\n/* ... 196 lines omitted ... */\n\t\t\tphp_info_print(\"\\nPHP License\\n\");\n\t\t\tphp_info_print(\"This program is free software; you can redistribute it and/or modify\\n\");\n\t\t\tphp_info_print(\"it under the terms of the PHP License as published by the PHP Group\\n\");\n\t\t\tphp_info_print(\"and included in the distribution in the file: LICENSE\\n\");\n\t\t\tphp_info_print(\"\\n\");\n\t\t\tphp_info_print(\"This program is distributed in the hope that it will be useful,\\n\");\n\t\t\tphp_info_print(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\n\t\t\tphp_info_print(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\\n\");\n\t\t\tphp_info_print(\"\\n\");\n\t\t\tphp_info_print(\"If you did not receive a copy of the PHP license, or have any\\n\");\n\t\t\tphp_info_print(\"questions about PHP licensing, please contact license@php.net.\\n\");\n\t\t}\n\t}\n\n\tif (!sapi_module.phpinfo_as_text) {\n\t\tphp_info_print(\"</div></body></html>\");\n\t}\n}\n/* }}} */\n\n```\n\n### sapi/cli/php_cli.c\n\n#### do_cli() [lines 661-1195]\n```c\n#endif\n/*}}}*/\n\nstatic int do_cli(int argc, char **argv) /* {{{ */\n{\n\tint c;\n\tzend_file_handle file_handle;\n\tint behavior = PHP_MODE_STANDARD;\n\tchar *reflection_what = NULL;\n\tvolatile int request_started = 0;\n\tvolatile int exit_status = 0;\n\tchar *php_optarg = NULL, *orig_optarg = NULL;\n\tint php_optind = 1, orig_optind = 1;\n\tchar *exec_direct=NULL, *exec_run=NULL, *exec_begin=NULL, *exec_end=NULL;\n\tchar *arg_free=NULL, **arg_excp=&arg_free;\n\tchar *script_file=NULL, *translated_path = NULL;\n\tint interactive=0;\n\tint lineno = 0;\n\tconst char *param_error=NULL;\n\tint hide_argv = 0;\n\n\tzend_try {\n\n\t\tCG(in_compilation) = 0; /* not initialized but needed for several options */\n\n\t\twhile ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {\n\t\t\tswitch (c) {\n\n\t\t\tcase 'i': /* php info & quit */\n\t\t\t\tif (php_request_startup()==FAILURE) {\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t\trequest_started = 1;\n\t\t\t\tphp_print_info(0xFFFFFFFF);\n\t\t\t\tphp_output_end_all();\n\t\t\t\texit_status = (c == '?' && argc > 1 && !strchr(argv[1], c));\n\t\t\t\tgoto out;\n\n\t\t\tcase 'v': /* show php version & quit */\n\t\t\t\tphp_printf(\"PHP %s (%s) (built: %s %s) ( %s)\\nCopyright (c) 1997-2018 The PHP Group\\n%s\",\n\t\t\t\t\tPHP_VERSION, cli_sapi_module.name, __DATE__, __TIME__,\n#if ZTS\n\t\t\t\t\t\"ZTS \"\n#else\n\t\t\t\t\t\"NTS \"\n#endif\n#ifdef COMPILER\n\t\t\t\t\tCOMPILER\n\t\t\t\t\t\" \"\n#endif\n#ifdef ARCHITECTURE\n\t\t\t\t\tARCHITECTURE\n\t\t\t\t\t\" \"\n#endif\n#if ZEND_DEBUG\n/* ... 460 lines omitted ... */\nout:\n\tif (request_started) {\n\t\tphp_request_shutdown((void *) 0);\n\t}\n\tif (translated_path) {\n\t\tfree(translated_path);\n\t}\n\tif (exit_status == 0) {\n\t\texit_status = EG(exit_status);\n\t}\n\treturn exit_status;\nerr:\n\tsapi_deactivate();\n\tzend_ini_deactivate();\n\texit_status = 1;\n\tgoto out;\n}\n/* }}} */\n\n/* {{{ main\n```\n\n### sapi/cgi/cgi_main.c\n\n#### region() [lines 2422-2430]\n```c\n\t\t\t\t\t\t\t\tphp_module_shutdown();\n\t\t\t\t\t\t\t\treturn FAILURE;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (no_headers) {\n\t\t\t\t\t\t\t\tSG(headers_sent) = 1;\n\t\t\t\t\t\t\t\tSG(request_info).no_headers = 1;\n\t\t\t\t\t\t\t}\n#if ZEND_DEBUG\n\t\t\t\t\t\t\tphp_printf(\"PHP %s (%s) (built: %s %s) (DEBUG)\\nCopyright (c) 1997-2018 The PHP Group\\n%s\", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());\n```\n\n### configure.ac\n\n#### region() [lines 1220-36]\n```\n\n```\n\n### sapi/fpm/fpm/fpm_main.c\n\n#### main() [lines 1567-2037]\n```c\n\n/* {{{ main\n */\nint main(int argc, char *argv[])\n{\n\tint exit_status = FPM_EXIT_OK;\n\tint cgi = 0, c, use_extended_info = 0;\n\tzend_file_handle file_handle;\n\n\t/* temporary locals */\n\tint orig_optind = php_optind;\n\tchar *orig_optarg = php_optarg;\n\tint ini_entries_len = 0;\n\t/* end of temporary locals */\n\n#ifdef ZTS\n\tvoid ***tsrm_ls;\n#endif\n\n\tint max_requests = 500;\n\tint requests = 0;\n\tint fcgi_fd = 0;\n\tfcgi_request *request;\n\tchar *fpm_config = NULL;\n\tchar *fpm_prefix = NULL;\n\tchar *fpm_pid = NULL;\n\tint test_conf = 0;\n\tint force_daemon = -1;\n\tint force_stderr = 0;\n\tint php_information = 0;\n\tint php_allow_to_run_as_root = 0;\n\n#ifdef HAVE_SIGNAL_H\n#if defined(SIGPIPE) && defined(SIG_IGN)\n\tsignal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so\n\t\t\t\t\t\t\t\tthat sockets created via fsockopen()\n\t\t\t\t\t\t\t\tdon't kill PHP if the remote site\n\t\t\t\t\t\t\t\tcloses it. in apache|apxs mode apache\n\t\t\t\t\t\t\t\tdoes that for us! thies@thieso.net\n\t\t\t\t\t\t\t\t20000419 */\n/* ... 139 lines omitted ... */\n\n\t\t\tcase 'v': /* show php version & quit */\n\t\t\t\tcgi_sapi_module.startup(&cgi_sapi_module);\n\t\t\t\tif (php_request_startup() == FAILURE) {\n\t\t\t\t\tSG(server_context) = NULL;\n\t\t\t\t\tphp_module_shutdown();\n\t\t\t\t\treturn FPM_EXIT_SOFTWARE;\n\t\t\t\t}\n\t\t\t\tSG(headers_sent) = 1;\n\t\t\t\tSG(request_info).no_headers = 1;\n\n#if ZEND_DEBUG\n\t\t\t\tphp_printf(\"PHP %s (%s) (built: %s %s) (DEBUG)\\nCopyright (c) 1997-2018 The PHP Group\\n%s\", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());\n#else\n\t\t\t\tphp_printf(\"PHP %s (%s) (built: %s %s)\\nCopyright (c) 1997-2018 The PHP Group\\n%s\", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());\n#endif\n\t\t\t\tphp_request_shutdown((void *) 0);\n\t\t\t\tfcgi_shutdown();\n\t\t\t\texit_status = FPM_EXIT_OK;\n\t\t\t\tgoto out;\n\t\t}\n\t}\n\n\tif (php_information) {\n\t\tcgi_sapi_module.phpinfo_as_text = 1;\n\t\tcgi_sapi_module.startup(&cgi_sapi_module);\n\t\tif (php_request_startup() == FAILURE) {\n\t\t\tSG(server_context) = NULL;\n\t\t\tphp_module_shutdown();\n/* ... 243 lines omitted ... */\n\n\tSG(server_context) = NULL;\n\tphp_module_shutdown();\n\n\tif (parent) {\n\t\tsapi_shutdown();\n\t}\n\n#ifdef ZTS\n\ttsrm_shutdown();\n#endif\n\n#if defined(PHP_WIN32) && ZEND_DEBUG && 0\n\t_CrtDumpMemoryLeaks();\n#endif\n\n\treturn exit_status;\n}\n/* }}} */\n\n```\n\n\n## Upstream Fix\n```diff\nIndex: php-7.2.4/ext/standard/info.c\n===================================================================\n--- php-7.2.4.orig/ext/standard/info.c\t2018-03-27 15:10:52.000000000 +0200\n+++ php-7.2.4/ext/standard/info.c\t2018-04-04 13:05:25.675487878 +0200\n@@ -830,7 +830,7 @@ PHPAPI void php_print_info(int flag)\n \t\tphp_info_print_box_end();\n \t\tphp_info_print_table_start();\n \t\tphp_info_print_table_row(2, \"System\", ZSTR_VAL(php_uname));\n-\t\tphp_info_print_table_row(2, \"Build Date\", __DATE__ \" \" __TIME__);\n+\t\t/*php_info_print_table_row(2, \"Build Date\", __DATE__ \" \" __TIME__);*/\n #ifdef COMPILER\n \t\tphp_info_print_table_row(2, \"Compiler\", COMPILER);\n #endif\n@@ -838,7 +838,7 @@ PHPAPI void php_print_info(int flag)\n \t\tphp_info_print_table_row(2, \"Architecture\", ARCHITECTURE);\n #endif\n #ifdef CONFIGURE_COMMAND\n-\t\tphp_info_print_table_row(2, \"Configure Command\", CONFIGURE_COMMAND );\n+\t\t/* php_info_print_table_row(2, \"Configure Command\", CONFIGURE_COMMAND ); */\n #endif\n \n \t\tif (sapi_module.pretty_name) {\nIndex: php-7.2.4/sapi/cli/php_cli.c\n===================================================================\n--- php-7.2.4.orig/sapi/cli/php_cli.c\t2018-03-27 15:10:57.000000000 +0200\n+++ php-7.2.4/sapi/cli/php_cli.c\t2018-04-04 13:05:25.675487878 +0200\n@@ -697,8 +697,8 @@ static int do_cli(int argc, char **argv)\n \t\t\t\tgoto out;\n \n \t\t\tcase 'v': /* show php version & quit */\n-\t\t\t\tphp_printf(\"PHP %s (%s) (built: %s %s) ( %s)\\nCopyright (c) 1997-2018 The PHP Group\\n%s\",\n-\t\t\t\t\tPHP_VERSION, cli_sapi_module.name, __DATE__, __TIME__,\n+\t\t\t\tphp_printf(\"PHP %s (%s) ( %s)\\nCopyright (c) 1997-2018 The PHP Group\\n%s\",\n+\t\t\t\t\tPHP_VERSION, cli_sapi_module.name,\n #if ZTS\n \t\t\t\t\t\"ZTS \"\n #else\nIndex: php-7.2.4/sapi/cgi/cgi_main.c\n===================================================================\n--- php-7.2.4.orig/sapi/cgi/cgi_main.c\t2018-03-27 15:10:57.000000000 +0200\n+++ php-7.2.4/sapi/cgi/cgi_main.c\t2018-04-04 13:05:25.675487878 +0200\n@@ -2427,9 +2427,9 @@ consult the installation file that came\n \t\t\t\t\t\t\t\tSG(request_info).no_headers = 1;\n \t\t\t\t\t\t\t}\n #if ZEND_DEBUG\n-\t\t\t\t\t\t\tphp_printf(\"PHP %s (%s) (built: %s %s) (DEBUG)\\nCopyright (c) 1997-2018 The PHP Group\\n%s\", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());\n+\t\t\t\t\t\t\tphp_printf(\"PHP %s (%s) (DEBUG)\\nCopyright (c) 1997-2018 The PHP Group\\n%s\", PHP_VERSION, sapi_module.name, get_zend_version());\n #else\n-\t\t\t\t\t\t\tphp_printf(\"PHP %s (%s) (built: %s %s)\\nCopyright (c) 1997-2018 The PHP Group\\n%s\", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());\n+\t\t\t\t\t\t\tphp_printf(\"PHP %s (%s) \\nCopyright (c) 1997-2018 The PHP Group\\n%s\", PHP_VERSION, sapi_module.name, get_zend_version());\n #endif\n \t\t\t\t\t\t\tphp_request_shutdown((void *) 0);\n \t\t\t\t\t\t\tfcgi_shutdown();\nIndex: php-7.2.4/configure.ac\n===================================================================\n--- php-7.2.4.orig/configure.ac\t2018-04-04 13:05:25.675487878 +0200\n+++ php-7.2.4/configure.ac\t2018-04-04 13:10:53.817149061 +0200\n@@ -1269,13 +1269,12 @@ EXTRA_LDFLAGS=\"$EXTRA_LDFLAGS $PHP_LDFLA\n EXTRA_LDFLAGS_PROGRAM=\"$EXTRA_LDFLAGS_PROGRAM $PHP_LDFLAGS\"\n \n # SOURCE_DATE_EPOCH for reproducible builds https://reproducible-builds.org/specs/source-date-epoch/\n-PHP_BUILD_DATE=`date --utc --date=\"@${SOURCE_DATE_EPOCH:-$(date +%s)}\" +%Y-%m-%d 2>/dev/null`\n-if test $? -ne 0 ; then\n-PHP_BUILD_DATE=`date -u +%Y-%m-%d`\n-fi\n+#totally fake, not used anywhere in userspace\n+PHP_BUILD_DATE=\"1970-01-01\"\n AC_DEFINE_UNQUOTED(PHP_BUILD_DATE,\"$PHP_BUILD_DATE\",[PHP build date])\n \n-PHP_UNAME=`uname -a | xargs`\n+dnl Totally fake, it wasnt and will never be reliable anyway.\n+PHP_UNAME=\"Linux suse 2.6.36 #1 SMP 2011-02-21 10:34:10 +0100 x86_64 x86_64 x86_64 GNU/Linux\"\n AC_DEFINE_UNQUOTED(PHP_UNAME,\"$PHP_UNAME\",[uname -a output])\n PHP_OS=`uname | xargs`\n AC_DEFINE_UNQUOTED(PHP_OS,\"$PHP_OS\",[uname output])\nIndex: php-7.2.4/sapi/fpm/fpm/fpm_main.c\n===================================================================\n--- php-7.2.4.orig/sapi/fpm/fpm/fpm_main.c\t2018-03-27 15:10:57.000000000 +0200\n+++ php-7.2.4/sapi/fpm/fpm/fpm_main.c\t2018-04-04 13:05:25.675487878 +0200\n@@ -1755,9 +1755,9 @@ int main(int argc, char *argv[])\n \t\t\t\tSG(request_info).no_headers = 1;\n \n #if ZEND_DEBUG\n-\t\t\t\tphp_printf(\"PHP %s (%s) (built: %s %s) (DEBUG)\\nCopyright (c) 1997-2018 The PHP Group\\n%s\", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());\n+\t\t\t\tphp_printf(\"PHP %s (%s) (DEBUG)\\nCopyright (c) 1997-2018 The PHP Group\\n%s\", PHP_VERSION, sapi_module.name, get_zend_version());\n #else\n-\t\t\t\tphp_printf(\"PHP %s (%s) (built: %s %s)\\nCopyright (c) 1997-2018 The PHP Group\\n%s\", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());\n+\t\t\t\tphp_printf(\"PHP %s (%s) \\nCopyright (c) 1997-2018 The PHP Group\\n%s\", PHP_VERSION, sapi_module.name, get_zend_version());\n #endif\n \t\t\t\tphp_request_shutdown((void *) 0);\n \t\t\t\tfcgi_shutdown();\n\n```\n\nGenerate a backported patch for the SUSE target version."
},
{
"role": "assistant",
"content": "Index: php-7.2.4/ext/standard/info.c\n===================================================================\n--- php-7.2.4.orig/ext/standard/info.c\t2018-03-27 15:10:52.000000000 +0200\n+++ php-7.2.4/ext/standard/info.c\t2018-04-04 13:05:25.675487878 +0200\n@@ -830,7 +830,7 @@ PHPAPI void php_print_info(int flag)\n \t\tphp_info_print_box_end();\n \t\tphp_info_print_table_start();\n \t\tphp_info_print_table_row(2, \"System\", ZSTR_VAL(php_uname));\n-\t\tphp_info_print_table_row(2, \"Build Date\", __DATE__ \" \" __TIME__);\n+\t\t/*php_info_print_table_row(2, \"Build Date\", __DATE__ \" \" __TIME__);*/\n #ifdef COMPILER\n \t\tphp_info_print_table_row(2, \"Compiler\", COMPILER);\n #endif\n@@ -838,7 +838,7 @@ PHPAPI void php_print_info(int flag)\n \t\tphp_info_print_table_row(2, \"Architecture\", ARCHITECTURE);\n #endif\n #ifdef CONFIGURE_COMMAND\n-\t\tphp_info_print_table_row(2, \"Configure Command\", CONFIGURE_COMMAND );\n+\t\t/* php_info_print_table_row(2, \"Configure Command\", CONFIGURE_COMMAND ); */\n #endif\n \n \t\tif (sapi_module.pretty_name) {\nIndex: php-7.2.4/sapi/cli/php_cli.c\n===================================================================\n--- php-7.2.4.orig/sapi/cli/php_cli.c\t2018-03-27 15:10:57.000000000 +0200\n+++ php-7.2.4/sapi/cli/php_cli.c\t2018-04-04 13:05:25.675487878 +0200\n@@ -697,8 +697,8 @@ static int do_cli(int argc, char **argv)\n \t\t\t\tgoto out;\n \n \t\t\tcase 'v': /* show php version & quit */\n-\t\t\t\tphp_printf(\"PHP %s (%s) (built: %s %s) ( %s)\\nCopyright (c) 1997-2018 The PHP Group\\n%s\",\n-\t\t\t\t\tPHP_VERSION, cli_sapi_module.name, __DATE__, __TIME__,\n+\t\t\t\tphp_printf(\"PHP %s (%s) ( %s)\\nCopyright (c) 1997-2018 The PHP Group\\n%s\",\n+\t\t\t\t\tPHP_VERSION, cli_sapi_module.name,\n #if ZTS\n \t\t\t\t\t\"ZTS \"\n #else\nIndex: php-7.2.4/sapi/cgi/cgi_main.c\n===================================================================\n--- php-7.2.4.orig/sapi/cgi/cgi_main.c\t2018-03-27 15:10:57.000000000 +0200\n+++ php-7.2.4/sapi/cgi/cgi_main.c\t2018-04-04 13:05:25.675487878 +0200\n@@ -2427,9 +2427,9 @@ consult the installation file that came\n \t\t\t\t\t\t\t\tSG(request_info).no_headers = 1;\n \t\t\t\t\t\t\t}\n #if ZEND_DEBUG\n-\t\t\t\t\t\t\tphp_printf(\"PHP %s (%s) (built: %s %s) (DEBUG)\\nCopyright (c) 1997-2018 The PHP Group\\n%s\", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());\n+\t\t\t\t\t\t\tphp_printf(\"PHP %s (%s) (DEBUG)\\nCopyright (c) 1997-2018 The PHP Group\\n%s\", PHP_VERSION, sapi_module.name, get_zend_version());\n #else\n-\t\t\t\t\t\t\tphp_printf(\"PHP %s (%s) (built: %s %s)\\nCopyright (c) 1997-2018 The PHP Group\\n%s\", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());\n+\t\t\t\t\t\t\tphp_printf(\"PHP %s (%s) \\nCopyright (c) 1997-2018 The PHP Group\\n%s\", PHP_VERSION, sapi_module.name, get_zend_version());\n #endif\n \t\t\t\t\t\t\tphp_request_shutdown((void *) 0);\n \t\t\t\t\t\t\tfcgi_shutdown();\nIndex: php-7.2.4/configure.ac\n===================================================================\n--- php-7.2.4.orig/configure.ac\t2018-04-04 13:05:25.675487878 +0200\n+++ php-7.2.4/configure.ac\t2018-04-04 13:10:53.817149061 +0200\n@@ -1269,13 +1269,12 @@ EXTRA_LDFLAGS=\"$EXTRA_LDFLAGS $PHP_LDFLA\n EXTRA_LDFLAGS_PROGRAM=\"$EXTRA_LDFLAGS_PROGRAM $PHP_LDFLAGS\"\n \n # SOURCE_DATE_EPOCH for reproducible builds https://reproducible-builds.org/specs/source-date-epoch/\n-PHP_BUILD_DATE=`date --utc --date=\"@${SOURCE_DATE_EPOCH:-$(date +%s)}\" +%Y-%m-%d 2>/dev/null`\n-if test $? -ne 0 ; then\n-PHP_BUILD_DATE=`date -u +%Y-%m-%d`\n-fi\n+#totally fake, not used anywhere in userspace\n+PHP_BUILD_DATE=\"1970-01-01\"\n AC_DEFINE_UNQUOTED(PHP_BUILD_DATE,\"$PHP_BUILD_DATE\",[PHP build date])\n \n-PHP_UNAME=`uname -a | xargs`\n+dnl Totally fake, it wasnt and will never be reliable anyway.\n+PHP_UNAME=\"Linux suse 2.6.36 #1 SMP 2011-02-21 10:34:10 +0100 x86_64 x86_64 x86_64 GNU/Linux\"\n AC_DEFINE_UNQUOTED(PHP_UNAME,\"$PHP_UNAME\",[uname -a output])\n PHP_OS=`uname | xargs`\n AC_DEFINE_UNQUOTED(PHP_OS,\"$PHP_OS\",[uname output])\nIndex: php-7.2.4/sapi/fpm/fpm/fpm_main.c\n===================================================================\n--- php-7.2.4.orig/sapi/fpm/fpm/fpm_main.c\t2018-03-27 15:10:57.000000000 +0200\n+++ php-7.2.4/sapi/fpm/fpm/fpm_main.c\t2018-04-04 13:05:25.675487878 +0200\n@@ -1755,9 +1755,9 @@ int main(int argc, char *argv[])\n \t\t\t\tSG(request_info).no_headers = 1;\n \n #if ZEND_DEBUG\n-\t\t\t\tphp_printf(\"PHP %s (%s) (built: %s %s) (DEBUG)\\nCopyright (c) 1997-2018 The PHP Group\\n%s\", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());\n+\t\t\t\tphp_printf(\"PHP %s (%s) (DEBUG)\\nCopyright (c) 1997-2018 The PHP Group\\n%s\", PHP_VERSION, sapi_module.name, get_zend_version());\n #else\n-\t\t\t\tphp_printf(\"PHP %s (%s) (built: %s %s)\\nCopyright (c) 1997-2018 The PHP Group\\n%s\", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());\n+\t\t\t\tphp_printf(\"PHP %s (%s) \\nCopyright (c) 1997-2018 The PHP Group\\n%s\", PHP_VERSION, sapi_module.name, get_zend_version());\n #endif\n \t\t\t\tphp_request_shutdown((void *) 0);\n \t\t\t\tfcgi_shutdown();\n"
}
] |
{
"id": "php7-11377-php7-no-build-date.patch",
"cves": [
"CVE-2019-11043"
],
"package": "php7",
"incident_id": 11377,
"patch_name": "php7-no-build-date.patch",
"tier": "identical",
"language": "c",
"patch_lines_changed": 25,
"patch_files_count": 5,
"total_tokens_est": 2596,
"has_source_context": true,
"upstream_enriched": false,
"suse_license": "PHP-3.01",
"upstream_license": "NOASSERTION",
"cve_id": "CVE-2019-11043",
"upstream_commit": null,
"upstream_repo": 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-2019-11043\n\nX-Git-Url: http://208.43.231.11:8000/?p=php-src.git;a=blobdiff_plain;f=ext%2Fexif%2Fexif.c;h=cad29b729548e4206f0697710cc9e177f26fdff3;hp=1147980f7730de0dfd13904a2ea6461bbf4eded8;hb=3462efa386f26d34306\n\n## Package\nphp7\n\n## Files to modify\n- ext/exif/exif.c\n\n## Target Source Code\n\n### ext/exif/exif.c\n\n#### region() [lines 3116-3226]\n```c\n\n/* {{{ exif_process_IFD_in_MAKERNOTE\n * Process nested IFDs directories in Maker Note. */\nstatic int exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * value_ptr, int value_len, char *offset_base, size_t IFDlength, size_t displacement)\n{\n\tsize_t i;\n\tint de, section_index = SECTION_MAKERNOTE;\n\tint NumDirEntries, old_motorola_intel;\n#ifdef KALLE_0\n\tint offset_diff;\n#endif\n\tconst maker_note_type *maker_note;\n\tchar *dir_start;\n\t\n\tfor (i=0; i<=sizeof(maker_note_array)/sizeof(maker_note_type); i++) {\n\t\tif (i==sizeof(maker_note_array)/sizeof(maker_note_type)) {\n#ifdef EXIF_DEBUG\n\t\t\texif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, \"No maker note data found. Detected maker: %s (length = %d)\", ImageInfo->make, strlen(ImageInfo->make));\n#endif\n\t\t\t/* unknown manufacturer, not an error, use it as a string */\n\t\t\treturn TRUE;\n\t\t}\n\n\t\tmaker_note = maker_note_array+i;\n\n\t\t/*exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, \"check (%s,%s)\", maker_note->make?maker_note->make:\"\", maker_note->model?maker_note->model:\"\");*/\n\t\tif (maker_note->make && (!ImageInfo->make || strcmp(maker_note->make, ImageInfo->make)))\n\t\t\tcontinue;\n\t\tif (maker_note->model && (!ImageInfo->model || strcmp(maker_note->model, ImageInfo->model)))\n\t\t\tcontinue;\n\t\tif (maker_note->id_string && strncmp(maker_note->id_string, value_ptr, maker_note->id_string_len))\n\t\t\tcontinue;\n\t\tbreak;\n\t}\n\t\n\tif (maker_note->offset >= value_len) {\n\t\t/* Do not go past the value end */\n\t\texif_error_docref(\"exif_read_data#error_ifd\" EXIFERR_CC, ImageInfo, E_WARNING, \"IFD data too short: 0x%04X offset 0x%04X\", value_len, maker_note->offset);\n\t\treturn FALSE;\n\t}\n\n\tdir_start = value_ptr + maker_note->offset;\n\n#ifdef EXIF_DEBUG\n\texif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, \"Process %s @x%04X + 0x%04X=%d: %s\", exif_get_sectionname(section_index), (int)dir_start-(int)offset_base+maker_note->offset+displacement, value_len, value_len, exif_char_dump(value_ptr, value_len, (int)dir_start-(int)offset_base+maker_note->offset+displacement));\n#endif\n\n\tImageInfo->sections_found |= FOUND_MAKERNOTE;\n\n\told_motorola_intel = ImageInfo->motorola_intel;\n\tswitch (maker_note->byte_order) {\n\t\tcase MN_ORDER_INTEL:\n\t\t\tImageInfo->motorola_intel = 0;\n\t\t\tbreak;\n\t\tcase MN_ORDER_MOTOROLA:\n\t\t\tImageInfo->motorola_intel = 1;\n\t\t\tbreak;\n\t\tdefault:\n\t\tcase MN_ORDER_NORMAL:\n\t\t\tbreak;\n\t}\n\n\tNumDirEntries = php_ifd_get16u(dir_start, ImageInfo->motorola_intel);\n\n\tswitch (maker_note->offset_mode) {\n\t\tcase MN_OFFSET_MAKER:\n\t\t\toffset_base = value_ptr;\n\t\t\tbreak;\n#ifdef KALLE_0\n\t\tcase MN_OFFSET_GUESS:\n\t\t\tif (maker_note->offset + 10 + 4 >= value_len) {\n\t\t\t\t/* Can not read dir_start+10 since it's beyond value end */\n\t\t\t\texif_error_docref(\"exif_read_data#error_ifd\" EXIFERR_CC, ImageInfo, E_WARNING, \"IFD data too short: 0x%04X\", value_len);\n\t\t\t\treturn FALSE;\n\t\t\t}\n\t\t\toffset_diff = 2 + NumDirEntries*12 + 4 - php_ifd_get32u(dir_start+10, ImageInfo->motorola_intel);\n#ifdef EXIF_DEBUG\n\t\t\texif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, \"Using automatic offset correction: 0x%04X\", ((int)dir_start-(int)offset_base+maker_note->offset+displacement) + offset_diff);\n#endif\n\t\t\tif (offset_diff < 0 || offset_diff >= value_len ) {\n\t\t\t\texif_error_docref(\"exif_read_data#error_ifd\" EXIFERR_CC, ImageInfo, E_WARNING, \"IFD data bad offset: 0x%04X length 0x%04X\", offset_diff, value_len);\n\t\t\t\treturn FALSE;\n\t\t\t}\n\t\t\toffset_base = value_ptr + offset_diff;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\tcase MN_OFFSET_NORMAL:\n\t\t\tbreak;\n\t}\n\n\tif ((2+NumDirEntries*12) > value_len) {\n\t\texif_error_docref(\"exif_read_data#error_ifd\" EXIFERR_CC, ImageInfo, E_WARNING, \"Illegal IFD size: 2 + 0x%04X*12 = 0x%04X > 0x%04X\", NumDirEntries, 2+NumDirEntries*12, value_len);\n\t\treturn FALSE;\n\t}\n\n\tfor (de=0;de<NumDirEntries;de++) {\n\t\tif (!exif_process_IFD_TAG(ImageInfo, dir_start + 2 + 12 * de,\n\t\t\t\t\t\t\t\t offset_base, IFDlength, displacement, section_index, 0, maker_note->tag_table)) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\tImageInfo->motorola_intel = old_motorola_intel;\n/*\tNextDirOffset (must be NULL) = php_ifd_get32u(dir_start+2+12*de, ImageInfo->motorola_intel);*/\n#ifdef EXIF_DEBUG\n\texif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, \"Subsection %s done\", exif_get_sectionname(SECTION_MAKERNOTE));\n#endif\n\treturn TRUE;\n}\n/* }}} */\n\n```\n\n#### region() [lines 3192-3200]\n```c\n#ifdef EXIF_DEBUG\n\t\t\texif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, \"Using automatic offset correction: 0x%04X\", ((int)dir_start-(int)offset_base+maker_note->offset+displacement) + offset_diff);\n#endif\n\t\t\tif (offset_diff < 0 || offset_diff >= value_len ) {\n\t\t\t\texif_error_docref(\"exif_read_data#error_ifd\" EXIFERR_CC, ImageInfo, E_WARNING, \"IFD data bad offset: 0x%04X length 0x%04X\", offset_diff, value_len);\n\t\t\t\treturn FALSE;\n\t\t\t}\n\t\t\toffset_base = value_ptr + offset_diff;\n\t\t\tbreak;\n```\n\n\n## Upstream Fix\n```diff\nX-Git-Url: http://208.43.231.11:8000/?p=php-src.git;a=blobdiff_plain;f=ext%2Fexif%2Fexif.c;h=cad29b729548e4206f0697710cc9e177f26fdff3;hp=1147980f7730de0dfd13904a2ea6461bbf4eded8;hb=3462efa386f26d343062094514af604c29e3edce;hpb=1baeae42703f9b2ec21fff787146eeca08d45535\n\nIndex: php-7.2.5/ext/exif/exif.c\n===================================================================\n--- php-7.2.5.orig/ext/exif/exif.c\t2018-08-04 09:18:43.566167854 +0200\n+++ php-7.2.5/ext/exif/exif.c\t2018-08-04 09:25:27.280266346 +0200\n@@ -3126,6 +3126,7 @@ static int exif_process_IFD_in_MAKERNOTE\n #endif\n \tconst maker_note_type *maker_note;\n \tchar *dir_start;\n+ int data_len;\n \t\n \tfor (i=0; i<=sizeof(maker_note_array)/sizeof(maker_note_type); i++) {\n \t\tif (i==sizeof(maker_note_array)/sizeof(maker_note_type)) {\n@@ -3180,6 +3181,7 @@ static int exif_process_IFD_in_MAKERNOTE\n \tswitch (maker_note->offset_mode) {\n \t\tcase MN_OFFSET_MAKER:\n \t\t\toffset_base = value_ptr;\n+\t\t\tdata_len = value_len;\n \t\t\tbreak;\n #ifdef KALLE_0\n \t\tcase MN_OFFSET_GUESS:\n@@ -3197,6 +3199,7 @@ static int exif_process_IFD_in_MAKERNOTE\n \t\t\t\treturn FALSE;\n \t\t\t}\n \t\t\toffset_base = value_ptr + offset_diff;\n+\t\t\tdata_len = value_len - offset_diff;\n \t\t\tbreak;\n #endif\n \t\tdefault:\n@@ -3211,7 +3214,7 @@ static int exif_process_IFD_in_MAKERNOTE\n \n \tfor (de=0;de<NumDirEntries;de++) {\n \t\tif (!exif_process_IFD_TAG(ImageInfo, dir_start + 2 + 12 * de,\n-\t\t\t\t\t\t\t\t offset_base, IFDlength, displacement, section_index, 0, maker_note->tag_table)) {\n+\t\t\t\t\t\t\t\t offset_base, data_len, displacement, section_index, 0, maker_note->tag_table)) {\n \t\t\treturn FALSE;\n \t\t}\n \t}\n\n```\n\nGenerate a backported patch for the SUSE target version."
},
{
"role": "assistant",
"content": "X-Git-Url: http://208.43.231.11:8000/?p=php-src.git;a=blobdiff_plain;f=ext%2Fexif%2Fexif.c;h=cad29b729548e4206f0697710cc9e177f26fdff3;hp=1147980f7730de0dfd13904a2ea6461bbf4eded8;hb=3462efa386f26d343062094514af604c29e3edce;hpb=1baeae42703f9b2ec21fff787146eeca08d45535\n\nIndex: php-7.2.5/ext/exif/exif.c\n===================================================================\n--- php-7.2.5.orig/ext/exif/exif.c\t2018-08-04 09:18:43.566167854 +0200\n+++ php-7.2.5/ext/exif/exif.c\t2018-08-04 09:25:27.280266346 +0200\n@@ -3126,6 +3126,7 @@ static int exif_process_IFD_in_MAKERNOTE\n #endif\n \tconst maker_note_type *maker_note;\n \tchar *dir_start;\n+ int data_len;\n \t\n \tfor (i=0; i<=sizeof(maker_note_array)/sizeof(maker_note_type); i++) {\n \t\tif (i==sizeof(maker_note_array)/sizeof(maker_note_type)) {\n@@ -3180,6 +3181,7 @@ static int exif_process_IFD_in_MAKERNOTE\n \tswitch (maker_note->offset_mode) {\n \t\tcase MN_OFFSET_MAKER:\n \t\t\toffset_base = value_ptr;\n+\t\t\tdata_len = value_len;\n \t\t\tbreak;\n #ifdef KALLE_0\n \t\tcase MN_OFFSET_GUESS:\n@@ -3197,6 +3199,7 @@ static int exif_process_IFD_in_MAKERNOTE\n \t\t\t\treturn FALSE;\n \t\t\t}\n \t\t\toffset_base = value_ptr + offset_diff;\n+\t\t\tdata_len = value_len - offset_diff;\n \t\t\tbreak;\n #endif\n \t\tdefault:\n@@ -3211,7 +3214,7 @@ static int exif_process_IFD_in_MAKERNOTE\n \n \tfor (de=0;de<NumDirEntries;de++) {\n \t\tif (!exif_process_IFD_TAG(ImageInfo, dir_start + 2 + 12 * de,\n-\t\t\t\t\t\t\t\t offset_base, IFDlength, displacement, section_index, 0, maker_note->tag_table)) {\n+\t\t\t\t\t\t\t\t offset_base, data_len, displacement, section_index, 0, maker_note->tag_table)) {\n \t\t\treturn FALSE;\n \t\t}\n \t}\n"
}
] |
{
"id": "php7-11377-php-CVE-2018-14851.patch",
"cves": [
"CVE-2019-11043"
],
"package": "php7",
"incident_id": 11377,
"patch_name": "php-CVE-2018-14851.patch",
"tier": "identical",
"language": "c",
"patch_lines_changed": 5,
"patch_files_count": 1,
"total_tokens_est": 965,
"has_source_context": true,
"upstream_enriched": false,
"suse_license": "PHP-3.01",
"upstream_license": "NOASSERTION",
"cve_id": "CVE-2019-11043",
"upstream_commit": null,
"upstream_repo": 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-2019-11043\n\n===================================================================\n\n## Package\nphp7\n\n## Files to modify\n- main/streams/plain_wrapper.c\n\n## Target Source Code\n\n### main/streams/plain_wrapper.c\n\n#### php_plain_files_rename() [lines 1130-1217]\n```c\n\treturn 1;\n}\n\nstatic int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context)\n{\n\tint ret;\n\n\tif (!url_from || !url_to) {\n\t\treturn 0;\n\t}\n\n#ifdef PHP_WIN32\n\tif (!php_win32_check_trailing_space(url_from, strlen(url_from))) {\n\t\tphp_win32_docref2_from_error(ERROR_INVALID_NAME, url_from, url_to);\n\t\treturn 0;\n\t}\n\tif (!php_win32_check_trailing_space(url_to, strlen(url_to))) {\n\t\tphp_win32_docref2_from_error(ERROR_INVALID_NAME, url_from, url_to);\n\t\treturn 0;\n\t}\n#endif\n\n\tif (strncasecmp(url_from, \"file://\", sizeof(\"file://\") - 1) == 0) {\n\t\turl_from += sizeof(\"file://\") - 1;\n\t}\n\n\tif (strncasecmp(url_to, \"file://\", sizeof(\"file://\") - 1) == 0) {\n\t\turl_to += sizeof(\"file://\") - 1;\n\t}\n\n\tif (php_check_open_basedir(url_from) || php_check_open_basedir(url_to)) {\n\t\treturn 0;\n\t}\n\n\tret = VCWD_RENAME(url_from, url_to);\n\n\tif (ret == -1) {\n#ifndef PHP_WIN32\n# ifdef EXDEV\n\t\tif (errno == EXDEV) {\n\t\t\tzend_stat_t sb;\n\t\t\tif (php_copy_file(url_from, url_to) == SUCCESS) {\n\t\t\t\tif (VCWD_STAT(url_from, &sb) == 0) {\n# ifndef TSRM_WIN32\n\t\t\t\t\tif (VCWD_CHMOD(url_to, sb.st_mode)) {\n\t\t\t\t\t\tif (errno == EPERM) {\n\t\t\t\t\t\t\tphp_error_docref2(NULL, url_from, url_to, E_WARNING, \"%s\", strerror(errno));\n\t\t\t\t\t\t\tVCWD_UNLINK(url_from);\n\t\t\t\t\t\t\treturn 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tphp_error_docref2(NULL, url_from, url_to, E_WARNING, \"%s\", strerror(errno));\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\t}\n\t\t\t\t\tif (VCWD_CHOWN(url_to, sb.st_uid, sb.st_gid)) {\n\t\t\t\t\t\tif (errno == EPERM) {\n\t\t\t\t\t\t\tphp_error_docref2(NULL, url_from, url_to, E_WARNING, \"%s\", strerror(errno));\n\t\t\t\t\t\t\tVCWD_UNLINK(url_from);\n\t\t\t\t\t\t\treturn 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tphp_error_docref2(NULL, url_from, url_to, E_WARNING, \"%s\", strerror(errno));\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\t}\n# endif\n\t\t\t\t\tVCWD_UNLINK(url_from);\n\t\t\t\t\treturn 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tphp_error_docref2(NULL, url_from, url_to, E_WARNING, \"%s\", strerror(errno));\n\t\t\treturn 0;\n\t\t}\n# endif\n#endif\n\n#ifdef PHP_WIN32\n\t\tphp_win32_docref2_from_error(GetLastError(), url_from, url_to);\n#else\n\t\tphp_error_docref2(NULL, url_from, url_to, E_WARNING, \"%s\", strerror(errno));\n#endif\n\t\treturn 0;\n\t}\n\n\t/* Clear stat cache (and realpath cache) */\n\tphp_clear_stat_cache(1, NULL, 0);\n\n\treturn 1;\n}\n\nstatic int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, int mode, int options, php_stream_context *context)\n```\n\n\n## Upstream Fix\n```diff\nIndex: php-7.2.5/main/streams/plain_wrapper.c\n===================================================================\n--- php-7.2.5.orig/main/streams/plain_wrapper.c\t2019-03-20 11:59:59.515315899 +0100\n+++ php-7.2.5/main/streams/plain_wrapper.c\t2019-03-20 12:00:44.107570303 +0100\n@@ -1168,34 +1168,51 @@ static int php_plain_files_rename(php_st\n # ifdef EXDEV\n \t\tif (errno == EXDEV) {\n \t\t\tzend_stat_t sb;\n+# if !defined(ZTS) && !defined(TSRM_WIN32) && !defined(NETWARE)\n+\t\t\t/* not sure what to do in ZTS case, umask is not thread-safe */\n+\t\t\tint oldmask = umask(077);\n+# endif\n+\t\t\tint success = 0;\n \t\t\tif (php_copy_file(url_from, url_to) == SUCCESS) {\n \t\t\t\tif (VCWD_STAT(url_from, &sb) == 0) {\n+\t\t\t\t\tsuccess = 1;\n # ifndef TSRM_WIN32\n-\t\t\t\t\tif (VCWD_CHMOD(url_to, sb.st_mode)) {\n-\t\t\t\t\t\tif (errno == EPERM) {\n-\t\t\t\t\t\t\tphp_error_docref2(NULL, url_from, url_to, E_WARNING, \"%s\", strerror(errno));\n-\t\t\t\t\t\t\tVCWD_UNLINK(url_from);\n-\t\t\t\t\t\t\treturn 1;\n-\t\t\t\t\t\t}\n+\t\t\t\t\t/*\n+\t\t\t\t\t * Try to set user and permission info on the target.\n+\t\t\t\t\t * If we're not root, then some of these may fail.\n+\t\t\t\t\t * We try chown first, to set proper group info, relying\n+\t\t\t\t\t * on the system environment to have proper umask to not allow\n+\t\t\t\t\t * access to the file in the meantime.\n+\t\t\t\t\t */\n+\t\t\t\t\tif (VCWD_CHOWN(url_to, sb.st_uid, sb.st_gid)) {\n \t\t\t\t\t\tphp_error_docref2(NULL, url_from, url_to, E_WARNING, \"%s\", strerror(errno));\n-\t\t\t\t\t\treturn 0;\n+\t\t\t\t\t\tif (errno != EPERM) {\n+\t\t\t\t\t\t\tsuccess = 0;\n+\t\t\t\t\t\t}\n \t\t\t\t\t}\n-\t\t\t\t\tif (VCWD_CHOWN(url_to, sb.st_uid, sb.st_gid)) {\n-\t\t\t\t\t\tif (errno == EPERM) {\n+\n+\t\t\t\t\tif (success) {\n+\t\t\t\t\t\tif (VCWD_CHMOD(url_to, sb.st_mode)) {\n \t\t\t\t\t\t\tphp_error_docref2(NULL, url_from, url_to, E_WARNING, \"%s\", strerror(errno));\n-\t\t\t\t\t\t\tVCWD_UNLINK(url_from);\n-\t\t\t\t\t\t\treturn 1;\n+\t\t\t\t\t\t\tif (errno != EPERM) {\n+\t\t\t\t\t\t\t\tsuccess = 0;\n+\t\t\t\t\t\t\t}\n \t\t\t\t\t\t}\n-\t\t\t\t\t\tphp_error_docref2(NULL, url_from, url_to, E_WARNING, \"%s\", strerror(errno));\n-\t\t\t\t\t\treturn 0;\n \t\t\t\t\t}\n # endif\n-\t\t\t\t\tVCWD_UNLINK(url_from);\n-\t\t\t\t\treturn 1;\n+\t\t\t\t\tif (success) {\n+\t\t\t\t\t\tVCWD_UNLINK(url_from);\n+\t\t\t\t\t}\n+\t\t\t\t} else {\n+\t\t\t\t\tphp_error_docref2(NULL, url_from, url_to, E_WARNING, \"%s\", strerror(errno));\n \t\t\t\t}\n+\t\t\t} else {\n+\t\t\t\tphp_error_docref2(NULL, url_from, url_to, E_WARNING, \"%s\", strerror(errno));\n \t\t\t}\n-\t\t\tphp_error_docref2(NULL, url_from, url_to, E_WARNING, \"%s\", strerror(errno));\n-\t\t\treturn 0;\n+# if !defined(ZTS) && !defined(TSRM_WIN32) && !defined(NETWARE)\n+\t\t\tumask(oldmask);\n+# endif\n+\t\t\treturn success;\n \t\t}\n # endif\n #endif\n\n```\n\nGenerate a backported patch for the SUSE target version."
},
{
"role": "assistant",
"content": "Index: php-7.2.5/main/streams/plain_wrapper.c\n===================================================================\n--- php-7.2.5.orig/main/streams/plain_wrapper.c\t2019-03-20 11:59:59.515315899 +0100\n+++ php-7.2.5/main/streams/plain_wrapper.c\t2019-03-20 12:00:44.107570303 +0100\n@@ -1168,34 +1168,51 @@ static int php_plain_files_rename(php_st\n # ifdef EXDEV\n \t\tif (errno == EXDEV) {\n \t\t\tzend_stat_t sb;\n+# if !defined(ZTS) && !defined(TSRM_WIN32) && !defined(NETWARE)\n+\t\t\t/* not sure what to do in ZTS case, umask is not thread-safe */\n+\t\t\tint oldmask = umask(077);\n+# endif\n+\t\t\tint success = 0;\n \t\t\tif (php_copy_file(url_from, url_to) == SUCCESS) {\n \t\t\t\tif (VCWD_STAT(url_from, &sb) == 0) {\n+\t\t\t\t\tsuccess = 1;\n # ifndef TSRM_WIN32\n-\t\t\t\t\tif (VCWD_CHMOD(url_to, sb.st_mode)) {\n-\t\t\t\t\t\tif (errno == EPERM) {\n-\t\t\t\t\t\t\tphp_error_docref2(NULL, url_from, url_to, E_WARNING, \"%s\", strerror(errno));\n-\t\t\t\t\t\t\tVCWD_UNLINK(url_from);\n-\t\t\t\t\t\t\treturn 1;\n-\t\t\t\t\t\t}\n+\t\t\t\t\t/*\n+\t\t\t\t\t * Try to set user and permission info on the target.\n+\t\t\t\t\t * If we're not root, then some of these may fail.\n+\t\t\t\t\t * We try chown first, to set proper group info, relying\n+\t\t\t\t\t * on the system environment to have proper umask to not allow\n+\t\t\t\t\t * access to the file in the meantime.\n+\t\t\t\t\t */\n+\t\t\t\t\tif (VCWD_CHOWN(url_to, sb.st_uid, sb.st_gid)) {\n \t\t\t\t\t\tphp_error_docref2(NULL, url_from, url_to, E_WARNING, \"%s\", strerror(errno));\n-\t\t\t\t\t\treturn 0;\n+\t\t\t\t\t\tif (errno != EPERM) {\n+\t\t\t\t\t\t\tsuccess = 0;\n+\t\t\t\t\t\t}\n \t\t\t\t\t}\n-\t\t\t\t\tif (VCWD_CHOWN(url_to, sb.st_uid, sb.st_gid)) {\n-\t\t\t\t\t\tif (errno == EPERM) {\n+\n+\t\t\t\t\tif (success) {\n+\t\t\t\t\t\tif (VCWD_CHMOD(url_to, sb.st_mode)) {\n \t\t\t\t\t\t\tphp_error_docref2(NULL, url_from, url_to, E_WARNING, \"%s\", strerror(errno));\n-\t\t\t\t\t\t\tVCWD_UNLINK(url_from);\n-\t\t\t\t\t\t\treturn 1;\n+\t\t\t\t\t\t\tif (errno != EPERM) {\n+\t\t\t\t\t\t\t\tsuccess = 0;\n+\t\t\t\t\t\t\t}\n \t\t\t\t\t\t}\n-\t\t\t\t\t\tphp_error_docref2(NULL, url_from, url_to, E_WARNING, \"%s\", strerror(errno));\n-\t\t\t\t\t\treturn 0;\n \t\t\t\t\t}\n # endif\n-\t\t\t\t\tVCWD_UNLINK(url_from);\n-\t\t\t\t\treturn 1;\n+\t\t\t\t\tif (success) {\n+\t\t\t\t\t\tVCWD_UNLINK(url_from);\n+\t\t\t\t\t}\n+\t\t\t\t} else {\n+\t\t\t\t\tphp_error_docref2(NULL, url_from, url_to, E_WARNING, \"%s\", strerror(errno));\n \t\t\t\t}\n+\t\t\t} else {\n+\t\t\t\tphp_error_docref2(NULL, url_from, url_to, E_WARNING, \"%s\", strerror(errno));\n \t\t\t}\n-\t\t\tphp_error_docref2(NULL, url_from, url_to, E_WARNING, \"%s\", strerror(errno));\n-\t\t\treturn 0;\n+# if !defined(ZTS) && !defined(TSRM_WIN32) && !defined(NETWARE)\n+\t\t\tumask(oldmask);\n+# endif\n+\t\t\treturn success;\n \t\t}\n # endif\n #endif\n"
}
] |
{
"id": "php7-11377-php-CVE-2019-9637.patch",
"cves": [
"CVE-2019-11043"
],
"package": "php7",
"incident_id": 11377,
"patch_name": "php-CVE-2019-9637.patch",
"tier": "identical",
"language": "c",
"patch_lines_changed": 51,
"patch_files_count": 1,
"total_tokens_est": 1382,
"has_source_context": true,
"upstream_enriched": false,
"suse_license": "PHP-3.01",
"upstream_license": "NOASSERTION",
"cve_id": "CVE-2019-11043",
"upstream_commit": null,
"upstream_repo": 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-2019-11043\n\n===================================================================\n\n## Package\nphp7\n\n## Files to modify\n- ext/gd/libgd/gd_bmp.c\n\n## Target Source Code\n\n### ext/gd/libgd/gd_bmp.c\n\n#### bmp_read_4bit() [lines 854-944]\n```c\n\treturn 0;\n}\n\nstatic int bmp_read_4bit(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info, bmp_hdr_t *header)\n{\n\tint ypos = 0, xpos = 0, row = 0, index = 0;\n\tint padding = 0, current_byte = 0;\n\n\tif (info->enctype != BMP_BI_RGB && info->enctype != BMP_BI_RLE4) {\n\t\treturn 1;\n\t}\n\n\tif (!info->numcolors) {\n\t\tinfo->numcolors = 16;\n\t} else if (info->numcolors < 0 || info->numcolors > 16) {\n\t\treturn 1;\n\t}\n\n\tif (bmp_read_palette(im, infile, info->numcolors, (info->type == BMP_PALETTE_4))) {\n\t\treturn 1;\n\t}\n\n\tim->colorsTotal = info->numcolors;\n\n\t/* There is a chance the data isn't until later, would be wierd but it is possible */\n\tif (gdTell(infile) != header->off) {\n\t\t/* Should make sure we don't seek past the file size */\n\t\tif (!gdSeek(infile, header->off)) {\n\t\t\treturn 1;\n\t\t}\n\t}\n\n\t/* The line must be divisible by 4, else its padded with NULLs */\n\tpadding = ((int)ceil(0.5 * info->width)) % 4;\n\tif (padding) {\n\t\tpadding = 4 - padding;\n\t}\n\n\tswitch (info->enctype) {\n\tcase BMP_BI_RGB:\n\t\tfor (ypos = 0; ypos < info->height; ++ypos) {\n\t\t\tif (info->topdown) {\n\t\t\t\trow = ypos;\n\t\t\t} else {\n\t\t\t\trow = info->height - ypos - 1;\n\t\t\t}\n\n\t\t\tfor (xpos = 0; xpos < info->width; xpos += 2) {\n\t\t\t\tif (!gdGetByte(¤t_byte, infile)) {\n\t\t\t\t\treturn 1;\n\t\t\t\t}\n\n\t\t\t\tindex = (current_byte >> 4) & 0x0f;\n\t\t\t\tif (im->open[index]) {\n\t\t\t\t\tim->open[index] = 0;\n\t\t\t\t}\n\t\t\t\tgdImageSetPixel(im, xpos, row, index);\n\n\t\t\t\t/* This condition may get called often, potential optimsations */\n\t\t\t\tif (xpos >= info->width) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tindex = current_byte & 0x0f;\n\t\t\t\tif (im->open[index]) {\n\t\t\t\t\tim->open[index] = 0;\n\t\t\t\t}\n\t\t\t\tgdImageSetPixel(im, xpos + 1, row, index);\n\t\t\t}\n\n\t\t\tfor (xpos = padding; xpos > 0; --xpos) {\n\t\t\t\tif (!gdGetByte(&index, infile)) {\n\t\t\t\t\treturn 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tbreak;\n\n\tcase BMP_BI_RLE4:\n\t\tif (bmp_read_rle(im, infile, info)) {\n\t\t\treturn 1;\n\t\t}\n\t\tbreak;\n\n\tdefault:\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\nstatic int bmp_read_8bit(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info, bmp_hdr_t *header)\n```\n\n#### gdImageBmpPtr() [lines 63-77]\n```c\n/*\n\tFunction: gdImageBmpPtr\n*/\nvoid * gdImageBmpPtr(gdImagePtr im, int *size, int compression)\n{\n\tvoid *rv;\n\tgdIOCtx *out = gdNewDynamicCtx(2048, NULL);\n\tif (out == NULL) return NULL;\n\tgdImageBmpCtx(im, out, compression);\n\trv = gdDPExtractData(out, size);\n\tout->gd_free(out);\n\treturn rv;\n}\n\n/*\n```\n\n#### gdImageBmp() [lines 77-88]\n```c\n/*\n\tFunction: gdImageBmp\n*/\nvoid gdImageBmp(gdImagePtr im, FILE *outFile, int compression)\n{\n\tgdIOCtx *out = gdNewFileCtx(outFile);\n\tif (out == NULL) return;\n\tgdImageBmpCtx(im, out, compression);\n\tout->gd_free(out);\n}\n\n/*\n```\n\n#### gdImageBmpCtx() [lines 88-292]\n```c\n/*\n\tFunction: gdImageBmpCtx\n*/\nvoid gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression)\n{\n\tint bitmap_size = 0, info_size, total_size, padding;\n\tint i, row, xpos, pixel;\n\tint error = 0;\n\tunsigned char *uncompressed_row = NULL, *uncompressed_row_start = NULL;\n\tFILE *tmpfile_for_compression = NULL;\n\tgdIOCtxPtr out_original = NULL;\n\n\t/* No compression if its true colour or we don't support seek */\n\tif (im->trueColor) {\n\t\tcompression = 0;\n\t}\n\n\tif (compression == 1 && !out->seek) {\n\t\t/* Try to create a temp file where we can seek */\n\t\tif ((tmpfile_for_compression = tmpfile()) == NULL) {\n\t\t\tcompression = 0;\n\t\t} else {\n\t\t\tout_original = out;\n\t\t\tif ((out = (gdIOCtxPtr)gdNewFileCtx(tmpfile_for_compression)) == NULL) {\n\t\t\t\tout = out_original;\n\t\t\t\tout_original = NULL;\n\t\t\t\tcompression = 0;\n\t\t\t}\n\t\t}\n\t}\n\n\tbitmap_size = ((im->sx * (im->trueColor ? 24 : 8)) / 8) * im->sy;\n\n\t/* 40 byte Windows v3 header */\n\tinfo_size = BMP_WINDOWS_V3;\n\n\t/* data for the palette */\n\tif (!im->trueColor) {\n\t\tinfo_size += im->colorsTotal * 4;\n\t\tif (compression) {\n/* ... 136 lines omitted ... */\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tgdPutBuf(copy_buffer , buffer_size, out_original);\n\t\t}\n\t\tgdFree(copy_buffer);\n\n\t\t/* Replace the temp with the original which now has data */\n\t\tout->gd_free(out);\n\t\tout = out_original;\n\t\tout_original = NULL;\n\t}\n\ncleanup:\n\tif (tmpfile_for_compression) {\n#ifdef _WIN32\n\t\t_rmtmp();\n#else\n\t\tfclose(tmpfile_for_compression);\n#endif\n\t\ttmpfile_for_compression = NULL;\n\t}\n\n\tif (out_original) {\n\t\tout_original->gd_free(out_original);\n\t}\n\treturn;\n}\n\nstatic int compress_row(unsigned char *row, int length)\n```\n\n\n## Upstream Fix\n```diff\nIndex: php-7.2.5/ext/gd/libgd/gd_bmp.c\n===================================================================\n--- php-7.2.5.orig/ext/gd/libgd/gd_bmp.c\t2018-04-24 17:09:54.000000000 +0200\n+++ php-7.2.5/ext/gd/libgd/gd_bmp.c\t2018-08-27 16:21:13.287949435 +0200\n@@ -40,6 +40,8 @@ static int bmp_read_4bit(gdImagePtr im,\n static int bmp_read_8bit(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info, bmp_hdr_t *header);\n static int bmp_read_rle(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info);\n \n+static int _gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression);\n+\n #define BMP_DEBUG(s)\n \n static int gdBMPPutWord(gdIOCtx *out, int w)\n@@ -68,8 +70,10 @@ void * gdImageBmpPtr(gdImagePtr im, int\n \tvoid *rv;\n \tgdIOCtx *out = gdNewDynamicCtx(2048, NULL);\n \tif (out == NULL) return NULL;\n-\tgdImageBmpCtx(im, out, compression);\n-\trv = gdDPExtractData(out, size);\n+\tif (!_gdImageBmpCtx(im, out, compression))\n+\t\trv = gdDPExtractData(out, size);\n+\telse\n+\t\trv = NULL;\n \tout->gd_free(out);\n \treturn rv;\n }\n@@ -90,12 +94,18 @@ void gdImageBmp(gdImagePtr im, FILE *out\n */\n void gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression)\n {\n+ _gdImageBmpCtx(im, out, compression);\n+}\n+\n+static int _gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression)\n+{\n \tint bitmap_size = 0, info_size, total_size, padding;\n \tint i, row, xpos, pixel;\n \tint error = 0;\n \tunsigned char *uncompressed_row = NULL, *uncompressed_row_start = NULL;\n \tFILE *tmpfile_for_compression = NULL;\n \tgdIOCtxPtr out_original = NULL;\n+\tint ret = 1;\n \n \t/* No compression if its true colour or we don't support seek */\n \tif (im->trueColor) {\n@@ -273,6 +283,7 @@ void gdImageBmpCtx(gdImagePtr im, gdIOCt\n \t\tout_original = NULL;\n \t}\n \n+\tret = 0;\n cleanup:\n \tif (tmpfile_for_compression) {\n #ifdef _WIN32\n@@ -286,7 +297,7 @@ cleanup:\n \tif (out_original) {\n \t\tout_original->gd_free(out_original);\n \t}\n-\treturn;\n+\treturn ret;\n }\n \n static int compress_row(unsigned char *row, int length)\n\n```\n\nGenerate a backported patch for the SUSE target version."
},
{
"role": "assistant",
"content": "Index: php-7.2.5/ext/gd/libgd/gd_bmp.c\n===================================================================\n--- php-7.2.5.orig/ext/gd/libgd/gd_bmp.c\t2018-04-24 17:09:54.000000000 +0200\n+++ php-7.2.5/ext/gd/libgd/gd_bmp.c\t2018-08-27 16:21:13.287949435 +0200\n@@ -40,6 +40,8 @@ static int bmp_read_4bit(gdImagePtr im,\n static int bmp_read_8bit(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info, bmp_hdr_t *header);\n static int bmp_read_rle(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info);\n \n+static int _gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression);\n+\n #define BMP_DEBUG(s)\n \n static int gdBMPPutWord(gdIOCtx *out, int w)\n@@ -68,8 +70,10 @@ void * gdImageBmpPtr(gdImagePtr im, int\n \tvoid *rv;\n \tgdIOCtx *out = gdNewDynamicCtx(2048, NULL);\n \tif (out == NULL) return NULL;\n-\tgdImageBmpCtx(im, out, compression);\n-\trv = gdDPExtractData(out, size);\n+\tif (!_gdImageBmpCtx(im, out, compression))\n+\t\trv = gdDPExtractData(out, size);\n+\telse\n+\t\trv = NULL;\n \tout->gd_free(out);\n \treturn rv;\n }\n@@ -90,12 +94,18 @@ void gdImageBmp(gdImagePtr im, FILE *out\n */\n void gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression)\n {\n+ _gdImageBmpCtx(im, out, compression);\n+}\n+\n+static int _gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression)\n+{\n \tint bitmap_size = 0, info_size, total_size, padding;\n \tint i, row, xpos, pixel;\n \tint error = 0;\n \tunsigned char *uncompressed_row = NULL, *uncompressed_row_start = NULL;\n \tFILE *tmpfile_for_compression = NULL;\n \tgdIOCtxPtr out_original = NULL;\n+\tint ret = 1;\n \n \t/* No compression if its true colour or we don't support seek */\n \tif (im->trueColor) {\n@@ -273,6 +283,7 @@ void gdImageBmpCtx(gdImagePtr im, gdIOCt\n \t\tout_original = NULL;\n \t}\n \n+\tret = 0;\n cleanup:\n \tif (tmpfile_for_compression) {\n #ifdef _WIN32\n@@ -286,7 +297,7 @@ cleanup:\n \tif (out_original) {\n \t\tout_original->gd_free(out_original);\n \t}\n-\treturn;\n+\treturn ret;\n }\n \n static int compress_row(unsigned char *row, int length)\n"
}
] |
{
"id": "php7-11377-php-CVE-2018-1000222.patch",
"cves": [
"CVE-2019-11043"
],
"package": "php7",
"incident_id": 11377,
"patch_name": "php-CVE-2018-1000222.patch",
"tier": "identical",
"language": "c",
"patch_lines_changed": 17,
"patch_files_count": 1,
"total_tokens_est": 1112,
"has_source_context": true,
"upstream_enriched": false,
"suse_license": "PHP-3.01",
"upstream_license": "NOASSERTION",
"cve_id": "CVE-2019-11043",
"upstream_commit": null,
"upstream_repo": 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-2019-11043\n\ncommit 25aa5f434dfb3337a6617b46224f1b505053d8e9\n\n## Package\nphp7\n\n## Files to modify\n- ext/exif/exif.c\n\n## Upstream Fix\n```diff\ncommit 25aa5f434dfb3337a6617b46224f1b505053d8e9\nAuthor: Stanislav Malyshev <stas@php.net>\nDate: Fri Mar 1 23:25:45 2019 -0800\n\n Fix integer overflows on 32-bits\n\ndiff --git a/ext/exif/exif.c b/ext/exif/exif.c\nindex cbde3effed..b4563927a5 100644\n--- a/ext/exif/exif.c\n+++ b/ext/exif/exif.c\n@@ -3567,10 +3567,10 @@ static int exif_process_IFD_in_TIFF(image_info_type *ImageInfo, size_t dir_offse\n \ttag_table_type tag_table = exif_get_tag_table(section_index);\n \n \tif (ImageInfo->ifd_nesting_level > MAX_IFD_NESTING_LEVEL) {\n- return FALSE;\n- }\n+\t\treturn FALSE;\n+\t}\n \n-\tif (ImageInfo->FileSize >= dir_offset+2) {\n+\tif (ImageInfo->FileSize >= 2 && ImageInfo->FileSize - 2 >= dir_offset) {\n \t\tsn = exif_file_sections_add(ImageInfo, M_PSEUDO, 2, NULL);\n #ifdef EXIF_DEBUG\n \t\texif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, \"Read from TIFF: filesize(x%04X), IFD dir(x%04X + x%04X)\", ImageInfo->FileSize, dir_offset, 2);\n@@ -3578,8 +3578,8 @@ static int exif_process_IFD_in_TIFF(image_info_type *ImageInfo, size_t dir_offse\n \t\tphp_stream_seek(ImageInfo->infile, dir_offset, SEEK_SET); /* we do not know the order of sections */\n \t\tphp_stream_read(ImageInfo->infile, (char*)ImageInfo->file.list[sn].data, 2);\n \t\tnum_entries = php_ifd_get16u(ImageInfo->file.list[sn].data, ImageInfo->motorola_intel);\n-\t\tdir_size = 2/*num dir entries*/ +12/*length of entry*/*num_entries +4/* offset to next ifd (points to thumbnail or NULL)*/;\n-\t\tif (ImageInfo->FileSize >= dir_offset+dir_size) {\n+\t\tdir_size = 2/*num dir entries*/ +12/*length of entry*/*(size_t)num_entries +4/* offset to next ifd (points to thumbnail or NULL)*/;\n+\t\tif (ImageInfo->FileSize >= dir_size && ImageInfo->FileSize - dir_size >= dir_offset) {\n #ifdef EXIF_DEBUG\n \t\t\texif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, \"Read from TIFF: filesize(x%04X), IFD dir(x%04X + x%04X), IFD entries(%d)\", ImageInfo->FileSize, dir_offset+2, dir_size-2, num_entries);\n #endif\n@@ -3662,9 +3662,9 @@ static int exif_process_IFD_in_TIFF(image_info_type *ImageInfo, size_t dir_offse\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t}\n-\t\t\tif (ImageInfo->FileSize >= dir_offset + ImageInfo->file.list[sn].size) {\n+\t\t\tif (ImageInfo->FileSize >= ImageInfo->file.list[sn].size && ImageInfo->FileSize - ImageInfo->file.list[sn].size >= dir_offset) {\n \t\t\t\tif (ifd_size > dir_size) {\n-\t\t\t\t\tif (dir_offset + ifd_size > ImageInfo->FileSize) {\n+\t\t\t\t\tif (ImageInfo->FileSize < ifd_size || dir_offset > ImageInfo->FileSize - ifd_size) {\n \t\t\t\t\t\texif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, \"Error in TIFF: filesize(x%04X) less than size of IFD(x%04X + x%04X)\", ImageInfo->FileSize, dir_offset, ifd_size);\n \t\t\t\t\t\treturn FALSE;\n \t\t\t\t\t}\n\n\n```\n\nGenerate a backported patch for the SUSE target version."
},
{
"role": "assistant",
"content": "commit 25aa5f434dfb3337a6617b46224f1b505053d8e9\nAuthor: Stanislav Malyshev <stas@php.net>\nDate: Fri Mar 1 23:25:45 2019 -0800\n\n Fix integer overflows on 32-bits\n\ndiff --git a/ext/exif/exif.c b/ext/exif/exif.c\nindex cbde3effed..b4563927a5 100644\n--- a/ext/exif/exif.c\n+++ b/ext/exif/exif.c\n@@ -3567,10 +3567,10 @@ static int exif_process_IFD_in_TIFF(image_info_type *ImageInfo, size_t dir_offse\n \ttag_table_type tag_table = exif_get_tag_table(section_index);\n \n \tif (ImageInfo->ifd_nesting_level > MAX_IFD_NESTING_LEVEL) {\n- return FALSE;\n- }\n+\t\treturn FALSE;\n+\t}\n \n-\tif (ImageInfo->FileSize >= dir_offset+2) {\n+\tif (ImageInfo->FileSize >= 2 && ImageInfo->FileSize - 2 >= dir_offset) {\n \t\tsn = exif_file_sections_add(ImageInfo, M_PSEUDO, 2, NULL);\n #ifdef EXIF_DEBUG\n \t\texif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, \"Read from TIFF: filesize(x%04X), IFD dir(x%04X + x%04X)\", ImageInfo->FileSize, dir_offset, 2);\n@@ -3578,8 +3578,8 @@ static int exif_process_IFD_in_TIFF(image_info_type *ImageInfo, size_t dir_offse\n \t\tphp_stream_seek(ImageInfo->infile, dir_offset, SEEK_SET); /* we do not know the order of sections */\n \t\tphp_stream_read(ImageInfo->infile, (char*)ImageInfo->file.list[sn].data, 2);\n \t\tnum_entries = php_ifd_get16u(ImageInfo->file.list[sn].data, ImageInfo->motorola_intel);\n-\t\tdir_size = 2/*num dir entries*/ +12/*length of entry*/*num_entries +4/* offset to next ifd (points to thumbnail or NULL)*/;\n-\t\tif (ImageInfo->FileSize >= dir_offset+dir_size) {\n+\t\tdir_size = 2/*num dir entries*/ +12/*length of entry*/*(size_t)num_entries +4/* offset to next ifd (points to thumbnail or NULL)*/;\n+\t\tif (ImageInfo->FileSize >= dir_size && ImageInfo->FileSize - dir_size >= dir_offset) {\n #ifdef EXIF_DEBUG\n \t\t\texif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, \"Read from TIFF: filesize(x%04X), IFD dir(x%04X + x%04X), IFD entries(%d)\", ImageInfo->FileSize, dir_offset+2, dir_size-2, num_entries);\n #endif\n@@ -3662,9 +3662,9 @@ static int exif_process_IFD_in_TIFF(image_info_type *ImageInfo, size_t dir_offse\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t}\n-\t\t\tif (ImageInfo->FileSize >= dir_offset + ImageInfo->file.list[sn].size) {\n+\t\t\tif (ImageInfo->FileSize >= ImageInfo->file.list[sn].size && ImageInfo->FileSize - ImageInfo->file.list[sn].size >= dir_offset) {\n \t\t\t\tif (ifd_size > dir_size) {\n-\t\t\t\t\tif (dir_offset + ifd_size > ImageInfo->FileSize) {\n+\t\t\t\t\tif (ImageInfo->FileSize < ifd_size || dir_offset > ImageInfo->FileSize - ifd_size) {\n \t\t\t\t\t\texif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, \"Error in TIFF: filesize(x%04X) less than size of IFD(x%04X + x%04X)\", ImageInfo->FileSize, dir_offset, ifd_size);\n \t\t\t\t\t\treturn FALSE;\n \t\t\t\t\t}\n\n"
}
] |
{
"id": "php7-11377-php-CVE-2019-9641.patch",
"cves": [
"CVE-2019-11043"
],
"package": "php7",
"incident_id": 11377,
"patch_name": "php-CVE-2019-9641.patch",
"tier": "identical",
"language": "c",
"patch_lines_changed": 14,
"patch_files_count": 1,
"total_tokens_est": 1463,
"has_source_context": false,
"upstream_enriched": false,
"suse_license": "PHP-3.01",
"upstream_license": "NOASSERTION",
"cve_id": "CVE-2019-11043",
"upstream_commit": null,
"upstream_repo": 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-2019-11043\n\n===================================================================\n\n## Package\nphp7\n\n## Files to modify\n- ext/exif/exif.c\n\n## Target Source Code\n\n### ext/exif/exif.c\n\n#### exif_scan_thumbnail() [lines 3884-3968]\n```c\n\n/* {{{ exif_scan_thumbnail\n * scan JPEG in thumbnail (memory) */\nstatic int exif_scan_thumbnail(image_info_type *ImageInfo)\n{\n\tuchar c, *data = (uchar*)ImageInfo->Thumbnail.data;\n\tint n, marker;\n\tsize_t length=2, pos=0;\n\tjpeg_sof_info sof_info;\n\n\tif (!data) {\n\t\treturn FALSE; /* nothing to do here */\n\t}\n\tif (memcmp(data, \"\\xFF\\xD8\\xFF\", 3)) {\n\t\tif (!ImageInfo->Thumbnail.width && !ImageInfo->Thumbnail.height) {\n\t\t\texif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, \"Thumbnail is not a JPEG image\");\n\t\t}\n\t\treturn FALSE;\n\t}\n\tfor (;;) {\n\t\tpos += length;\n\t\tif (pos>=ImageInfo->Thumbnail.size)\n\t\t\treturn FALSE;\n\t\tc = data[pos++];\n\t\tif (pos>=ImageInfo->Thumbnail.size)\n\t\t\treturn FALSE;\n\t\tif (c != 0xFF) {\n\t\t\treturn FALSE;\n\t\t}\n\t\tn = 8;\n\t\twhile ((c = data[pos++]) == 0xFF && n--) {\n\t\t\tif (pos+3>=ImageInfo->Thumbnail.size)\n\t\t\t\treturn FALSE;\n\t\t\t/* +3 = pos++ of next check when reaching marker + 2 bytes for length */\n\t\t}\n\t\tif (c == 0xFF)\n\t\t\treturn FALSE;\n\t\tmarker = c;\n\t\tlength = php_jpg_get16(data+pos);\n\t\tif (pos+length>=ImageInfo->Thumbnail.size) {\n\t\t\treturn FALSE;\n\t\t}\n#ifdef EXIF_DEBUG\n\t\texif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, \"Thumbnail: process section(x%02X=%s) @ x%04X + x%04X\", marker, exif_get_markername(marker), pos, length);\n#endif\n\t\tswitch (marker) {\n\t\t\tcase M_SOF0:\n\t\t\tcase M_SOF1:\n\t\t\tcase M_SOF2:\n\t\t\tcase M_SOF3:\n\t\t\tcase M_SOF5:\n\t\t\tcase M_SOF6:\n\t\t\tcase M_SOF7:\n\t\t\tcase M_SOF9:\n\t\t\tcase M_SOF10:\n\t\t\tcase M_SOF11:\n\t\t\tcase M_SOF13:\n\t\t\tcase M_SOF14:\n\t\t\tcase M_SOF15:\n\t\t\t\t/* handle SOFn block */\n\t\t\t\texif_process_SOFn(data+pos, marker, &sof_info);\n\t\t\t\tImageInfo->Thumbnail.height = sof_info.height;\n\t\t\t\tImageInfo->Thumbnail.width = sof_info.width;\n#ifdef EXIF_DEBUG\n\t\t\t\texif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, \"Thumbnail: size: %d * %d\", sof_info.width, sof_info.height);\n#endif\n\t\t\t\treturn TRUE;\n\n\t\t\tcase M_SOS:\n\t\t\tcase M_EOI:\n\t\t\t\texif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, \"Could not compute size of thumbnail\");\n\t\t\t\treturn FALSE;\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\t/* just skip */\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\texif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, \"Could not compute size of thumbnail\");\n\treturn FALSE;\n}\n/* }}} */\n\n```\n\n#### PHP_FUNCTION() [lines 2738-2759]\n```c\n\n/* {{{ proto string exif_tagname(int index)\n\tGet headername for index or false if not defined */\nPHP_FUNCTION(exif_tagname)\n{\n\tzend_long tag;\n\tchar *szTemp;\n\n\tif (zend_parse_parameters(ZEND_NUM_ARGS(), \"l\", &tag) == FAILURE) {\n\t\treturn;\n\t}\n\n\tszTemp = exif_get_tagname(tag, NULL, 0, tag_table_IFD);\n\n\tif (tag < 0 || !szTemp || !szTemp[0]) {\n\t\tRETURN_FALSE;\n\t}\n\n\tRETURN_STRING(szTemp)\n}\n/* }}} */\n\n```\n\n\n## Upstream Fix\n```diff\nIndex: php-7.2.5/ext/exif/exif.c\n===================================================================\n--- php-7.2.5.orig/ext/exif/exif.c\t2019-03-19 15:47:49.703923660 +0100\n+++ php-7.2.5/ext/exif/exif.c\t2019-03-19 15:49:57.408673458 +0100\n@@ -3924,7 +3924,7 @@ static int exif_scan_thumbnail(image_inf\n \t\t\treturn FALSE;\n \t\tmarker = c;\n \t\tlength = php_jpg_get16(data+pos);\n-\t\tif (pos+length>=ImageInfo->Thumbnail.size) {\n+\t\tif (length > ImageInfo->Thumbnail.size || pos >= ImageInfo->Thumbnail.size - length) {\n \t\t\treturn FALSE;\n \t\t}\n #ifdef EXIF_DEBUG\n@@ -3945,6 +3945,10 @@ static int exif_scan_thumbnail(image_inf\n \t\t\tcase M_SOF14:\n \t\t\tcase M_SOF15:\n \t\t\t\t/* handle SOFn block */\n+\t\t\t\tif (length < 8 || ImageInfo->Thumbnail.size - 8 < pos) {\n+\t\t\t\t\t/* exif_process_SOFn needs 8 bytes */\n+\t\t\t\t\treturn FALSE;\n+\t\t\t\t}\n \t\t\t\texif_process_SOFn(data+pos, marker, &sof_info);\n \t\t\t\tImageInfo->Thumbnail.height = sof_info.height;\n \t\t\t\tImageInfo->Thumbnail.width = sof_info.width;\n@@ -4678,7 +4682,9 @@ PHP_FUNCTION(exif_thumbnail)\n \tZVAL_STRINGL(return_value, ImageInfo.Thumbnail.data, ImageInfo.Thumbnail.size);\n \tif (arg_c >= 3) {\n \t\tif (!ImageInfo.Thumbnail.width || !ImageInfo.Thumbnail.height) {\n-\t\t\texif_scan_thumbnail(&ImageInfo);\n+\t\t\tif (!exif_scan_thumbnail(&ImageInfo)) {\n+\t\t\t\tImageInfo.Thumbnail.width = ImageInfo.Thumbnail.height = 0;\n+\t\t\t}\n \t\t}\n \t\tzval_dtor(z_width);\n \t\tzval_dtor(z_height);\n\n```\n\nGenerate a backported patch for the SUSE target version."
},
{
"role": "assistant",
"content": "Index: php-7.2.5/ext/exif/exif.c\n===================================================================\n--- php-7.2.5.orig/ext/exif/exif.c\t2019-03-19 15:47:49.703923660 +0100\n+++ php-7.2.5/ext/exif/exif.c\t2019-03-19 15:49:57.408673458 +0100\n@@ -3924,7 +3924,7 @@ static int exif_scan_thumbnail(image_inf\n \t\t\treturn FALSE;\n \t\tmarker = c;\n \t\tlength = php_jpg_get16(data+pos);\n-\t\tif (pos+length>=ImageInfo->Thumbnail.size) {\n+\t\tif (length > ImageInfo->Thumbnail.size || pos >= ImageInfo->Thumbnail.size - length) {\n \t\t\treturn FALSE;\n \t\t}\n #ifdef EXIF_DEBUG\n@@ -3945,6 +3945,10 @@ static int exif_scan_thumbnail(image_inf\n \t\t\tcase M_SOF14:\n \t\t\tcase M_SOF15:\n \t\t\t\t/* handle SOFn block */\n+\t\t\t\tif (length < 8 || ImageInfo->Thumbnail.size - 8 < pos) {\n+\t\t\t\t\t/* exif_process_SOFn needs 8 bytes */\n+\t\t\t\t\treturn FALSE;\n+\t\t\t\t}\n \t\t\t\texif_process_SOFn(data+pos, marker, &sof_info);\n \t\t\t\tImageInfo->Thumbnail.height = sof_info.height;\n \t\t\t\tImageInfo->Thumbnail.width = sof_info.width;\n@@ -4678,7 +4682,9 @@ PHP_FUNCTION(exif_thumbnail)\n \tZVAL_STRINGL(return_value, ImageInfo.Thumbnail.data, ImageInfo.Thumbnail.size);\n \tif (arg_c >= 3) {\n \t\tif (!ImageInfo.Thumbnail.width || !ImageInfo.Thumbnail.height) {\n-\t\t\texif_scan_thumbnail(&ImageInfo);\n+\t\t\tif (!exif_scan_thumbnail(&ImageInfo)) {\n+\t\t\t\tImageInfo.Thumbnail.width = ImageInfo.Thumbnail.height = 0;\n+\t\t\t}\n \t\t}\n \t\tzval_dtor(z_width);\n \t\tzval_dtor(z_height);\n"
}
] |
{
"id": "php7-11377-php-CVE-2019-9640.patch",
"cves": [
"CVE-2019-11043"
],
"package": "php7",
"incident_id": 11377,
"patch_name": "php-CVE-2019-9640.patch",
"tier": "identical",
"language": "c",
"patch_lines_changed": 10,
"patch_files_count": 1,
"total_tokens_est": 828,
"has_source_context": true,
"upstream_enriched": false,
"suse_license": "PHP-3.01",
"upstream_license": "NOASSERTION",
"cve_id": "CVE-2019-11043",
"upstream_commit": null,
"upstream_repo": 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-2020-1730\n\nCVE-2020-1730: Fix a possible segfault when zeroing AES-CTR\n\n## Package\nlibssh\n\n## Files to modify\n- src/libcrypto.c\n\n## Target Source Code\n\n### src/libcrypto.c\n\n#### aes_ctr_encrypt() [lines 618-638]\n```c\n return SSH_OK;\n}\n\nstatic void aes_ctr_encrypt(struct ssh_cipher_struct *cipher, void *in, void *out,\n unsigned long len) {\n unsigned char tmp_buffer[AES_BLOCK_SIZE];\n unsigned int num=0;\n /* Some things are special with ctr128 :\n * In this case, tmp_buffer is not being used, because it is used to store temporary data\n * when an encryption is made on lengths that are not multiple of blocksize.\n * Same for num, which is being used to store the current offset in blocksize in CTR\n * function.\n */\n#ifdef HAVE_OPENSSL_CRYPTO_CTR128_ENCRYPT\n CRYPTO_ctr128_encrypt(in, out, len, &cipher->aes_key->key, cipher->aes_key->IV, tmp_buffer, &num, (block128_f)AES_encrypt);\n#else\n AES_ctr128_encrypt(in, out, len, &cipher->aes_key->key, cipher->aes_key->IV, tmp_buffer, &num);\n#endif /* HAVE_OPENSSL_CRYPTO_CTR128_ENCRYPT */\n}\n\nstatic void aes_ctr_cleanup(struct ssh_cipher_struct *cipher){\n```\n\n\n### Type definitions\n\n```c\n/* from libssh/crypto.h */\nstruct ssh_cipher_struct {\n const char *name; /* ssh name of the algorithm */\n unsigned int blocksize; /* blocksize of the algo */\n enum ssh_cipher_e ciphertype;\n uint32_t lenfield_blocksize; /* blocksize of the packet length field */\n size_t keylen; /* length of the key structure */\n#ifdef HAVE_LIBGCRYPT\n gcry_cipher_hd_t *key;\n#elif defined HAVE_LIBCRYPTO\n struct ssh_3des_key_schedule *des3_key;\n struct ssh_aes_key_schedule *aes_key;\n const EVP_CIPHER *cipher;\n EVP_CIPHER_CTX *ctx;\n#elif defined HAVE_LIBMBEDCRYPTO\n mbedtls_cipher_context_t encrypt_ctx;\n mbedtls_cipher_context_t decrypt_ctx;\n mbedtls_cipher_type_t type;\n#endif\n struct chacha20_poly1305_keysched *chacha20_schedule;\n unsigned int keysize; /* bytes of key used. != keylen */\n size_t tag_size; /* overhead required for tag */\n /* sets the new key for immediate use */\n int (*set_encrypt_key)(struct ssh_cipher_struct *cipher, void *key, void *IV);\n int (*set_decrypt_key)(struct ssh_cipher_struct *cipher, void *key, void *IV);\n void (*encrypt)(struct ssh_cipher_struct *cipher, void *in, void *out,\n unsigned long len);\n void (*decrypt)(struct ssh_cipher_struct *cipher, void *in, void *out,\n unsigned long len);\n void (*aead_encrypt)(struct ssh_cipher_struct *cipher, void *in, void *out,\n size_t len, uint8_t *mac, uint64_t seq);\n int (*aead_decrypt_length)(struct ssh_cipher_struct *cipher, void *in,\n uint8_t *out, size_t len, uint64_t seq);\n int (*aead_decrypt)(struct ssh_cipher_struct *cipher, void *complete_packet, uint8_t *out,\n size_t encrypted_size, uint64_t seq);\n void (*cleanup)(struct ssh_cipher_struct *cipher);\n};\n```\n\n\n## Upstream Fix\n```diff\nFrom fa772dbe48f6c716f130e80562840d47dda5a1b7 Mon Sep 17 00:00:00 2001\nFrom: Andreas Schneider <asn@cryptomilk.org>\nDate: Tue, 11 Feb 2020 11:52:33 +0100\nSubject: [PATCH] CVE-2020-1730: Fix a possible segfault when zeroing AES-CTR\n key\n\nFixes T213\n\nSigned-off-by: Andreas Schneider <asn@cryptomilk.org>\nReviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>\n---\n src/libcrypto.c | 8 ++++++--\n 1 file changed, 6 insertions(+), 2 deletions(-)\n\ndiff --git a/src/libcrypto.c b/src/libcrypto.c\nindex b3792264..e9f519ec 100644\n--- a/src/libcrypto.c\n+++ b/src/libcrypto.c\n@@ -713,8 +713,12 @@ aes_ctr_encrypt(struct ssh_cipher_struct *cipher,\n }\n \n static void aes_ctr_cleanup(struct ssh_cipher_struct *cipher){\n- explicit_bzero(cipher->aes_key, sizeof(*cipher->aes_key));\n- SAFE_FREE(cipher->aes_key);\n+ if (cipher != NULL) {\n+ if (cipher->aes_key != NULL) {\n+ explicit_bzero(cipher->aes_key, sizeof(*cipher->aes_key));\n+ }\n+ SAFE_FREE(cipher->aes_key);\n+ }\n }\n \n #endif /* HAVE_OPENSSL_EVP_AES_CTR */\n-- \n2.26.0\n\n\n```\n\nGenerate a backported patch for the SUSE target version."
},
{
"role": "assistant",
"content": "From fa772dbe48f6c716f130e80562840d47dda5a1b7 Mon Sep 17 00:00:00 2001\nFrom: Andreas Schneider <asn@cryptomilk.org>\nDate: Tue, 11 Feb 2020 11:52:33 +0100\nSubject: [PATCH] CVE-2020-1730: Fix a possible segfault when zeroing AES-CTR\n key\n\nFixes T213\n\nSigned-off-by: Andreas Schneider <asn@cryptomilk.org>\nReviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>\n---\n src/libcrypto.c | 8 ++++++--\n 1 file changed, 6 insertions(+), 2 deletions(-)\n\ndiff --git a/src/libcrypto.c b/src/libcrypto.c\nindex b3792264..e9f519ec 100644\n--- a/src/libcrypto.c\n+++ b/src/libcrypto.c\n@@ -713,8 +713,12 @@ aes_ctr_encrypt(struct ssh_cipher_struct *cipher,\n }\n \n static void aes_ctr_cleanup(struct ssh_cipher_struct *cipher){\n- explicit_bzero(cipher->aes_key, sizeof(*cipher->aes_key));\n- SAFE_FREE(cipher->aes_key);\n+ if (cipher != NULL) {\n+ if (cipher->aes_key != NULL) {\n+ explicit_bzero(cipher->aes_key, sizeof(*cipher->aes_key));\n+ }\n+ SAFE_FREE(cipher->aes_key);\n+ }\n }\n \n #endif /* HAVE_OPENSSL_EVP_AES_CTR */\n-- \n2.26.0\n\n"
}
] |
{
"id": "libssh-12292-0001-CVE-2020-1730-Fix-a-possible-segfault-when-zeroing-A.patch",
"cves": [
"CVE-2020-1730"
],
"package": "libssh",
"incident_id": 12292,
"patch_name": "0001-CVE-2020-1730-Fix-a-possible-segfault-when-zeroing-A.patch",
"tier": "identical",
"language": "c",
"patch_lines_changed": 9,
"patch_files_count": 1,
"total_tokens_est": 656,
"has_source_context": true,
"upstream_enriched": false,
"suse_license": "LGPL-2.1-or-later",
"upstream_license": "NOASSERTION",
"cve_id": "CVE-2020-1730",
"upstream_commit": null,
"upstream_repo": 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-2020-1730\n\ntests: Add aes-gcm ciphers tests\n\n## Package\nlibssh\n\n## Files to modify\n- tests/client/torture_algorithms.c\n- tests/pkd/pkd_hello.c\n\n## Upstream Fix\n```diff\nFrom 42bd7cdf6c6e50786155c904821fc62d6d8e5acb Mon Sep 17 00:00:00 2001\nFrom: Jakub Jelen <jjelen@redhat.com>\nDate: Mon, 8 Oct 2018 13:31:12 +0200\nSubject: [PATCH] tests: Add aes-gcm ciphers tests\n\nSigned-off-by: Jakub Jelen <jjelen@redhat.com>\nReviewed-by: Andreas Schneider <asn@cryptomilk.org>\n---\n tests/client/torture_algorithms.c | 20 ++++++++++++++++++++\n tests/pkd/pkd_hello.c | 29 +++++++++++++++++++++++++++--\n 2 files changed, 47 insertions(+), 2 deletions(-)\n\ndiff --git a/tests/client/torture_algorithms.c b/tests/client/torture_algorithms.c\nindex c216c99b..9bb67410 100644\n--- a/tests/client/torture_algorithms.c\n+++ b/tests/client/torture_algorithms.c\n@@ -240,6 +240,20 @@ static void torture_algorithms_aes256_ctr_hmac_sha2_512(void **state) {\n test_algorithm(s->ssh.session, NULL/*kex*/, \"aes256-ctr\", \"hmac-sha2-512\");\n }\n \n+static void torture_algorithms_aes128_gcm(void **state)\n+{\n+ struct torture_state *s = *state;\n+\n+ test_algorithm(s->ssh.session, NULL/*kex*/, \"aes128-gcm@openssh.com\", NULL);\n+}\n+\n+static void torture_algorithms_aes256_gcm(void **state)\n+{\n+ struct torture_state *s = *state;\n+\n+ test_algorithm(s->ssh.session, NULL/*kex*/, \"aes256-gcm@openssh.com\", NULL);\n+}\n+\n static void torture_algorithms_3des_cbc_hmac_sha1(void **state) {\n struct torture_state *s = *state;\n \n@@ -464,6 +478,12 @@ int torture_run_tests(void) {\n cmocka_unit_test_setup_teardown(torture_algorithms_aes256_ctr_hmac_sha2_512,\n session_setup,\n session_teardown),\n+ cmocka_unit_test_setup_teardown(torture_algorithms_aes128_gcm,\n+ session_setup,\n+ session_teardown),\n+ cmocka_unit_test_setup_teardown(torture_algorithms_aes256_gcm,\n+ session_setup,\n+ session_teardown),\n cmocka_unit_test_setup_teardown(torture_algorithms_3des_cbc_hmac_sha1,\n session_setup,\n session_teardown),\ndiff --git a/tests/pkd/pkd_hello.c b/tests/pkd/pkd_hello.c\nindex e14316ec..0fa72d04 100644\n--- a/tests/pkd/pkd_hello.c\n+++ b/tests/pkd/pkd_hello.c\n@@ -383,6 +383,8 @@ static int torture_pkd_setup_ecdsa_521(void **state) {\n #endif\n \n #define CHACHA20 \"chacha20-poly1305@openssh.com\"\n+#define AES128_GCM \"aes128-gcm@openssh.com\"\n+#define AES256_GCM \"aes256-gcm@openssh.com\"\n \n #ifdef HAVE_DSA\n #define PKDTESTS_CIPHER_OPENSSHONLY(f, client, ciphercmd) \\\n@@ -390,9 +392,13 @@ static int torture_pkd_setup_ecdsa_521(void **state) {\n f(client, rsa_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_rsa, teardown) \\\n f(client, rsa_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_rsa, teardown) \\\n f(client, rsa_chacha20, ciphercmd(CHACHA20), setup_rsa, teardown) \\\n+ f(client, rsa_aes128_gcm, ciphercmd(AES128_GCM), setup_rsa, teardown) \\\n+ f(client, rsa_aes256_gcm, ciphercmd(AES256_GCM), setup_rsa, teardown) \\\n f(client, dsa_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_dsa, teardown) \\\n f(client, dsa_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_dsa, teardown) \\\n f(client, dsa_chacha20, ciphercmd(CHACHA20), setup_dsa, teardown) \\\n+ f(client, dsa_aes128_gcm, ciphercmd(AES128_GCM), setup_dsa, teardown) \\\n+ f(client, dsa_aes256_gcm, ciphercmd(AES256_GCM), setup_dsa, teardown) \\\n f(client, ed25519_3des_cbc, ciphercmd(\"3des-cbc\"), setup_ed25519, teardown) \\\n f(client, ed25519_aes128_cbc, ciphercmd(\"aes128-cbc\"), setup_ed25519, teardown) \\\n f(client, ed25519_aes128_ctr, ciphercmd(\"aes128-ctr\"), setup_ed25519, teardown) \\\n@@ -401,21 +407,31 @@ static int torture_pkd_setup_ecdsa_521(void **state) {\n f(client, ed25519_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_ed25519, teardown) \\\n f(client, ed25519_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_ed25519, teardown) \\\n f(client, ed25519_chacha20, ciphercmd(CHACHA20), setup_ed25519, teardown) \\\n+ f(client, ed25519_aes128_gcm, ciphercmd(AES128_GCM), setup_ed25519, teardown) \\\n+ f(client, ed25519_aes256_gcm, ciphercmd(AES256_GCM), setup_ed25519, teardown) \\\n f(client, ecdsa_256_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_ecdsa_256, teardown) \\\n f(client, ecdsa_256_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_ecdsa_256, teardown) \\\n f(client, ecdsa_256_chacha20, ciphercmd(CHACHA20), setup_ecdsa_256, teardown) \\\n+ f(client, ecdsa_256_aes128_gcm, ciphercmd(AES128_GCM), setup_ecdsa_256, teardown) \\\n+ f(client, ecdsa_256_aes256_gcm, ciphercmd(AES256_GCM), setup_ecdsa_256, teardown) \\\n f(client, ecdsa_384_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_ecdsa_384, teardown) \\\n f(client, ecdsa_384_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_ecdsa_384, teardown) \\\n f(client, ecdsa_384_chacha20, ciphercmd(CHACHA20), setup_ecdsa_384, teardown) \\\n+ f(client, ecdsa_384_aes128_gcm, ciphercmd(AES128_GCM), setup_ecdsa_384, teardown) \\\n+ f(client, ecdsa_384_aes256_gcm, ciphercmd(AES256_GCM), setup_ecdsa_384, teardown) \\\n f(client, ecdsa_521_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_ecdsa_521, teardown) \\\n f(client, ecdsa_521_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_ecdsa_521, teardown) \\\n- f(client, ecdsa_521_chacha20, ciphercmd(CHACHA20), setup_ecdsa_521, teardown)\n+ f(client, ecdsa_521_chacha20, ciphercmd(CHACHA20), setup_ecdsa_521, teardown) \\\n+ f(client, ecdsa_521_aes128_gcm, ciphercmd(AES128_GCM), setup_ecdsa_521, teardown) \\\n+ f(client, ecdsa_521_aes256_gcm, ciphercmd(AES256_GCM), setup_ecdsa_521, teardown)\n #else\n #define PKDTESTS_CIPHER_OPENSSHONLY(f, client, ciphercmd) \\\n /* Ciphers. */ \\\n f(client, rsa_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_rsa, teardown) \\\n f(client, rsa_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_rsa, teardown) \\\n f(client, rsa_chacha20, ciphercmd(CHACHA20), setup_rsa, teardown) \\\n+ f(client, rsa_aes128_gcm, ciphercmd(AES128_GCM), setup_rsa, teardown) \\\n+ f(client, rsa_aes256_gcm, ciphercmd(AES256_GCM), setup_rsa, teardown) \\\n f(client, ed25519_3des_cbc, ciphercmd(\"3des-cbc\"), setup_ed25519, teardown) \\\n f(client, ed25519_aes128_cbc, ciphercmd(\"aes128-cbc\"), setup_ed25519, teardown) \\\n f(client, ed25519_aes128_ctr, ciphercmd(\"aes128-ctr\"), setup_ed25519, teardown) \\\n@@ -424,17 +440,26 @@ static int torture_pkd_setup_ecdsa_521(void **state) {\n f(client, ed25519_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_ed25519, teardown) \\\n f(client, ed25519_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_ed25519, teardown) \\\n f(client, ed25519_chacha20, ciphercmd(CHACHA20), setup_ed25519, teardown) \\\n+ f(client, ed25519_aes128_gcm, ciphercmd(AES128_GCM), setup_ed25519, teardown) \\\n+ f(client, ed25519_aes256_gcm, ciphercmd(AES256_GCM), setup_ed25519, teardown) \\\n f(client, ecdsa_256_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_ecdsa_256, teardown) \\\n f(client, ecdsa_256_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_ecdsa_256, teardown) \\\n f(client, ecdsa_256_chacha20, ciphercmd(CHACHA20), setup_ecdsa_256, teardown) \\\n+ f(client, ecdsa_256_aes128_gcm, ciphercmd(AES128_GCM), setup_ecdsa_256, teardown) \\\n+ f(client, ecdsa_256_aes256_gcm, ciphercmd(AES256_GCM), setup_ecdsa_256, teardown) \\\n f(client, ecdsa_384_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_ecdsa_384, teardown) \\\n f(client, ecdsa_384_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_ecdsa_384, teardown) \\\n f(client, ecdsa_384_chacha20, ciphercmd(CHACHA20), setup_ecdsa_384, teardown) \\\n+ f(client, ecdsa_384_aes128_gcm, ciphercmd(AES128_GCM), setup_ecdsa_384, teardown) \\\n+ f(client, ecdsa_384_aes256_gcm, ciphercmd(AES256_GCM), setup_ecdsa_384, teardown) \\\n f(client, ecdsa_521_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_ecdsa_521, teardown) \\\n f(client, ecdsa_521_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_ecdsa_521, teardown) \\\n- f(client, ecdsa_521_chacha20, ciphercmd(CHACHA20), setup_ecdsa_521, teardown)\n+ f(client, ecdsa_521_chacha20, ciphercmd(CHACHA20), setup_ecdsa_521, teardown) \\\n+ f(client, ecdsa_521_aes128_gcm, ciphercmd(AES128_GCM), setup_ecdsa_521, teardown) \\\n+ f(client, ecdsa_521_aes256_gcm, ciphercmd(AES256_GCM), setup_ecdsa_521, teardown)\n #endif\n \n+\n #ifdef HAVE_DSA\n #define PKDTESTS_MAC(f, client, maccmd) \\\n /* MACs. */ \\\n-- \n2.21.0\n\n\n```\n\nGenerate a backported patch for the SUSE target version."
},
{
"role": "assistant",
"content": "From 42bd7cdf6c6e50786155c904821fc62d6d8e5acb Mon Sep 17 00:00:00 2001\nFrom: Jakub Jelen <jjelen@redhat.com>\nDate: Mon, 8 Oct 2018 13:31:12 +0200\nSubject: [PATCH] tests: Add aes-gcm ciphers tests\n\nSigned-off-by: Jakub Jelen <jjelen@redhat.com>\nReviewed-by: Andreas Schneider <asn@cryptomilk.org>\n---\n tests/client/torture_algorithms.c | 20 ++++++++++++++++++++\n tests/pkd/pkd_hello.c | 29 +++++++++++++++++++++++++++--\n 2 files changed, 47 insertions(+), 2 deletions(-)\n\ndiff --git a/tests/client/torture_algorithms.c b/tests/client/torture_algorithms.c\nindex c216c99b..9bb67410 100644\n--- a/tests/client/torture_algorithms.c\n+++ b/tests/client/torture_algorithms.c\n@@ -240,6 +240,20 @@ static void torture_algorithms_aes256_ctr_hmac_sha2_512(void **state) {\n test_algorithm(s->ssh.session, NULL/*kex*/, \"aes256-ctr\", \"hmac-sha2-512\");\n }\n \n+static void torture_algorithms_aes128_gcm(void **state)\n+{\n+ struct torture_state *s = *state;\n+\n+ test_algorithm(s->ssh.session, NULL/*kex*/, \"aes128-gcm@openssh.com\", NULL);\n+}\n+\n+static void torture_algorithms_aes256_gcm(void **state)\n+{\n+ struct torture_state *s = *state;\n+\n+ test_algorithm(s->ssh.session, NULL/*kex*/, \"aes256-gcm@openssh.com\", NULL);\n+}\n+\n static void torture_algorithms_3des_cbc_hmac_sha1(void **state) {\n struct torture_state *s = *state;\n \n@@ -464,6 +478,12 @@ int torture_run_tests(void) {\n cmocka_unit_test_setup_teardown(torture_algorithms_aes256_ctr_hmac_sha2_512,\n session_setup,\n session_teardown),\n+ cmocka_unit_test_setup_teardown(torture_algorithms_aes128_gcm,\n+ session_setup,\n+ session_teardown),\n+ cmocka_unit_test_setup_teardown(torture_algorithms_aes256_gcm,\n+ session_setup,\n+ session_teardown),\n cmocka_unit_test_setup_teardown(torture_algorithms_3des_cbc_hmac_sha1,\n session_setup,\n session_teardown),\ndiff --git a/tests/pkd/pkd_hello.c b/tests/pkd/pkd_hello.c\nindex e14316ec..0fa72d04 100644\n--- a/tests/pkd/pkd_hello.c\n+++ b/tests/pkd/pkd_hello.c\n@@ -383,6 +383,8 @@ static int torture_pkd_setup_ecdsa_521(void **state) {\n #endif\n \n #define CHACHA20 \"chacha20-poly1305@openssh.com\"\n+#define AES128_GCM \"aes128-gcm@openssh.com\"\n+#define AES256_GCM \"aes256-gcm@openssh.com\"\n \n #ifdef HAVE_DSA\n #define PKDTESTS_CIPHER_OPENSSHONLY(f, client, ciphercmd) \\\n@@ -390,9 +392,13 @@ static int torture_pkd_setup_ecdsa_521(void **state) {\n f(client, rsa_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_rsa, teardown) \\\n f(client, rsa_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_rsa, teardown) \\\n f(client, rsa_chacha20, ciphercmd(CHACHA20), setup_rsa, teardown) \\\n+ f(client, rsa_aes128_gcm, ciphercmd(AES128_GCM), setup_rsa, teardown) \\\n+ f(client, rsa_aes256_gcm, ciphercmd(AES256_GCM), setup_rsa, teardown) \\\n f(client, dsa_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_dsa, teardown) \\\n f(client, dsa_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_dsa, teardown) \\\n f(client, dsa_chacha20, ciphercmd(CHACHA20), setup_dsa, teardown) \\\n+ f(client, dsa_aes128_gcm, ciphercmd(AES128_GCM), setup_dsa, teardown) \\\n+ f(client, dsa_aes256_gcm, ciphercmd(AES256_GCM), setup_dsa, teardown) \\\n f(client, ed25519_3des_cbc, ciphercmd(\"3des-cbc\"), setup_ed25519, teardown) \\\n f(client, ed25519_aes128_cbc, ciphercmd(\"aes128-cbc\"), setup_ed25519, teardown) \\\n f(client, ed25519_aes128_ctr, ciphercmd(\"aes128-ctr\"), setup_ed25519, teardown) \\\n@@ -401,21 +407,31 @@ static int torture_pkd_setup_ecdsa_521(void **state) {\n f(client, ed25519_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_ed25519, teardown) \\\n f(client, ed25519_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_ed25519, teardown) \\\n f(client, ed25519_chacha20, ciphercmd(CHACHA20), setup_ed25519, teardown) \\\n+ f(client, ed25519_aes128_gcm, ciphercmd(AES128_GCM), setup_ed25519, teardown) \\\n+ f(client, ed25519_aes256_gcm, ciphercmd(AES256_GCM), setup_ed25519, teardown) \\\n f(client, ecdsa_256_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_ecdsa_256, teardown) \\\n f(client, ecdsa_256_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_ecdsa_256, teardown) \\\n f(client, ecdsa_256_chacha20, ciphercmd(CHACHA20), setup_ecdsa_256, teardown) \\\n+ f(client, ecdsa_256_aes128_gcm, ciphercmd(AES128_GCM), setup_ecdsa_256, teardown) \\\n+ f(client, ecdsa_256_aes256_gcm, ciphercmd(AES256_GCM), setup_ecdsa_256, teardown) \\\n f(client, ecdsa_384_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_ecdsa_384, teardown) \\\n f(client, ecdsa_384_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_ecdsa_384, teardown) \\\n f(client, ecdsa_384_chacha20, ciphercmd(CHACHA20), setup_ecdsa_384, teardown) \\\n+ f(client, ecdsa_384_aes128_gcm, ciphercmd(AES128_GCM), setup_ecdsa_384, teardown) \\\n+ f(client, ecdsa_384_aes256_gcm, ciphercmd(AES256_GCM), setup_ecdsa_384, teardown) \\\n f(client, ecdsa_521_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_ecdsa_521, teardown) \\\n f(client, ecdsa_521_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_ecdsa_521, teardown) \\\n- f(client, ecdsa_521_chacha20, ciphercmd(CHACHA20), setup_ecdsa_521, teardown)\n+ f(client, ecdsa_521_chacha20, ciphercmd(CHACHA20), setup_ecdsa_521, teardown) \\\n+ f(client, ecdsa_521_aes128_gcm, ciphercmd(AES128_GCM), setup_ecdsa_521, teardown) \\\n+ f(client, ecdsa_521_aes256_gcm, ciphercmd(AES256_GCM), setup_ecdsa_521, teardown)\n #else\n #define PKDTESTS_CIPHER_OPENSSHONLY(f, client, ciphercmd) \\\n /* Ciphers. */ \\\n f(client, rsa_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_rsa, teardown) \\\n f(client, rsa_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_rsa, teardown) \\\n f(client, rsa_chacha20, ciphercmd(CHACHA20), setup_rsa, teardown) \\\n+ f(client, rsa_aes128_gcm, ciphercmd(AES128_GCM), setup_rsa, teardown) \\\n+ f(client, rsa_aes256_gcm, ciphercmd(AES256_GCM), setup_rsa, teardown) \\\n f(client, ed25519_3des_cbc, ciphercmd(\"3des-cbc\"), setup_ed25519, teardown) \\\n f(client, ed25519_aes128_cbc, ciphercmd(\"aes128-cbc\"), setup_ed25519, teardown) \\\n f(client, ed25519_aes128_ctr, ciphercmd(\"aes128-ctr\"), setup_ed25519, teardown) \\\n@@ -424,17 +440,26 @@ static int torture_pkd_setup_ecdsa_521(void **state) {\n f(client, ed25519_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_ed25519, teardown) \\\n f(client, ed25519_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_ed25519, teardown) \\\n f(client, ed25519_chacha20, ciphercmd(CHACHA20), setup_ed25519, teardown) \\\n+ f(client, ed25519_aes128_gcm, ciphercmd(AES128_GCM), setup_ed25519, teardown) \\\n+ f(client, ed25519_aes256_gcm, ciphercmd(AES256_GCM), setup_ed25519, teardown) \\\n f(client, ecdsa_256_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_ecdsa_256, teardown) \\\n f(client, ecdsa_256_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_ecdsa_256, teardown) \\\n f(client, ecdsa_256_chacha20, ciphercmd(CHACHA20), setup_ecdsa_256, teardown) \\\n+ f(client, ecdsa_256_aes128_gcm, ciphercmd(AES128_GCM), setup_ecdsa_256, teardown) \\\n+ f(client, ecdsa_256_aes256_gcm, ciphercmd(AES256_GCM), setup_ecdsa_256, teardown) \\\n f(client, ecdsa_384_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_ecdsa_384, teardown) \\\n f(client, ecdsa_384_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_ecdsa_384, teardown) \\\n f(client, ecdsa_384_chacha20, ciphercmd(CHACHA20), setup_ecdsa_384, teardown) \\\n+ f(client, ecdsa_384_aes128_gcm, ciphercmd(AES128_GCM), setup_ecdsa_384, teardown) \\\n+ f(client, ecdsa_384_aes256_gcm, ciphercmd(AES256_GCM), setup_ecdsa_384, teardown) \\\n f(client, ecdsa_521_aes192_cbc, ciphercmd(\"aes192-cbc\"), setup_ecdsa_521, teardown) \\\n f(client, ecdsa_521_aes192_ctr, ciphercmd(\"aes192-ctr\"), setup_ecdsa_521, teardown) \\\n- f(client, ecdsa_521_chacha20, ciphercmd(CHACHA20), setup_ecdsa_521, teardown)\n+ f(client, ecdsa_521_chacha20, ciphercmd(CHACHA20), setup_ecdsa_521, teardown) \\\n+ f(client, ecdsa_521_aes128_gcm, ciphercmd(AES128_GCM), setup_ecdsa_521, teardown) \\\n+ f(client, ecdsa_521_aes256_gcm, ciphercmd(AES256_GCM), setup_ecdsa_521, teardown)\n #endif\n \n+\n #ifdef HAVE_DSA\n #define PKDTESTS_MAC(f, client, maccmd) \\\n /* MACs. */ \\\n-- \n2.21.0\n\n"
}
] |
{
"id": "libssh-12292-0001-tests-Add-aes-gcm-ciphers-tests.patch",
"cves": [
"CVE-2020-1730"
],
"package": "libssh",
"incident_id": 12292,
"patch_name": "0001-tests-Add-aes-gcm-ciphers-tests.patch",
"tier": "identical",
"language": "c",
"patch_lines_changed": 50,
"patch_files_count": 2,
"total_tokens_est": 4735,
"has_source_context": false,
"upstream_enriched": false,
"suse_license": "LGPL-2.1-or-later",
"upstream_license": "NOASSERTION",
"cve_id": "CVE-2020-1730",
"upstream_commit": null,
"upstream_repo": 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-2020-1730\n\nlibgcrypt: Implement OpenSSH-compatible AES-GCM ciphers using\n\n## Package\nlibssh\n\n## Files to modify\n- include/libssh/crypto.h\n- src/kex.c\n- src/libgcrypt.c\n\n## Target Source Code\n\n### include/libssh/crypto.h\n\n#### region() [lines 93-171]\n```c\n#endif\n ssh_string ecdh_client_pubkey;\n ssh_string ecdh_server_pubkey;\n#endif\n#ifdef HAVE_CURVE25519\n ssh_curve25519_privkey curve25519_privkey;\n ssh_curve25519_pubkey curve25519_client_pubkey;\n ssh_curve25519_pubkey curve25519_server_pubkey;\n#endif\n ssh_string dh_server_signature; /* information used by dh_handshake. */\n size_t digest_len; /* len of all the fields below */\n unsigned char *session_id;\n unsigned char *secret_hash; /* Secret hash is same as session id until re-kex */\n unsigned char *encryptIV;\n unsigned char *decryptIV;\n unsigned char *decryptkey;\n unsigned char *encryptkey;\n unsigned char *encryptMAC;\n unsigned char *decryptMAC;\n unsigned char hmacbuf[DIGEST_MAX_LEN];\n struct ssh_cipher_struct *in_cipher, *out_cipher; /* the cipher structures/objects */\n enum ssh_hmac_e in_hmac, out_hmac; /* the MAC algorithms used */\n\n ssh_key server_pubkey;\n int do_compress_out; /* idem */\n int do_compress_in; /* don't set them, set the option instead */\n int delayed_compress_in; /* Use of zlib@openssh.org */\n int delayed_compress_out;\n void *compress_out_ctx; /* don't touch it */\n void *compress_in_ctx; /* really, don't */\n /* kex sent by server, client, and mutually elected methods */\n struct ssh_kex_struct server_kex;\n struct ssh_kex_struct client_kex;\n char *kex_methods[SSH_KEX_METHODS];\n enum ssh_key_exchange_e kex_type;\n enum ssh_mac_e mac_type; /* Mac operations to use for key gen */\n};\n\nstruct ssh_cipher_struct {\n const char *name; /* ssh name of the algorithm */\n unsigned int blocksize; /* blocksize of the algo */\n enum ssh_cipher_e ciphertype;\n uint32_t lenfield_blocksize; /* blocksize of the packet length field */\n size_t keylen; /* length of the key structure */\n#ifdef HAVE_LIBGCRYPT\n gcry_cipher_hd_t *key;\n#elif defined HAVE_LIBCRYPTO\n struct ssh_3des_key_schedule *des3_key;\n struct ssh_aes_key_schedule *aes_key;\n const EVP_CIPHER *cipher;\n EVP_CIPHER_CTX *ctx;\n#elif defined HAVE_LIBMBEDCRYPTO\n mbedtls_cipher_context_t encrypt_ctx;\n mbedtls_cipher_context_t decrypt_ctx;\n mbedtls_cipher_type_t type;\n#endif\n struct chacha20_poly1305_keysched *chacha20_schedule;\n unsigned int keysize; /* bytes of key used. != keylen */\n size_t tag_size; /* overhead required for tag */\n /* sets the new key for immediate use */\n int (*set_encrypt_key)(struct ssh_cipher_struct *cipher, void *key, void *IV);\n int (*set_decrypt_key)(struct ssh_cipher_struct *cipher, void *key, void *IV);\n void (*encrypt)(struct ssh_cipher_struct *cipher, void *in, void *out,\n unsigned long len);\n void (*decrypt)(struct ssh_cipher_struct *cipher, void *in, void *out,\n unsigned long len);\n void (*aead_encrypt)(struct ssh_cipher_struct *cipher, void *in, void *out,\n size_t len, uint8_t *mac, uint64_t seq);\n int (*aead_decrypt_length)(struct ssh_cipher_struct *cipher, void *in,\n uint8_t *out, size_t len, uint64_t seq);\n int (*aead_decrypt)(struct ssh_cipher_struct *cipher, void *complete_packet, uint8_t *out,\n size_t encrypted_size, uint64_t seq);\n void (*cleanup)(struct ssh_cipher_struct *cipher);\n};\n\nconst struct ssh_cipher_struct *ssh_get_chacha20poly1305_cipher(void);\n\n#endif /* _CRYPTO_H_ */\n\n```\n\n### src/kex.c\n\n#### region() [lines 1-98]\n```c\n/*\n * kex.c - key exchange\n *\n * This file is part of the SSH Library\n *\n * Copyright (c) 2003-2008 by Aris Adamantiadis\n *\n * The SSH Library is free software; you can redistribute it and/or modify\n * it 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 (at your\n * option) any later version.\n *\n * The SSH Library is distributed in the hope that it will be useful, but\n * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\n * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public\n * License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public License\n * along with the SSH Library; see the file COPYING. If not, write to\n * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,\n * MA 02111-1307, USA.\n */\n\n#include \"config.h\"\n\n#include <string.h>\n#include <stdlib.h>\n#include <stdio.h>\n#include <stdbool.h>\n\n#include \"libssh/priv.h\"\n#include \"libssh/buffer.h\"\n#include \"libssh/dh.h\"\n#include \"libssh/kex.h\"\n#include \"libssh/session.h\"\n#include \"libssh/ssh2.h\"\n#include \"libssh/string.h\"\n#include \"libssh/curve25519.h\"\n#include \"libssh/knownhosts.h\"\n#include \"libssh/misc.h\"\n#include \"libssh/pki.h\"\n\n#ifdef HAVE_LIBGCRYPT\n# define BLOWFISH \"blowfish-cbc,\"\n# define AES \"aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,\"\n# define DES \"3des-cbc\"\n# define DES_SUPPORTED \"3des-cbc\"\n\n#elif defined HAVE_LIBMBEDCRYPTO\n# define BLOWFISH \"blowfish-cbc,\"\n# define AES \"aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,\"\n# define DES \"3des-cbc\"\n# define DES_SUPPORTED \"3des-cbc\"\n\n#elif defined(HAVE_LIBCRYPTO)\n\n# ifdef HAVE_OPENSSL_BLOWFISH_H\n# define BLOWFISH \"blowfish-cbc,\"\n# else /* HAVE_OPENSSL_BLOWFISH_H */\n# define BLOWFISH \"\"\n# endif /* HAVE_OPENSSL_BLOWFISH_H */\n\n# ifdef HAVE_OPENSSL_AES_H\n# ifdef BROKEN_AES_CTR\n# define AES \"aes256-cbc,aes192-cbc,aes128-cbc,\"\n# else /* BROKEN_AES_CTR */\n# define AES \"aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,\"\n# endif /* BROKEN_AES_CTR */\n# else /* HAVE_OPENSSL_AES_H */\n# define AES \"\"\n# endif /* HAVE_OPENSSL_AES_H */\n\n# define DES \"3des-cbc\"\n# define DES_SUPPORTED \"3des-cbc\"\n#endif /* HAVE_LIBCRYPTO */\n\n#ifdef WITH_ZLIB\n#define ZLIB \"none,zlib,zlib@openssh.com\"\n#else\n#define ZLIB \"none\"\n#endif\n\n#ifdef HAVE_CURVE25519\n#define CURVE25519 \"curve25519-sha256,curve25519-sha256@libssh.org,\"\n#else\n#define CURVE25519 \"\"\n#endif\n\n#ifdef HAVE_ECDH\n#define ECDH \"ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,\"\n#define PUBLIC_KEY_ALGORITHMS \"ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-rsa,rsa-sha2-512,rsa-sha2-256,ssh-dss\"\n#else\n#ifdef HAVE_DSA\n#define PUBLIC_KEY_ALGORITHMS \"ssh-ed25519,ssh-rsa,rsa-sha2-512,rsa-sha2-256,ssh-dss\"\n#else\n#define PUBLIC_KEY_ALGORITHMS \"ssh-ed25519,ssh-rsa,rsa-sha2-512,rsa-sha2-256\"\n#endif\n#define ECDH \"\"\n```\n\n\n## Upstream Fix\n```diff\nFrom 5790036a2305d5610ac55adb5382ea55d043998f Mon Sep 17 00:00:00 2001\nFrom: Jakub Jelen <jjelen@redhat.com>\nDate: Mon, 1 Oct 2018 14:32:05 +0200\nSubject: [PATCH] libgcrypt: Implement OpenSSH-compatible AES-GCM ciphers using\n libgcrypt\n\nSigned-off-by: Jakub Jelen <jjelen@redhat.com>\nReviewed-by: Andreas Schneider <asn@cryptomilk.org>\n---\n include/libssh/crypto.h | 1 +\n src/kex.c | 4 +-\n src/libgcrypt.c | 201 ++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 205 insertions(+), 1 deletion(-)\n\ndiff --git a/include/libssh/crypto.h b/include/libssh/crypto.h\nindex fc375a4f..8777f0c9 100644\n--- a/include/libssh/crypto.h\n+++ b/include/libssh/crypto.h\n@@ -142,6 +142,7 @@ struct ssh_cipher_struct {\n size_t keylen; /* length of the key structure */\n #ifdef HAVE_LIBGCRYPT\n gcry_cipher_hd_t *key;\n+ unsigned char last_iv[AES_GCM_IVLEN];\n #elif defined HAVE_LIBCRYPTO\n struct ssh_3des_key_schedule *des3_key;\n struct ssh_aes_key_schedule *aes_key;\ndiff --git a/src/kex.c b/src/kex.c\nindex e0fd5680..382d88fb 100644\n--- a/src/kex.c\n+++ b/src/kex.c\n@@ -40,7 +40,9 @@\n \n #ifdef HAVE_LIBGCRYPT\n # define BLOWFISH \"blowfish-cbc,\"\n-# define AES \"aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,\"\n+# define AES \"aes256-gcm@openssh.com,aes128-gcm@openssh.com,\" \\\n+ \"aes256-ctr,aes192-ctr,aes128-ctr,\" \\\n+ \"aes256-cbc,aes192-cbc,aes128-cbc,\"\n # define DES \"3des-cbc\"\n # define DES_SUPPORTED \"3des-cbc\"\n \ndiff --git a/src/libgcrypt.c b/src/libgcrypt.c\nindex f004ffe2..7160bb1c 100644\n--- a/src/libgcrypt.c\n+++ b/src/libgcrypt.c\n@@ -353,6 +353,8 @@ static int aes_set_key(struct ssh_cipher_struct *cipher, void *key, void *IV) {\n }\n if(strstr(cipher->name,\"-ctr\"))\n mode=GCRY_CIPHER_MODE_CTR;\n+ if (strstr(cipher->name, \"-gcm\"))\n+ mode = GCRY_CIPHER_MODE_GCM;\n switch (cipher->keysize) {\n case 128:\n if (gcry_cipher_open(&cipher->key[0], GCRY_CIPHER_AES128,\n@@ -386,6 +388,11 @@ static int aes_set_key(struct ssh_cipher_struct *cipher, void *key, void *IV) {\n SAFE_FREE(cipher->key);\n return -1;\n }\n+ } else if (mode == GCRY_CIPHER_MODE_GCM) {\n+ /* Store the IV so we can handle the packet counter increments later\n+ * The IV is passed to the cipher context later.\n+ */\n+ memcpy(cipher->last_iv, IV, AES_GCM_IVLEN);\n } else {\n if(gcry_cipher_setctr(cipher->key[0],IV,16)){\n SAFE_FREE(cipher->key);\n@@ -407,6 +414,172 @@ static void aes_decrypt(struct ssh_cipher_struct *cipher, void *in, void *out,\n gcry_cipher_decrypt(cipher->key[0], out, len, in, len);\n }\n \n+static int\n+aes_aead_get_length(struct ssh_cipher_struct *cipher,\n+ void *in,\n+ uint8_t *out,\n+ size_t len,\n+ uint64_t seq)\n+{\n+ (void)seq;\n+\n+ /* The length is not encrypted: Copy it to the result buffer */\n+ memcpy(out, in, len);\n+\n+ return SSH_OK;\n+}\n+\n+/* Increment 64b integer in network byte order */\n+static void\n+uint64_inc(unsigned char *counter)\n+{\n+ int i;\n+\n+ for (i = 7; i >= 0; i--) {\n+ counter[i]++;\n+ if (counter[i])\n+ return;\n+ }\n+}\n+\n+static void\n+aes_gcm_encrypt(struct ssh_cipher_struct *cipher,\n+ void *in,\n+ void *out,\n+ size_t len,\n+ uint8_t *tag,\n+ uint64_t seq)\n+{\n+ gpg_error_t err;\n+ size_t aadlen, authlen;\n+\n+ (void)seq;\n+\n+ aadlen = cipher->lenfield_blocksize;\n+ authlen = cipher->tag_size;\n+\n+ /* increment IV */\n+ err = gcry_cipher_setiv(cipher->key[0],\n+ cipher->last_iv,\n+ AES_GCM_IVLEN);\n+ /* This actualy does not increment the packet counter for the\n+ * current encryption operation, but for the next one. The first\n+ * operation needs to be completed with the derived IV.\n+ *\n+ * The IV buffer has the following structure:\n+ * [ 4B static IV ][ 8B packet counter ][ 4B block counter ]\n+ */\n+ uint64_inc(cipher->last_iv + 4);\n+ if (err) {\n+ SSH_LOG(SSH_LOG_WARNING, \"gcry_cipher_setiv failed: %s\",\n+ gpg_strerror(err));\n+ return;\n+ }\n+\n+ /* Pass the authenticated data (packet_length) */\n+ err = gcry_cipher_authenticate(cipher->key[0], in, aadlen);\n+ if (err) {\n+ SSH_LOG(SSH_LOG_WARNING, \"gcry_cipher_authenticate failed: %s\",\n+ gpg_strerror(err));\n+ return;\n+ }\n+ memcpy(out, in, aadlen);\n+\n+ /* Encrypt the rest of the data */\n+ err = gcry_cipher_encrypt(cipher->key[0],\n+ (unsigned char *)out + aadlen,\n+ len - aadlen,\n+ (unsigned char *)in + aadlen,\n+ len - aadlen);\n+ if (err) {\n+ SSH_LOG(SSH_LOG_WARNING, \"gcry_cipher_encrypt failed: %s\",\n+ gpg_strerror(err));\n+ return;\n+ }\n+\n+ /* Calculate the tag */\n+ err = gcry_cipher_gettag(cipher->key[0],\n+ (void *)tag,\n+ authlen);\n+ if (err) {\n+ SSH_LOG(SSH_LOG_WARNING, \"gcry_cipher_gettag failed: %s\",\n+ gpg_strerror(err));\n+ return;\n+ }\n+}\n+\n+static int\n+aes_gcm_decrypt(struct ssh_cipher_struct *cipher,\n+ void *complete_packet,\n+ uint8_t *out,\n+ size_t encrypted_size,\n+ uint64_t seq)\n+{\n+ gpg_error_t err;\n+ size_t aadlen, authlen;\n+\n+ (void)seq;\n+\n+ aadlen = cipher->lenfield_blocksize;\n+ authlen = cipher->tag_size;\n+\n+ /* increment IV */\n+ err = gcry_cipher_setiv(cipher->key[0],\n+ cipher->last_iv,\n+ AES_GCM_IVLEN);\n+ /* This actualy does not increment the packet counter for the\n+ * current encryption operation, but for the next one. The first\n+ * operation needs to be completed with the derived IV.\n+ *\n+ * The IV buffer has the following structure:\n+ * [ 4B static IV ][ 8B packet counter ][ 4B block counter ]\n+ */\n+ uint64_inc(cipher->last_iv + 4);\n+ if (err) {\n+ SSH_LOG(SSH_LOG_WARNING, \"gcry_cipher_setiv failed: %s\",\n+ gpg_strerror(err));\n+ return SSH_ERROR;\n+ }\n+\n+ /* Pass the authenticated data (packet_length) */\n+ err = gcry_cipher_authenticate(cipher->key[0],\n+ complete_packet,\n+ aadlen);\n+ if (err) {\n+ SSH_LOG(SSH_LOG_WARNING, \"gcry_cipher_authenticate failed: %s\",\n+ gpg_strerror(err));\n+ return SSH_ERROR;\n+ }\n+ /* Do not copy the length to the target buffer, because it is already processed */\n+ //memcpy(out, complete_packet, aadlen);\n+\n+ /* Encrypt the rest of the data */\n+ err = gcry_cipher_decrypt(cipher->key[0],\n+ out,\n+ encrypted_size,\n+ (unsigned char *)complete_packet + aadlen,\n+ encrypted_size);\n+ if (err) {\n+ SSH_LOG(SSH_LOG_WARNING, \"gcry_cipher_decrypt failed: %s\",\n+ gpg_strerror(err));\n+ return SSH_ERROR;\n+ }\n+\n+ /* Check the tag */\n+ err = gcry_cipher_checktag(cipher->key[0],\n+ (unsigned char *)complete_packet + aadlen + encrypted_size,\n+ authlen);\n+ if (gpg_err_code(err) == GPG_ERR_CHECKSUM) {\n+ SSH_LOG(SSH_LOG_WARNING, \"The authentication tag does not match\");\n+ return SSH_ERROR;\n+ } else if (err != GPG_ERR_NO_ERROR) {\n+ SSH_LOG(SSH_LOG_WARNING, \"General error while decryption: %s\",\n+ gpg_strerror(err));\n+ return SSH_ERROR;\n+ }\n+ return SSH_OK;\n+}\n+\n static int des3_set_key(struct ssh_cipher_struct *cipher, void *key, void *IV) {\n if (cipher->key == NULL) {\n if (alloc_key(cipher) < 0) {\n@@ -519,6 +692,34 @@ static struct ssh_cipher_struct ssh_ciphertab[] = {\n .encrypt = aes_encrypt,\n .decrypt = aes_decrypt\n },\n+ {\n+ .name = \"aes128-gcm@openssh.com\",\n+ .blocksize = 16,\n+ .lenfield_blocksize = 4, /* not encrypted, but authenticated */\n+ .keylen = sizeof(gcry_cipher_hd_t),\n+ .key = NULL,\n+ .keysize = 128,\n+ .tag_size = AES_GCM_TAGLEN,\n+ .set_encrypt_key = aes_set_key,\n+ .set_decrypt_key = aes_set_key,\n+ .aead_encrypt = aes_gcm_encrypt,\n+ .aead_decrypt_length = aes_aead_get_length,\n+ .aead_decrypt = aes_gcm_decrypt,\n+ },\n+ {\n+ .name = \"aes256-gcm@openssh.com\",\n+ .blocksize = 16,\n+ .lenfield_blocksize = 4, /* not encrypted, but authenticated */\n+ .keylen = sizeof(gcry_cipher_hd_t),\n+ .key = NULL,\n+ .keysize = 256,\n+ .tag_size = AES_GCM_TAGLEN,\n+ .set_encrypt_key = aes_set_key,\n+ .set_decrypt_key = aes_set_key,\n+ .aead_encrypt = aes_gcm_encrypt,\n+ .aead_decrypt_length = aes_aead_get_length,\n+ .aead_decrypt = aes_gcm_decrypt,\n+ },\n {\n .name = \"3des-cbc\",\n .blocksize = 8,\n-- \n2.21.0\n\n\n```\n\nGenerate a backported patch for the SUSE target version."
},
{
"role": "assistant",
"content": "From 5790036a2305d5610ac55adb5382ea55d043998f Mon Sep 17 00:00:00 2001\nFrom: Jakub Jelen <jjelen@redhat.com>\nDate: Mon, 1 Oct 2018 14:32:05 +0200\nSubject: [PATCH] libgcrypt: Implement OpenSSH-compatible AES-GCM ciphers using\n libgcrypt\n\nSigned-off-by: Jakub Jelen <jjelen@redhat.com>\nReviewed-by: Andreas Schneider <asn@cryptomilk.org>\n---\n include/libssh/crypto.h | 1 +\n src/kex.c | 4 +-\n src/libgcrypt.c | 201 ++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 205 insertions(+), 1 deletion(-)\n\ndiff --git a/include/libssh/crypto.h b/include/libssh/crypto.h\nindex fc375a4f..8777f0c9 100644\n--- a/include/libssh/crypto.h\n+++ b/include/libssh/crypto.h\n@@ -142,6 +142,7 @@ struct ssh_cipher_struct {\n size_t keylen; /* length of the key structure */\n #ifdef HAVE_LIBGCRYPT\n gcry_cipher_hd_t *key;\n+ unsigned char last_iv[AES_GCM_IVLEN];\n #elif defined HAVE_LIBCRYPTO\n struct ssh_3des_key_schedule *des3_key;\n struct ssh_aes_key_schedule *aes_key;\ndiff --git a/src/kex.c b/src/kex.c\nindex e0fd5680..382d88fb 100644\n--- a/src/kex.c\n+++ b/src/kex.c\n@@ -40,7 +40,9 @@\n \n #ifdef HAVE_LIBGCRYPT\n # define BLOWFISH \"blowfish-cbc,\"\n-# define AES \"aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,\"\n+# define AES \"aes256-gcm@openssh.com,aes128-gcm@openssh.com,\" \\\n+ \"aes256-ctr,aes192-ctr,aes128-ctr,\" \\\n+ \"aes256-cbc,aes192-cbc,aes128-cbc,\"\n # define DES \"3des-cbc\"\n # define DES_SUPPORTED \"3des-cbc\"\n \ndiff --git a/src/libgcrypt.c b/src/libgcrypt.c\nindex f004ffe2..7160bb1c 100644\n--- a/src/libgcrypt.c\n+++ b/src/libgcrypt.c\n@@ -353,6 +353,8 @@ static int aes_set_key(struct ssh_cipher_struct *cipher, void *key, void *IV) {\n }\n if(strstr(cipher->name,\"-ctr\"))\n mode=GCRY_CIPHER_MODE_CTR;\n+ if (strstr(cipher->name, \"-gcm\"))\n+ mode = GCRY_CIPHER_MODE_GCM;\n switch (cipher->keysize) {\n case 128:\n if (gcry_cipher_open(&cipher->key[0], GCRY_CIPHER_AES128,\n@@ -386,6 +388,11 @@ static int aes_set_key(struct ssh_cipher_struct *cipher, void *key, void *IV) {\n SAFE_FREE(cipher->key);\n return -1;\n }\n+ } else if (mode == GCRY_CIPHER_MODE_GCM) {\n+ /* Store the IV so we can handle the packet counter increments later\n+ * The IV is passed to the cipher context later.\n+ */\n+ memcpy(cipher->last_iv, IV, AES_GCM_IVLEN);\n } else {\n if(gcry_cipher_setctr(cipher->key[0],IV,16)){\n SAFE_FREE(cipher->key);\n@@ -407,6 +414,172 @@ static void aes_decrypt(struct ssh_cipher_struct *cipher, void *in, void *out,\n gcry_cipher_decrypt(cipher->key[0], out, len, in, len);\n }\n \n+static int\n+aes_aead_get_length(struct ssh_cipher_struct *cipher,\n+ void *in,\n+ uint8_t *out,\n+ size_t len,\n+ uint64_t seq)\n+{\n+ (void)seq;\n+\n+ /* The length is not encrypted: Copy it to the result buffer */\n+ memcpy(out, in, len);\n+\n+ return SSH_OK;\n+}\n+\n+/* Increment 64b integer in network byte order */\n+static void\n+uint64_inc(unsigned char *counter)\n+{\n+ int i;\n+\n+ for (i = 7; i >= 0; i--) {\n+ counter[i]++;\n+ if (counter[i])\n+ return;\n+ }\n+}\n+\n+static void\n+aes_gcm_encrypt(struct ssh_cipher_struct *cipher,\n+ void *in,\n+ void *out,\n+ size_t len,\n+ uint8_t *tag,\n+ uint64_t seq)\n+{\n+ gpg_error_t err;\n+ size_t aadlen, authlen;\n+\n+ (void)seq;\n+\n+ aadlen = cipher->lenfield_blocksize;\n+ authlen = cipher->tag_size;\n+\n+ /* increment IV */\n+ err = gcry_cipher_setiv(cipher->key[0],\n+ cipher->last_iv,\n+ AES_GCM_IVLEN);\n+ /* This actualy does not increment the packet counter for the\n+ * current encryption operation, but for the next one. The first\n+ * operation needs to be completed with the derived IV.\n+ *\n+ * The IV buffer has the following structure:\n+ * [ 4B static IV ][ 8B packet counter ][ 4B block counter ]\n+ */\n+ uint64_inc(cipher->last_iv + 4);\n+ if (err) {\n+ SSH_LOG(SSH_LOG_WARNING, \"gcry_cipher_setiv failed: %s\",\n+ gpg_strerror(err));\n+ return;\n+ }\n+\n+ /* Pass the authenticated data (packet_length) */\n+ err = gcry_cipher_authenticate(cipher->key[0], in, aadlen);\n+ if (err) {\n+ SSH_LOG(SSH_LOG_WARNING, \"gcry_cipher_authenticate failed: %s\",\n+ gpg_strerror(err));\n+ return;\n+ }\n+ memcpy(out, in, aadlen);\n+\n+ /* Encrypt the rest of the data */\n+ err = gcry_cipher_encrypt(cipher->key[0],\n+ (unsigned char *)out + aadlen,\n+ len - aadlen,\n+ (unsigned char *)in + aadlen,\n+ len - aadlen);\n+ if (err) {\n+ SSH_LOG(SSH_LOG_WARNING, \"gcry_cipher_encrypt failed: %s\",\n+ gpg_strerror(err));\n+ return;\n+ }\n+\n+ /* Calculate the tag */\n+ err = gcry_cipher_gettag(cipher->key[0],\n+ (void *)tag,\n+ authlen);\n+ if (err) {\n+ SSH_LOG(SSH_LOG_WARNING, \"gcry_cipher_gettag failed: %s\",\n+ gpg_strerror(err));\n+ return;\n+ }\n+}\n+\n+static int\n+aes_gcm_decrypt(struct ssh_cipher_struct *cipher,\n+ void *complete_packet,\n+ uint8_t *out,\n+ size_t encrypted_size,\n+ uint64_t seq)\n+{\n+ gpg_error_t err;\n+ size_t aadlen, authlen;\n+\n+ (void)seq;\n+\n+ aadlen = cipher->lenfield_blocksize;\n+ authlen = cipher->tag_size;\n+\n+ /* increment IV */\n+ err = gcry_cipher_setiv(cipher->key[0],\n+ cipher->last_iv,\n+ AES_GCM_IVLEN);\n+ /* This actualy does not increment the packet counter for the\n+ * current encryption operation, but for the next one. The first\n+ * operation needs to be completed with the derived IV.\n+ *\n+ * The IV buffer has the following structure:\n+ * [ 4B static IV ][ 8B packet counter ][ 4B block counter ]\n+ */\n+ uint64_inc(cipher->last_iv + 4);\n+ if (err) {\n+ SSH_LOG(SSH_LOG_WARNING, \"gcry_cipher_setiv failed: %s\",\n+ gpg_strerror(err));\n+ return SSH_ERROR;\n+ }\n+\n+ /* Pass the authenticated data (packet_length) */\n+ err = gcry_cipher_authenticate(cipher->key[0],\n+ complete_packet,\n+ aadlen);\n+ if (err) {\n+ SSH_LOG(SSH_LOG_WARNING, \"gcry_cipher_authenticate failed: %s\",\n+ gpg_strerror(err));\n+ return SSH_ERROR;\n+ }\n+ /* Do not copy the length to the target buffer, because it is already processed */\n+ //memcpy(out, complete_packet, aadlen);\n+\n+ /* Encrypt the rest of the data */\n+ err = gcry_cipher_decrypt(cipher->key[0],\n+ out,\n+ encrypted_size,\n+ (unsigned char *)complete_packet + aadlen,\n+ encrypted_size);\n+ if (err) {\n+ SSH_LOG(SSH_LOG_WARNING, \"gcry_cipher_decrypt failed: %s\",\n+ gpg_strerror(err));\n+ return SSH_ERROR;\n+ }\n+\n+ /* Check the tag */\n+ err = gcry_cipher_checktag(cipher->key[0],\n+ (unsigned char *)complete_packet + aadlen + encrypted_size,\n+ authlen);\n+ if (gpg_err_code(err) == GPG_ERR_CHECKSUM) {\n+ SSH_LOG(SSH_LOG_WARNING, \"The authentication tag does not match\");\n+ return SSH_ERROR;\n+ } else if (err != GPG_ERR_NO_ERROR) {\n+ SSH_LOG(SSH_LOG_WARNING, \"General error while decryption: %s\",\n+ gpg_strerror(err));\n+ return SSH_ERROR;\n+ }\n+ return SSH_OK;\n+}\n+\n static int des3_set_key(struct ssh_cipher_struct *cipher, void *key, void *IV) {\n if (cipher->key == NULL) {\n if (alloc_key(cipher) < 0) {\n@@ -519,6 +692,34 @@ static struct ssh_cipher_struct ssh_ciphertab[] = {\n .encrypt = aes_encrypt,\n .decrypt = aes_decrypt\n },\n+ {\n+ .name = \"aes128-gcm@openssh.com\",\n+ .blocksize = 16,\n+ .lenfield_blocksize = 4, /* not encrypted, but authenticated */\n+ .keylen = sizeof(gcry_cipher_hd_t),\n+ .key = NULL,\n+ .keysize = 128,\n+ .tag_size = AES_GCM_TAGLEN,\n+ .set_encrypt_key = aes_set_key,\n+ .set_decrypt_key = aes_set_key,\n+ .aead_encrypt = aes_gcm_encrypt,\n+ .aead_decrypt_length = aes_aead_get_length,\n+ .aead_decrypt = aes_gcm_decrypt,\n+ },\n+ {\n+ .name = \"aes256-gcm@openssh.com\",\n+ .blocksize = 16,\n+ .lenfield_blocksize = 4, /* not encrypted, but authenticated */\n+ .keylen = sizeof(gcry_cipher_hd_t),\n+ .key = NULL,\n+ .keysize = 256,\n+ .tag_size = AES_GCM_TAGLEN,\n+ .set_encrypt_key = aes_set_key,\n+ .set_decrypt_key = aes_set_key,\n+ .aead_encrypt = aes_gcm_encrypt,\n+ .aead_decrypt_length = aes_aead_get_length,\n+ .aead_decrypt = aes_gcm_decrypt,\n+ },\n {\n .name = \"3des-cbc\",\n .blocksize = 8,\n-- \n2.21.0\n\n"
}
] |
{
"id": "libssh-12292-0001-libgcrypt-Implement-OpenSSH-compatible-AES-GCM-ciphe.patch",
"cves": [
"CVE-2020-1730"
],
"package": "libssh",
"incident_id": 12292,
"patch_name": "0001-libgcrypt-Implement-OpenSSH-compatible-AES-GCM-ciphe.patch",
"tier": "identical",
"language": "c",
"patch_lines_changed": 207,
"patch_files_count": 3,
"total_tokens_est": 4773,
"has_source_context": true,
"upstream_enriched": false,
"suse_license": "LGPL-2.1-or-later",
"upstream_license": "NOASSERTION",
"cve_id": "CVE-2020-1730",
"upstream_commit": null,
"upstream_repo": 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-2020-1730\n\n===================================================================\n\n## Package\nlibssh\n\n## Files to modify\n- tests/unittests/torture_misc.c\n- DefineOptions.cmake\n\n## Target Source Code\n\n### tests/unittests/torture_misc.c\n\n#### torture_timeout_elapsed() [lines 192-207]\n```c\n free(tmp);\n}\n\nstatic void torture_timeout_elapsed(void **state){\n struct ssh_timestamp ts;\n (void) state;\n ssh_timestamp_init(&ts);\n usleep(50000);\n assert_true(ssh_timeout_elapsed(&ts,25));\n assert_false(ssh_timeout_elapsed(&ts,30000));\n assert_false(ssh_timeout_elapsed(&ts,75));\n assert_true(ssh_timeout_elapsed(&ts,0));\n assert_false(ssh_timeout_elapsed(&ts,-1));\n}\n\nstatic void torture_timeout_update(void **state){\n```\n\n#### torture_timeout_update() [lines 204-219]\n```c\n assert_false(ssh_timeout_elapsed(&ts,-1));\n}\n\nstatic void torture_timeout_update(void **state){\n struct ssh_timestamp ts;\n (void) state;\n ssh_timestamp_init(&ts);\n usleep(50000);\n assert_int_equal(ssh_timeout_update(&ts,25), 0);\n assert_in_range(ssh_timeout_update(&ts,30000),29000,29960);\n assert_in_range(ssh_timeout_update(&ts,75),1,40);\n assert_int_equal(ssh_timeout_update(&ts,0),0);\n assert_int_equal(ssh_timeout_update(&ts,-1),-1);\n}\n\nstatic void torture_ssh_analyze_banner(void **state) {\n```\n\n### DefineOptions.cmake\n\n#### option() [lines 1-49]\n```\noption(WITH_GSSAPI \"Build with GSSAPI support\" ON)\noption(WITH_ZLIB \"Build with ZLIB support\" ON)\noption(WITH_SFTP \"Build with SFTP support\" ON)\noption(WITH_SERVER \"Build with SSH server support\" ON)\noption(WITH_STATIC_LIB \"Build with a static library\" OFF)\noption(WITH_DEBUG_CRYPTO \"Build with cryto debug output\" OFF)\noption(WITH_DEBUG_PACKET \"Build with packet debug output\" OFF)\noption(WITH_DEBUG_CALLTRACE \"Build with calltrace debug output\" ON)\noption(WITH_GCRYPT \"Compile against libgcrypt\" OFF)\noption(WITH_MBEDTLS \"Compile against libmbedtls\" OFF)\noption(WITH_PCAP \"Compile with Pcap generation support\" ON)\noption(WITH_INTERNAL_DOC \"Compile doxygen internal documentation\" OFF)\noption(UNIT_TESTING \"Build with unit tests\" OFF)\noption(CLIENT_TESTING \"Build with client tests; requires openssh\" OFF)\noption(SERVER_TESTING \"Build with server tests; requires openssh and dropbear\" OFF)\noption(WITH_BENCHMARKS \"Build benchmarks tools\" OFF)\noption(WITH_EXAMPLES \"Build examples\" ON)\noption(WITH_NACL \"Build with libnacl (curve25519)\" ON)\noption(WITH_SYMBOL_VERSIONING \"Build with symbol versioning\" ON)\noption(WITH_ABI_BREAK \"Allow ABI break\" OFF)\noption(FUZZ_TESTING \"Build with fuzzer for the server\" OFF)\noption(PICKY_DEVELOPER \"Build with picky developer flags\" OFF)\n\nif (WITH_ZLIB)\n set(WITH_LIBZ ON)\nelse (WITH_ZLIB)\n set(WITH_LIBZ OFF)\nendif (WITH_ZLIB)\n\nif(WITH_BENCHMARKS)\n set(UNIT_TESTING ON)\nendif(WITH_BENCHMARKS)\n\nif (WITH_STATIC_LIB)\n set(BUILD_STATIC_LIB ON)\nendif (WITH_STATIC_LIB)\n\nif (UNIT_TESTING)\n set(BUILD_STATIC_LIB ON)\nendif (UNIT_TESTING)\n\nif (WITH_NACL)\n set(WITH_NACL ON)\nendif (WITH_NACL)\n\nif (WITH_ABI_BREAK)\n set(WITH_SYMBOL_VERSIONING ON)\nendif (WITH_ABI_BREAK)\n\n```\n\n\n## Upstream Fix\n```diff\nIndex: libssh-0.8.2/tests/unittests/torture_misc.c\n===================================================================\n--- libssh-0.8.2.orig/tests/unittests/torture_misc.c\t2018-08-30 08:12:50.355846083 +0200\n+++ libssh-0.8.2/tests/unittests/torture_misc.c\t2018-08-30 08:12:54.831889573 +0200\n@@ -197,11 +197,13 @@ static void torture_timeout_elapsed(void\n (void) state;\n ssh_timestamp_init(&ts);\n usleep(50000);\n+#ifndef SLOW_TEST_SYSTEM\n assert_true(ssh_timeout_elapsed(&ts,25));\n assert_false(ssh_timeout_elapsed(&ts,30000));\n assert_false(ssh_timeout_elapsed(&ts,75));\n assert_true(ssh_timeout_elapsed(&ts,0));\n assert_false(ssh_timeout_elapsed(&ts,-1));\n+#endif /* SLOW_TEST_SYSTEM */\n }\n \n static void torture_timeout_update(void **state){\n@@ -209,11 +211,13 @@ static void torture_timeout_update(void\n (void) state;\n ssh_timestamp_init(&ts);\n usleep(50000);\n+#ifndef SLOW_TEST_SYSTEM\n assert_int_equal(ssh_timeout_update(&ts,25), 0);\n assert_in_range(ssh_timeout_update(&ts,30000),29000,29960);\n assert_in_range(ssh_timeout_update(&ts,75),1,40);\n assert_int_equal(ssh_timeout_update(&ts,0),0);\n assert_int_equal(ssh_timeout_update(&ts,-1),-1);\n+#endif /* SLOW_TEST_SYSTEM */\n }\n \n static void torture_ssh_analyze_banner(void **state) {\nIndex: libssh-0.8.2/DefineOptions.cmake\n===================================================================\n--- libssh-0.8.2.orig/DefineOptions.cmake\t2018-08-30 08:12:50.355846083 +0200\n+++ libssh-0.8.2/DefineOptions.cmake\t2018-08-30 08:13:25.020182668 +0200\n@@ -20,6 +20,7 @@ option(WITH_SYMBOL_VERSIONING \"Build wit\n option(WITH_ABI_BREAK \"Allow ABI break\" OFF)\n option(FUZZ_TESTING \"Build with fuzzer for the server\" OFF)\n option(PICKY_DEVELOPER \"Build with picky developer flags\" OFF)\n+option(SLOW_TEST_SYSTEM \"Disable tests that fail on slow systems\" OFF)\n \n if (WITH_ZLIB)\n set(WITH_LIBZ ON)\n@@ -46,3 +47,8 @@ endif (WITH_NACL)\n if (WITH_ABI_BREAK)\n set(WITH_SYMBOL_VERSIONING ON)\n endif (WITH_ABI_BREAK)\n+\n+if (SLOW_TEST_SYSTEM)\n+ set (SLOW_TEST_SYSTEM ON)\n+ add_definitions(-DSLOW_TEST_SYSTEM)\n+endif (SLOW_TEST_SYSTEM)\n\n```\n\nGenerate a backported patch for the SUSE target version."
},
{
"role": "assistant",
"content": "Index: libssh-0.8.2/tests/unittests/torture_misc.c\n===================================================================\n--- libssh-0.8.2.orig/tests/unittests/torture_misc.c\t2018-08-30 08:12:50.355846083 +0200\n+++ libssh-0.8.2/tests/unittests/torture_misc.c\t2018-08-30 08:12:54.831889573 +0200\n@@ -197,11 +197,13 @@ static void torture_timeout_elapsed(void\n (void) state;\n ssh_timestamp_init(&ts);\n usleep(50000);\n+#ifndef SLOW_TEST_SYSTEM\n assert_true(ssh_timeout_elapsed(&ts,25));\n assert_false(ssh_timeout_elapsed(&ts,30000));\n assert_false(ssh_timeout_elapsed(&ts,75));\n assert_true(ssh_timeout_elapsed(&ts,0));\n assert_false(ssh_timeout_elapsed(&ts,-1));\n+#endif /* SLOW_TEST_SYSTEM */\n }\n \n static void torture_timeout_update(void **state){\n@@ -209,11 +211,13 @@ static void torture_timeout_update(void\n (void) state;\n ssh_timestamp_init(&ts);\n usleep(50000);\n+#ifndef SLOW_TEST_SYSTEM\n assert_int_equal(ssh_timeout_update(&ts,25), 0);\n assert_in_range(ssh_timeout_update(&ts,30000),29000,29960);\n assert_in_range(ssh_timeout_update(&ts,75),1,40);\n assert_int_equal(ssh_timeout_update(&ts,0),0);\n assert_int_equal(ssh_timeout_update(&ts,-1),-1);\n+#endif /* SLOW_TEST_SYSTEM */\n }\n \n static void torture_ssh_analyze_banner(void **state) {\nIndex: libssh-0.8.2/DefineOptions.cmake\n===================================================================\n--- libssh-0.8.2.orig/DefineOptions.cmake\t2018-08-30 08:12:50.355846083 +0200\n+++ libssh-0.8.2/DefineOptions.cmake\t2018-08-30 08:13:25.020182668 +0200\n@@ -20,6 +20,7 @@ option(WITH_SYMBOL_VERSIONING \"Build wit\n option(WITH_ABI_BREAK \"Allow ABI break\" OFF)\n option(FUZZ_TESTING \"Build with fuzzer for the server\" OFF)\n option(PICKY_DEVELOPER \"Build with picky developer flags\" OFF)\n+option(SLOW_TEST_SYSTEM \"Disable tests that fail on slow systems\" OFF)\n \n if (WITH_ZLIB)\n set(WITH_LIBZ ON)\n@@ -46,3 +47,8 @@ endif (WITH_NACL)\n if (WITH_ABI_BREAK)\n set(WITH_SYMBOL_VERSIONING ON)\n endif (WITH_ABI_BREAK)\n+\n+if (SLOW_TEST_SYSTEM)\n+ set (SLOW_TEST_SYSTEM ON)\n+ add_definitions(-DSLOW_TEST_SYSTEM)\n+endif (SLOW_TEST_SYSTEM)\n"
}
] |
{
"id": "libssh-12292-0001-disable-timeout-test-on-slow-buildsystems.patch",
"cves": [
"CVE-2020-1730"
],
"package": "libssh",
"incident_id": 12292,
"patch_name": "0001-disable-timeout-test-on-slow-buildsystems.patch",
"tier": "identical",
"language": "c",
"patch_lines_changed": 10,
"patch_files_count": 2,
"total_tokens_est": 1210,
"has_source_context": true,
"upstream_enriched": false,
"suse_license": "LGPL-2.1-or-later",
"upstream_license": "NOASSERTION",
"cve_id": "CVE-2020-1730",
"upstream_commit": null,
"upstream_repo": 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-2020-27749, CVE-2020-27779, CVE-2020-14372, CVE-2020-25632, CVE-2021-20233, CVE-2021-20225, CVE-2020-25647\n\n===================================================================\n\n## Package\ngrub2\n\n## Files to modify\n- grub-2.04~rc1/grub-core/kern/ieee1275/openfw.c\n- grub-2.04~rc1/grub-core/normal/main.c\n- grub-2.04~rc1/include/grub/ieee1275/ieee1275.h\n\n## Target Source Code\n\n### grub-core/kern/ieee1275/openfw.c\n\n#### grub_ieee1275_canonicalise_devname() [lines 522-567]\n```c\n\n/* Resolve aliases. */\nchar *\ngrub_ieee1275_canonicalise_devname (const char *path)\n{\n struct canon_args\n {\n struct grub_ieee1275_common_hdr common;\n grub_ieee1275_cell_t path;\n grub_ieee1275_cell_t buf;\n grub_ieee1275_cell_t inlen;\n grub_ieee1275_cell_t outlen;\n }\n args;\n char *buf = NULL;\n grub_size_t bufsize = 64;\n int i;\n\n for (i = 0; i < 2; i++)\n {\n grub_free (buf);\n\n buf = grub_malloc (bufsize);\n if (!buf)\n\treturn NULL;\n\n INIT_IEEE1275_COMMON (&args.common, \"canon\", 3, 1);\n args.path = (grub_ieee1275_cell_t) path;\n args.buf = (grub_ieee1275_cell_t) buf;\n args.inlen = (grub_ieee1275_cell_t) (bufsize - 1);\n\n if (IEEE1275_CALL_ENTRY_FN (&args) == -1)\n\treturn 0;\n if (args.outlen > bufsize - 1)\n\t{\n\t bufsize = args.outlen + 2;\n\t continue;\n\t}\n return buf;\n }\n /* Shouldn't reach here. */\n grub_free (buf);\n return NULL;\n}\n\nchar *\n```\n\n#### grub_ieee1275_cas_reboot() [lines 579-594]\n```c\n return NULL;\n }\n\n bootpath = (char *) grub_malloc ((grub_size_t) bootpath_size + 64);\n if (! bootpath)\n {\n grub_print_error ();\n return NULL;\n }\n grub_ieee1275_get_property (grub_ieee1275_chosen, \"bootpath\", bootpath,\n (grub_size_t) bootpath_size + 1, 0);\n bootpath[bootpath_size] = '\\0';\n\n return bootpath;\n}\n\n```\n\n#### grub_ieee1275_set_boot_last_label() [lines 602-594]\n```c\n\n```\n\n### grub-core/normal/main.c\n\n#### grub_normal_execute() [lines 257-297]\n```c\n/* Read the config file CONFIG and execute the menu interface or\n the command line interface if BATCH is false. */\nvoid\ngrub_normal_execute (const char *config, int nested, int batch)\n{\n grub_menu_t menu = 0;\n const char *prefix;\n\n if (! nested)\n {\n prefix = grub_env_get (\"prefix\");\n read_lists (prefix);\n grub_register_variable_hook (\"prefix\", NULL, read_lists_hook);\n }\n\n grub_boot_time (\"Executing config file\");\n\n if (config)\n {\n menu = read_config_file (config);\n\n /* Ignore any error. */\n grub_errno = GRUB_ERR_NONE;\n }\n\n grub_boot_time (\"Executed config file\");\n\n if (! batch)\n {\n if (menu && menu->size)\n\t{\n\n\t grub_boot_time (\"Entering menu\");\n\t grub_show_menu (menu, nested, 0);\n\t if (nested)\n\t grub_normal_free_menu (menu);\n\t}\n }\n}\n\n/* This starts the normal mode. */\n```\n\n### include/grub/ieee1275/ieee1275.h\n\n#### EXPORT_FUNC() [lines 214-267]\n```c\nint EXPORT_FUNC(grub_ieee1275_milliseconds) (grub_uint32_t *msecs);\nint EXPORT_FUNC(grub_ieee1275_set_address) (grub_ieee1275_ihandle_t ihandle,\n grub_uint32_t target,\n grub_uint32_t lun);\nint EXPORT_FUNC(grub_ieee1275_no_data_command) (grub_ieee1275_ihandle_t ihandle,\n const void *cmd_addr,\n grub_ssize_t *result);\nint EXPORT_FUNC(grub_ieee1275_decode_unit4) (grub_ieee1275_ihandle_t ihandle,\n void *addr, grub_size_t size,\n grub_uint32_t *phy_lo,\n grub_uint32_t *phy_hi,\n grub_uint32_t *lun_lo,\n grub_uint32_t *lun_hi);\nchar *EXPORT_FUNC(grub_ieee1275_encode_uint4) (grub_ieee1275_ihandle_t ihandle,\n grub_uint32_t phy_lo,\n grub_uint32_t phy_hi,\n grub_uint32_t lun_lo,\n grub_uint32_t lun_hi,\n grub_size_t *size);\nint EXPORT_FUNC(grub_ieee1275_get_block_size) (grub_ieee1275_ihandle_t ihandle);\n\ngrub_err_t EXPORT_FUNC(grub_claimmap) (grub_addr_t addr, grub_size_t size);\n\nint\nEXPORT_FUNC(grub_ieee1275_map) (grub_addr_t phys, grub_addr_t virt,\n\t\t\t\tgrub_size_t size, grub_uint32_t mode);\n\nchar *EXPORT_FUNC(grub_ieee1275_encode_devname) (const char *path);\nchar *EXPORT_FUNC(grub_ieee1275_get_filename) (const char *path);\nint EXPORT_FUNC(grub_ieee1275_devices_iterate) (int (*hook)\n\t\t\t\t\t\t(struct grub_ieee1275_devalias *\n\t\t\t\t\t\t alias));\nchar *EXPORT_FUNC(grub_ieee1275_get_aliasdevname) (const char *path);\nchar *EXPORT_FUNC(grub_ieee1275_canonicalise_devname) (const char *path);\nchar *EXPORT_FUNC(grub_ieee1275_get_device_type) (const char *path);\nchar *EXPORT_FUNC(grub_ieee1275_get_devname) (const char *path);\n\nvoid EXPORT_FUNC(grub_ieee1275_devalias_init_iterator) (struct grub_ieee1275_devalias *alias);\nvoid EXPORT_FUNC(grub_ieee1275_devalias_free) (struct grub_ieee1275_devalias *alias);\nint EXPORT_FUNC(grub_ieee1275_devalias_next) (struct grub_ieee1275_devalias *alias);\nvoid EXPORT_FUNC(grub_ieee1275_children_peer) (struct grub_ieee1275_devalias *alias);\nvoid EXPORT_FUNC(grub_ieee1275_children_first) (const char *devpath,\n\t\t\t\t\t\tstruct grub_ieee1275_devalias *alias);\n\nchar *EXPORT_FUNC(grub_ieee1275_get_boot_dev) (void);\n\n#define FOR_IEEE1275_DEVALIASES(alias) for (grub_ieee1275_devalias_init_iterator (&(alias)); grub_ieee1275_devalias_next (&(alias));)\n\n#define FOR_IEEE1275_DEVCHILDREN(devpath, alias) for (grub_ieee1275_children_first ((devpath), &(alias)); \\\n\t\t\t\t\t\t (alias).name;\t\\\n\t\t\t\t\t\t grub_ieee1275_children_peer (&(alias)))\n\n#endif /* ! GRUB_IEEE1275_HEADER */\n\n```\n\n\n## Upstream Fix\n```diff\nIndex: grub-2.04~rc1/grub-core/kern/ieee1275/openfw.c\n===================================================================\n--- grub-2.04~rc1.orig/grub-core/kern/ieee1275/openfw.c\n+++ grub-2.04~rc1/grub-core/kern/ieee1275/openfw.c\n@@ -595,7 +595,7 @@ grub_ieee1275_canonicalise_devname (cons\n \n /* Check if it's a CAS reboot. If so, set the script to be executed. */\n int\n-grub_ieee1275_cas_reboot (char *script)\n+grub_ieee1275_cas_reboot (char **script)\n {\n grub_uint32_t ibm_ca_support_reboot;\n grub_uint32_t ibm_fw_nbr_reboots;\n@@ -628,16 +628,37 @@ grub_ieee1275_cas_reboot (char *script)\n \n if (ibm_ca_support_reboot || ibm_fw_nbr_reboots)\n {\n- if (! grub_ieee1275_get_property_length (options, \"boot-last-label\", &actual))\n- {\n- if (actual > 1024)\n- script = grub_realloc (script, actual + 1);\n- grub_ieee1275_get_property (options, \"boot-last-label\", script, actual,\n- &actual);\n- return 0;\n- }\n+ grub_ssize_t len;\n+ char *buf;\n+\n+ if (grub_ieee1275_get_property_length (options, \"boot-last-label\", &len)\n+\t\t|| len <= 0)\n+\t{\n+\t grub_dprintf (\"ieee1275\", \"boot-last-label missing or invalid\\n\");\n+\t goto out;\n+\t}\n+ /* The returned property string length may not include terminating null byte, and in\n+ a bid to avoid out of bound access we allocate one more byte to add it back */\n+ buf = grub_malloc ((grub_size_t)len + 1);\n+ if (!buf)\n+\t{\n+\t grub_print_error ();\n+\t goto out;\n+\t}\n+ if (grub_ieee1275_get_property (options, \"boot-last-label\", buf, (grub_size_t)len + 1, &actual)\n+\t\t|| actual < 0)\n+\t{\n+\t grub_dprintf (\"ieee1275\", \"error while get boot-last-label property\\n\");\n+\t grub_free (buf);\n+\t goto out;\n+\t}\n+ /* Add terminating null byte */\n+ buf[len] = '\\0';\n+ *script = buf;\n+ return 0;\n }\n \n+out:\n grub_ieee1275_set_boot_last_label (\"\");\n \n return -1;\n@@ -651,8 +672,9 @@ int grub_ieee1275_set_boot_last_label (c\n grub_dprintf(\"ieee1275\", \"set boot_last_label (size: %\" PRIxGRUB_SIZE \")\\n\", grub_strlen(text));\n if (! grub_ieee1275_finddevice (\"/options\", &options) &&\n options != (grub_ieee1275_ihandle_t) -1)\n+ /* To be on the safe side, set the property string with terminating null byte */\n grub_ieee1275_set_property (options, \"boot-last-label\", text,\n- grub_strlen (text), &actual);\n+ grub_strlen (text) + 1, &actual);\n return 0;\n }\n \nIndex: grub-2.04~rc1/grub-core/normal/main.c\n===================================================================\n--- grub-2.04~rc1.orig/grub-core/normal/main.c\n+++ grub-2.04~rc1/grub-core/normal/main.c\n@@ -281,10 +281,9 @@ grub_normal_execute (const char *config,\n #ifdef GRUB_MACHINE_IEEE1275\n int boot;\n boot = 0;\n- char *script;\n+ char *script = NULL;\n char *dummy[1] = { NULL };\n- script = grub_malloc (1024);\n- if (! grub_ieee1275_cas_reboot (script))\n+ if (! grub_ieee1275_cas_reboot (&script) && script)\n {\n if (! grub_script_execute_new_scope (script, 0, dummy))\n boot = 1;\nIndex: grub-2.04~rc1/include/grub/ieee1275/ieee1275.h\n===================================================================\n--- grub-2.04~rc1.orig/include/grub/ieee1275/ieee1275.h\n+++ grub-2.04~rc1/include/grub/ieee1275/ieee1275.h\n@@ -263,7 +263,7 @@ int EXPORT_FUNC(grub_ieee1275_devalias_n\n void EXPORT_FUNC(grub_ieee1275_children_peer) (struct grub_ieee1275_devalias *alias);\n void EXPORT_FUNC(grub_ieee1275_children_first) (const char *devpath,\n \t\t\t\t\t\tstruct grub_ieee1275_devalias *alias);\n-int EXPORT_FUNC(grub_ieee1275_cas_reboot) (char *script);\n+int EXPORT_FUNC(grub_ieee1275_cas_reboot) (char **script);\n int EXPORT_FUNC(grub_ieee1275_set_boot_last_label) (const char *text);\n \n char *EXPORT_FUNC(grub_ieee1275_get_boot_dev) (void);\n\n```\n\nGenerate a backported patch for the SUSE target version."
},
{
"role": "assistant",
"content": "Index: grub-2.04~rc1/grub-core/kern/ieee1275/openfw.c\n===================================================================\n--- grub-2.04~rc1.orig/grub-core/kern/ieee1275/openfw.c\n+++ grub-2.04~rc1/grub-core/kern/ieee1275/openfw.c\n@@ -595,7 +595,7 @@ grub_ieee1275_canonicalise_devname (cons\n \n /* Check if it's a CAS reboot. If so, set the script to be executed. */\n int\n-grub_ieee1275_cas_reboot (char *script)\n+grub_ieee1275_cas_reboot (char **script)\n {\n grub_uint32_t ibm_ca_support_reboot;\n grub_uint32_t ibm_fw_nbr_reboots;\n@@ -628,16 +628,37 @@ grub_ieee1275_cas_reboot (char *script)\n \n if (ibm_ca_support_reboot || ibm_fw_nbr_reboots)\n {\n- if (! grub_ieee1275_get_property_length (options, \"boot-last-label\", &actual))\n- {\n- if (actual > 1024)\n- script = grub_realloc (script, actual + 1);\n- grub_ieee1275_get_property (options, \"boot-last-label\", script, actual,\n- &actual);\n- return 0;\n- }\n+ grub_ssize_t len;\n+ char *buf;\n+\n+ if (grub_ieee1275_get_property_length (options, \"boot-last-label\", &len)\n+\t\t|| len <= 0)\n+\t{\n+\t grub_dprintf (\"ieee1275\", \"boot-last-label missing or invalid\\n\");\n+\t goto out;\n+\t}\n+ /* The returned property string length may not include terminating null byte, and in\n+ a bid to avoid out of bound access we allocate one more byte to add it back */\n+ buf = grub_malloc ((grub_size_t)len + 1);\n+ if (!buf)\n+\t{\n+\t grub_print_error ();\n+\t goto out;\n+\t}\n+ if (grub_ieee1275_get_property (options, \"boot-last-label\", buf, (grub_size_t)len + 1, &actual)\n+\t\t|| actual < 0)\n+\t{\n+\t grub_dprintf (\"ieee1275\", \"error while get boot-last-label property\\n\");\n+\t grub_free (buf);\n+\t goto out;\n+\t}\n+ /* Add terminating null byte */\n+ buf[len] = '\\0';\n+ *script = buf;\n+ return 0;\n }\n \n+out:\n grub_ieee1275_set_boot_last_label (\"\");\n \n return -1;\n@@ -651,8 +672,9 @@ int grub_ieee1275_set_boot_last_label (c\n grub_dprintf(\"ieee1275\", \"set boot_last_label (size: %\" PRIxGRUB_SIZE \")\\n\", grub_strlen(text));\n if (! grub_ieee1275_finddevice (\"/options\", &options) &&\n options != (grub_ieee1275_ihandle_t) -1)\n+ /* To be on the safe side, set the property string with terminating null byte */\n grub_ieee1275_set_property (options, \"boot-last-label\", text,\n- grub_strlen (text), &actual);\n+ grub_strlen (text) + 1, &actual);\n return 0;\n }\n \nIndex: grub-2.04~rc1/grub-core/normal/main.c\n===================================================================\n--- grub-2.04~rc1.orig/grub-core/normal/main.c\n+++ grub-2.04~rc1/grub-core/normal/main.c\n@@ -281,10 +281,9 @@ grub_normal_execute (const char *config,\n #ifdef GRUB_MACHINE_IEEE1275\n int boot;\n boot = 0;\n- char *script;\n+ char *script = NULL;\n char *dummy[1] = { NULL };\n- script = grub_malloc (1024);\n- if (! grub_ieee1275_cas_reboot (script))\n+ if (! grub_ieee1275_cas_reboot (&script) && script)\n {\n if (! grub_script_execute_new_scope (script, 0, dummy))\n boot = 1;\nIndex: grub-2.04~rc1/include/grub/ieee1275/ieee1275.h\n===================================================================\n--- grub-2.04~rc1.orig/include/grub/ieee1275/ieee1275.h\n+++ grub-2.04~rc1/include/grub/ieee1275/ieee1275.h\n@@ -263,7 +263,7 @@ int EXPORT_FUNC(grub_ieee1275_devalias_n\n void EXPORT_FUNC(grub_ieee1275_children_peer) (struct grub_ieee1275_devalias *alias);\n void EXPORT_FUNC(grub_ieee1275_children_first) (const char *devpath,\n \t\t\t\t\t\tstruct grub_ieee1275_devalias *alias);\n-int EXPORT_FUNC(grub_ieee1275_cas_reboot) (char *script);\n+int EXPORT_FUNC(grub_ieee1275_cas_reboot) (char **script);\n int EXPORT_FUNC(grub_ieee1275_set_boot_last_label) (const char *text);\n \n char *EXPORT_FUNC(grub_ieee1275_get_boot_dev) (void);\n"
}
] |
{
"id": "grub2-15947-grub2-ppc64-cas-fix-double-free.patch",
"cves": [
"CVE-2020-14372",
"CVE-2020-25632",
"CVE-2020-25647",
"CVE-2020-27749",
"CVE-2020-27779",
"CVE-2021-20225",
"CVE-2021-20233"
],
"package": "grub2",
"incident_id": 15947,
"patch_name": "grub2-ppc64-cas-fix-double-free.patch",
"tier": "identical",
"language": "c",
"patch_lines_changed": 49,
"patch_files_count": 3,
"total_tokens_est": 2141,
"has_source_context": true,
"upstream_enriched": false,
"suse_license": "GPL-3.0-or-later",
"upstream_license": null,
"cve_id": "CVE-2020-27749",
"upstream_commit": null,
"upstream_repo": 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-2020-27749, CVE-2020-27779, CVE-2020-14372, CVE-2020-25632, CVE-2021-20233, CVE-2021-20225, CVE-2020-25647\n\nutil/mkimage: Improve data_size value calculation\n\n## Package\ngrub2\n\n## Files to modify\n- util/mkimage.c\n\n## Target Source Code\n\n### util/mkimage.c\n\n#### grub_install_generate_image() [lines 1160-1754]\n```c\n break;\n }\n\n switch (image_target->id)\n {\n case IMAGE_I386_PC:\n case IMAGE_I386_PC_PXE:\n case IMAGE_I386_PC_ELTORITO:\n {\n\tunsigned num;\n\tchar *boot_path, *boot_img;\n\tsize_t boot_size;\n\n\tnum = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS);\n\tif (image_target->id == IMAGE_I386_PC_PXE)\n\t {\n\t char *pxeboot_path, *pxeboot_img;\n\t size_t pxeboot_size;\n\t grub_uint32_t *ptr;\n\t \n\t pxeboot_path = grub_util_get_path (dir, \"pxeboot.img\");\n\t pxeboot_size = grub_util_get_image_size (pxeboot_path);\n\t pxeboot_img = grub_util_read_image (pxeboot_path);\n\t \n\t grub_util_write_image (pxeboot_img, pxeboot_size, out,\n\t\t\t\t outname);\n\t free (pxeboot_img);\n\t free (pxeboot_path);\n\n\t /* Remove Multiboot header to avoid confusing ipxe. */\n\t for (ptr = (grub_uint32_t *) core_img;\n\t\t ptr < (grub_uint32_t *) (core_img + MULTIBOOT_SEARCH); ptr++)\n\t if (*ptr == grub_host_to_target32 (MULTIBOOT_HEADER_MAGIC)\n\t\t && grub_target_to_host32 (ptr[0])\n\t\t + grub_target_to_host32 (ptr[1])\n\t\t + grub_target_to_host32 (ptr[2]) == 0)\n\t\t{\n\t\t *ptr = 0;\n\t\t break;\n\t\t}\n/* ... 51 lines omitted ... */\n\tstruct grub_pe32_section_table *mods_section, *reloc_section;\n\tstatic const grub_uint8_t stub[] = GRUB_PE32_MSDOS_STUB;\n\tint header_size;\n\tint reloc_addr;\n\n\tif (image_target->voidp_sizeof == 4)\n\t header_size = EFI32_HEADER_SIZE;\n\telse\n\t header_size = EFI64_HEADER_SIZE;\n\n\treloc_addr = ALIGN_UP (header_size + core_size,\n\t\t\t GRUB_PE32_FILE_ALIGNMENT);\n\n\tpe_size = ALIGN_UP (reloc_addr + layout.reloc_size,\n\t\t\t GRUB_PE32_FILE_ALIGNMENT);\n\tpe_img = xmalloc (reloc_addr + layout.reloc_size);\n\tmemset (pe_img, 0, header_size);\n\tmemcpy ((char *) pe_img + header_size, core_img, core_size);\n\tmemset ((char *) pe_img + header_size + core_size, 0, reloc_addr - (header_size + core_size));\n\tmemcpy ((char *) pe_img + reloc_addr, layout.reloc_section, layout.reloc_size);\n\theader = pe_img;\n\n\t/* The magic. */\n\tmemcpy (header, stub, GRUB_PE32_MSDOS_STUB_SIZE);\n\tmemcpy (header + GRUB_PE32_MSDOS_STUB_SIZE, \"PE\\0\\0\",\n\t\tGRUB_PE32_SIGNATURE_SIZE);\n/* ... 458 lines omitted ... */\n\t {\n\t if (comp == GRUB_COMPRESSION_NONE)\n\t target_addr = (image_target->link_addr - decompress_size);\n\t else\n\t target_addr = ALIGN_UP (image_target->link_addr\n\t\t\t\t + layout.kernel_size + total_module_size, 32);\n\t }\n\telse\n\t target_addr = image_target->link_addr;\n\tif (image_target->voidp_sizeof == 4)\n\t grub_mkimage_generate_elf32 (image_target, note, &core_img, &core_size,\n\t\t\t\t target_addr, &layout);\n\telse\n\t grub_mkimage_generate_elf64 (image_target, note, &core_img, &core_size,\n\t\t\t\t target_addr, &layout);\n }\n break;\n }\n\n grub_util_write_image (core_img, core_size, out, outname);\n```\n\n\n## Upstream Fix\n```diff\nFrom f1baa6c380bea958b8004a0764a4464d798ee3aa Mon Sep 17 00:00:00 2001\nFrom: Peter Jones <pjones@redhat.com>\nDate: Thu, 11 Feb 2021 17:07:33 +0100\nSubject: [PATCH 36/45] util/mkimage: Improve data_size value calculation\n\nAccording to \"Microsoft Portable Executable and Common Object File Format\nSpecification\", the Optional Header SizeOfInitializedData field contains:\n\n Size of the initialized data section, or the sum of all such sections if\n there are multiple data sections.\n\nMake this explicit by adding the GRUB kernel data size to the sum of all\nthe modules sizes. The ALIGN_UP() is not required by the PE spec but do\nit to avoid alignment issues.\n\nSigned-off-by: Peter Jones <pjones@redhat.com>\nSigned-off-by: Javier Martinez Canillas <javierm@redhat.com>\nReviewed-by: Daniel Kiper <daniel.kiper@oracle.com>\n---\n util/mkimage.c | 6 +++++-\n 1 file changed, 5 insertions(+), 1 deletion(-)\n\ndiff --git a/util/mkimage.c b/util/mkimage.c\nindex deaef5666..853a52179 100644\n--- a/util/mkimage.c\n+++ b/util/mkimage.c\n@@ -1260,6 +1260,7 @@ grub_install_generate_image (const char *dir, const char *prefix,\n \tvoid *pe_img;\n \tgrub_uint8_t *header;\n \tvoid *sections;\n+\tsize_t scn_size;\n \tsize_t pe_size;\n \tstruct grub_pe32_coff_header *c;\n \tstruct grub_pe32_section_table *text_section, *data_section;\n@@ -1362,7 +1363,10 @@ grub_install_generate_image (const char *dir, const char *prefix,\n \t\t\t\t\t\t| GRUB_PE32_SCN_MEM_EXECUTE\n \t\t\t\t\t\t| GRUB_PE32_SCN_MEM_READ);\n \n-\tPE_OHDR (o32, o64, data_size) = grub_host_to_target32 (reloc_addr - layout.exec_size - header_size);\n+\tscn_size = ALIGN_UP (layout.kernel_size - layout.exec_size, GRUB_PE32_FILE_ALIGNMENT);\n+\tPE_OHDR (o32, o64, data_size) = grub_host_to_target32 (scn_size +\n+\t\t\t\t\t\t\t ALIGN_UP (total_module_size,\n+\t\t\t\t\t\t\t\t\t GRUB_PE32_FILE_ALIGNMENT));\n \n \tdata_section = text_section + 1;\n \tstrcpy (data_section->name, \".data\");\n-- \n2.26.2\n\n\n```\n\nGenerate a backported patch for the SUSE target version."
},
{
"role": "assistant",
"content": "From f1baa6c380bea958b8004a0764a4464d798ee3aa Mon Sep 17 00:00:00 2001\nFrom: Peter Jones <pjones@redhat.com>\nDate: Thu, 11 Feb 2021 17:07:33 +0100\nSubject: [PATCH 36/45] util/mkimage: Improve data_size value calculation\n\nAccording to \"Microsoft Portable Executable and Common Object File Format\nSpecification\", the Optional Header SizeOfInitializedData field contains:\n\n Size of the initialized data section, or the sum of all such sections if\n there are multiple data sections.\n\nMake this explicit by adding the GRUB kernel data size to the sum of all\nthe modules sizes. The ALIGN_UP() is not required by the PE spec but do\nit to avoid alignment issues.\n\nSigned-off-by: Peter Jones <pjones@redhat.com>\nSigned-off-by: Javier Martinez Canillas <javierm@redhat.com>\nReviewed-by: Daniel Kiper <daniel.kiper@oracle.com>\n---\n util/mkimage.c | 6 +++++-\n 1 file changed, 5 insertions(+), 1 deletion(-)\n\ndiff --git a/util/mkimage.c b/util/mkimage.c\nindex deaef5666..853a52179 100644\n--- a/util/mkimage.c\n+++ b/util/mkimage.c\n@@ -1260,6 +1260,7 @@ grub_install_generate_image (const char *dir, const char *prefix,\n \tvoid *pe_img;\n \tgrub_uint8_t *header;\n \tvoid *sections;\n+\tsize_t scn_size;\n \tsize_t pe_size;\n \tstruct grub_pe32_coff_header *c;\n \tstruct grub_pe32_section_table *text_section, *data_section;\n@@ -1362,7 +1363,10 @@ grub_install_generate_image (const char *dir, const char *prefix,\n \t\t\t\t\t\t| GRUB_PE32_SCN_MEM_EXECUTE\n \t\t\t\t\t\t| GRUB_PE32_SCN_MEM_READ);\n \n-\tPE_OHDR (o32, o64, data_size) = grub_host_to_target32 (reloc_addr - layout.exec_size - header_size);\n+\tscn_size = ALIGN_UP (layout.kernel_size - layout.exec_size, GRUB_PE32_FILE_ALIGNMENT);\n+\tPE_OHDR (o32, o64, data_size) = grub_host_to_target32 (scn_size +\n+\t\t\t\t\t\t\t ALIGN_UP (total_module_size,\n+\t\t\t\t\t\t\t\t\t GRUB_PE32_FILE_ALIGNMENT));\n \n \tdata_section = text_section + 1;\n \tstrcpy (data_section->name, \".data\");\n-- \n2.26.2\n\n"
}
] |
{
"id": "grub2-15947-0036-util-mkimage-Improve-data_size-value-calculation.patch",
"cves": [
"CVE-2020-14372",
"CVE-2020-25632",
"CVE-2020-25647",
"CVE-2020-27749",
"CVE-2020-27779",
"CVE-2021-20225",
"CVE-2021-20233"
],
"package": "grub2",
"incident_id": 15947,
"patch_name": "0036-util-mkimage-Improve-data_size-value-calculation.patch",
"tier": "identical",
"language": "c",
"patch_lines_changed": 7,
"patch_files_count": 1,
"total_tokens_est": 1095,
"has_source_context": true,
"upstream_enriched": false,
"suse_license": "GPL-3.0-or-later",
"upstream_license": null,
"cve_id": "CVE-2020-27749",
"upstream_commit": null,
"upstream_repo": 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-2020-27749, CVE-2020-27779, CVE-2020-14372, CVE-2020-25632, CVE-2021-20233, CVE-2021-20225, CVE-2020-25647\n\nsquash! Don't allow insmod when secure boot is enabled.\n\n## Package\ngrub2\n\n## Files to modify\n- grub-core/kern/dl.c\n- grub-core/kern/efi/efi.c\n- include/grub/efi/efi.h\n\n## Target Source Code\n\n### grub-core/kern/dl.c\n\n#### region() [lines 1-97]\n```c\n/* dl.c - loadable module support */\n/*\n * GRUB -- GRand Unified Bootloader\n * Copyright (C) 2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc.\n *\n * GRUB is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * GRUB 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 General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with GRUB. If not, see <http://www.gnu.org/licenses/>.\n */\n\n/* Force native word size */\n#define GRUB_TARGET_WORDSIZE (8 * GRUB_CPU_SIZEOF_VOID_P)\n\n#include <config.h>\n#include <grub/elf.h>\n#include <grub/dl.h>\n#include <grub/misc.h>\n#include <grub/mm.h>\n#include <grub/err.h>\n#include <grub/types.h>\n#include <grub/symbol.h>\n#include <grub/file.h>\n#include <grub/env.h>\n#include <grub/cache.h>\n#include <grub/i18n.h>\n\n/* Platforms where modules are in a readonly area of memory. */\n#if defined(GRUB_MACHINE_QEMU)\n#define GRUB_MODULES_MACHINE_READONLY\n#endif\n\n\f\n\n#pragma GCC diagnostic ignored \"-Wcast-align\"\n\ngrub_dl_t grub_dl_head = 0;\n\ngrub_err_t\ngrub_dl_add (grub_dl_t mod);\n\n/* Keep global so that GDB scripts work. */\ngrub_err_t\ngrub_dl_add (grub_dl_t mod)\n{\n if (grub_dl_get (mod->name))\n return grub_error (GRUB_ERR_BAD_MODULE,\n\t\t \"`%s' is already loaded\", mod->name);\n\n return GRUB_ERR_NONE;\n}\n\nstatic void\ngrub_dl_remove (grub_dl_t mod)\n{\n grub_dl_t *p, q;\n\n for (p = &grub_dl_head, q = *p; q; p = &q->next, q = *p)\n if (q == mod)\n {\n\t*p = q->next;\n\treturn;\n }\n}\n\n\f\n\nstruct grub_symbol\n{\n struct grub_symbol *next;\n const char *name;\n void *addr;\n int isfunc;\n grub_dl_t mod;\t/* The module to which this symbol belongs. */\n};\ntypedef struct grub_symbol *grub_symbol_t;\n\n/* The size of the symbol table. */\n#define GRUB_SYMTAB_SIZE\t509\n\n/* The symbol table (using an open-hash). */\nstatic struct grub_symbol *grub_symtab[GRUB_SYMTAB_SIZE];\n\n/* Simple hash function. */\nstatic unsigned\ngrub_symbol_hash (const char *s)\n{\n unsigned key = 0;\n\n```\n\n#### grub_dl_load_file() [lines 679-724]\n```c\n\n/* Load a module from the file FILENAME. */\ngrub_dl_t\ngrub_dl_load_file (const char *filename)\n{\n grub_file_t file = NULL;\n grub_ssize_t size;\n void *core = 0;\n grub_dl_t mod = 0;\n\n grub_boot_time (\"Loading module %s\", filename);\n\n file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE);\n if (! file)\n return 0;\n\n size = grub_file_size (file);\n core = grub_malloc (size);\n if (! core)\n {\n grub_file_close (file);\n return 0;\n }\n\n if (grub_file_read (file, core, size) != (int) size)\n {\n grub_file_close (file);\n grub_free (core);\n return 0;\n }\n\n /* We must close this before we try to process dependencies.\n Some disk backends do not handle gracefully multiple concurrent\n opens of the same device. */\n grub_file_close (file);\n\n mod = grub_dl_load_core (core, size);\n grub_free (core);\n if (! mod)\n return 0;\n\n mod->ref_count--;\n return mod;\n}\n\n/* Load a module using a symbolic name. */\n```\n\n### grub-core/kern/efi/efi.c\n\n#### grub_efi_get_variable_with_attributes() [lines 229-363]\n```c\n grub_efi_status_t status;\n grub_efi_uintn_t datasize = 0;\n grub_efi_runtime_services_t *r;\n grub_efi_char16_t *var16;\n void *data;\n grub_size_t len, len16;\n\n *datasize_out = 0;\n\n len = grub_strlen (var);\n len16 = len * GRUB_MAX_UTF16_PER_UTF8;\n var16 = grub_malloc ((len16 + 1) * sizeof (var16[0]));\n if (!var16)\n return NULL;\n len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL);\n var16[len16] = 0;\n\n r = grub_efi_system_table->runtime_services;\n\n status = efi_call_5 (r->get_variable, var16, guid, NULL, &datasize, NULL);\n\n if (status != GRUB_EFI_BUFFER_TOO_SMALL || !datasize)\n {\n grub_free (var16);\n return NULL;\n }\n\n data = grub_malloc (datasize);\n if (!data)\n {\n grub_free (var16);\n return NULL;\n }\n\n status = efi_call_5 (r->get_variable, var16, guid, NULL, &datasize, data);\n grub_free (var16);\n\n if (status == GRUB_EFI_SUCCESS)\n {\n *datasize_out = datasize;\n return data;\n }\n\n grub_free (data);\n return NULL;\n}\n\n#pragma GCC diagnostic ignored \"-Wcast-align\"\n\n/* Search the mods section from the PE32/PE32+ image. This code uses\n a PE32 header, but should work with PE32+ as well. */\ngrub_addr_t\ngrub_efi_modules_addr (void)\n{\n grub_efi_loaded_image_t *image;\n struct grub_pe32_header *header;\n struct grub_pe32_coff_header *coff_header;\n struct grub_pe32_section_table *sections;\n struct grub_pe32_section_table *section;\n struct grub_module_info *info;\n grub_uint16_t i;\n\n image = grub_efi_get_loaded_image (grub_efi_image_handle);\n if (! image)\n return 0;\n\n header = image->image_base;\n coff_header = &(header->coff_header);\n sections\n = (struct grub_pe32_section_table *) ((char *) coff_header\n\t\t\t\t\t + sizeof (*coff_header)\n\t\t\t\t\t + coff_header->optional_header_size);\n\n for (i = 0, section = sections;\n i < coff_header->num_sections;\n i++, section++)\n {\n if (grub_strcmp (section->name, \"mods\") == 0)\n\tbreak;\n }\n\n if (i == coff_header->num_sections)\n return 0;\n\n info = (struct grub_module_info *) ((char *) image->image_base\n\t\t\t\t + section->virtual_address);\n if (info->magic != GRUB_MODULE_MAGIC)\n return 0;\n\n return (grub_addr_t) info;\n}\n\n#pragma GCC diagnostic error \"-Wcast-align\"\n\n/* ... 21 lines omitted ... */\n\t{\n\t grub_efi_uint16_t len;\n\t len = ((GRUB_EFI_DEVICE_PATH_LENGTH (dp) - 4)\n\t\t / sizeof (grub_efi_char16_t));\n\t filesize += GRUB_MAX_UTF8_PER_UTF16 * len + 2;\n\t}\n\n dp = GRUB_EFI_NEXT_DEVICE_PATH (dp);\n }\n\n if (!filesize)\n return NULL;\n\n dp = dp0;\n\n p = name = grub_malloc (filesize);\n if (!name)\n return NULL;\n\n while (1)\n```\n\n### include/grub/efi/efi.h\n\n#### EXPORT_FUNC() [lines 42-122]\n```c\n\t\t\t\t grub_efi_uintn_t pages,\n\t\t\t\t\t grub_efi_allocate_type_t alloctype,\n\t\t\t\t\t grub_efi_memory_type_t memtype);\nvoid *\nEXPORT_FUNC(grub_efi_allocate_fixed) (grub_efi_physical_address_t address,\n\t\t\t\t grub_efi_uintn_t pages);\nvoid *\nEXPORT_FUNC(grub_efi_allocate_any_pages) (grub_efi_uintn_t pages);\nvoid EXPORT_FUNC(grub_efi_free_pages) (grub_efi_physical_address_t address,\n\t\t\t\t grub_efi_uintn_t pages);\ngrub_efi_uintn_t EXPORT_FUNC(grub_efi_find_mmap_size) (void);\nint\nEXPORT_FUNC(grub_efi_get_memory_map) (grub_efi_uintn_t *memory_map_size,\n\t\t\t\t grub_efi_memory_descriptor_t *memory_map,\n\t\t\t\t grub_efi_uintn_t *map_key,\n\t\t\t\t grub_efi_uintn_t *descriptor_size,\n\t\t\t\t grub_efi_uint32_t *descriptor_version);\nvoid grub_efi_memory_fini (void);\ngrub_efi_loaded_image_t *EXPORT_FUNC(grub_efi_get_loaded_image) (grub_efi_handle_t image_handle);\nvoid EXPORT_FUNC(grub_efi_print_device_path) (grub_efi_device_path_t *dp);\nchar *EXPORT_FUNC(grub_efi_get_filename) (grub_efi_device_path_t *dp);\ngrub_efi_device_path_t *\nEXPORT_FUNC(grub_efi_get_device_path) (grub_efi_handle_t handle);\ngrub_efi_device_path_t *\nEXPORT_FUNC(grub_efi_find_last_device_path) (const grub_efi_device_path_t *dp);\ngrub_efi_device_path_t *\nEXPORT_FUNC(grub_efi_duplicate_device_path) (const grub_efi_device_path_t *dp);\ngrub_err_t EXPORT_FUNC (grub_efi_finish_boot_services) (grub_efi_uintn_t *outbuf_size, void *outbuf,\n\t\t\t\t\t\t\tgrub_efi_uintn_t *map_key,\n\t\t\t\t\t\t\tgrub_efi_uintn_t *efi_desc_size,\n\t\t\t\t\t\t\tgrub_efi_uint32_t *efi_desc_version);\ngrub_err_t EXPORT_FUNC (grub_efi_set_virtual_address_map) (grub_efi_uintn_t memory_map_size,\n\t\t\t\t\t\t\t grub_efi_uintn_t descriptor_size,\n\t\t\t\t\t\t\t grub_efi_uint32_t descriptor_version,\n\t\t\t\t\t\t\t grub_efi_memory_descriptor_t *virtual_map);\nvoid *EXPORT_FUNC (grub_efi_get_variable) (const char *variable,\n\t\t\t\t\t const grub_efi_guid_t *guid,\n\t\t\t\t\t grub_size_t *datasize_out);\ngrub_err_t\nEXPORT_FUNC (grub_efi_set_variable) (const char *var,\n\t\t\t\t const grub_efi_guid_t *guid,\n\t\t\t\t void *data,\n\t\t\t\t grub_size_t datasize);\nint\nEXPORT_FUNC (grub_efi_compare_device_paths) (const grub_efi_device_path_t *dp1,\n\t\t\t\t\t const grub_efi_device_path_t *dp2);\n\nextern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd, \n\t\t\t\t\t\tchar **device,\n\t\t\t\t\t\tchar **path);\n\n#if defined(__arm__) || defined(__aarch64__) || defined(__riscv)\nvoid *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void);\ngrub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *);\n#include <grub/cpu/linux.h>\ngrub_err_t grub_arch_efi_linux_check_image(struct linux_arch_kernel_header *lh);\ngrub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, grub_size_t size,\n char *args);\n#endif\n\ngrub_addr_t grub_efi_modules_addr (void);\n\nvoid grub_efi_mm_init (void);\nvoid grub_efi_mm_fini (void);\nvoid grub_efi_init (void);\nvoid grub_efi_fini (void);\nvoid grub_efi_set_prefix (void);\n\n/* Variables. */\nextern grub_efi_system_table_t *EXPORT_VAR(grub_efi_system_table);\nextern grub_efi_handle_t EXPORT_VAR(grub_efi_image_handle);\n\nextern int EXPORT_VAR(grub_efi_is_finished);\n\nstruct grub_net_card;\n\ngrub_efi_handle_t\ngrub_efinet_get_device_handle (struct grub_net_card *card);\n\n#endif /* ! GRUB_EFI_EFI_HEADER */\n\n```\n\n\n## Upstream Fix\n```diff\nFrom 8dd3206f43e17e6aa7d5ce98c453c9ee471f830f Mon Sep 17 00:00:00 2001\nFrom: Michael Chang <mchang@suse.com>\nDate: Fri, 11 Dec 2020 23:01:59 +0800\nSubject: [PATCH 43/45] squash! Don't allow insmod when secure boot is enabled.\n\nUse grub_efi_get_secureboot to get secure boot status\n---\n grub-core/kern/dl.c | 4 ++--\n grub-core/kern/efi/efi.c | 28 ----------------------------\n include/grub/efi/efi.h | 1 -\n 3 files changed, 2 insertions(+), 31 deletions(-)\n\ndiff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c\nindex e02f2afc5..93f08dfce 100644\n--- a/grub-core/kern/dl.c\n+++ b/grub-core/kern/dl.c\n@@ -39,7 +39,7 @@\n #endif\n \n #ifdef GRUB_MACHINE_EFI\n-#include <grub/efi/efi.h>\n+#include <grub/efi/sb.h>\n #endif\n \n \f\n@@ -702,7 +702,7 @@ grub_dl_load_file (const char *filename)\n grub_boot_time (\"Loading module %s\", filename);\n \n #ifdef GRUB_MACHINE_EFI\n- if (grub_efi_secure_boot ())\n+ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)\n {\n #if 0\n /* This is an error, but grub2-mkconfig still generates a pile of\ndiff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c\nindex 92e99b441..32f1b2ec7 100644\n--- a/grub-core/kern/efi/efi.c\n+++ b/grub-core/kern/efi/efi.c\n@@ -278,34 +278,6 @@ grub_efi_get_variable_with_attributes (const char *var,\n return status;\n }\n \n-grub_efi_boolean_t\n-grub_efi_secure_boot (void)\n-{\n- grub_efi_guid_t efi_var_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID;\n- grub_size_t datasize;\n- char *secure_boot = NULL;\n- char *setup_mode = NULL;\n- grub_efi_boolean_t ret = 0;\n-\n- secure_boot = grub_efi_get_variable(\"SecureBoot\", &efi_var_guid, &datasize);\n-\n- if (datasize != 1 || !secure_boot)\n- goto out;\n-\n- setup_mode = grub_efi_get_variable(\"SetupMode\", &efi_var_guid, &datasize);\n-\n- if (datasize != 1 || !setup_mode)\n- goto out;\n-\n- if (*secure_boot && !*setup_mode)\n- ret = 1;\n-\n- out:\n- grub_free (secure_boot);\n- grub_free (setup_mode);\n- return ret;\n-}\n-\n grub_efi_status_t\n grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,\n \t\t grub_size_t *datasize_out, void **data_out)\ndiff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h\nindex 568d80030..08f6ee00a 100644\n--- a/include/grub/efi/efi.h\n+++ b/include/grub/efi/efi.h\n@@ -91,7 +91,6 @@ EXPORT_FUNC (grub_efi_set_variable) (const char *var,\n \t\t\t\t const grub_efi_guid_t *guid,\n \t\t\t\t void *data,\n \t\t\t\t grub_size_t datasize);\n-grub_efi_boolean_t EXPORT_FUNC (grub_efi_secure_boot) (void);\n int\n EXPORT_FUNC (grub_efi_compare_device_paths) (const grub_efi_device_path_t *dp1,\n \t\t\t\t\t const grub_efi_device_path_t *dp2);\n-- \n2.26.2\n\n\n```\n\nGenerate a backported patch for the SUSE target version."
},
{
"role": "assistant",
"content": "From 8dd3206f43e17e6aa7d5ce98c453c9ee471f830f Mon Sep 17 00:00:00 2001\nFrom: Michael Chang <mchang@suse.com>\nDate: Fri, 11 Dec 2020 23:01:59 +0800\nSubject: [PATCH 43/45] squash! Don't allow insmod when secure boot is enabled.\n\nUse grub_efi_get_secureboot to get secure boot status\n---\n grub-core/kern/dl.c | 4 ++--\n grub-core/kern/efi/efi.c | 28 ----------------------------\n include/grub/efi/efi.h | 1 -\n 3 files changed, 2 insertions(+), 31 deletions(-)\n\ndiff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c\nindex e02f2afc5..93f08dfce 100644\n--- a/grub-core/kern/dl.c\n+++ b/grub-core/kern/dl.c\n@@ -39,7 +39,7 @@\n #endif\n \n #ifdef GRUB_MACHINE_EFI\n-#include <grub/efi/efi.h>\n+#include <grub/efi/sb.h>\n #endif\n \n \f\n@@ -702,7 +702,7 @@ grub_dl_load_file (const char *filename)\n grub_boot_time (\"Loading module %s\", filename);\n \n #ifdef GRUB_MACHINE_EFI\n- if (grub_efi_secure_boot ())\n+ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)\n {\n #if 0\n /* This is an error, but grub2-mkconfig still generates a pile of\ndiff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c\nindex 92e99b441..32f1b2ec7 100644\n--- a/grub-core/kern/efi/efi.c\n+++ b/grub-core/kern/efi/efi.c\n@@ -278,34 +278,6 @@ grub_efi_get_variable_with_attributes (const char *var,\n return status;\n }\n \n-grub_efi_boolean_t\n-grub_efi_secure_boot (void)\n-{\n- grub_efi_guid_t efi_var_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID;\n- grub_size_t datasize;\n- char *secure_boot = NULL;\n- char *setup_mode = NULL;\n- grub_efi_boolean_t ret = 0;\n-\n- secure_boot = grub_efi_get_variable(\"SecureBoot\", &efi_var_guid, &datasize);\n-\n- if (datasize != 1 || !secure_boot)\n- goto out;\n-\n- setup_mode = grub_efi_get_variable(\"SetupMode\", &efi_var_guid, &datasize);\n-\n- if (datasize != 1 || !setup_mode)\n- goto out;\n-\n- if (*secure_boot && !*setup_mode)\n- ret = 1;\n-\n- out:\n- grub_free (secure_boot);\n- grub_free (setup_mode);\n- return ret;\n-}\n-\n grub_efi_status_t\n grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,\n \t\t grub_size_t *datasize_out, void **data_out)\ndiff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h\nindex 568d80030..08f6ee00a 100644\n--- a/include/grub/efi/efi.h\n+++ b/include/grub/efi/efi.h\n@@ -91,7 +91,6 @@ EXPORT_FUNC (grub_efi_set_variable) (const char *var,\n \t\t\t\t const grub_efi_guid_t *guid,\n \t\t\t\t void *data,\n \t\t\t\t grub_size_t datasize);\n-grub_efi_boolean_t EXPORT_FUNC (grub_efi_secure_boot) (void);\n int\n EXPORT_FUNC (grub_efi_compare_device_paths) (const grub_efi_device_path_t *dp1,\n \t\t\t\t\t const grub_efi_device_path_t *dp2);\n-- \n2.26.2\n\n"
}
] |
{
"id": "grub2-15947-0043-squash-Don-t-allow-insmod-when-secure-boot-is-enable.patch",
"cves": [
"CVE-2020-14372",
"CVE-2020-25632",
"CVE-2020-25647",
"CVE-2020-27749",
"CVE-2020-27779",
"CVE-2021-20225",
"CVE-2021-20233"
],
"package": "grub2",
"incident_id": 15947,
"patch_name": "0043-squash-Don-t-allow-insmod-when-secure-boot-is-enable.patch",
"tier": "identical",
"language": "c",
"patch_lines_changed": 34,
"patch_files_count": 3,
"total_tokens_est": 1476,
"has_source_context": true,
"upstream_enriched": false,
"suse_license": "GPL-3.0-or-later",
"upstream_license": null,
"cve_id": "CVE-2020-27749",
"upstream_commit": null,
"upstream_repo": 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-2020-27749, CVE-2020-27779, CVE-2020-14372, CVE-2020-25632, CVE-2021-20233, CVE-2021-20225, CVE-2020-25647\n\nscript: Avoid a use-after-free when redefining a\n\n## Package\ngrub2\n\n## Files to modify\n- grub-core/script/execute.c\n- grub-core/script/function.c\n- grub-core/script/parser.y\n- include/grub/script_sh.h\n\n## Target Source Code\n\n### grub-core/script/execute.c\n\n#### grub_script_function_call() [lines 822-849]\n```c\n\n/* Execute a function call. */\ngrub_err_t\ngrub_script_function_call (grub_script_function_t func, int argc, char **args)\n{\n grub_err_t ret = 0;\n unsigned long loops = active_loops;\n struct grub_script_scope *old_scope;\n struct grub_script_scope new_scope;\n\n active_loops = 0;\n new_scope.flags = 0;\n new_scope.shifts = 0;\n new_scope.argv.argc = argc;\n new_scope.argv.args = args;\n\n old_scope = scope;\n scope = &new_scope;\n\n ret = grub_script_execute (func->func);\n\n function_return = 0;\n active_loops = loops;\n replace_scope (old_scope); /* free any scopes by setparams */\n return ret;\n}\n\n/* Helper for grub_script_execute_sourcecode. */\n```\n\n### grub-core/script/function.c\n\n#### grub_script_function_create() [lines 25-77]\n```c\ngrub_script_function_t grub_script_function_list;\n\ngrub_script_function_t\ngrub_script_function_create (struct grub_script_arg *functionname_arg,\n\t\t\t struct grub_script *cmd)\n{\n grub_script_function_t func;\n grub_script_function_t *p;\n\n func = (grub_script_function_t) grub_malloc (sizeof (*func));\n if (! func)\n return 0;\n\n func->name = grub_strdup (functionname_arg->str);\n if (! func->name)\n {\n grub_free (func);\n return 0;\n }\n\n func->func = cmd;\n\n /* Keep the list sorted for simplicity. */\n p = &grub_script_function_list;\n while (*p)\n {\n if (grub_strcmp ((*p)->name, func->name) >= 0)\n\tbreak;\n\n p = &((*p)->next);\n }\n\n /* If the function already exists, overwrite the old function. */\n if (*p && grub_strcmp ((*p)->name, func->name) == 0)\n {\n grub_script_function_t q;\n\n q = *p;\n grub_script_free (q->func);\n q->func = cmd;\n grub_free (func);\n func = q;\n }\n else\n {\n func->next = *p;\n *p = func;\n }\n\n return func;\n}\n\nvoid\n```\n\n### include/grub/script_sh.h\n\n#### region() [lines 312-414]\n```c\nstruct grub_script_mem *grub_script_mem_record (struct grub_parser_param *state);\nstruct grub_script_mem *grub_script_mem_record_stop (struct grub_parser_param *state,\n\t\t\t\t\t\t struct grub_script_mem *restore);\nvoid *grub_script_malloc (struct grub_parser_param *state, grub_size_t size);\n\n/* Functions used by bison. */\nunion YYSTYPE;\nint grub_script_yylex (union YYSTYPE *, struct grub_parser_param *);\nint grub_script_yyparse (struct grub_parser_param *);\nvoid grub_script_yyerror (struct grub_parser_param *, char const *);\n\n/* Commands to execute, don't use these directly. */\ngrub_err_t grub_script_execute_cmdline (struct grub_script_cmd *cmd);\ngrub_err_t grub_script_execute_cmdlist (struct grub_script_cmd *cmd);\ngrub_err_t grub_script_execute_cmdif (struct grub_script_cmd *cmd);\ngrub_err_t grub_script_execute_cmdfor (struct grub_script_cmd *cmd);\ngrub_err_t grub_script_execute_cmdwhile (struct grub_script_cmd *cmd);\n\n/* Execute any GRUB pre-parsed command or script. */\ngrub_err_t grub_script_execute (struct grub_script *script);\ngrub_err_t grub_script_execute_sourcecode (const char *source);\ngrub_err_t grub_script_execute_new_scope (const char *source, int argc, char **args);\n\n/* Break command for loops. */\ngrub_err_t grub_script_break (grub_command_t cmd, int argc, char *argv[]);\n\n/* SHIFT command for GRUB script. */\ngrub_err_t grub_script_shift (grub_command_t cmd, int argc, char *argv[]);\n\n/* SETPARAMS command for GRUB script functions. */\ngrub_err_t grub_script_setparams (grub_command_t cmd, int argc, char *argv[]);\n\n/* RETURN command for functions. */\ngrub_err_t grub_script_return (grub_command_t cmd, int argc, char *argv[]);\n\n/* This variable points to the parsed command. This is used to\n communicate with the bison code. */\nextern struct grub_script_cmd *grub_script_parsed;\n\n\f\n\n/* The function description. */\nstruct grub_script_function\n{\n /* The name. */\n char *name;\n\n /* The script function. */\n struct grub_script *func;\n\n /* The flags. */\n unsigned flags;\n\n /* The next element. */\n struct grub_script_function *next;\n\n int references;\n};\ntypedef struct grub_script_function *grub_script_function_t;\n\nextern grub_script_function_t grub_script_function_list;\n\n#define FOR_SCRIPT_FUNCTIONS(var) for((var) = grub_script_function_list; \\\n\t\t\t\t (var); (var) = (var)->next)\n\ngrub_script_function_t grub_script_function_create (struct grub_script_arg *functionname,\n\t\t\t\t\t\t struct grub_script *cmd);\nvoid grub_script_function_remove (const char *name);\ngrub_script_function_t grub_script_function_find (char *functionname);\n\ngrub_err_t grub_script_function_call (grub_script_function_t func,\n\t\t\t\t int argc, char **args);\n\nchar **\ngrub_script_execute_arglist_to_argv (struct grub_script_arglist *arglist, int *count);\n\ngrub_err_t\ngrub_normal_parse_line (char *line,\n\t\t\tgrub_reader_getline_t getline_func,\n\t\t\tvoid *getline_func_data);\n\nstatic inline struct grub_script *\ngrub_script_ref (struct grub_script *script)\n{\n if (script)\n script->refcnt++;\n return script;\n}\n\nstatic inline void\ngrub_script_unref (struct grub_script *script)\n{\n if (! script)\n return;\n\n if (sc\n/* ... truncated ... */\n```\n\n\n## Upstream Fix\n```diff\nFrom 809f3a26897f5f648325c5741e72dc1b3db828ee Mon Sep 17 00:00:00 2001\nFrom: Chris Coulson <chris.coulson@canonical.com>\nDate: Fri, 10 Jul 2020 14:41:45 +0100\nSubject: [PATCH 19/27] script: Avoid a use-after-free when redefining a\n function during execution\n\nDefining a new function with the same name as a previously defined\nfunction causes the grub_script and associated resources for the\nprevious function to be freed. If the previous function is currently\nexecuting when a function with the same name is defined, this results\nin use-after-frees when processing subsequent commands in the original\nfunction.\n\nInstead, reject a new function definition if it has the same name as\na previously defined function, and that function is currently being\nexecuted. Although a behavioural change, this should be backwards\ncompatible with existing configurations because they can't be\ndependent on the current behaviour without being broken.\n\nSigned-off-by: Chris Coulson <chris.coulson@canonical.com>\nReviewed-by: Daniel Kiper <daniel.kiper@oracle.com>\n---\n grub-core/script/execute.c | 2 ++\n grub-core/script/function.c | 16 +++++++++++++---\n grub-core/script/parser.y | 3 ++-\n include/grub/script_sh.h | 2 ++\n 4 files changed, 19 insertions(+), 4 deletions(-)\n\ndiff --git a/grub-core/script/execute.c b/grub-core/script/execute.c\nindex 8a9161cc8..ce83edd4b 100644\n--- a/grub-core/script/execute.c\n+++ b/grub-core/script/execute.c\n@@ -838,7 +838,9 @@ grub_script_function_call (grub_script_function_t func, int argc, char **args)\n old_scope = scope;\n scope = &new_scope;\n \n+ func->executing++;\n ret = grub_script_execute (func->func);\n+ func->executing--;\n \n function_return = 0;\n active_loops = loops;\ndiff --git a/grub-core/script/function.c b/grub-core/script/function.c\nindex d36655e51..3aad04bf9 100644\n--- a/grub-core/script/function.c\n+++ b/grub-core/script/function.c\n@@ -34,6 +34,7 @@ grub_script_function_create (struct grub_script_arg *functionname_arg,\n func = (grub_script_function_t) grub_malloc (sizeof (*func));\n if (! func)\n return 0;\n+ func->executing = 0;\n \n func->name = grub_strdup (functionname_arg->str);\n if (! func->name)\n@@ -60,10 +61,19 @@ grub_script_function_create (struct grub_script_arg *functionname_arg,\n grub_script_function_t q;\n \n q = *p;\n- grub_script_free (q->func);\n- q->func = cmd;\n grub_free (func);\n- func = q;\n+ if (q->executing > 0)\n+ {\n+ grub_error (GRUB_ERR_BAD_ARGUMENT,\n+\t\t N_(\"attempt to redefine a function being executed\"));\n+ func = NULL;\n+ }\n+ else\n+ {\n+ grub_script_free (q->func);\n+ q->func = cmd;\n+ func = q;\n+ }\n }\n else\n {\ndiff --git a/grub-core/script/parser.y b/grub-core/script/parser.y\nindex 4f0ab8319..f80b86b6f 100644\n--- a/grub-core/script/parser.y\n+++ b/grub-core/script/parser.y\n@@ -289,7 +289,8 @@ function: \"function\" \"name\"\n \t grub_script_mem_free (state->func_mem);\n \t else {\n \t script->children = state->scripts;\n-\t grub_script_function_create ($2, script);\n+\t if (!grub_script_function_create ($2, script))\n+\t\tgrub_script_free (script);\n \t }\n \n \t state->scripts = $<scripts>3;\ndiff --git a/include/grub/script_sh.h b/include/grub/script_sh.h\nindex b382bcf09..6c48e0751 100644\n--- a/include/grub/script_sh.h\n+++ b/include/grub/script_sh.h\n@@ -361,6 +361,8 @@ struct grub_script_function\n \n /* The next element. */\n struct grub_script_function *next;\n+\n+ unsigned executing;\n };\n typedef struct grub_script_function *grub_script_function_t;\n \n-- \n2.27.0\n\n\n```\n\nGenerate a backported patch for the SUSE target version."
},
{
"role": "assistant",
"content": "From 809f3a26897f5f648325c5741e72dc1b3db828ee Mon Sep 17 00:00:00 2001\nFrom: Chris Coulson <chris.coulson@canonical.com>\nDate: Fri, 10 Jul 2020 14:41:45 +0100\nSubject: [PATCH 19/27] script: Avoid a use-after-free when redefining a\n function during execution\n\nDefining a new function with the same name as a previously defined\nfunction causes the grub_script and associated resources for the\nprevious function to be freed. If the previous function is currently\nexecuting when a function with the same name is defined, this results\nin use-after-frees when processing subsequent commands in the original\nfunction.\n\nInstead, reject a new function definition if it has the same name as\na previously defined function, and that function is currently being\nexecuted. Although a behavioural change, this should be backwards\ncompatible with existing configurations because they can't be\ndependent on the current behaviour without being broken.\n\nSigned-off-by: Chris Coulson <chris.coulson@canonical.com>\nReviewed-by: Daniel Kiper <daniel.kiper@oracle.com>\n---\n grub-core/script/execute.c | 2 ++\n grub-core/script/function.c | 16 +++++++++++++---\n grub-core/script/parser.y | 3 ++-\n include/grub/script_sh.h | 2 ++\n 4 files changed, 19 insertions(+), 4 deletions(-)\n\ndiff --git a/grub-core/script/execute.c b/grub-core/script/execute.c\nindex 8a9161cc8..ce83edd4b 100644\n--- a/grub-core/script/execute.c\n+++ b/grub-core/script/execute.c\n@@ -838,7 +838,9 @@ grub_script_function_call (grub_script_function_t func, int argc, char **args)\n old_scope = scope;\n scope = &new_scope;\n \n+ func->executing++;\n ret = grub_script_execute (func->func);\n+ func->executing--;\n \n function_return = 0;\n active_loops = loops;\ndiff --git a/grub-core/script/function.c b/grub-core/script/function.c\nindex d36655e51..3aad04bf9 100644\n--- a/grub-core/script/function.c\n+++ b/grub-core/script/function.c\n@@ -34,6 +34,7 @@ grub_script_function_create (struct grub_script_arg *functionname_arg,\n func = (grub_script_function_t) grub_malloc (sizeof (*func));\n if (! func)\n return 0;\n+ func->executing = 0;\n \n func->name = grub_strdup (functionname_arg->str);\n if (! func->name)\n@@ -60,10 +61,19 @@ grub_script_function_create (struct grub_script_arg *functionname_arg,\n grub_script_function_t q;\n \n q = *p;\n- grub_script_free (q->func);\n- q->func = cmd;\n grub_free (func);\n- func = q;\n+ if (q->executing > 0)\n+ {\n+ grub_error (GRUB_ERR_BAD_ARGUMENT,\n+\t\t N_(\"attempt to redefine a function being executed\"));\n+ func = NULL;\n+ }\n+ else\n+ {\n+ grub_script_free (q->func);\n+ q->func = cmd;\n+ func = q;\n+ }\n }\n else\n {\ndiff --git a/grub-core/script/parser.y b/grub-core/script/parser.y\nindex 4f0ab8319..f80b86b6f 100644\n--- a/grub-core/script/parser.y\n+++ b/grub-core/script/parser.y\n@@ -289,7 +289,8 @@ function: \"function\" \"name\"\n \t grub_script_mem_free (state->func_mem);\n \t else {\n \t script->children = state->scripts;\n-\t grub_script_function_create ($2, script);\n+\t if (!grub_script_function_create ($2, script))\n+\t\tgrub_script_free (script);\n \t }\n \n \t state->scripts = $<scripts>3;\ndiff --git a/include/grub/script_sh.h b/include/grub/script_sh.h\nindex b382bcf09..6c48e0751 100644\n--- a/include/grub/script_sh.h\n+++ b/include/grub/script_sh.h\n@@ -361,6 +361,8 @@ struct grub_script_function\n \n /* The next element. */\n struct grub_script_function *next;\n+\n+ unsigned executing;\n };\n typedef struct grub_script_function *grub_script_function_t;\n \n-- \n2.27.0\n\n"
}
] |
{
"id": "grub2-15947-0009-script-Avoid-a-use-after-free-when-redefining-a-func.patch",
"cves": [
"CVE-2020-14372",
"CVE-2020-25632",
"CVE-2020-25647",
"CVE-2020-27749",
"CVE-2020-27779",
"CVE-2021-20225",
"CVE-2021-20233"
],
"package": "grub2",
"incident_id": 15947,
"patch_name": "0009-script-Avoid-a-use-after-free-when-redefining-a-func.patch",
"tier": "identical",
"language": "c",
"patch_lines_changed": 24,
"patch_files_count": 4,
"total_tokens_est": 1983,
"has_source_context": true,
"upstream_enriched": false,
"suse_license": "GPL-3.0-or-later",
"upstream_license": null,
"cve_id": "CVE-2020-27749",
"upstream_commit": null,
"upstream_repo": 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-2020-27749, CVE-2020-27779, CVE-2020-14372, CVE-2020-25632, CVE-2021-20233, CVE-2021-20225, CVE-2020-25647\n\nkern/parser: Fix a memory leak\n\n## Package\ngrub2\n\n## Files to modify\n- grub-core/kern/parser.c\n\n## Target Source Code\n\n### grub-core/kern/parser.c\n\n#### grub_parser_split_cmdline() [lines 130-237]\n```c\n}\n\ngrub_err_t\ngrub_parser_split_cmdline (const char *cmdline,\n\t\t\t grub_reader_getline_t getline, void *getline_data,\n\t\t\t int *argc, char ***argv)\n{\n grub_parser_state_t state = GRUB_PARSER_STATE_TEXT;\n /* XXX: Fixed size buffer, perhaps this buffer should be dynamically\n allocated. */\n char buffer[1024];\n char *bp = buffer;\n char *rd = (char *) cmdline;\n char varname[200];\n char *vp = varname;\n char *args;\n int i;\n\n *argc = 0;\n do\n {\n if (!rd || !*rd)\n\t{\n\t if (getline)\n\t getline (&rd, 1, getline_data);\n\t else\n\t break;\n\t}\n\n if (!rd)\n\tbreak;\n\n for (; *rd; rd++)\n\t{\n\t grub_parser_state_t newstate;\n\t char use;\n\n\t newstate = grub_parser_cmdline_state (state, *rd, &use);\n\n\t /* If a variable was being processed and this character does\n\t not describe the variable anymore, write the variable to\n\t the buffer. */\n\t add_var (varname, &bp, &vp, state, newstate);\n\n\t if (check_varstate (newstate))\n\t {\n\t if (use)\n\t\t*(vp++) = use;\n\t }\n\t else\n\t {\n\t if (newstate == GRUB_PARSER_STATE_TEXT\n\t\t && state != GRUB_PARSER_STATE_ESC && grub_isspace (use))\n\t\t{\n\t\t /* Don't add more than one argument if multiple\n\t\t spaces are used. */\n\t\t if (bp != buffer && *(bp - 1))\n\t\t {\n\t\t *(bp++) = '\\0';\n\t\t (*argc)++;\n\t\t }\n\t\t}\n\t else if (use)\n\t\t*(bp++) = use;\n\t }\n\t state = newstate;\n\t}\n }\n while (state != GRUB_PARSER_STATE_TEXT && !check_varstate (state));\n\n /* A special case for when the last character was part of a\n variable. */\n add_var (varname, &bp, &vp, state, GRUB_PARSER_STATE_TEXT);\n\n if (bp != buffer && *(bp - 1))\n {\n *(bp++) = '\\0';\n (*argc)++;\n }\n\n /* Reserve memory for the return values. */\n args = grub_malloc (bp - buffer);\n if (!args)\n return grub_errno;\n grub_memcpy (args, buffer, bp - buffer);\n\n *argv = grub_malloc (sizeof (char *) * (*argc + 1));\n if (!*argv)\n {\n grub_free (args);\n return grub_errno;\n }\n\n /* The arguments are separated with 0's, setup argv so it points to\n the right values. */\n bp = args;\n for (i = 0; i < *argc; i++)\n {\n (*argv)[i] = bp;\n while (*bp)\n\tbp++;\n bp++;\n }\n\n return 0;\n}\n\n/* Helper for grub_parser_execute. */\n```\n\n\n## Upstream Fix\n```diff\nFrom 808a80c385ad7519b49616ae4f6b0961f64217da Mon Sep 17 00:00:00 2001\nFrom: Chris Coulson <chris.coulson@canonical.com>\nDate: Wed, 18 Nov 2020 00:59:24 +0000\nSubject: [PATCH 25/45] kern/parser: Fix a memory leak\n\nThe getline() function supplied to grub_parser_split_cmdline() returns\na newly allocated buffer and can be called multiple times, but the\nreturned buffer is never freed.\n\nSigned-off-by: Chris Coulson <chris.coulson@canonical.com>\nReviewed-by: Daniel Kiper <daniel.kiper@oracle.com>\n---\n grub-core/kern/parser.c | 20 ++++++++++++++++----\n 1 file changed, 16 insertions(+), 4 deletions(-)\n\ndiff --git a/grub-core/kern/parser.c b/grub-core/kern/parser.c\nindex d1cf061ad..39e4df65b 100644\n--- a/grub-core/kern/parser.c\n+++ b/grub-core/kern/parser.c\n@@ -140,6 +140,7 @@ grub_parser_split_cmdline (const char *cmdline,\n char buffer[1024];\n char *bp = buffer;\n char *rd = (char *) cmdline;\n+ char *rp = rd;\n char varname[200];\n char *vp = varname;\n char *args;\n@@ -149,10 +150,18 @@ grub_parser_split_cmdline (const char *cmdline,\n *argv = NULL;\n do\n {\n- if (!rd || !*rd)\n+ if (rp == NULL || *rp == '\\0')\n \t{\n+\t if (rd != cmdline)\n+\t {\n+\t grub_free (rd);\n+\t rd = rp = NULL;\n+\t }\n \t if (getline)\n-\t getline (&rd, 1, getline_data);\n+\t {\n+\t getline (&rd, 1, getline_data);\n+\t rp = rd;\n+\t }\n \t else\n \t break;\n \t}\n@@ -160,12 +169,12 @@ grub_parser_split_cmdline (const char *cmdline,\n if (!rd)\n \tbreak;\n \n- for (; *rd; rd++)\n+ for (; *rp != '\\0'; rp++)\n \t{\n \t grub_parser_state_t newstate;\n \t char use;\n \n-\t newstate = grub_parser_cmdline_state (state, *rd, &use);\n+\t newstate = grub_parser_cmdline_state (state, *rp, &use);\n \n \t /* If a variable was being processed and this character does\n \t not describe the variable anymore, write the variable to\n@@ -198,6 +207,9 @@ grub_parser_split_cmdline (const char *cmdline,\n }\n while (state != GRUB_PARSER_STATE_TEXT && !check_varstate (state));\n \n+ if (rd != cmdline)\n+ grub_free (rd);\n+\n /* A special case for when the last character was part of a\n variable. */\n add_var (varname, &bp, &vp, state, GRUB_PARSER_STATE_TEXT);\n-- \n2.26.2\n\n\n```\n\nGenerate a backported patch for the SUSE target version."
},
{
"role": "assistant",
"content": "From 808a80c385ad7519b49616ae4f6b0961f64217da Mon Sep 17 00:00:00 2001\nFrom: Chris Coulson <chris.coulson@canonical.com>\nDate: Wed, 18 Nov 2020 00:59:24 +0000\nSubject: [PATCH 25/45] kern/parser: Fix a memory leak\n\nThe getline() function supplied to grub_parser_split_cmdline() returns\na newly allocated buffer and can be called multiple times, but the\nreturned buffer is never freed.\n\nSigned-off-by: Chris Coulson <chris.coulson@canonical.com>\nReviewed-by: Daniel Kiper <daniel.kiper@oracle.com>\n---\n grub-core/kern/parser.c | 20 ++++++++++++++++----\n 1 file changed, 16 insertions(+), 4 deletions(-)\n\ndiff --git a/grub-core/kern/parser.c b/grub-core/kern/parser.c\nindex d1cf061ad..39e4df65b 100644\n--- a/grub-core/kern/parser.c\n+++ b/grub-core/kern/parser.c\n@@ -140,6 +140,7 @@ grub_parser_split_cmdline (const char *cmdline,\n char buffer[1024];\n char *bp = buffer;\n char *rd = (char *) cmdline;\n+ char *rp = rd;\n char varname[200];\n char *vp = varname;\n char *args;\n@@ -149,10 +150,18 @@ grub_parser_split_cmdline (const char *cmdline,\n *argv = NULL;\n do\n {\n- if (!rd || !*rd)\n+ if (rp == NULL || *rp == '\\0')\n \t{\n+\t if (rd != cmdline)\n+\t {\n+\t grub_free (rd);\n+\t rd = rp = NULL;\n+\t }\n \t if (getline)\n-\t getline (&rd, 1, getline_data);\n+\t {\n+\t getline (&rd, 1, getline_data);\n+\t rp = rd;\n+\t }\n \t else\n \t break;\n \t}\n@@ -160,12 +169,12 @@ grub_parser_split_cmdline (const char *cmdline,\n if (!rd)\n \tbreak;\n \n- for (; *rd; rd++)\n+ for (; *rp != '\\0'; rp++)\n \t{\n \t grub_parser_state_t newstate;\n \t char use;\n \n-\t newstate = grub_parser_cmdline_state (state, *rd, &use);\n+\t newstate = grub_parser_cmdline_state (state, *rp, &use);\n \n \t /* If a variable was being processed and this character does\n \t not describe the variable anymore, write the variable to\n@@ -198,6 +207,9 @@ grub_parser_split_cmdline (const char *cmdline,\n }\n while (state != GRUB_PARSER_STATE_TEXT && !check_varstate (state));\n \n+ if (rd != cmdline)\n+ grub_free (rd);\n+\n /* A special case for when the last character was part of a\n variable. */\n add_var (varname, &bp, &vp, state, GRUB_PARSER_STATE_TEXT);\n-- \n2.26.2\n\n"
}
] |
{
"id": "grub2-15947-0025-kern-parser-Fix-a-memory-leak.patch",
"cves": [
"CVE-2020-14372",
"CVE-2020-25632",
"CVE-2020-25647",
"CVE-2020-27749",
"CVE-2020-27779",
"CVE-2021-20225",
"CVE-2021-20233"
],
"package": "grub2",
"incident_id": 15947,
"patch_name": "0025-kern-parser-Fix-a-memory-leak.patch",
"tier": "identical",
"language": "c",
"patch_lines_changed": 21,
"patch_files_count": 1,
"total_tokens_est": 1247,
"has_source_context": true,
"upstream_enriched": false,
"suse_license": "GPL-3.0-or-later",
"upstream_license": null,
"cve_id": "CVE-2020-27749",
"upstream_commit": null,
"upstream_repo": null
}
|
CVE Backport Dataset v5
Security patch backporting dataset for SUSE/openSUSE: up to 94,604 real-world CVE backporting examples across 1,121 packages and 2,055 CVEs, with per-example SPDX license metadata.
Successor to cve-backport-v4-dataset, built from the full SUSE maintenance incident archive (6,699 incidents).
Configurations
| Config | Train | Eval | Total | Description |
|---|---|---|---|---|
| realistic (default) | 21,173 | 2,361 | 23,534 | Quality-filtered, capped at 200/package for diversity |
| optimistic | 66,942 | 7,517 | 74,459 | All quality-passed examples, no per-package cap |
| maximalistic | 85,104 | 9,500 | 94,604 | Everything — includes oversized and tiny patches |
| kernel | 104 | 16 | 120 | Kernel-related packages only (crash, kernel-firmware) |
from datasets import load_dataset
# Default: realistic (recommended for training)
ds = load_dataset("anicka/cve-backport-v5-dataset")
# All quality-passed examples
ds = load_dataset("anicka/cve-backport-v5-dataset", "optimistic")
# Everything
ds = load_dataset("anicka/cve-backport-v5-dataset", "maximalistic")
# Kernel only
ds = load_dataset("anicka/cve-backport-v5-dataset", "kernel")
What each config contains
- realistic: Best for training. Quality-filtered (valid format, reasonable token count, deduped), then capped at 200 examples per package to ensure diversity across the 994 packages. 90/10 train/eval split.
- optimistic: Everything that passed quality filters. Same packages as realistic but uncapped — high-frequency packages like openssl may have 500+ examples. Good for experiments with larger models.
- maximalistic: The full archive including oversized patches (>7500 tokens), very small patches (<3 lines changed), and near-duplicates. Useful for research or if you want to apply your own filtering.
- kernel: Tiny subset with kernel-related packages (crash dump analysis, firmware). Included for completeness.
What this dataset contains
Each example is a real CVE backporting task: an upstream security patch paired with its SUSE-adapted backport.
The model input (user message) contains:
- CVE identifier and description (from NVD)
- Target package name and version (e.g.
openssl-1_1) - Upstream fix (unified diff from the upstream project)
- Target source code (function-level context, when available — 15% of realistic examples)
The model output (assistant message) is the adapted SUSE backport patch in Index: quilt format.
Example structure
{
"messages": [
{"role": "system", "content": "You are a security patch backporting assistant..."},
{"role": "user", "content": "## CVE: CVE-2022-29824\n...upstream patch...\nGenerate a backported patch..."},
{"role": "assistant", "content": "Index: libxml2-2.9.1/buf.c\n===\n--- ..."}
],
"metadata": {
"id": "libxml2-4248-libpng12-CVE-2015-7981.patch",
"cves": ["CVE-2015-7981"],
"package": "libxml2",
"tier": "identical",
"language": "c",
"patch_lines_changed": 9,
"has_source_context": false,
"suse_license": "Zlib",
"upstream_license": "NOASSERTION"
}
}
Dataset statistics (realistic config)
| Metric | Value |
|---|---|
| Total examples | 23,534 |
| Unique packages | 994 |
| Unique CVEs | 2,055 |
| Identical patches | 20,981 (89%) |
| Adapted patches | 2,553 (11%) |
| With source context | 3,536 (15%) |
| Maintenance incidents | 6,699 |
Top packages
openssl, openssh, xen, qemu, php7, python, salt, systemd, libxml2, ImageMagick, wireshark, mariadb, java, pacemaker, bind, and 979 more.
Language distribution
| Language | Examples | Percentage |
|---|---|---|
| C | 17,755 | 75.4% |
| C++ | 2,313 | 9.8% |
| Python | 1,702 | 7.2% |
| Shell | 597 | 2.5% |
| Java | 375 | 1.6% |
| JavaScript | 349 | 1.5% |
| Go | 229 | 1.0% |
| Other (Perl, Ruby, PHP, Rust, TS) | 214 | 0.9% |
License distribution
| License family | Examples | Percentage |
|---|---|---|
| GPL-2.x | 7,123 | 30.3% |
| LGPL | 4,017 | 17.1% |
| GPL-3.x | 3,412 | 14.5% |
| MIT | 2,466 | 10.5% |
| BSD | 1,793 | 7.6% |
| Python | 891 | 3.8% |
| Apache | 857 | 3.6% |
| OpenSSL | 824 | 3.5% |
| MPL | 764 | 3.2% |
| PHP | 403 | 1.7% |
| AGPL | 188 | 0.8% |
| PostgreSQL | 95 | 0.4% |
| Other | 701 | 3.0% |
Source and licensing
Derived from publicly available patches in the openSUSE Open Build Service. Each example's metadata.suse_license field indicates the SPDX license of the source package. CVE descriptions are from the National Vulnerability Database (public domain).
See LICENSE.md for full licensing details.
Changes from v4
- 11.6x more examples (23,534 vs 2,031 in realistic; 94,604 total) — full maintenance incident archive
- 11x more packages (994 vs 90)
- 10x more CVEs (2,055 vs 200+)
- Four dataset configurations for different use cases
- Per-example SPDX license identifiers (not just license family names)
- Quality-filtered for token budget (max 7,500 tokens per example in realistic)
Intended use
Training models to assist with security patch backporting — adapting upstream CVE fixes for older SUSE/openSUSE package versions.
References
- cve-backport-tool — CLI inference tool
- cve-backport-qwen32b-phase3 — trained model (v4)
- cve-backport-v4-dataset — previous version
- openSUSE Open Build Service
- Downloads last month
- 24