3 SDP XML security fixes
Subsystems (2)
v4 cover 3 SDP XML security fixes
Changes since v3:
- Fixed some "line length exceeds 80 columns" warnings
- Fixed "macros should not use a trailing semicolon" warnings
- Fixed "Missing a blank line after declarations" warning
- Fixed distcheck
Changes since v2:
- Reorder commits so that unit tests are added after the fix, so as not to break "git bisect"
- Add "Fix stack overflow when converting large sequences to XML" patch
- Fix crash in unit test when test files are missing
Changes since v1:
- Added "Fix memory leak when adding duplicate attributes"
Bastien Nocera (9):
unit: Add test for sdp_xml_parse_record()
sdp-xml: Fix crash caused by type confusion when parsing crafted SDP
XML
unit: Add test for sdp-xml type-confusion bug
sdp-xml: Fix memory leak when adding duplicate attributes
unit: Add test for sdp-xml duplicate attribute bug
sdp-xml: Optimise parsing large sequences
unit: Add test for slow element_end() append
sdp-xml: Fix stack overflow when converting large sequences to XML
unit: Add convert_sdp_record_to_xml() to SDP XML testing
Makefile.am | 15 ++ src/sdp-xml.c | 61 +++++++- unit/sdp-xml/Bluetooth_HID-sdp_record.xml | 123 +++++++++++++++ .../compute-seq-size-type-confusion.xml | 9 ++ unit/sdp-xml/duplicate-attribute.xml | 4 + unit/sdp-xml/qt-SerialPortSDPRecord.xml | 57 +++++++ unit/test-sdp-xml.c | 143 ++++++++++++++++++ 7 files changed, 404 insertions(+), 8 deletions(-) create mode 100644 unit/sdp-xml/Bluetooth_HID-sdp_record.xml create mode 100644 unit/sdp-xml/compute-seq-size-type-confusion.xml create mode 100644 unit/sdp-xml/duplicate-attribute.xml create mode 100644 unit/sdp-xml/qt-SerialPortSDPRecord.xml create mode 100644 unit/test-sdp-xml.c
Signature · 1 line
2.55.0
PATCH v4 1/9 unit: Add test for sdp_xml_parse_record()
This adds 2 example XML files from other repositories, under a fair use license exception.
--- Makefile.am | 13 +++ unit/sdp-xml/Bluetooth_HID-sdp_record.xml | 123 ++++++++++++++++++++++ unit/sdp-xml/qt-SerialPortSDPRecord.xml | 57 ++++++++++ unit/test-sdp-xml.c | 85 +++++++++++++++ 4 files changed, 278 insertions(+) create mode 100644 unit/sdp-xml/Bluetooth_HID-sdp_record.xml create mode 100644 unit/sdp-xml/qt-SerialPortSDPRecord.xml create mode 100644 unit/test-sdp-xml.c
Makefile.am +13 -0
@@ -637,6 +637,19 @@ unit_test_sdp_SOURCES = unit/test-sdp.c \ unit_test_sdp_LDADD = lib/libbluetooth-internal.la \ src/libshared-glib.la $(GLIB_LIBS) +unit_tests += unit/test-sdp-xml + +unit_test_sdp_xml_SOURCES = unit/test-sdp-xml.c \ + src/sdp-xml.c src/sdp-xml.h \ + src/log.h src/log.c +unit_test_sdp_xml_LDADD = lib/libbluetooth-internal.la \ + src/libshared-glib.la $(GLIB_LIBS) +unit_test_sdp_xml_CFLAGS = $(AM_CFLAGS) $(GLIB_CFLAGS) -DTOP_SRCDIR=\""$(srcdir)"\" +unit_test_sdp_xml_CPPFLAGS = -I$(srcdir)/lib + +EXTRA_DIST += unit/sdp-xml/Bluetooth_HID-sdp_record.xml \ + unit/sdp-xml/qt-SerialPortSDPRecord.xml + unit_tests += unit/test-avdtp unit_test_avdtp_SOURCES = unit/test-avdtp.c \
unit/sdp-xml/Bluetooth_HID-sdp_record.xml new file +123 -0
123 lines not on this page · raw message
unit/sdp-xml/qt-SerialPortSDPRecord.xml new file +57 -0
57 lines not on this page · raw message
unit/test-sdp-xml.c new file +85 -0
85 lines not on this page · raw message
Signature · 1 line
2.55.0
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1144549
---Test result---
Test Summary:
CheckPatch FAIL 4.32 seconds GitLint FAIL 3.30 seconds BuildEll PASS 20.39 seconds BluezMake PASS 593.99 seconds MakeCheck PASS 19.11 seconds MakeDistcheck PASS 156.18 seconds CheckValgrind PASS 230.92 seconds CheckSmatch PASS 319.34 seconds bluezmakeextell PASS 103.13 seconds IncrementalBuild PASS 666.91 seconds ScanBuild PASS 994.86 seconds
Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[BlueZ,v4,2/9] sdp-xml: Fix crash caused by type confusion when parsing crafted SDP XML ERROR:BAD_SIGN_OFF: Unrecognized email address: 'Aisle Research'
#72:
Reported-by: Aisle Research
WARNING:BAD_SIGN_OFF: Non-standard signature: Co-authored-by:
#73:
Co-authored-by: Aisle Research
ERROR:BAD_SIGN_OFF: Unrecognized email address: 'Aisle Research' #73:
Co-authored-by: Aisle Research
/github/workspace/src/patch/14745004.patch total: 2 errors, 1 warnings, 47 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/github/workspace/src/patch/14745004.patch has style problems, please review.
NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[BlueZ,v4,3/9] unit: Add test for sdp-xml type-confusion bug WARNING:BAD_SIGN_OFF: Non-standard signature: Co-authored-by:
#55:
Co-authored-by: Aisle Research
ERROR:BAD_SIGN_OFF: Unrecognized email address: 'Aisle Research' #55:
Co-authored-by: Aisle Research
/github/workspace/src/patch/14745007.patch total: 1 errors, 1 warnings, 24 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/github/workspace/src/patch/14745007.patch has style problems, please review.
NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[BlueZ,v4,4/9] sdp-xml: Fix memory leak when adding duplicate attributes WARNING:COMMIT_LOG_LONG_LINE: Possible unwrapped commit description (prefer a maximum 75 chars per line) #64:
#0 0x7f896a8ef24f in calloc (/lib64/libasan.so.8+0xef24f) (BuildId: 5395ec74f54d9ec7bf97c06583dd39a96c230822)
ERROR:BAD_SIGN_OFF: Unrecognized email address: 'Aisle Research' #73:
Reported-by: Aisle Research
WARNING:BAD_SIGN_OFF: Non-standard signature: Co-authored-by:
#74:
Co-authored-by: Aisle Research
ERROR:BAD_SIGN_OFF: Unrecognized email address: 'Aisle Research' #74:
Co-authored-by: Aisle Research
/github/workspace/src/patch/14745005.patch total: 2 errors, 2 warnings, 12 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/github/workspace/src/patch/14745005.patch has style problems, please review.
NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[BlueZ,v4,5/9] unit: Add test for sdp-xml duplicate attribute bug WARNING:BAD_SIGN_OFF: Non-standard signature: Co-authored-by:
#55:
Co-authored-by: Aisle Research
ERROR:BAD_SIGN_OFF: Unrecognized email address: 'Aisle Research' #55:
Co-authored-by: Aisle Research
/github/workspace/src/patch/14745012.patch total: 1 errors, 1 warnings, 19 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/github/workspace/src/patch/14745012.patch has style problems, please review.
NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[BlueZ,v4,6/9] sdp-xml: Optimise parsing large sequences WARNING:LONG_LINE: line length of 86 exceeds 80 columns #104: FILE: src/sdp-xml.c:631:
+ ctx_data->stack_head->next->tail = ctx_data->stack_head->data;
/github/workspace/src/patch/14745009.patch total: 0 errors, 1 warnings, 36 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/github/workspace/src/patch/14745009.patch has style problems, please review.
NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[BlueZ,v4,7/9] unit: Add test for slow element_end() append WARNING:LINE_SPACING: Missing a blank line after declarations #86: FILE: unit/test-sdp-xml.c:85:
+ struct test_data *t = (struct test_data *) data;
+ parse_xml(t->s->str, t->s->len, TRUE);
/github/workspace/src/patch/14745011.patch total: 0 errors, 1 warnings, 57 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/github/workspace/src/patch/14745011.patch has style problems, please review.
NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[BlueZ,v4,8/9] sdp-xml: Fix stack overflow when converting large sequences to XML
WARNING:COMMIT_LOG_LONG_LINE: Possible unwrapped commit description (prefer a maximum 75 chars per line)
#59:
==1684518==ERROR: AddressSanitizer: stack-overflow on address 0x7fff7fb40d98 (pc 0x7fbe1ee95c2b bp 0x7fff7fb41610 sp 0x7fff7fb40d70 T0)
ERROR:SPACING: space required after that ',' (ctx:VxV) #87: FILE: src/sdp-xml.c:688:
+ int indent_level,void *data,
^
/github/workspace/src/patch/14745008.patch total: 1 errors, 1 warnings, 30 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/github/workspace/src/patch/14745008.patch has style problems, please review.
NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
##############################
Test: GitLint - FAIL
Desc: Run gitlint
Output:
[BlueZ,v4,2/9] sdp-xml: Fix crash caused by type confusion when parsing crafted SDP XML
1: T1 Title exceeds max length (87>80): "[BlueZ,v4,2/9] sdp-xml: Fix crash caused by type confusion when parsing crafted SDP XML" [BlueZ,v4,4/9] sdp-xml: Fix memory leak when adding duplicate attributes
13: B1 Line exceeds max length (113>80): " #0 0x7f896a8ef24f in calloc (/lib64/libasan.so.8+0xef24f) (BuildId: 5395ec74f54d9ec7bf97c06583dd39a96c230822)"
17: B1 Line exceeds max length (113>80): " #0 0x7f896a8ef24f in calloc (/lib64/libasan.so.8+0xef24f) (BuildId: 5395ec74f54d9ec7bf97c06583dd39a96c230822)"
[BlueZ,v4,8/9] sdp-xml: Fix stack overflow when converting large sequences to XML
1: T1 Title exceeds max length (81>80): "[BlueZ,v4,8/9] sdp-xml: Fix stack overflow when converting large sequences to XML"
8: B1 Line exceeds max length (135>80): "==1684518==ERROR: AddressSanitizer: stack-overflow on address 0x7fff7fb40d98 (pc 0x7fbe1ee95c2b bp 0x7fff7fb41610 sp 0x7fff7fb40d70 T0)"
9: B1 Line exceeds max length (156>80): " #0 0x7fbe1ee95c2b in printf_common(void*, char const*, __va_list_tag*) (/lib64/libasan.so.8+0x95c2b) (BuildId: 5395ec74f54d9ec7bf97c06583dd39a96c230822)"
10: B1 Line exceeds max length (116>80): " #1 0x7fbe1eeb72d6 in vsnprintf (/lib64/libasan.so.8+0xb72d6) (BuildId: 5395ec74f54d9ec7bf97c06583dd39a96c230822)" 11: B1 Line exceeds max length (115>80): " #2 0x7fbe1eeb94f4 in snprintf (/lib64/libasan.so.8+0xb94f4) (BuildId: 5395ec74f54d9ec7bf97c06583dd39a96c230822)" 12: B1 Line exceeds max length (101>80): " #3 0x000000401fc2 in convert_raw_data_to_xml ../../../../Projects/jhbuild/bluez/src/sdp-xml.c:709" 13: B1 Line exceeds max length (101>80): " #4 0x000000401c4f in convert_raw_data_to_xml ../../../../Projects/jhbuild/bluez/src/sdp-xml.c:994" 15: B1 Line exceeds max length (103>80): " #246 0x000000401c4f in convert_raw_data_to_xml ../../../../Projects/jhbuild/bluez/src/sdp-xml.c:994"
17: B1 Line exceeds max length (121>80): "SUMMARY: AddressSanitizer: stack-overflow ../../../../Projects/jhbuild/bluez/src/sdp-xml.c:709 in convert_raw_data_to_xml"
https://github.com/bluez/bluez/pull/2396
---
Regards,
Linux Bluetooth
This is an automated email and please do not reply to this email.
Dear Submitter,
This series was picked up by the CI more than 2 weeks ago and the pull request created for it is still open, which means the series was never applied to the tree.
Series: 3 SDP XML security fixes
Pull Request: https://github.com/bluez/bluez/pull/2396
Created: 2026-08-12 08:52:51+00:00
The pull request has been closed and no further action is taken on this series.
If the change should still be considered, it must be resent to the Linux Bluetooth mailing list ([email protected]) so that it is picked up again.
---
Regards,
Linux Bluetooth
PATCH v4 2/9 sdp-xml: Fix crash caused by type confusion when parsing crafted SDP XML
In reply to Bastien NoceraWhen element_end() processes </attribute>, it frees ctx_data->stack_head and clears the stack even if parsing is still nested inside a parent container.
If a crafted ServiceRecord places a nested <attribute> inside <sequence>, a later sibling scalar element such as <uint64> can become the new stack head. When the closing </sequence> is then processed, compute_seq_size() is reached without first validating that the current node is actually a sequence.
sdp_data_t.val stores both scalar members such as uint64 and the dataseq pointer in the same union. As a result, attacker-controlled scalar data can be reinterpreted as a linked-list pointer and traversed until bluetoothd crashes.
See https://github.com/bluez/bluez/security/advisories/GHSA-7mmr-gwqx-vc34
Reported-by: Aisle Research
Co-authored-by: Aisle Research
--- src/sdp-xml.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
src/sdp-xml.c +22 -1
@@ -529,7 +529,9 @@ static void element_end(GMarkupParseContext *context,return ;if (!strcmp (element_name,"attribute" )) { -if (ctx_data->stack_head && ctx_data->stack_head->data) { +/* Attributes are expected at top-level record scope. */ +if (ctx_data->stack_head && ctx_data->stack_head->data && + ctx_data->stack_head->next ==NULL ) {int ret =sdp_attr_add (ctx_data->record, ctx_data->attr_id, ctx_data->stack_head->data);if (ret ==-1 )
@@ -539,6 +541,11 @@ static void element_end(GMarkupParseContext *context, ctx_data->stack_head->data =NULL ;sdp_xml_data_free (ctx_data->stack_head); ctx_data->stack_head =NULL ; + }else if (ctx_data->stack_head && ctx_data->stack_head->next) { +g_set_error (err,G_MARKUP_ERROR , +G_MARKUP_ERROR_INVALID_CONTENT , +"Nested <attribute> is invalid" ); +return ; }else {DBG ("No data for attribute 0x%04x" , ctx_data->attr_id); }
@@ -558,6 +565,13 @@ static void element_end(GMarkupParseContext *context, }if (!strcmp (element_name,"sequence" )) { +if (!SDP_IS_SEQ (ctx_data->stack_head->data->dtd)) { +g_set_error (err,G_MARKUP_ERROR , +G_MARKUP_ERROR_INVALID_CONTENT , +"Mismatched </sequence> close" ); +return ; + } + ctx_data->stack_head->data->unitSize =compute_seq_size (ctx_data->stack_head->data);if (ctx_data->stack_head->data->unitSize >USHRT_MAX ) {
@@ -570,6 +584,13 @@ static void element_end(GMarkupParseContext *context, ctx_data->stack_head->data->unitSize +=sizeof (uint8_t ); } }else if (!strcmp (element_name,"alternate" )) { +if (!SDP_IS_ALT (ctx_data->stack_head->data->dtd)) { +g_set_error (err,G_MARKUP_ERROR , +G_MARKUP_ERROR_INVALID_CONTENT , +"Mismatched </alternate> close" ); +return ; + } + ctx_data->stack_head->data->unitSize =compute_seq_size (ctx_data->stack_head->data);if (ctx_data->stack_head->data->unitSize >USHRT_MAX ) {
Signature · 1 line
2.55.0
PATCH v4 3/9 unit: Add test for sdp-xml type-confusion bug
In reply to Bastien NoceraSee https://github.com/bluez/bluez/security/advisories/GHSA-7mmr-gwqx-vc34
Co-authored-by: Aisle Research
--- Makefile.am | 1 + unit/sdp-xml/compute-seq-size-type-confusion.xml | 9 +++++++++ unit/test-sdp-xml.c | 2 ++ 3 files changed, 12 insertions(+) create mode 100644 unit/sdp-xml/compute-seq-size-type-confusion.xml
Makefile.am +1 -0
@@ -648,6 +648,7 @@ unit_test_sdp_xml_CFLAGS = $(AM_CFLAGS) $(GLIB_CFLAGS) -DTOP_SRCDIR=\""$(srcdir) unit_test_sdp_xml_CPPFLAGS = -I$(srcdir)/lib EXTRA_DIST += unit/sdp-xml/Bluetooth_HID-sdp_record.xml \ + unit/sdp-xml/compute-seq-size-type-confusion.xml \ unit/sdp-xml/qt-SerialPortSDPRecord.xml unit_tests += unit/test-avdtp
unit/sdp-xml/compute-seq-size-type-confusion.xml new file +9 -0
@@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<record> +<attribute id="0x0001"> +<sequence> +<attribute id="0x0002"><uint8 value="0x01"/></attribute> +<uint64 value="0x4141414141414141"/> +</sequence> +</attribute> +</record>
unit/test-sdp-xml.c +2 -0
@@ -80,6 +80,8 @@ int main(int argc, char *argv[])DEFINE_TEST ("Bluetooth_HID-sdp_record.xml" , TRUE);DEFINE_TEST ("qt-SerialPortSDPRecord.xml" , TRUE); +/* From https://github.com/bluez/bluez/security/advisories/GHSA-7mmr-gwqx-vc34 */ +DEFINE_TEST ("compute-seq-size-type-confusion.xml" , FALSE);return tester_run (); }
Signature · 1 line
2.55.0
PATCH v4 4/9 sdp-xml: Fix memory leak when adding duplicate attributes
In reply to Bastien NoceraWhen sdp_attr_add() fails because an attribute is duplicated, don't unset its pointer in the parsing context data. As the attribute wasn't added to the record, the ownership of the attribute didn't get passed to the record either.
Don't set the pointer to NULL so it gets freed when cleaning up the context.
Fixes those 2 ASan warnings:
Direct leak of 48 byte(s) in 1 object(s) allocated from:
#0 0x7f896a8ef24f in calloc (/lib64/libasan.so.8+0xef24f) (BuildId: 5395ec74f54d9ec7bf97c06583dd39a96c230822)
#1 0x562042b747f2 in sdp_data_alloc_with_length lib/bluetooth/sdp.c:350Indirect leak of 2 byte(s) in 1 object(s) allocated from:
#0 0x7f896a8ef24f in calloc (/lib64/libasan.so.8+0xef24f) (BuildId: 5395ec74f54d9ec7bf97c06583dd39a96c230822)
#1 0x562042b74bd7 in sdp_data_alloc_with_length lib/bluetooth/sdp.c:425See https://github.com/bluez/bluez/security/advisories/GHSA-75v6-6q44-57hc
Reported-by: Aisle Research
Co-authored-by: Aisle Research
--- src/sdp-xml.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
src/sdp-xml.c +4 -1
@@ -537,8 +537,11 @@ static void element_end(GMarkupParseContext *context,if (ret ==-1 )DBG ("Could not add attribute 0x%04x" , ctx_data->attr_id); +else { +/* ownership transferred to record */ + ctx_data->stack_head->data =NULL ; + } - ctx_data->stack_head->data =NULL ;sdp_xml_data_free (ctx_data->stack_head); ctx_data->stack_head =NULL ; }else if (ctx_data->stack_head && ctx_data->stack_head->next) {
Signature · 1 line
2.55.0
PATCH v4 5/9 unit: Add test for sdp-xml duplicate attribute bug
In reply to Bastien NoceraSee https://github.com/bluez/bluez/security/advisories/GHSA-75v6-6q44-57hc
Co-authored-by: Aisle Research
--- Makefile.am | 1 + unit/sdp-xml/duplicate-attribute.xml | 4 ++++ unit/test-sdp-xml.c | 2 ++ 3 files changed, 7 insertions(+) create mode 100644 unit/sdp-xml/duplicate-attribute.xml
Makefile.am +1 -0
@@ -649,6 +649,7 @@ unit_test_sdp_xml_CPPFLAGS = -I$(srcdir)/lib EXTRA_DIST += unit/sdp-xml/Bluetooth_HID-sdp_record.xml \ unit/sdp-xml/compute-seq-size-type-confusion.xml \ + unit/sdp-xml/duplicate-attribute.xml \ unit/sdp-xml/qt-SerialPortSDPRecord.xml unit_tests += unit/test-avdtp
unit/sdp-xml/duplicate-attribute.xml new file +4 -0
@@ -0,0 +1,4 @@ +<record> +<attribute id="0x0001"><text value="A"/></attribute> +<attribute id="0x0001"><text value="B"/></attribute> +</record>
unit/test-sdp-xml.c +2 -0
@@ -82,6 +82,8 @@ int main(int argc, char *argv[])DEFINE_TEST ("qt-SerialPortSDPRecord.xml" , TRUE);/* From https://github.com/bluez/bluez/security/advisories/GHSA-7mmr-gwqx-vc34 */ DEFINE_TEST ("compute-seq-size-type-confusion.xml" , FALSE); +/* From https://github.com/bluez/bluez/security/advisories/GHSA-75v6-6q44-57hc */ +DEFINE_TEST ("duplicate-attribute.xml" , TRUE);return tester_run (); }
Signature · 1 line
2.55.0
PATCH v4 6/9 sdp-xml: Optimise parsing large sequences
In reply to Bastien NoceraSDP sequences are stored as single-linked lists, so appending members to a sequence requires finding the tail of the list before the insertion.
Finding the tail of the list always starts at the beginning of the list, so takes longer and longer as the list grows bigger.
Keep track of the tail to avoid that problem. This cuts down the sequence_on_squared() test from around 3 to 4 seconds to less than 0.1 seconds.
--- src/sdp-xml.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
src/sdp-xml.c +14 -3
@@ -44,6 +44,7 @@ struct sdp_xml_data {char type;/* 0 = Text or Hexadecimal */ char *name;/* Name, optional in the dtd */ /* TODO: What is it used for? */ +sdp_data_t *tail;/* Tail for O(1) dataseq append */ };struct context_data {
@@ -609,6 +610,7 @@ static void element_end(GMarkupParseContext *context,if (ctx_data->stack_head->next && ctx_data->stack_head->data && ctx_data->stack_head->next->data) { +sdp_data_t *tail;switch (ctx_data->stack_head->next->data->dtd) {case SDP_SEQ8 :case SDP_SEQ16 :
@@ -616,10 +618,19 @@ static void element_end(GMarkupParseContext *context,case SDP_ALT8 :case SDP_ALT16 :case SDP_ALT32 : - ctx_data->stack_head->next->data->val.dataseq = -sdp_seq_append (ctx_data->stack_head->next->data->val.dataseq, - ctx_data->stack_head->data); + tail = ctx_data->stack_head->next->data->val.dataseq ? + ctx_data->stack_head->next->tail :NULL ; +if (tail) { +sdp_seq_append (tail, + ctx_data->stack_head->data); + }else { + ctx_data->stack_head->next->data->val.dataseq = +sdp_seq_append (NULL , + ctx_data->stack_head->data); + } + ctx_data->stack_head->next->tail = ctx_data->stack_head->data; ctx_data->stack_head->data =NULL ; + ctx_data->stack_head->tail =NULL ;break ; }
Signature · 1 line
2.55.0
PATCH v4 7/9 unit: Add test for slow element_end() append
In reply to Bastien NoceraThis uses 40k iterations as this takes a visible amount of time on a pretty fast desktop machine (3-4 secs on an i9 9900k).
See: https://github.com/bluez/bluez/security/advisories/GHSA-4p57-mrcv-r2jc
--- unit/test-sdp-xml.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
unit/test-sdp-xml.c +46 -0
@@ -65,6 +65,47 @@ static void parse_xml_for_filename(gconstpointer data)g_free (path); } +#define XML_START \ + "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" \ + "<record>\n" \ + " <attribute id=\"0x0004\">\n" \ + " <sequence>" + +#define XML_VALUE \ + " <uint8 value=\"0x01\" />\n" + +#define XML_END \ + " </sequence>\n" \ + " </attribute>\n" \ + "</record>" + +static void sequence_on_squared (gconstpointer data) +{ +struct test_data *t = (struct test_data *) data; +parse_xml (t->s->str, t->s->len, TRUE); +} + +static void sequence_on_squared_setup (gconstpointer data) +{ +struct test_data *t = (struct test_data *) data; +guint i; + + t->s =g_string_new (XML_START ); +for (i =0 ; i <40000 ; i++) + t->s =g_string_append (t->s,XML_VALUE ); + t->s =g_string_append (t->s,XML_END ); + +tester_setup_complete (); +} + +static void sequence_on_squared_teardown (gconstpointer data) +{ +struct test_data *t = (struct test_data *) data; + +g_string_free (t->s, TRUE); +tester_teardown_complete (); +} +#define DEFINE_TEST (fname, res) { \ data.expected_result = res; \ data.filename = fname; \
@@ -85,5 +126,10 @@ int main(int argc, char *argv[])/* From https://github.com/bluez/bluez/security/advisories/GHSA-75v6-6q44-57hc */ DEFINE_TEST ("duplicate-attribute.xml" , TRUE); +tester_add ("/sequence_on_squared" , &data, + sequence_on_squared_setup, + sequence_on_squared, + sequence_on_squared_teardown); +return tester_run (); }
Signature · 1 line
2.55.0
PATCH v4 8/9 sdp-xml: Fix stack overflow when converting large sequences to XML
In reply to Bastien NoceraDon't make convert_raw_data_to_xml() call itself recursively X times if there are X elements in a sequence.
AddressSanitizer:DEADLYSIGNAL
=================================================================
==1684518==ERROR: AddressSanitizer: stack-overflow on address 0x7fff7fb40d98 (pc 0x7fbe1ee95c2b bp 0x7fff7fb41610 sp 0x7fff7fb40d70 T0)
#0 0x7fbe1ee95c2b in printf_common(void*, char const*, __va_list_tag*) (/lib64/libasan.so.8+0x95c2b) (BuildId: 5395ec74f54d9ec7bf97c06583dd39a96c230822)
#1 0x7fbe1eeb72d6 in vsnprintf (/lib64/libasan.so.8+0xb72d6) (BuildId: 5395ec74f54d9ec7bf97c06583dd39a96c230822)
#2 0x7fbe1eeb94f4 in snprintf (/lib64/libasan.so.8+0xb94f4) (BuildId: 5395ec74f54d9ec7bf97c06583dd39a96c230822)
#3 0x000000401fc2 in convert_raw_data_to_xml ../../../../Projects/jhbuild/bluez/src/sdp-xml.c:709
#4 0x000000401c4f in convert_raw_data_to_xml ../../../../Projects/jhbuild/bluez/src/sdp-xml.c:994
[...]
#246 0x000000401c4f in convert_raw_data_to_xml ../../../../Projects/jhbuild/bluez/src/sdp-xml.c:994SUMMARY: AddressSanitizer: stack-overflow ../../../../Projects/jhbuild/bluez/src/sdp-xml.c:709 in convert_raw_data_to_xml
--- src/sdp-xml.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
src/sdp-xml.c +13 -3
@@ -681,9 +681,12 @@ sdp_record_t *sdp_xml_parse_record(const char *data, int size)return record; } -static void convert_raw_data_to_xml (sdp_data_t *value,int indent_level, -void *data,void (*appender)(void *,const char *)) +void *data,void (*appender)(void *,const char *)); + +static inline void convert_raw_data_to_xml_element (sdp_data_t *value, +int indent_level,void *data, +void (*appender)(void *,const char *)) {int i, hex;char buf[STRBUFSIZE ];
@@ -1001,8 +1004,15 @@ static void convert_raw_data_to_xml(sdp_data_t *value, int indent_level,break ; } +} -convert_raw_data_to_xml (value->next, indent_level, data, appender); +static void convert_raw_data_to_xml (sdp_data_t *value,int indent_level, +void *data,void (*appender)(void *,const char *)) +{ +for (; value !=NULL ; value = value->next) { +convert_raw_data_to_xml_element (value, indent_level, + data, appender); + } }struct conversion_data {
Signature · 1 line
2.55.0
PATCH v4 9/9 unit: Add convert_sdp_record_to_xml() to SDP XML testing
In reply to Bastien NoceraThis tests SDP binary to XML conversion, including whether a fix for a stack overflow when dealing with large sequences, like in sequence_on_squared(), works correctly.
--- unit/test-sdp-xml.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
unit/test-sdp-xml.c +9 -1
@@ -28,6 +28,12 @@ struct test_data {gboolean expected_result; }; +static void doprintf (void *data,const char *str) +{ +/* Do nothing for our tests */ +/* printf("%s", str); */ +} +static void parse_xml (gconstpointer data,gsize len,gboolean expected_result) {sdp_record_t *rec =NULL ;
@@ -39,8 +45,10 @@ static void parse_xml(gconstpointer data, gsize len, gboolean expected_result)tester_test_passed (); elsetester_test_failed (); -if (rec) +if (rec) { +convert_sdp_record_to_xml (rec,0 , doprintf);sdp_record_free (rec); + } }static void parse_xml_for_filename (gconstpointer data)
Signature · 1 line
2.55.0
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Hello:
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Quoted 6 lines · On Wed, 12 Aug 2026 10:01:31 +0200 you wrote:
Changes since v3:
- Fixed some "line length exceeds 80 columns" warnings
- Fixed "macros should not use a trailing semicolon" warnings
- Fixed "Missing a blank line after declarations" warning
- Fixed distcheck
Quoted 7 lines
Changes since v2:
- Reorder commits so that unit tests are added after the fix, so as not to break "git bisect"
- Add "Fix stack overflow when converting large sequences to XML" patch
- Fix crash in unit test when test files are missing[...]
Here is the summary with links:
- [BlueZ,v4,1/9] unit: Add test for sdp_xml_parse_record()
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=e55ff8818f72 - [BlueZ,v4,2/9] sdp-xml: Fix crash caused by type confusion when parsing crafted SDP XML https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=985e643d78b0 - [BlueZ,v4,3/9] unit: Add test for sdp-xml type-confusion bug https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=a92683ce81ab - [BlueZ,v4,4/9] sdp-xml: Fix memory leak when adding duplicate attributes https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=ae6c543e892f - [BlueZ,v4,5/9] unit: Add test for sdp-xml duplicate attribute bug https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=ab91b4528229 - [BlueZ,v4,6/9] sdp-xml: Optimise parsing large sequences (no matching commit) - [BlueZ,v4,7/9] unit: Add test for slow element_end() append https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=95fa5735562e - [BlueZ,v4,8/9] sdp-xml: Fix stack overflow when converting large sequences to XML https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=e9caa7d3e2bf - [BlueZ,v4,9/9] unit: Add convert_sdp_record_to_xml() to SDP XML testing https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=d01ba78b1d8a
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html