Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDEV-35554/ MDEV-33158 UBSAN runtime error: call to function show_cached_thread_count() (and plugin interface) #3737

Merged

Conversation

grooverdan
Copy link
Member

  • The Jira issue number for this PR is: MDEV-35554

Description

clang/UBSAN shows this up as an error as the argument is incorrect.

The argument is void* rather than char*.

Release Notes

not required.

How can this PR be tested?

basic bootstrap when compiled WITH_UBSAN under clang.

If the changes are not amenable to automated testing, please explain why not and carefully describe how to test manually.

Basing the PR against the correct MariaDB version

  • This is a new feature or a refactoring, and the PR is based against the main branch.
  • This is a bug fix, and the PR is based against the earliest maintained branch in which the bug can be reproduced.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

@grooverdan grooverdan added the MariaDB Foundation Pull requests created by MariaDB Foundation label Jan 9, 2025
@grooverdan grooverdan requested a review from bnestere January 9, 2025 06:36
@grooverdan grooverdan force-pushed the MDEV-35554-ubsan-show_cached_thread_count branch from 8116295 to 50ebc21 Compare January 9, 2025 07:18
@grooverdan grooverdan changed the title MDEV-35554 runtime error: call to function show_cached_thread_count() MDEV-35554/ MDEV-33158 UBSAN runtime error: call to function show_cached_thread_count() (and plugin interface) Jan 9, 2025
@grooverdan grooverdan force-pushed the MDEV-35554-ubsan-show_cached_thread_count branch from 6dcbc88 to d85cd2a Compare January 10, 2025 04:21
@mariadb-YuchenPei
Copy link
Contributor

The spider commit (d85cd2a) lgtm, thanks for the fix

Copy link
Contributor

@bnestere bnestere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @grooverdan !

The first two commits look good, thanks! I left a couple minor notes to consider. Also, I am leaving the third commit for @mariadb-YuchenPei to review.

@@ -3227,6 +3227,11 @@ static int *mysql_sys_var_int(THD* thd, int offset)
return (int *) intern_sys_var_ptr(thd, offset, true);
}

static unsigned int *mysql_sys_var_uint(THD* thd, int offset)
{
return (unsigned int *) intern_sys_var_ptr(thd, offset, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of C-style casts in this area, though it's cpp code. Perhaps now would be a good time to refactor them to the proper casting style.

@@ -714,8 +714,8 @@ int spider_udf_bg_copy_exec_sql(
long long spider_copy_tables_body(
UDF_INIT *initid,
UDF_ARGS *args,
char *is_null,
char *error
unsigned char *is_null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the MDEV-35735 JIRA you mention

performed manual testing in UBSAN environment as its not completely runable in mtr:

I'd say that'd be good to mention in the commit message too (along with the test case, and also some more detail on why you couldn't use MTR)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although now after some of my own attempts to reproduce/test the issue (which I couldn't actually reproduce the error following the JIRA commands), I now see @mariadb-YuchenPei is assigned to review the spider changes, so I'll let him take over for this part.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mariadb-YuchenPei has reviewed it. Sorry, was in previous comment.

with manual CONC-711 changes it was quite testable in MTR and this should bemerged into the server soon.

case PLUGIN_VAR_BOOL:
((thdvar_bool_t *) opt)->resolve= mysql_sys_var_char;
break;
case PLUGIN_VAR_INT:
((thdvar_int_t *) opt)->resolve= mysql_sys_var_int;
break;
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED:
((thdvar_uint_t *) opt)->resolve= mysql_sys_var_uint;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in the second commit message (for MDEV-33158), it'd be good to re-mention the MTR tests that verify the fixes, as you do on JIRA.

through pointer to incorrect function type.

The argument is void* rather than char* and was missing
system_status_var * as an argument.

This shows up with UBSAN testing under clang.

Reviewer: Brandon Nesterenko
@grooverdan grooverdan force-pushed the MDEV-35554-ubsan-show_cached_thread_count branch from d85cd2a to 058813b Compare January 12, 2025 02:00
In plugins, use the correct resolver for ULONG and ULONGLONG
types.

InnoDB has a UINT type as evidenced by "Unknown variable type code 0x182
in plugin 'InnoDB'." so the implementation for UNSIGNED INT was added.

Any InnoDB mtr test that changes lock_wait_timeout,
spider_param_force_commit and some MyRocks unsigned thread server
variables can verify this change is correct.

Reviewer: Brandon Nesterenko
There were too many C casts rather than C++ casts here.

Started a partial conversion covering within-file scoped
changes.

Suggested by Brandon Nesterenko
The mismatch occurs on the function calls as in the sql/sql_udf.h the
types of "error" and "is_null" are unsigned char rather than char.

This is corrected for the udf functions:
* spider_direct_sql
* spider_direct_bg_sql
* spider_flush_table_mon_cache
* spider_copy_tables
* spider_ping_table

Reviewer: Yuchen Pei
@grooverdan grooverdan force-pushed the MDEV-35554-ubsan-show_cached_thread_count branch from 058813b to 645e2a0 Compare January 12, 2025 02:12
@grooverdan grooverdan enabled auto-merge (rebase) January 12, 2025 02:13
@grooverdan grooverdan merged commit cb26d41 into MariaDB:10.5 Jan 12, 2025
8 of 9 checks passed
@grooverdan grooverdan deleted the MDEV-35554-ubsan-show_cached_thread_count branch January 12, 2025 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MariaDB Foundation Pull requests created by MariaDB Foundation
Development

Successfully merging this pull request may close these issues.

3 participants