-
Couldn't load subscription status.
- Fork 37
mdadm/Assemble: alloc superblock in Assemble #207
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
Conversation
|
@mwilck would you like to take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Assemble.c
Outdated
| * load_devices may release superblock which passes to it | ||
| * and alloc new superblock for it. | ||
| */ | ||
| *super = st; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it would be more obvious if you just pass super instead of &st to load_devices?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do that, use of st should probably be replaced by (*super).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this way, the patch will be a big one because st is used in many places after load_devices.
|
Hi all This patch introduces a regression problem which can be found by case 07autoassemble. The command is: After investigating, the related codes are: Now the logic depends on the original superblock every time. In this patch, it replaces the pointer if the original memory is released. So I plan to remove the first argument supertype in the Assemble function. I'll update this PR after fixing these problems. |
7af474e to
8a3a41d
Compare
|
Hi all I updated the PR and regression test has passed: |
Now it allocs superblock outside Assemble and frees the memory outside Assemble. But the memory can be freed and realloc in Assemble. So freed memory will be dereferenced outside Assemble. This patch moves the memory management into Assemble. So it's more safe and the input arguments is less. This can be reproduced by: mdadm -CR /dev/md0 -l1 -n2 /dev/loop0 /dev/loop1 --assume-clean mdadm -Ss mdadm -A -e 1.2 /dev/md0 /dev/loop0 /dev/loop1 Signed-off-by: Xiao Ni <xni@redhat.com>
8a3a41d to
31c7341
Compare
|
Regression test pass with latest update: |
load_devices may replaces superblock pointer if it finds the better one from member disks. In this way, it releases the memory which passes to Assemble by argument pointer st. The function main doesn't know this. So it may dereference a memory region which has been released after existing from Assemble.
This can be reproduced by:
mdadm -CR /dev/md0 -l1 -n2 /dev/loop0 /dev/loop1 --assume-clean mdadm -Ss
mdadm -A -e 1.2 /dev/md0 /dev/loop0 /dev/loop1
This patch uses a double pointer as the argument for Assemble. So it can reset the pointer after load_devices.