From patchwork Mon Apr 22 09:25:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shoaib Rao X-Patchwork-Id: 13638091 X-Patchwork-Delegate: kuba@kernel.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 2971A4CB55 for ; Mon, 22 Apr 2024 09:25:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713777920; cv=fail; b=qk4MWIqW8ChNymdnHl0hZ30Psrnic1/RYZWkYlDQb/Jx2GeROHZroCcwR0ii/PPgrE2gglWLSjLv56hYbM9RIf2p9zJIQZAtd0YEovkOip65ylFi2KK5Bm772utNkwCY8IQxag24ZfYdupma3foS2DQxZx3V/qVrlcnsc8/M0Bs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713777920; c=relaxed/simple; bh=fqk6nznsJ30uU6CulbfOU7I8vMmvnM4GE9s+AO3/stw=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=EuMsttRVXzcgdXq/Qaax1IkPmc9B03G+B7TNN83Yn7zO7YpyyZW6RCfXmZOYiNB+kus4K4Is8NmiMoaZh3wWCZorXWUqvhfG16jjVLRkqAhFhuteqdwbvshxxLql78p255aLfMv2he4wnChJZLVNpd4t+1EgJK1iaMPC6zw/umY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=aFT7CMt6; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=I1eleJ8U; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="aFT7CMt6"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="I1eleJ8U" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43M8AUwk009688; Mon, 22 Apr 2024 09:25:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=PaZOnVWchFQMlVS/D3PmBOqVkOGf5l+BW56QIJn5fz8=; b=aFT7CMt6mxDNXEtG6qnyOpX+gXPAS/GHfwvMQw3BlENHirSeTBozp+vfxbOA7k2Pqaj7 lA8DrQVOpDwJJsabH0s1mvT8fItHaQkcuBQXs44IsLDGu62a/BoVjvjpdZFhujPCdmOx IR94vxOfLGIKqwdq4RlZM6Z4jhovmDimwB0BHuX18IfgeXZWL6+SAMHqTmJjvB36jnhS p4tDdA12+W4ESyeZ9umIiGQroUSC+dzXsGP8KtcykLAXZ7qqY+7DaY8UyEcqHM/IwFLK NLMiw4r6LfwgiL48yP63I/CClywPbADuD9eHw1NALX/DAcYIcSIzKzppGhPRGx93CrYx JQ== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xm4a2a8qq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Apr 2024 09:25:11 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43M8MfMD010913; Mon, 22 Apr 2024 09:25:10 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2169.outbound.protection.outlook.com [104.47.57.169]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xm455pbte-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Apr 2024 09:25:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aepF+6dvI8uPSUH7bhJLH3Y+CWOILteFVIV3vjmx43Hxid2uS7hXyKJwGwstKiHkznZDspXlj20GGJhsa151qo+PFQ6l7t5RvWaGnXEwTByro7uJE8whPdMnZLnG9dR2g7UqSUZ0vFoKfqE+je+u0eFmat5NAbNvnepi0Ym0Uhbnbjy/Lk9HQ2haGkcnZk9FIdfk3Tzbd0lS6iW9UgsIuJl1NF8MealIUPVLhy1Zmgo1A49l4GO6niMMKKkklk0789adShVDkk1W2TDDinapK6hglwv1oFq6DJe1VR2drRhZLHWenGiUbzcmLzoXS6TKy7kckk36NzfelNsdmuv8Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PaZOnVWchFQMlVS/D3PmBOqVkOGf5l+BW56QIJn5fz8=; b=YN1uwKkNW9fj6gF8DV9T7r6hX8+Bn6u+ersIHW0Xkm4fevFgvMpB9CctCAdjbW+vFdRZ1+UKGIrikqxZ2BwQuaDQl8rIZ8NJQ5UGYo2CmvyHFRgbu6Bag2zcEoBZUKJ3wdEZkEYgyn7PVO1QzbSHEXZmANpK8FbDdZ5QmZjQdOswv7d+WnRuazghmUYDjo4gH1jR4B8o/Jwj14sSm+q1ifz8MnL1ggU0GNXVWUeHqjZBICowz22CoQcgQKU0HRG87eehJ7ZXHHizj3/GbMTmm+VHF5EO6kHRSnTfFfkJki5dkspYcZdvq7zwTjeHA7O/pG3qXOTQq8vJzenICpqF0A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PaZOnVWchFQMlVS/D3PmBOqVkOGf5l+BW56QIJn5fz8=; b=I1eleJ8UfpZs9rSfBXwYOTj8V0tpQo02pfeSQWT4YaTraT34nIj/c+OLU6BlElshvib+KUqF3molSYzRePzYGXRz4rbGA/KOBTBgUx2ldOtyFvD6Kylg+Syw5V8kN9YS51FN4qvFPFuxIpEfknTM6vFs2pGEiS4iVrLmeU9W4Lk= Received: from CH3PR10MB6833.namprd10.prod.outlook.com (2603:10b6:610:150::8) by CY5PR10MB6071.namprd10.prod.outlook.com (2603:10b6:930:39::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Mon, 22 Apr 2024 09:25:08 +0000 Received: from CH3PR10MB6833.namprd10.prod.outlook.com ([fe80::8372:fd65:d1ad:2485]) by CH3PR10MB6833.namprd10.prod.outlook.com ([fe80::8372:fd65:d1ad:2485%5]) with mapi id 15.20.7472.044; Mon, 22 Apr 2024 09:25:08 +0000 From: Rao Shoaib To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: kuniyu@amazon.com, netdev@vger.kernel.org, Rao Shoaib Subject: [PATCH net v3] af_unix: Read with MSG_PEEK loops if the first unread byte is OOB Date: Mon, 22 Apr 2024 02:25:03 -0700 Message-Id: <20240422092503.1014699-1-Rao.Shoaib@oracle.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: BY3PR05CA0041.namprd05.prod.outlook.com (2603:10b6:a03:39b::16) To CH3PR10MB6833.namprd10.prod.outlook.com (2603:10b6:610:150::8) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR10MB6833:EE_|CY5PR10MB6071:EE_ X-MS-Office365-Filtering-Correlation-Id: e813cc57-7044-4144-4c3b-08dc62ae1a41 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5K23cCzdXs7GpmyUUOKDRjdNtKg6c+0Zmh7v6FKeCiYdVCSh53XggOx89Qf+a/mGZ1KkmzO9qsBnpErBJHE8nCm+hdZbtzW6nBK9oqIQVrtgioXuoykP0DcdT3Ea9Svm0RpBplEUnL9b5mje1DihxvYnyDMuodlMhFKWF4U0rsc07OPiGKEBTV/9muwrJ5cRZxmSSC2yGIGfd8stT2JZ0/1kolHrbWjgEHHCoPCK8bT3S57Foy5CtRVTZm5crHbidMcTDJ67CmmQWS0BQ830DfFNyfZLeMgZM+IsqvFli7ojxs/+3lsq57JAdaZ9A24Iu5v+z41+efTFeBLb5V/eu9xIPNMXRnebWaR5Kiyz4ulJymdvfSigDBEOVfSZlw/oQ0+SFmAKj/d+1qkHEKwz2dijjNicV3DJ7LngX7j+RoVVXk6V+qdspvXduRP/q6L4qfx01vJ34bnsQ1sivGwPlY36Vksc8nyB7NdYIQZkhucO3nIA3DIUoS+QQV8tj0Rz/wdMqDM6xcKGGGxWFY8VaGeK8RJnCdhqdQzYp2vGYR1be4naPKxQUQYFZSnK7C6P0cy8CeT48MtMsk34/5xgbCd4W/3AKdwpzbj6p++69nbkQd/Y18RchSGg6rzmsAPnf6IRUf6Dq5v1N6c/0ZzXcU1OWg7RmwxpGgwPfR+RidJHyUrPuN8UoBrTSDvLNFLRD/BWDqIf8bmttdwCbgss9WGNEnBWQ6BwNwBYoMTN7PZwTtqRy7ahKEEMTdNwBbRxeWxVFSxwYmaVu4rwzKxRXtBAINeBreRaJxCnusATiWSvf5SWxoDatci+LanmItkJ7Z6P3+Yjqo1XN+6A3uxFR3JaDazY0lDZ3tPnRkvhvlAH/379AfX/XUFX26TsUC/8Zo9QzsbsSbhjvoNsJajfD/yQAH1tEjNaaXO/UrNRRW3PakfQLdrFbeFrOf5BmHT7+Yl/odVKDGDvOvNARM0CP9j8DtMiQtgArd+ipMEMHoXnKu6CfrC9yuHzBeTziDocESqn0Yc0tVehrB9BhiQdAtJcVZWqI8VDr/TFIKGAbb9aOVb2djdhOsTP+T7eGxRlPHxTKzJtI6o7a6FVyymaQyBsguplpWQ2Aq0rwg35A7aWIgCAlNrJBo9w/a4fFdO+p4BcMJWrgTR7KXlZDJo3F6W22u3Y6IYibbEzlgX3w+3QGOYWhD0wp7YS/I8MlLFXS43bg3xzEUJY1CDdQdXxJdRjvxjMijQFANGE3/fZ34VZ2zsNKpUB5arWra83xB/BvB8zUrAK3miRof5c0AFsKA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR10MB6833.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366007)(1800799015)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YPwpo80Mv5uswoEdx/8WO3WCEcWNFxE7HHVb8JzGwfrE9Of8DHJWuee4s3g2E/b5TvVx/bSgxvH436bahi8j40OpyWONPiV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BPk0dmcMIuAI8dv0zVsOBqVpSpYHW0e5Nx4Sif8XdpM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e813cc57-7044-4144-4c3b-08dc62ae1a41 X-MS-Exchange-CrossTenant-AuthSource: CH3PR10MB6833.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2024 09:25:08.5431 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: AWFJB8UWNopKP1k46pXYC+4Vs3XXpxHDIr7DmgQxpq3uXewny45gQMABdCtn7ftNPotoJHCoMHkOSSTxiX2bwQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR10MB6071 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-22_05,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404220038 X-Proofpoint-GUID: SSQPVr37asVU4uKQvDVcsldGCFUx7fIb X-Proofpoint-ORIG-GUID: SSQPVr37asVU4uKQvDVcsldGCFUx7fIb X-Patchwork-Delegate: kuba@kernel.org Read with MSG_PEEK flag loops if the first byte to read is an OOB byte. commit 22dd70eb2c3d ("af_unix: Don't peek OOB data without MSG_OOB.") addresses the loop issue but does not address the issue that no data beyond OOB byte can be read. >>> from socket import * >>> c1, c2 = socketpair(AF_UNIX, SOCK_STREAM) >>> c1.send(b'a', MSG_OOB) 1 >>> c1.send(b'b') 1 >>> c2.recv(1, MSG_PEEK | MSG_DONTWAIT) b'b' Fixes: 314001f0bf92 ("af_unix: Add OOB support") Signed-off-by: Rao Shoaib --- net/unix/af_unix.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 9a6ad5974dff..ed5f70735435 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -2658,19 +2658,19 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk, if (skb == u->oob_skb) { if (copied) { skb = NULL; - } else if (sock_flag(sk, SOCK_URGINLINE)) { - if (!(flags & MSG_PEEK)) { + } else if (!(flags & MSG_PEEK)) { + if (sock_flag(sk, SOCK_URGINLINE)) { WRITE_ONCE(u->oob_skb, NULL); consume_skb(skb); + } else { + skb_unlink(skb, &sk->sk_receive_queue); + WRITE_ONCE(u->oob_skb, NULL); + if (!WARN_ON_ONCE(skb_unref(skb))) + kfree_skb(skb); + skb = skb_peek(&sk->sk_receive_queue); } - } 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))) - kfree_skb(skb); - skb = skb_peek(&sk->sk_receive_queue); + } else if (!sock_flag(sk, SOCK_URGINLINE)) { + skb = skb_peek_next(skb, &sk->sk_receive_queue); } } } @@ -2747,9 +2747,11 @@ 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 && copied) { + if (!skb) { unix_state_unlock(sk); - break; + if (copied || (flags & MSG_PEEK)) + break; + goto redo; } } #endif