Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Mon, 12 Oct 2020 15:59:01 +0300
From: Jouni Roivas <jouni.roivas@...era.com>
To: <musl@...ts.openwall.com>
Subject: [PATCH] Skip writing first iovec if it's empty

In case the first iovec is empty, skip writing it. Usually writing
zero length iovec is no-op, but in case of certain special cases this
causes the write to fail.

This affects at least cgroups under sysfs, since it doesn't properly
support writev with multiple iovec. For those kernel tends to handle
them as simple as possible, passing each iovec separately. In case
of zero length write into cgroups file causes kernel to return error.
Thus if writing the first iovec fails for being zero length, it
causes the whole write to fail even if writing the second iovec would
succeed. This happens for example when doing unbuffered write with
musl to a file under cgroups. Fix the issue here, since if kernel
gets fixed for this specific case, it still doesn't get fixed for
older kernels, nor any other possible similar case.
---
 src/stdio/__stdio_write.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/stdio/__stdio_write.c b/src/stdio/__stdio_write.c
index d2d89475..eedce03a 100644
--- a/src/stdio/__stdio_write.c
+++ b/src/stdio/__stdio_write.c
@@ -11,6 +11,10 @@ size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len)
 	size_t rem = iov[0].iov_len + iov[1].iov_len;
 	int iovcnt = 2;
 	ssize_t cnt;
+	if (iov[0].iov_len == 0) {
+		iov++;
+		iovcnt--;
+	}
 	for (;;) {
 		cnt = syscall(SYS_writev, f->fd, iov, iovcnt);
 		if (cnt == rem) {
-- 
2.25.1

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.