[minicoredumper] The read will in all infinite loop #8

Dongyang dongyang626 at gmail.com
Wed Mar 22 03:28:28 CET 2023


Hi guys,

I don't see my previous email in the
https://lists.linutronix.de/pipermail/minicoredumper/
And I also don't see any feedback. Not sure whether you received the email.
So I re-sent the email again.  :)

Best Regards,
Dongyang

Dongyang <dongyang626 at gmail.com> 于2023年3月20日周一 22:17写道:

> Dear all,
>
> I created an issue at  https://github.com/diamon/minicoredumper/issues/8
> Maybe some guys only check their email. So I also forward the contents to
> this mailing list, thanks :)
>
> In the below situation, the read will in an infinite loop:
>
> If the PID 123 triggered the core dump and Minicoredumper started to read
> the /proc/123/mem (dump_compressed_tar-->copy_data-->read_file_fd).
> At this time, if the OOM is triggered, then the PID 123 is killed by
> SIGKILL.
> The read will return zero.
>
> But in the read_file_fd, the code doesn't check the zero condition.   When
> the "r" is 0,  the "len" will never to 0,  then into an infinite loop.
>
> static ssize_t read_file_fd(int fd, char *dst, int len)
> {
> 	size_t size = 0;
> 	int r;
>
> 	do {
> 		r = read(fd, dst + size, len);
>
> 		if (r == -1) {
> 			info("Couldn't read file fd=%d; error %s", fd,
> 			     strerror(errno));
> 			return r;
> 		}
>
> 		if (r > 0) {
>
> 			size += r;
> 			len -= r;
> 		}
> 	} while (len > 0);
>
> 	return size;
> }
>
> I'm also checking whether the read return zero is reasonable.  Maybe it
> should return -1 (Input/output error)?
>
> Anyway, I think we need to add a check for "read return 0".
>
> Here is our patch, please check it, thanks :)
>
> 0001-minicoredumper-add-return-check-for-read-funcfion.patch
> <https://github.com/diamon/minicoredumper/files/11019031/0001-minicoredumper-add-return-check-for-read-funcfion.patch>
>
> Best Regards,
> Dongyang
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linutronix.de/pipermail/minicoredumper/attachments/20230322/0a814d02/attachment.htm>


More information about the minicoredumper mailing list