From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from albireo.enyo.de (albireo.enyo.de [37.24.231.21]) by sourceware.org (Postfix) with ESMTPS id 0A4E8385780A for ; Mon, 16 Nov 2020 21:22:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0A4E8385780A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=deneb.enyo.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=fw@deneb.enyo.de Received: from [172.17.203.2] (helo=deneb.enyo.de) by albireo.enyo.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) id 1kelxd-0004Nd-69; Mon, 16 Nov 2020 21:22:53 +0000 Received: from fw by deneb.enyo.de with local (Exim 4.92) (envelope-from ) id 1kelxd-0004L9-3R; Mon, 16 Nov 2020 22:22:53 +0100 From: Florian Weimer To: Adhemerval Zanella via Libc-alpha Subject: Re: [PATCH] linux: mips: Fix getdents64 fallback on mips64-n32 References: <20201116211743.2228063-1-adhemerval.zanella@linaro.org> Date: Mon, 16 Nov 2020 22:22:53 +0100 In-Reply-To: <20201116211743.2228063-1-adhemerval.zanella@linaro.org> (Adhemerval Zanella via Libc-alpha's message of "Mon, 16 Nov 2020 18:17:43 -0300") Message-ID: <873619gfo2.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_NUMSUBJECT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Nov 2020 21:22:56 -0000 * Adhemerval Zanella via Libc-alpha: > GCC mainline shows the following error: > > ../sysdeps/unix/sysv/linux/mips/mips64/getdents64.c: In function '__getdents64': > ../sysdeps/unix/sysv/linux/mips/mips64/getdents64.c:121:7: error: 'memcpy' forming offset [4, 7] is out of the bounds [0, 4] [-Werror=array-bounds] > 121 | memcpy (((char *) dp + offsetof (struct dirent64, d_ino)), > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 122 | KDP_MEMBER (kdp, d_ino), sizeof ((struct dirent64){0}.d_ino)); > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > ../sysdeps/unix/sysv/linux/mips/mips64/getdents64.c:123:7: error: 'memcpy' forming offset [4, 7] is out of the bounds [0, 4] [-Werror=array-bounds] > 123 | memcpy (((char *) dp + offsetof (struct dirent64, d_off)), > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 124 | KDP_MEMBER (kdp, d_off), sizeof ((struct dirent64){0}.d_off)); > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > The issue is due both d_ino and d_off fields for mips64-n32 > kernel_dirent are 32-bits, while this is using memcpy to copy 64 bits > from it into the glibc dirent64. > > The fix is to use a temporary variable to read the correct type > from kernel_dirent. I think I suggested to cut back on the macro magic and simply have appropriately defined structs, with a sequence like this: memcpy to first temporary struct field-by-field assignment from first temporary struct to second struct memcpy from second temporary struct Would that work? (Sorry if my message got through and this suggestion was already considered.)