From nobody Thu May 2 21:15:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1584444804; cv=none; d=zohomail.com; s=zohoarc; b=YCOFomOsdHEyF2dqZJEzK7s1zBvfSL9EtyIl9CEzgZwC84SEL6pkdo8YJ3TDNh8yu0eashERxHLPPXRapRJH2PIxbibH4JBeiCJCtT0HPc6FUlNoMmbARrG/uSzCe+bF/x6f9N59YcA0UZ9tciMwPy8bHdK1uUOJhkSYWhPN8Fk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584444804; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=WmJlBqTMa5CmdiFIToGjODDNiC8IWRj11NilEIEtQyE=; b=bxIhWyImoYhLO03u9/llJinca2jcym2QquK2n6Kic27Bkf2kPN3PnSyfU1o20tT3RTwxzPO2DN+BoYUxxJqqta5ABiw9M8WHD4insKwfA4vpCrr8BFgv9eoxeSqfSZGqDNC6VAqkK6xGyhD4yv8UVpgtRsaynGgWr/vFEd/LOOw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158444480461022.915042485279173; Tue, 17 Mar 2020 04:33:24 -0700 (PDT) Received: from localhost ([::1]:58986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEATL-0002s2-By for importer@patchew.org; Tue, 17 Mar 2020 07:33:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35019) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEAS1-0002QX-GT for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:32:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEARz-0008W2-Rl for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:32:01 -0400 Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]:34341) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEARz-0008DR-GI for qemu-devel@nongnu.org; Tue, 17 Mar 2020 07:31:59 -0400 Received: by mail-lj1-x242.google.com with SMTP id s13so22388985ljm.1 for ; Tue, 17 Mar 2020 04:31:59 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id a18sm2105691ljn.85.2020.03.17.04.31.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Mar 2020 04:31:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WmJlBqTMa5CmdiFIToGjODDNiC8IWRj11NilEIEtQyE=; b=F+QLlWXHueXk9FIie+nFx5HGLWeGdYJkP1o+weY4/OE7tGYvjaycevNwN888rlgn8/ nTLBUXpuzAe/IDou25ef/q2vc4WvRwwug6YUdLnhfXfZVDS8027fcl7ELowhrgXoSEtY KB/HU3ypUqaJZR6sLIjBk22EL59kT6FsLYCgoS79hCVnV/7uXK3bACbOAImWiQ5zfDmV OlqVjFhQ0dUs97Wu5f1FzjrVVB4iciokJnoUKu5vXptLshhJeBCg7P7kDhQ349KTiC7w /97l8ecM3Q9N+M80A4VduEj/zPXxW7kDiUmHHsoK/FaHIwVXsqo7l7hu1VHHRoZeT6xI r3Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WmJlBqTMa5CmdiFIToGjODDNiC8IWRj11NilEIEtQyE=; b=pjwsuP8AlwCCkxI0SXI3z3Ghutanq/6rqqeCrZuLfUp9mQ90Idoa7uJtIximfNTw+x 8ENDUwbdpUnTDvvyImi6KwYUVjCB0H2KEFnYuK8dfckvzvnSYZyVRGahKh5aLxNNHCAr vOeaIUC51VsA+zBlgj2ZDfKjF2R+0rmqKQvrNVEvszcGcL+RDce57/HOV3/JrXR0wWk0 J2oox2F+zPbuN2KXWo3Uf/7CfAnEForVajIFflw743+kcN80h8DopBMBKb2/HOzPQu6O WwyxpAl6vfGJEd2IFxSUCyTvX+Xcpwzt92IjTvnFrQQEw7/oSfCBBKDWksEt/oFe8lvj 7s8w== X-Gm-Message-State: ANhLgQ1U7IhX6VIuBDYZ1ZUQC0pg9rbb4unIE0a5s/94XiPDq1c8vBKw EhSWnGlk+9tIRHmtrtmM60xZtg== X-Google-Smtp-Source: ADFU+vuUA0PtGuRfrupcVqALAoBlNnXdvyHxT7lgi1sZxyelUn5XW7P+x0jA+NKEwgdlYgklvWkvNA== X-Received: by 2002:a2e:9804:: with SMTP id a4mr500667ljj.180.1584444717157; Tue, 17 Mar 2020 04:31:57 -0700 (PDT) From: Linus Walleij To: Theodore Ts'o , Andreas Dilger Subject: [PATCH] ext4: Give 32bit personalities 32bit hashes Date: Tue, 17 Mar 2020 12:31:53 +0100 Message-Id: <20200317113153.7945-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::242 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , linux-api@vger.kernel.org, Linus Walleij , qemu-devel@nongnu.org, stable@vger.kernel.org, Florian Weimer , Andy Lutomirski , linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" It was brought to my attention that this bug from 2018 was still unresolved: 32 bit emulators like QEMU were given 64 bit hashes when running 32 bit emulation on 64 bit systems. The personality(2) system call supports to let processes indicate that they are 32 bit Linux to the kernel. This was suggested by Teo in the original thread, so I just wired it up and it solves the problem. Programs that need the 32 bit hash only need to issue the personality(PER_LINUX32) call and things start working. I made a test program like this: #include #include #include #include #include #include int main(int argc, char** argv) { DIR* dir; personality(PER_LINUX32); dir =3D opendir("/boot"); printf("dir=3D%p\n", dir); printf("readdir(dir)=3D%p\n", readdir(dir)); printf("errno=3D%d: %s\n", errno, strerror(errno)); return 0; } This was compiled with an ARM32 toolchain from Bootlin using glibc 2.28 and thus suffering from the bug. Before the patch: $ ./readdir-bug dir=3D0x86000 readdir(dir)=3D(nil) errno=3D75: Value too large for defined data type After the patch: $ ./readdir-bug dir=3D0x86000 readdir(dir)=3D0x86020 errno=3D0: Success Problem solved. Cc: Florian Weimer Cc: Peter Maydell Cc: Andy Lutomirski Cc: stable@vger.kernel.org Suggested-by: Theodore Ts'o Link: https://bugs.launchpad.net/qemu/+bug/1805913 Link: https://lore.kernel.org/lkml/87bm56vqg4.fsf@mid.deneb.enyo.de/ Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=3D205957 Signed-off-by: Linus Walleij --- fs/ext4/dir.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c index 9aa1f75409b0..3faf9edf3e92 100644 --- a/fs/ext4/dir.c +++ b/fs/ext4/dir.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "ext4.h" #include "xattr.h" =20 @@ -618,6 +619,14 @@ static int ext4_dx_readdir(struct file *file, struct d= ir_context *ctx) =20 static int ext4_dir_open(struct inode * inode, struct file * filp) { + /* + * If we are currently running e.g. a 32 bit emulator on + * a 64 bit machine, the emulator will indicate that it needs + * a 32 bit personality and thus 32 bit hashes from the file + * system. + */ + if (personality(current->personality) =3D=3D PER_LINUX32) + filp->f_mode |=3D FMODE_32BITHASH; if (IS_ENCRYPTED(inode)) return fscrypt_get_encryption_info(inode) ? -EACCES : 0; return 0; --=20 2.24.1