Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3504462ybb; Tue, 31 Mar 2020 06:39:00 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsf2XJ+jXZmqBwFbgLf2/k5PSbeRpluScRQC/WCQxbBcziJDd+puwv8HMN4QJ33gCs82JbC X-Received: by 2002:aca:5808:: with SMTP id m8mr2133480oib.155.1585661940051; Tue, 31 Mar 2020 06:39:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585661940; cv=none; d=google.com; s=arc-20160816; b=FMS8W+lLUHvaPCbjJftdLS3IXuz+8nrUw20grCNIxH6O81w6k03nWn6cDmBJ1VNK0n kCu2UiS3to+wpXGadbw9vADT66njnjgRgjtD7rtpUCfdI/pQ2XURFlQwrIAQW4J7b8pe PsiBI47td9vNqqU0qJlkRqG5KpZaWo8NWCAjYd0CMlB556EIkXB1483nsV0myc4LW/Jk Z5VeWXiQ5F4Ov6Y9DNBatLSPys73VHFCmr8juhTt6OVbp90+MWoJj6anX6t/SpZBc3aX omPK3OVX2RI3emTOp036us1eji1USf3nU/SEexGQeyHnLxrdC32gInRo1CeD7AaFTWb1 KkPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=aU5iLCuWaH4zxyOLw8e9l2ANSFZT9vUFLRpaEbsCIeI=; b=Woxg0vn212nyCbhy5H+Qaf4AgDKQaRhmRcJiXRkj0RUdO8+vRgIQDHYbdcwgP6bWGz 2dTF+7lNpn8C/UF9/+YGSv5iNEXG/G3PTrRAtNEc3TvXu/40pXiRfAkjvTEQiJEBP8GO uWGgh7MDv+kgYql7y6QYLhZT9fv5UfI9j7l565bEVwBGFgzBiMKYQQ9Fu3+r8wcCVoco 9W8gf3uv3KCZHbkGfilLptYR0e8lCbHOBhoigLiC8Cl9bdwJT+vxlF9PA8Ey/NUgwCZQ oOTslFpPaKdJa80hR4f4rdG5iMIQgyslxXnj47S1XoxDdQiGmSTw29z0TYGV7kP1VOoq oFqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M2bf+eVp; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j26si8377875otk.98.2020.03.31.06.38.45; Tue, 31 Mar 2020 06:39:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M2bf+eVp; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730755AbgCaNhv (ORCPT + 99 others); Tue, 31 Mar 2020 09:37:51 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:46416 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730810AbgCaNhu (ORCPT ); Tue, 31 Mar 2020 09:37:50 -0400 Received: by mail-lf1-f65.google.com with SMTP id q5so17299183lfb.13 for ; Tue, 31 Mar 2020 06:37:47 -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=aU5iLCuWaH4zxyOLw8e9l2ANSFZT9vUFLRpaEbsCIeI=; b=M2bf+eVpkauwEFyb4CxmjaPvpl1N7Yad7zfCQI7ftWmBLkeJPC0XXouWV2QI8hxZp0 SWvodVcZIL6Bb/b/rJIkQwkInHpjgZ5o+LFL4a9Pq3M4CqV+zv5VdnUEa/Y9J4upA+Im 9Jw34jRSN6kWPZ+k5VsdGo8jY+lJaogNfFrBKMbUo/M+wp9QThZUUdUXu+DGnXp8u5k2 KPhTqiN5HAQpCWvh1il9cj1mhxWhSyWq/d4wVo+nmE3Zy9I/KddzW5kBlWk/4bQIKCOR Av5ZU2ntiH08RXx7Vy7fMOQlQY1fz06o4VosndadGp4GHJG5h/oOYOtMMvQhx/Kp3hXh clpg== 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=aU5iLCuWaH4zxyOLw8e9l2ANSFZT9vUFLRpaEbsCIeI=; b=s+u5gkhxLgjXlRZ6QIN6Da3Yu1OYJGuM+UrAnovFKItnio0O5l1cpA5A+RUFGUx0Wc j90pdu+ejfjb4n7TNPUl3EPVfDaflm+cdJCHkwn91AzAptGVI1NJ5KQu5KSaQmTD6xQ2 QN74BQ1RUl0DwLbB0ux6EH8kRalOQ8zMeBQVuGcplDYzVt0kuj5uG+ic7yiXelc6DB11 ClGu351ZVEpgdCI7a98dMVreraVsEjzzZk+Q9SpYeCfx2BfysrLU7+gK/G/Rw4uUYPUb snB4w0kdihkG/dxG5FcAPAd3UKTA7lR4BkTu2aHKbUjPwMpm1TkVGGbDn2oTT6MwQWv6 O8qQ== X-Gm-Message-State: AGi0PuY42ccGenWl8aUJsOZ8pgm1XQ+AHTRDNajZwMbLxOquLCUStwRr ke+oM0y3fBjjPU6Aj8vz7s/ppg== X-Received: by 2002:a19:ad43:: with SMTP id s3mr11555874lfd.63.1585661866597; Tue, 31 Mar 2020 06:37:46 -0700 (PDT) Received: from localhost.localdomain (c-f3d7225c.014-348-6c756e10.bbcust.telenor.se. [92.34.215.243]) by smtp.gmail.com with ESMTPSA id x128sm9837994lff.67.2020.03.31.06.37.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 06:37:45 -0700 (PDT) From: Linus Walleij To: Theodore Ts'o , Andreas Dilger Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, qemu-devel@nongnu.org, Linus Walleij , Florian Weimer , Peter Maydell , Andy Lutomirski Subject: [PATCH] fcntl: Add 32bit filesystem mode Date: Tue, 31 Mar 2020 15:35:36 +0200 Message-Id: <20200331133536.3328-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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. This adds a fcntl() operation to set the underlying filesystem into 32bit mode even if the file hanle was opened using 64bit mode without the compat syscalls. Programs that need the 32 bit file system behavior need to issue a fcntl() system call such as in this example: #define F_SET_FILE_32BIT_FS (1024 + 15) int main(int argc, char** argv) { DIR* dir; int err; int fd; dir = opendir("/boot"); fd = dirfd(dir); err = fcntl(fd, F_SET_FILE_32BIT_FS); if (err) { printf("fcntl() failed! err=%d\n", err); return 1; } printf("dir=%p\n", dir); printf("readdir(dir)=%p\n", readdir(dir)); printf("errno=%d: %s\n", errno, strerror(errno)); return 0; } This can be pretty hard to test since C libraries and linux userspace security extensions aggressively filter the parameters that are passed down and allowed to commit into actual system calls. Cc: Florian Weimer Cc: Peter Maydell Cc: Andy Lutomirski 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/fcntl.c | 4 ++++ include/uapi/linux/fcntl.h | 9 +++++++++ tools/include/uapi/linux/fcntl.h | 9 +++++++++ tools/perf/trace/beauty/fcntl.c | 3 ++- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/fs/fcntl.c b/fs/fcntl.c index 2e4c0fa2074b..d194b1265bd4 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -426,6 +426,10 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg, case F_SET_FILE_RW_HINT: err = fcntl_rw_hint(filp, cmd, arg); break; + case F_SET_FILE_32BIT_FS: + filp->f_mode |= FMODE_32BITHASH; + err = 0; + break; default: break; } diff --git a/include/uapi/linux/fcntl.h b/include/uapi/linux/fcntl.h index ca88b7bce553..b9ad934147e8 100644 --- a/include/uapi/linux/fcntl.h +++ b/include/uapi/linux/fcntl.h @@ -73,6 +73,15 @@ */ #define RWF_WRITE_LIFE_NOT_SET RWH_WRITE_LIFE_NOT_SET +/* + * This instructs the kernel to provide 32bit semantics (such as hashes) from + * the file system layer, when running a userland that depend on 32bit + * semantics on a kernel that supports 64bit userland, but does not use the + * compat ioctl() for e.g. open(), so that the kernel would otherwise assume + * that the userland process is capable of dealing with 64bit semantics. + */ +#define F_SET_FILE_32BIT_FS (F_LINUX_SPECIFIC_BASE + 15) + /* * Types of directory notifications that may be requested. */ diff --git a/tools/include/uapi/linux/fcntl.h b/tools/include/uapi/linux/fcntl.h index ca88b7bce553..b9ad934147e8 100644 --- a/tools/include/uapi/linux/fcntl.h +++ b/tools/include/uapi/linux/fcntl.h @@ -73,6 +73,15 @@ */ #define RWF_WRITE_LIFE_NOT_SET RWH_WRITE_LIFE_NOT_SET +/* + * This instructs the kernel to provide 32bit semantics (such as hashes) from + * the file system layer, when running a userland that depend on 32bit + * semantics on a kernel that supports 64bit userland, but does not use the + * compat ioctl() for e.g. open(), so that the kernel would otherwise assume + * that the userland process is capable of dealing with 64bit semantics. + */ +#define F_SET_FILE_32BIT_FS (F_LINUX_SPECIFIC_BASE + 15) + /* * Types of directory notifications that may be requested. */ diff --git a/tools/perf/trace/beauty/fcntl.c b/tools/perf/trace/beauty/fcntl.c index 56ef83b3d130..da80264678cb 100644 --- a/tools/perf/trace/beauty/fcntl.c +++ b/tools/perf/trace/beauty/fcntl.c @@ -94,7 +94,8 @@ size_t syscall_arg__scnprintf_fcntl_arg(char *bf, size_t size, struct syscall_ar cmd == F_OFD_SETLK || cmd == F_OFD_SETLKW || cmd == F_OFD_GETLK || cmd == F_GETOWN_EX || cmd == F_SETOWN_EX || cmd == F_GET_RW_HINT || cmd == F_SET_RW_HINT || - cmd == F_GET_FILE_RW_HINT || cmd == F_SET_FILE_RW_HINT) + cmd == F_GET_FILE_RW_HINT || cmd == F_SET_FILE_RW_HINT || + cmd == F_SET_FILE_32BIT_FS) return syscall_arg__scnprintf_hex(bf, size, arg); return syscall_arg__scnprintf_long(bf, size, arg); -- 2.25.1