From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4ECC81420BE; Tue, 23 Apr 2024 21:44:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713908693; cv=none; b=LOmsuOAIJx9czUAs/TFdy8lPZY9Z1CKanUWlH6FJXGpiY886HkA7ciKPSm2p9qEj+pl7ZWLCSHLTBHLp2XM2k+u3cU7jRtfxDCocrrvb/Mcptgnikttm4EH/FTOdwoBrUzZr1kBgm+UtfoCmKO57fnOwZqcPF6+ZVu34rALYs1o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713908693; c=relaxed/simple; bh=SVuihGkICe0yqTPq6ROZuDvS4cRylPJMkjEm1iTaiDk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KHWsAvNIysGkvZoC93vgOSiKqAoadhdiNdgVSTzhr2LfiMQLn7XKShnoJ/RVk7glMaGBtVfLPZBjUrShkxWod71jFbMNNtFzuPua83aR8RuNYTa2xGKKeXQUgMlCZmtTKWKP3I59QBORlYbK+nVgyxFexHZCL1KqxeHV15e2+0U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=dR1E4tSx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="dR1E4tSx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BADFC32782; Tue, 23 Apr 2024 21:44:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1713908693; bh=SVuihGkICe0yqTPq6ROZuDvS4cRylPJMkjEm1iTaiDk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dR1E4tSxgcsk1J8pHDUDhxCG3++PU1VYzm/HsHHmBhd5HEegOdulZ/iFqokyqeNyD 3ZHyNuIcobonaNriEbm0yuI4T4E3lBQKQqRNcWJwbSCDNhm/dl3ei32NnMR3PR7U8L +SuRcfAyzTnwcP08c50mM+zz3faVJXlklqEaKbc0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kuniyuki Iwashima , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.1 041/141] af_unix: Dont peek OOB data without MSG_OOB. Date: Tue, 23 Apr 2024 14:38:29 -0700 Message-ID: <20240423213854.605817900@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423213853.356988651@linuxfoundation.org> References: <20240423213853.356988651@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kuniyuki Iwashima [ Upstream commit 22dd70eb2c3d754862964377a75abafd3167346b ] Currently, we can read OOB data without MSG_OOB by using MSG_PEEK when OOB data is sitting on the front row, which is apparently wrong. >>> from socket import * >>> c1, c2 = socketpair(AF_UNIX, SOCK_STREAM) >>> c1.send(b'a', MSG_OOB) 1 >>> c2.recv(1, MSG_PEEK | MSG_DONTWAIT) b'a' If manage_oob() is called when no data has been copied, we only check if the socket enables SO_OOBINLINE or MSG_PEEK is not used. Otherwise, the skb is returned as is. However, here we should return NULL if MSG_PEEK is set and no data has been copied. Also, in such a case, we should not jump to the redo label because we will be caught in the loop and hog the CPU until normal data comes in. Then, we need to handle skb == NULL case with the if-clause below the manage_oob() block. With this patch: >>> from socket import * >>> c1, c2 = socketpair(AF_UNIX, SOCK_STREAM) >>> c1.send(b'a', MSG_OOB) 1 >>> c2.recv(1, MSG_PEEK | MSG_DONTWAIT) Traceback (most recent call last): File "", line 1, in BlockingIOError: [Errno 11] Resource temporarily unavailable Fixes: 314001f0bf92 ("af_unix: Add OOB support") Signed-off-by: Kuniyuki Iwashima Link: https://lore.kernel.org/r/20240410171016.7621-3-kuniyu@amazon.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/unix/af_unix.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 6af6f82e89464..f28e2956fea58 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -2675,7 +2675,9 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk, WRITE_ONCE(u->oob_skb, NULL); consume_skb(skb); } - } else if (!(flags & MSG_PEEK)) { + } else if (flags & MSG_PEEK) { + skb = NULL; + } else { skb_unlink(skb, &sk->sk_receive_queue); WRITE_ONCE(u->oob_skb, NULL); if (!WARN_ON_ONCE(skb_unref(skb))) @@ -2757,11 +2759,9 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state, #if IS_ENABLED(CONFIG_AF_UNIX_OOB) if (skb) { skb = manage_oob(skb, sk, flags, copied); - if (!skb) { + if (!skb && copied) { unix_state_unlock(sk); - if (copied) - break; - goto redo; + break; } } #endif -- 2.43.0