From patchwork Tue Mar 17 11:31:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 184610 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp4015253ile; Tue, 17 Mar 2020 04:33:51 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvx3HVzmrmrWzABdqiU+/5L4QOOGdE/jNtuPBoQ5934w81d+LwRB3yn2pOSG7zaP3jtEu91 X-Received: by 2002:a37:b984:: with SMTP id j126mr4056723qkf.3.1584444831702; Tue, 17 Mar 2020 04:33:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584444831; cv=none; d=google.com; s=arc-20160816; b=cgqtqMjNnCHtjbQ+Kp0S7P/xgqSP25N7GIsU9UMMGg2cMnT/5GXUn25kbBL7PMfAxi +39+rvFioiREk4c+hi7b/WCqqNDZ2cZQDwRB4xDibPU2TKFh5Mt1CFCE6RyB1Gw81nL3 9F4r3h2OvlpkrxotM2wTf5EoFYLYiEOViDOhy1ZfHKgpId1qIcbQn5ollm/6Y/mwxU0Y eBPdgGwD4AvggEWDoqotINKzSUbrI5OYWY87eT2rilTS/1vAqkB4EhzyovKwPg7G6Duu VXJYxWLhj4eG7R5tPcOvDVaEeV2Iuxv8PHBg16DnpGsQVI4EEbJVJ1QSCvBfivXliMAD iuzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature; bh=WmJlBqTMa5CmdiFIToGjODDNiC8IWRj11NilEIEtQyE=; b=RoJqntz5TE3VgqTtHCPG2MyymEVt9ZSh4VGKEdok+wpw5gz46yTolLbJ41F/vlXz/t 4G20wtmnweHONaiiCb4cX333JXG2H+kzh+VibSy2qS+TfEWRJU7dKlqBMpnzdS0QBasV +zbCWdchrw3hsgiJEehCX89jU3m07e7+0JSlrNGmtwKXCQgi+ljQwQH3O/voRKvbcRPv o+/OY8+XE7bxo9kNwjVP9NITqqK7mXVOakmudVBfsDQ5T/pC20SeGS+c9BDXjlqo/sEx x2M6LZkAGtf/7kWjhyVlwJ8Uxiq1FNXDMdoAPUHtMiRMXhwAtTM1z7SAAiNks7odA3eH OP5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=F+QLlWXH; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y50si1585041qtj.387.2020.03.17.04.33.51 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Mar 2020 04:33:51 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=F+QLlWXH; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:58992 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEATn-0003iC-8G for patch@linaro.org; Tue, 17 Mar 2020 07:33:51 -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) 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-Received: by 2002:a2e:9804:: with SMTP id a4mr500667ljj.180.1584444717157; Tue, 17 Mar 2020 04:31:57 -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) 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 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 = opendir("/boot"); printf("dir=%p\n", dir); printf("readdir(dir)=%p\n", readdir(dir)); printf("errno=%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=0x86000 readdir(dir)=(nil) errno=75: Value too large for defined data type After the patch: $ ./readdir-bug dir=0x86000 readdir(dir)=0x86020 errno=0: 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=205957 Signed-off-by: Linus Walleij --- fs/ext4/dir.c | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.24.1 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" @@ -618,6 +619,14 @@ static int ext4_dx_readdir(struct file *file, struct dir_context *ctx) 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) == PER_LINUX32) + filp->f_mode |= FMODE_32BITHASH; if (IS_ENCRYPTED(inode)) return fscrypt_get_encryption_info(inode) ? -EACCES : 0; return 0;