Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 12 Feb 2023 21:23:21 +0300
From: Alexey Izbyshev <izbyshev@...ras.ru>
To: musl@...ts.openwall.com
Subject: Re: [PATCH] mq_notify: fix close/recv race on failure path

On 2023-02-12 03:32, Rich Felker wrote:
diff --git a/src/mq/mq_notify.c b/src/mq/mq_notify.c
index a42888d2..8eac71ed 100644
--- a/src/mq/mq_notify.c
+++ b/src/mq/mq_notify.c
@@ -10,6 +10,8 @@
  struct args {
  	sem_t sem;
  	int sock;
+	mqd_t mqd;
+	int err;
  	const struct sigevent *sev;
  };

@@ -21,8 +23,21 @@ static void *start(void *p)
  	int s = args->sock;
  	void (*func)(union sigval) = args->sev->sigev_notify_function;
  	union sigval val = args->sev->sigev_value;
+	struct sigevent sev2;
+	static const char zeros[32];
+	int err = 0;

+	sev2.sigev_notify = SIGEV_THREAD;
+	sev2.sigev_signo = s;
+	sev2.sigev_value.sival_ptr = (void *)&zeros;
+
+	err = 0;

This assignment is redundant.

Maybe this hunk could be simplified by getting rid of err and simply 
doing "args->err = -__syscall(SYS_mq_notify, args->mqd, &sev2)".

Except for this nit, the patches look good to me, thanks!

Alexey

+	if (syscall(SYS_mq_notify, args->mqd, &sev2) < 0)
+		err = errno;
+	args->err = err;
  	sem_post(&args->sem);
+	if (err) return 0;
+
  	n = recv(s, buf, sizeof(buf), MSG_NOSIGNAL|MSG_WAITALL);
  	close(s);
  	if (n==sizeof buf && buf[sizeof buf - 1] == 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.