From nobody Mon Sep 16 18:50:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1720451760; cv=none; d=zohomail.com; s=zohoarc; b=FTgnN/EI8sKvZhwKgWThHutAfjXsKO+67xdHV1ZIZ0JQFmgisJLhxihfRcnPsCCyESluGzIcSRYdA6684S9yMgA1Dvw0h7NbeSr7sr0Cgywgh4GAepI81vQWkdcpJXJoVgQhq6Tmc4s5sjDBbBWYKNWK8+79Jz3amOIcfuMExYU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720451760; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=JorMuW4I5W/Tw/+HTvqxoRUw26KYmT9WGUSw3CyJxJk=; b=LFb7R5WFHtCVyN+L9CCHqS7Bx57S1wHy8u4ENx9TzatmcDI5cebTozjYVaDYHhrHqEQyRrUqKis6U4tvCUBwFSCn55nrmlvE8IwileiIrhXg2SaHMp1I0FlMJcaLGtIC2Akb06O1NdpPmU2pl41QOQ73U1eIEKLo5NIaK4nBhUo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1720451760683316.7966539059246; Mon, 8 Jul 2024 08:16:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.755488.1163855 (Exim 4.92) (envelope-from ) id 1sQq5R-0003fR-Q1; Mon, 08 Jul 2024 15:15:29 +0000 Received: by outflank-mailman (output) from mailman id 755488.1163855; Mon, 08 Jul 2024 15:15:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sQq5R-0003fK-NC; Mon, 08 Jul 2024 15:15:29 +0000 Received: by outflank-mailman (input) for mailman id 755488; Mon, 08 Jul 2024 15:15:28 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sQq5Q-0003fE-T1 for xen-devel@lists.xenproject.org; Mon, 08 Jul 2024 15:15:28 +0000 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [2a00:1450:4864:20::631]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e7a3bc23-3d3c-11ef-8776-851b0ebba9a2; Mon, 08 Jul 2024 17:15:26 +0200 (CEST) Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-a728f74c23dso481373766b.1 for ; Mon, 08 Jul 2024 08:15:26 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a872df7sm2306066b.224.2024.07.08.08.15.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jul 2024 08:15:24 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e7a3bc23-3d3c-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1720451725; x=1721056525; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=JorMuW4I5W/Tw/+HTvqxoRUw26KYmT9WGUSw3CyJxJk=; b=GIdsnE9ITZj69Qxfh/B07MhuPVK73xfPJFzV8TLoxtG6NoUlW2BXfH7yLo71+OEoWZ fuVbAtgHZn4F1+ojZ29kU89NlCAQXQbJ5Q28DKFxGz8zLDpiI8UcGOMKr/MyRr7Gz3bZ zJScDL4dDxjJnSERnh++4h19hQJ6dKVTR/VlE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720451725; x=1721056525; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JorMuW4I5W/Tw/+HTvqxoRUw26KYmT9WGUSw3CyJxJk=; b=j9oCh2Z1uKOehWAbML8N1UpSs5eoSnvy/nBN52KQeO954Fq9bEIzxn2UP1wfkbXabs RJniwKhiHgLTuux0yWHvE+y9J0/PFMBkzesuksNjO2DX79RRoPSHGkO/iMQ4nAVMecuC pTagqGR0yIxb/5r7jhUfmHovV1zscMt6pVUE1UfX2ogMPw/dYdUYAQtXIJSK9yimYfFH LGwPncnZDMiEp4SdXLaAcUT02YCnnw+4r1XHejfDjKDV6Tvib3LhIHWbYHUwV4XCRJ33 KXYCEaWI9kb0sL7F55XYU0eIVz3lyvu0oql0KSA8a0JEMaPKVLxfnQs5/swcDTPetb/2 92sQ== X-Gm-Message-State: AOJu0YzsbMfdD3Aw3X7d+mLOhvuGP6nuewOHiOG6tZsQom5tMz2MJS/U SNWuoUtBl3amkbdngVTdEyPemECgOIyUwT1EsUY0DS02SS4akthwinO4zXUx3nhL4vJBSU+38fh i X-Google-Smtp-Source: AGHT+IFnbEosj0cuR/WmvUenjK8i+dT+ovnQFtFih9q68pm05a0xRhwtiufROB/43GZoqB9X+sl5TA== X-Received: by 2002:a17:906:1c13:b0:a77:c002:e4ac with SMTP id a640c23a62f3a-a77c002eafbmr657468766b.0.1720451725269; Mon, 08 Jul 2024 08:15:25 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Ross Lagerwall , Anthony PERARD , Juergen Gross , Oleksii Kurochko , Jan Beulich Subject: [PATCH for-4.19] tools/libxs: Fix fcntl() invocation in set_cloexec() Date: Mon, 8 Jul 2024 16:15:22 +0100 Message-Id: <20240708151522.2176290-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1720451762739100001 Content-Type: text/plain; charset="utf-8" set_cloexec() had a bit too much copy&pate from setnonblock(), and insufficient testing on ancient versions of Linux... As written (emulating ancient linux by undef'ing O_CLOEXEC), strace shows: open("/dev/xen/xenbus", O_RDWR) =3D 3 fcntl(3, F_GETFL) =3D 0x8002 (flags O_RDWR|O_LARGEF= ILE) fcntl(3, 0x8003 /* F_??? */, 0x7ffe4a771d90) =3D -1 EINVAL (Invalid argum= ent) close(3) =3D 0 which is obviously nonsense. Switch F_GETFL -> F_GETFD, and fix the second invocation to use F_SETFD. W= ith this, strace is rather happer: open("/dev/xen/xenbus", O_RDWR) =3D 3 fcntl(3, F_GETFD) =3D 0 fcntl(3, F_SETFD, FD_CLOEXEC) =3D 0 Fixes: bf7c1464706a ("tools/libxs: Fix CLOEXEC handling in get_dev()") Reported-by: Ross Lagerwall Signed-off-by: Andrew Cooper Reviewed-by: Juergen Gross Reviewed-by: Ross Lagerwall --- CC: Anthony PERARD CC: Juergen Gross CC: Ross Lagerwall CC: Oleksii Kurochko CC: Jan Beulich I'm embarassed to say that this was only spotted by Ross when I was cherrypicking fixes from staging-4.17 into the XenServer patchqueue. This is urgent to take for 4.19, and to backport into 4.17/18 seeing as the breakage has been backported already. --- tools/libs/store/xs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/libs/store/xs.c b/tools/libs/store/xs.c index c8845b69e284..38a6ce3cf2ea 100644 --- a/tools/libs/store/xs.c +++ b/tools/libs/store/xs.c @@ -182,12 +182,12 @@ static bool setnonblock(int fd, int nonblock) { =20 static bool set_cloexec(int fd) { - int flags =3D fcntl(fd, F_GETFL); + int flags =3D fcntl(fd, F_GETFD); =20 if (flags < 0) return false; =20 - return fcntl(fd, flags | FD_CLOEXEC) >=3D 0; + return fcntl(fd, F_SETFD, flags | FD_CLOEXEC) >=3D 0; } =20 static int pipe_cloexec(int fds[2]) --=20 2.39.2