nfsrahead: fix uninitialised memory crash and refine fast-path logging
Subsystems (2)
cover nfsrahead: fix uninitialised memory crash and refine fast-path logging
Hi Steve, Yi,
This series addresses two issues stemming from the recent fast-path optimisation used to reject non-NFS block devices, which were caught during blktests.
1. [PATCH 1/2] fixes the glibc abort(3) by explicitly zero-initialising the device_info struct. This prevents the cleanup path from attempting to free uninitialised stack memory when the fast-path triggers an early exit.
2. [PATCH 2/2] updates the error handling in main() to log a descriptive debug message rather than a general error when a device is intentionally skipped, preventing misleading udev journal spam.
Aaron Tomlin (2):
nfsrahead: zero-initialise device_info struct
nfsrahead: quieten misleading error for non-NFS block devices
tools/nfsrahead/main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
Signature · 1 line
2.51.0
PATCH 1/2 nfsrahead: zero-initialise device_info struct
A recent commit introduced a fast-path rejection mechanism to prevent udev worker thread exhaustion. However, this optimisation exposed a bug in the initialisation of the device_info struct in main().
When the fast-path is triggered (e.g., for a physical block device like 8:16), get_device_info() instantly returns -ENODEV. Because this early exit occurs before get_mountinfo() is invoked, init_device_info() is never called.
Consequently, the device_info struct remains populated with uninitialised stack memory. When main() catches the error and jumps to the cleanup path, free_device_info() attempts to call free() on garbage pointers, resulting in a glibc abort(3).
Fix this by explicitly zero-initialising the device_info struct at declaration, preventing the cleanup path from freeing uninitialised memory during an early exit.
--- tools/nfsrahead/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/nfsrahead/main.c +1 -1
@@ -191,7 +191,7 @@ static int conf_get_readahead(const char *kind) {int main (int argc,char **argv) {int ret =0 , opt; -struct device_info device; +struct device_info device = {0 };unsigned int readahead =128 , log_level, log_stderr =0 ;
Signature · 1 line
2.51.0
PATCH 2/2 nfsrahead: quieten misleading error for non-NFS block devices
In reply to Aaron TomlinWhen get_device_info() evaluates a physical block device via the fast-path rejection logic, it deliberately returns -ENODEV.
Previously, main() handled this by logging a D_GENERAL error ("unable to find device"). Because udev invokes nfsrahead for all block devices across the system, this results in misleading journal spam for devices that were intentionally skipped, rather than genuinely missing.
Update the error handling logic in main() to explicitly catch the -ENODEV return code. When encountered, log a more accurate "skipping non-NFS device" message at the D_ALL debugging level. This prevents unnecessary journal noise whilst maintaining the existing behaviour of returning the errno exit status.
--- tools/nfsrahead/main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/nfsrahead/main.c +5 -1
@@ -218,7 +218,11 @@ int main(int argc, char **argv)if ((argc - optind) !=1 )xlog_err ("expected the device number of a BDI; is udev ok?" ); -if ((ret =get_device_info (argv[optind], &device)) !=0 || device.fstype ==NULL ) { + ret =get_device_info (argv[optind], &device); +if (ret == -ENODEV ) { +xlog (D_ALL ,"skipping non-NFS device %s\n" , argv[optind]); + goto out; + }else if (ret !=0 || device.fstype ==NULL ) {xlog (D_GENERAL ,"unable to find device %s\n" , argv[optind]); goto out; }
Signature · 1 line
2.51.0
Hi Aaron
Verified the issue was fixed now with your patch, thanks.
Quoted 26 lines · Aaron Tomlin
Hi Steve, Yi,
This series addresses two issues stemming from the recent fast-path optimisation used to reject non-NFS block devices, which were caught during blktests.
1. [PATCH 1/2] fixes the glibc abort(3) by explicitly zero-initialising the
device_infostruct. This prevents the cleanup path from attempting to free uninitialised stack memory when the fast-path triggers an early exit.2. [PATCH 2/2] updates the error handling in
main()to log a descriptive debug message rather than a general error when a device is intentionally skipped, preventing misleading udev journal spam.Aaron Tomlin (2):
nfsrahead: zero-initialisedevice_infostruct
nfsrahead: quieten misleading error for non-NFS block devicestools/nfsrahead/main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)--
2.51.0
Signature · 2 lines
Best Regards, Yi Zhang
Quoted 5 lines · Yi Zhang
Hi Aaron
Verified the issue was fixed now with your patch, thanks.
Tested-by Yi Zhang <[email protected]>
Thank you very much!!! A new release is on its way!
steved.
Quoted 30 lines · Aaron Tomlin
Quoted 26 lines
Hi Steve, Yi,
This series addresses two issues stemming from the recent fast-path optimisation used to reject non-NFS block devices, which were caught during blktests.
1. [PATCH 1/2] fixes the glibc abort(3) by explicitly zero-initialising the
device_infostruct. This prevents the cleanup path from attempting to free uninitialised stack memory when the fast-path triggers an early exit.2. [PATCH 2/2] updates the error handling in
main()to log a descriptive debug message rather than a general error when a device is intentionally skipped, preventing misleading udev journal spam.Aaron Tomlin (2):
nfsrahead: zero-initialisedevice_infostruct
nfsrahead: quieten misleading error for non-NFS block devicestools/nfsrahead/main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)--
2.51.0
Quoted 5 lines · Yi Zhang
Hi Aaron
Verified the issue was fixed now with your patch, thanks.
Tested-by Yi Zhang <[email protected]>
Hi Yi,
Thank you for testing.
Kind regards,
Signature · 1 line
Aaron Tomlin
Quoted 15 lines · Aaron Tomlin
Hi Steve, Yi,
This series addresses two issues stemming from the recent fast-path optimisation used to reject non-NFS block devices, which were caught during blktests.
1. [PATCH 1/2] fixes the glibc abort(3) by explicitly zero-initialising the
device_infostruct. This prevents the cleanup path from attempting to free uninitialised stack memory when the fast-path triggers an early exit.2. [PATCH 2/2] updates the error handling in
main()to log a descriptive debug message rather than a general error when a device is intentionally skipped, preventing misleading udev journal spam.
Quoted 7 lines
Aaron Tomlin (2):
nfsrahead: zero-initialisedevice_infostruct
nfsrahead: quieten misleading error for non-NFS block devicestools/nfsrahead/main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
Committed... (tag: nfs-utils-2-8-7-rc1)
steved.