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

Fix 'zdb -o' segmentation fault #5917

Merged
merged 1 commit into from
Mar 24, 2017

Conversation

loli10K
Copy link
Contributor

@loli10K loli10K commented Mar 23, 2017

Motivation and Context

Since the integration of ed828c0 (OpenZFS 7280 - Allow changing global libzpool variables in zdb and ztest through command line) zdb has been segfaulting consistently while running "zdb_001_neg" in the ZTS.

It looks like glibc doesn't handle NULL as the first parameter to strchr():

root@debian-8-zfs:~# gdb -q -ex 'file zdb' -ex 'run -o'
Reading symbols from zdb...done.
Starting program: /usr/sbin/zdb -o
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
__strchr_sse2 () at ../sysdeps/x86_64/multiarch/../strchr.S:32
32	../sysdeps/x86_64/multiarch/../strchr.S: No such file or directory.
(gdb) bt
#0  __strchr_sse2 () at ../sysdeps/x86_64/multiarch/../strchr.S:32
#1  0x00007ffff72dbac6 in set_global_var (arg=0x0) at util.c:185
#2  0x0000000000414ebc in main (argc=2, argv=0x7fffffffece8) at zdb.c:4125
(gdb) up
#1  0x00007ffff72dbac6 in set_global_var (arg=0x0) at util.c:185
185		if ((varval = strchr(arg, '=')) != NULL) {
(gdb) p arg
$1 = 0x0
(gdb) 

Illumos libc has a different behaviour (https://github.com/illumos/illumos-gate/blob/master/usr/src/lib/libc/i386/gen/strchr.s#L39):

	ENTRY(strchr)
	mov 4(%esp), %ecx		/ src string here
	mov 8(%esp), %edx		/ character to find
	mov %ecx, %eax			/ save src
	and $3, %ecx			/ check if src is aligned
	jz prepword			/ search wordwise if it is

	cmpb %dl, (%eax)		/ src == char?
	jz done
	cmpb $0, (%eax)			/ src == 0?
	jz not_found

Maybe this is implementation specific? Anyway, since we can't force the libc on the user i think we should handle this.

How Has This Been Tested?

Manual testing

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the ZFS on Linux code style requirements.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • Change has been approved by a ZFS on Linux member.

Fix a regression accidentally introduced by OpenZFS 7280 in ed828c0: since
whether to accept NULL as a valid first parameter in strchr() is implemetation
specific we add an additional check to avoid crashing.

Signed-off-by: loli10K <ezomori.nozomu@gmail.com>
@mention-bot
Copy link

@loli10K, thanks for your PR! By analyzing the history of the files in this pull request, we identified @behlendorf, @tonyhutter and @heary-cao to be potential reviewers.

Copy link
Contributor

@behlendorf behlendorf left a comment

Choose a reason for hiding this comment

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

LGTM.

@behlendorf behlendorf merged commit 7b0dc2a into openzfs:master Mar 24, 2017
@loli10K loli10K deleted the fix-zdb-openzfs-7280 branch March 24, 2017 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants