From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=159.69.126.157 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796564559; b=3tXwPn7Z+wGeb3VOYwjYv8mRLSV+JRrg1Yzqhdn2MoQz3M0Cq+dR/nn9sJcFiVN9rFc2 wvZSY9qWJ3Rt3WFW9a295k6gX1sUAcurVBG/i451NqvKYZDNO4yB/0GxPpGpBdrC9BTWU wD7ssSJEZJKjMjDDM124nFCEnhu1rc19NDvaPCAGXgt4rTQzbl2IbcpC1+Gf/wb0npIeh qVU/Sd6sZ00SLiAg9W1R4SqgDAubrMuwaNfHgaxg1zz+4YEthYKbSv18/AP+9jplXUzEt WAamzSxsyhtoXmjmscMeTL3TOIoQ2EVXrBHwxUZbBM/CYHaQcaCMoi7ZOvAC1hjKJRg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796564559; h=DMARC-Filter:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition: Content-Transfer-Encoding:In-Reply-To; bh=7HiEQqh+tsfIlgfufmlAQrhFzg1GQlNUYlLLCpnlmuM=; b=5VtG72IENz+EyRgQmoWqrCdXVjzI2U1/o2YbKdTCDFNGCG3ACxgbrgWGqWSG5Vv6gKgz 72e4SNbKUTWKt6vuDCUc+zE1zgSncc7B5G/+nLV3XemL5XJlb1IGy865tl+dzeE8UGQ5y qGBW18FbntzMDTo9FZKXq7v+/6uVLAZ/JqC04YsnPdjgz/WJ+GpCQrzK/qBFnEG0irQ48 5kNIe0j6KL+vJUVoOnt2m6OTvDzlgKBTyhNJumXetngmqBkuW6PmDew5vtCRP9BR1CpAn uPSY2TumXRItcbwNmTzZb084awDJ7zZmWUUFfPZtYgsURrAvdu9SDqUMnpY43QA/W0g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass header.d=weissschuh.net header.i=@weissschuh.net header.a=rsa-sha256 header.s=mail header.b=tXhcwsLs; arc=none smtp.remote-ip=159.69.126.157 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7DCC606A321 for ; Sun, 6 Dec 2026 13:42:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A7DCC606A321 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=weissschuh.net header.i=@weissschuh.net header.a=rsa-sha256 header.s=mail header.b=tXhcwsLs DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1796564550; bh=P2CKahsf00fL/hJu/uR+JwLZJekjt3WrkD/G/ddY6YA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=tXhcwsLs1kTSVA0Z3p/o19+RKSVQwQBESuAyIc0li2192tHhXYxHKw4abdGs2ixEZ lNRMvzsJuz45AHoKosiZFDNc0zw1j1+XBv6ii8GNWBxbrdzm/eJL/B4BH/nd31KIiH c8JFWGnshTWHbjg09pjNxT0NFPFI/ZlwouK7fLjk= Date: Sun, 6 Dec 2026 14:42:30 +0100 From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: David Laight Cc: Willy Tarreau , linux-kernel@vger.kernel.org, Danish Khateeb , hch@lst.de Subject: Re: [PATCH v2 3/4] tools/nolibc: add support for fcntl() Message-ID: <82fbde7b-8896-4909-88dc-c535abeba76b@message-id.t-8ch.de> References: <20261202-nolibc-fcntl-v2-0-651ff5781baa@weissschuh.net> <20261202-nolibc-fcntl-v2-3-651ff5781baa@weissschuh.net> <20261206130803.60d5f61d@pumpkin> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20261206130803.60d5f61d@pumpkin> Hi! On 2026-12-06 13:08:03+0000, David Laight wrote: > On Sat, 5 Dec 2026 15:25:36 +0100 > Willy Tarreau wrote: > > On Wed, Dec 02, 2026 at 08:29:48AM +0100, Thomas Weißschuh wrote: > > > Add the fcntl() function. > > > > > > Special handling is necessary for 'struct flock'. > > > The definition from the UAPI headers is not large-file capable. > > > Provide a custom definition which is compatible with 'struct flock64' > > > on 32-bit systems and 'struct flock' on 64-bit ones. > > > > > > Signed-off-by: Thomas Weißschuh > > (...) > > > --- a/tools/include/nolibc/types.h > > > +++ b/tools/include/nolibc/types.h > > > @@ -32,6 +32,21 @@ struct timeval { > > > #include > > > #undef timeval > > > > > > +struct flock { > > > + short l_type; > > > + short l_whence; > > > + __kernel_loff_t l_start; > > > + __kernel_loff_t l_len; > > > + __kernel_pid_t l_pid; > > > +#if defined(__sparc__) > > > + short __pad; > > > +#endif > > > +}; > > > > The commit message makes no mention of this pad and nothing here explains > > why it is necessary nor if other architectures might need it in the > > future. I suspect it might be that __kernel_pid_t would be 16-bit there, > > but I really don't know. I think a comment here in front of__pad to say > > why/when it's needed would help. > > My brain remembers something about sparc having an extra field. > But I can't remember what it was used for, and it was __unused when the > file was added to Linux for 1.3.44. > The corresponding types.h has a 32bit pid_t - so it isn't just an > explicit pad. > (Although SunOS might have had a 16bit pid and made the pad reasonable.) > > I think it also pointless, The size of the structure isn't passed into the > kernel (it would need and ioctl() that used IORW()) and the kernel doesn't > seem to have ever cleared the user field. Because the size is not passed into the kernel it is important to have the padding in the nolibc type. The kernel will read/write as many bytes as its UAPI definition has. If we leave off the padding member the kernel will read/write out of bounds. This will work most of the time for fcntl(), as the bytes are written as they were read just before. However it is racy and can break in wonderous ways if the out of bounds access is in a different mapping. We don't care about the MIPS padding/sysid as these are specific to 32-bit 'struct flock' and there the nolibc 'struct flock' is really 'struct flock64'. I'll add some more explanations for this. > It might be relevant if you were compiling against the Linux headers but > expected to run on some other OS - but that just won't work. > (SYSV sparc binaries would 'just about' run on SunOS - but it was largely > theoretical and was responsible for some nasty bugs.) Nolibc only ever cares about running on Linux. > Rather more problematic is MIPS32, change 9f79b8b7 'simplified' the pad. > But managed to move the l_sysid field the other side of l_pid. Indeed. (...) Thomas