Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp345454pxx; Thu, 29 Oct 2020 04:12:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcqENIsPF2YRuiLpG62EnjY+whcFV5Lnl79ZNaT3kHokyLIZgMz+02syei8gHtP83YPCYF X-Received: by 2002:a05:6402:c12:: with SMTP id co18mr3298580edb.162.1603969973243; Thu, 29 Oct 2020 04:12:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603969973; cv=none; d=google.com; s=arc-20160816; b=Y27m4MKbexN8bl2VkJUkbY7xA6TmiUk1j+iI1Ksdr0Iiyv+OjK9B7wZbz2pvoxgitQ VlcB/CexlB2UwLdR/dXMlY6ppomzyuIRwj8d20xZSeCwW52Ty+f2g4e1+MbsUR2dp7GY Ak+b+ht5hEg9z8v1gESXWnJ07XkmdfCcjRKhGjzGp+vS/4UnfXCm2ggDcgqHBLSCt6sw K6Sp8FYkYKnpD9T6biJBApuIcI+YsJMSBLUeJQIGtFXqIMny+6PCFqzi+x27Gx7YWZpZ O/vFieZ8JS/BujwodZ9WgaDJbgoy6liHiYHCKovv7sn9tp4+pfUUzyO5nR34DyvBPoLH XJ3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:message-id:in-reply-to:date:references:subject:cc:to :from:dkim-signature; bh=aqvn+Wuq7DAtJoPn4mKsiaT5Chc8jfwDj7vkOMTXOn4=; b=VDOce2S8b5qCpDDGvlmQB5ZLXTtpHSksiv1EIhT0BaWwjQE4W6f6h+UHzoguu9cIXh POc4FfkeXa/MADJv79sjUj/RdEL9kchBph0mjnuT9HoUOtzhZY482Vpgr8et2HAPfYg9 JfFwnK/ZZbiN5wGgfWoJSJz8aRLd/rPFoomn4t69t41coP0p9ERAnyr1B2mwlsHVyCEy Ro7BYNy951Liw7fyD5ppflW9EEuVGAAlKXtgPy62qQpRHg2sw2Fj0eVf411s8eYz6NTA 8mIhdaNv07S6pAab+/4gHGzT8DqNpIDnJS62nuIiXFOb+VmG7bU5+t8mMF7sYNYgmpNH jb1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="a6Gv/JuU"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t24si1646300edr.506.2020.10.29.04.12.30; Thu, 29 Oct 2020 04:12:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="a6Gv/JuU"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727661AbgJ2LJv (ORCPT + 99 others); Thu, 29 Oct 2020 07:09:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:27111 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727645AbgJ2LJo (ORCPT ); Thu, 29 Oct 2020 07:09:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603969782; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aqvn+Wuq7DAtJoPn4mKsiaT5Chc8jfwDj7vkOMTXOn4=; b=a6Gv/JuUGMDneiPTdQccYCMb5OdoHXyGbJZ8vLDZC+kSmzCePVa9AEy5oUamsmLn9rMQv5 Az1P0DM2sEt+BkLhmaI1NjONvQabXyOzURLYVVDmmHv4Ui7KEHl8pZGKpB0AIKBWBxRcz3 AlOrfw2Qyi8WrJt/SCssOQ+qOV2Rquk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-70-tjK1E6hEPG24CUiMtdYPcw-1; Thu, 29 Oct 2020 07:09:40 -0400 X-MC-Unique: tjK1E6hEPG24CUiMtdYPcw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 40EF710E2186; Thu, 29 Oct 2020 11:09:39 +0000 (UTC) Received: from oldenburg2.str.redhat.com (ovpn-113-60.ams2.redhat.com [10.36.113.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D3EC8196F3; Thu, 29 Oct 2020 11:09:37 +0000 (UTC) From: Florian Weimer To: Alejandro Colomar via Libc-alpha Cc: libc-help@sourceware.org, Alejandro Colomar , linux-man , "linux-kernel@vger.kernel.org" , "Michael Kerrisk (man-pages)" Subject: Re: Possible bug in getdents64()? References: <829387c9-50d7-3d29-83bf-c4fec17cf9dd@gmail.com> <01065580-8602-52e6-0cca-22d1aa20a540@gmail.com> Date: Thu, 29 Oct 2020 12:09:36 +0100 In-Reply-To: <01065580-8602-52e6-0cca-22d1aa20a540@gmail.com> (Alejandro Colomar via Libc-alpha's message of "Thu, 29 Oct 2020 12:04:13 +0100") Message-ID: <87eelhthjj.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Alejandro Colomar via Libc-alpha: > [[ CC +=3D linux-man, linux-kernel, libc-alpha, mtk ]] > > On 2020-10-28 20:26, Alejandro Colomar wrote: >> The manual page for getdents64() says the prototype should be the >> following: >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int getdents64(unsigned int fd, st= ruct linux_dirent64 *dirp, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned int count); >>=20 >> Note the type of 'count': 'unsigned int' >> (usually a 32-bit unsigned integer). >> And the Linux kernel seems to use those types (fs/readdir.c:351): >> SYSCALL_DEFINE3(getdents64, unsigned int, fd, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct linux_dirent64 __user= *, dirent, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned int, count) >> { >> ... >> } >> But glibc uses 'size_t' (usually a 64-bit unsigned integer) >> for the parameter 'count' (sysdeps/unix/linux/getdents64.c:25): >>=20 >> /* The kernel struct linux_dirent64 matches the 'struct dirent64' type.= =C2=A0 */ >> ssize_t >> __getdents64 (int fd, void *buf, size_t nbytes) >> { >> =C2=A0 /* The system call takes an unsigned int argument, and some leng= th >> =C2=A0=C2=A0=C2=A0=C2=A0 checks in the kernel use an int type.=C2=A0 */ >> =C2=A0 if (nbytes > INT_MAX) >> =C2=A0=C2=A0=C2=A0 nbytes =3D INT_MAX; >> =C2=A0 return INLINE_SYSCALL_CALL (getdents64, fd, buf, nbytes); >> } >> libc_hidden_def (__getdents64) >> weak_alias (__getdents64, getdents64) >>=20 >> Isn't it undefined behavior to pass a variable of a different >> (larger) type to a variadic function than what it expects? >> Is that behavior defined in this implementation? >> Wouldn't a cast to 'unsigned int' be needed? There is no variadic function involved here. INLINE_SYSCALL_CALL takes care of the zero extension to the register internally, irrespective of the argument type. (The register is of type long int or long long int, depending on the architecture.) Thanks, Florian --=20 Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn, Commercial register: Amtsgericht Muenchen, HRB 153243, Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'N= eill