From nobody Tue May 21 06:41:12 2024 Delivered-To: importer@patchew.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=1597057412; cv=none; d=zohomail.com; s=zohoarc; b=jup5vnOWY8kV9OPx8ZRmArp0RHGz1gvFKm+QfoG3Cglhw7okKGJoHkja09FC+IGp09cCj1vdPMYj/BPU9fhUiHC3hlUrUNICrXfOJaT2x1RA2spm4fiKDQceLxvwhGqyLnqug9c8kol8dUZQfR3nXKERVGWd4FHqpmYAO59n5vY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597057412; 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=U2JMQwQuDgHlcfFwPb65GGl9226SqxYKSo8gW1+qV4A=; b=mjElLJVSMzL1oy1O+zixV+o87o+v4zOwXzyt2Hs7F473YDek3//aO3v9/PLq4EXPbsy6sdZNXfH/APoi15t21A6zqiycjNuVRJAty5eeiZtsM7zNfQqXi+nldkxvP51S7LmaxNKafiJoV7+ofUaSqgRSMytJcRQ51B2p1pWF5FE= 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 15970574125741007.5702307915207; Mon, 10 Aug 2020 04:03:32 -0700 (PDT) Received: from localhost ([::1]:34372 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k55aT-0006qP-Qj for importer@patchew.org; Mon, 10 Aug 2020 07:03:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37054) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k55Zk-0006PW-4j for qemu-devel@nongnu.org; Mon, 10 Aug 2020 07:02:44 -0400 Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]:42996) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k55Zg-0006Uk-SF for qemu-devel@nongnu.org; Mon, 10 Aug 2020 07:02:43 -0400 Received: by mail-lj1-x243.google.com with SMTP id t6so9049948ljk.9 for ; Mon, 10 Aug 2020 04:02:39 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id k12sm10551672lfe.68.2020.08.10.04.02.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2020 04:02:37 -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=U2JMQwQuDgHlcfFwPb65GGl9226SqxYKSo8gW1+qV4A=; b=ycd09Q6Ye7sc8xqUC49v6AA4FxlLR1Hhhh1W8l247b5DxMeoGrHGyCyBbcY+ZiSH90 GeV1Cf91H5eFnM79C4JBDeH9AXTAfcF7ZDnLEOm5K2bMnAM4iFLTNk+ZxhgM0X9fCmmD ZTurMhH/RXWXDFaHBRgqIxCSL+pjcAemO3QhifUTqZlHj2WS1S6BNKnBgDBRLmszQ3V9 Ps1F8x7lzay/fBYHEHQ45zhw8pAG4B+koE1WUB9pF9+RVvc3+qiJ738gc55yoaogOoOE ImEfQsr/iFcxtv087s9yBFxnrKp3K/GIPtIvcZcMneoY3EMVmvCGymFyzAAwYhiONzBa 3oEA== 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=U2JMQwQuDgHlcfFwPb65GGl9226SqxYKSo8gW1+qV4A=; b=ksIappXDJSSJU07OB8qmkpVFVIERe/2pKL4SSSx/SiWrwcOxi3bf6Y0HA7kdJZh9PZ mh33wKIAxAbdjPSlIAdQPHtB5IJ4mxCuweBangms/vI2RS+uA5HynT1Z2NR0h70qT6g4 rvhxH6ICbe+76EcXdrk8dUMXbnfnGfFRESZyx+Y8n2BXJmkQsGW0z8uw5t+J0hQeYk6O IU5YRsgVw6zaAuX4vClx/0s+yZexM7BG4nOI4aHiIlbbxQFGKLh/hG7kkAv2j6sfn93j EBjwefSo8qTWY8HrOatf1WiWJ9hNYpA6xL+ZIJYep2rIzsvP+0wmnvfaNJHVLoEAJfPw 3T+Q== X-Gm-Message-State: AOAM531mV2Ke09NMB0fykVgoQ1qtah/WPR+rdtqvA14s12cugJjTYTr6 RtdF7A/s4ZEoApK3ufixjHBoDQ== X-Google-Smtp-Source: ABdhPJw3yxD6ZDS/L2suPjxFjHfDzdlOqM5qnYl24R3NyHXPuk0N9Bpai2F2cl0Q/XqafWDMauOqGA== X-Received: by 2002:a2e:9e8a:: with SMTP id f10mr262329ljk.330.1597057357892; Mon, 10 Aug 2020 04:02:37 -0700 (PDT) From: Linus Walleij To: Theodore Ts'o , Andreas Dilger Subject: [PATCH v3] fcntl: Add 32bit filesystem mode Date: Mon, 10 Aug 2020 13:02:33 +0200 Message-Id: <20200810110233.4374-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2a00:1450:4864:20::243; envelope-from=linus.walleij@linaro.org; helo=mail-lj1-x243.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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, 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. This adds a flag to the fcntl() F_GETFD and F_SETFD operations to set the underlying filesystem into 32bit mode even if the file handle 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 FD_32BIT_MODE 2 int main(int argc, char** argv) { DIR* dir; int err; int fd; dir =3D opendir("/boot"); fd =3D dirfd(dir); err =3D fcntl(fd, F_SETFD, FD_32BIT_MODE); if (err) { printf("fcntl() failed! err=3D%d\n", err); return 1; } 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 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=3D205957 Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Realized that I also have to clear the flag correspondingly if someone ask for !FD_32BIT_MODE after setting it the first time. ChangeLog v1->v2: - Use a new flag FD_32BIT_MODE to F_GETFD and F_SETFD instead of a new fcntl operation, there is already a fcntl operation to set random flags. - Sorry for taking forever to respin this patch :( --- fs/fcntl.c | 7 +++++++ include/uapi/asm-generic/fcntl.h | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/fs/fcntl.c b/fs/fcntl.c index 2e4c0fa2074b..a937be835924 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -335,10 +335,17 @@ static long do_fcntl(int fd, unsigned int cmd, unsign= ed long arg, break; case F_GETFD: err =3D get_close_on_exec(fd) ? FD_CLOEXEC : 0; + /* Report 32bit file system mode */ + if (filp->f_mode & FMODE_32BITHASH) + err |=3D FD_32BIT_MODE; break; case F_SETFD: err =3D 0; set_close_on_exec(fd, arg & FD_CLOEXEC); + if (arg & FD_32BIT_MODE) + filp->f_mode |=3D FMODE_32BITHASH; + else + filp->f_mode &=3D ~FMODE_32BITHASH; break; case F_GETFL: err =3D filp->f_flags; diff --git a/include/uapi/asm-generic/fcntl.h b/include/uapi/asm-generic/fc= ntl.h index 9dc0bf0c5a6e..edd3573cb7ef 100644 --- a/include/uapi/asm-generic/fcntl.h +++ b/include/uapi/asm-generic/fcntl.h @@ -160,6 +160,14 @@ struct f_owner_ex { =20 /* for F_[GET|SET]FL */ #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ +/* + * This instructs the kernel to provide 32bit semantics (such as hashes) f= rom + * 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 assu= me + * that the userland process is capable of dealing with 64bit semantics. + */ +#define FD_32BIT_MODE 2 =20 /* for posix fcntl() and lockf() */ #ifndef F_RDLCK --=20 2.26.2