From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796275513; b=O1lLHZf6W133/gQ4canb27yZ+lDsdnN+40qZHZ05aO5EAACN3/m4Ne7++qEMh66uIuK5 +OAmmWPmG9DkAbnLH0Fw68ZsSNdMFFeYeiL5err5C989xHEj/ZWml1Zz+BDTc4+nvipWZ U0+G+LKgmPKvgeOBGhPdjLopwPS1VH5K98FcZsyl0UQ2wmCzmdUmuspas/+d9oOS9HU0z M/NB0uGZT/HSkk6MF6ykqGrU88gK8v5fcdBCYlqx/UX5WXUZwv9q1Pbj2uqLHgsRJlIFr PJ0K6poh/SmUMIj9fT0NG4rLE3WQ9pnZ7NyYldTawXqMZ+EmPW1LRkWFZU4b7C9VpRw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796275513; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=i9dib1rk9wpl559+KGYpflCiWGPuPZ6DBuh7gqsPFGo=; b=4HzHiRQfhcyYHK27LzviuTy7VqWlp2fy6IM/qsqqNNdonBeQ09DII7IHVG7VedfpQ6s/ mCpiQYhQMDUyM094Cd/Z/eD0AMjHYRYQ4ztd014f3L8ZnlAGgySMpbPx0SPTua1+L++mt 6QGVP8ipLyVW/TCSsTPfbLe3agedAXcC9UE28L1oKR2hoCX0R1jVPUlD8PbXDhmd8CsuR OrcoqJJOpoElXpVdqRmMnIO6pAGY3AnCOZLVvv1lGatHt9C/Y1Rp0hdDyQhbLrkZ5lFnz +TO8Q8+nyy3sZvpwGrNpVYWbQazjC37xAKSZKgVGJ3xK/QbpiwaKciNWQx3d9etguOA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=z0dtjmnn; arc=none smtp.remote-ip=209.85.215.171 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E657F606A32C for ; Thu, 3 Dec 2026 05:25:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E657F606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=z0dtjmnn Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-cdb75699c7cso5381850a12.2 for ; Wed, 02 Dec 2026 21:25:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796275512; x=1796880312; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=i9dib1rk9wpl559+KGYpflCiWGPuPZ6DBuh7gqsPFGo=; b=z0dtjmnnLGnGEDpN553qxYmQlWbb2vwxqtJiFRkbHoR36IxaSJ2wbiQx7fpWYFtB5s MikVqvIts2ILGaYrNb3Qp92vkgHXerh0Fy5BQbvS70I+QU3EpHeIWZSU2geHcF9pknuL dAyR7YX8Nqip5HLmGRknu9M6ZdPVRro4gvDywCHcQUNoCLDMNLDKTnN2a8AconoxH/Rn 3glJNfLPV+qqRhrcBcG88tWoq0FQz0GldacvAfU8lngKEbwoyhQFNXnoIuKpL802edQU dxYfB6rGRZs+kxw3btr/2iQZug7IGF6Uf9fIWhQGcjILoXvtHKEpU1lteFyI7EbZ1uXo uEQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796275512; x=1796880312; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=i9dib1rk9wpl559+KGYpflCiWGPuPZ6DBuh7gqsPFGo=; b=GXXefG2gVgTcvo8rHjdIqgV1DSwkjA4LYgK8lRiwQmYBLWXtkhF3mG4uxRbyzU1qCp /9NwIMm9osIvcSwrjuRgMkcYGIehAf4Kirmm8ILmyZEYJgLv++ELVHWhFw5sKVlqFOVu 1n60AkBKojTZ1GXqa5QLLw8H0Z7ybsRwSek9bmNy3QlxkootrzJSFYYh0/rFJE2FQJj7 837MNk2EJp6MiMEyaILsFvf2m5QJfivgSa9j9mrZr9umF9ZO+qxbasbyzjQrAGwsUD34 3z2FK35DXQ0ocx4W/QhYXZTxIfbUA7yjlIFdgCJDG5DN1I8Lt1ZDa4NIjF8zDwz40Fqr +QfA== X-Forwarded-Encrypted: i=1; AL+hErGGkLE2oV7zzm4bCLhJ+NNnHpkMt5mRweF6PVRAwe0FaUE4wmZQ3/Z8FLenD/Y7z6jYTepglxecqmL/rnVY@vger.kernel.org X-Gm-Message-State: APuU4Z9r3S5kqtmL8y8Qn/wvIurSSJ/5thminyxbgfHqQJtJw++0raD/ /bNIuEKxgzI9vFRV0twJZx7R0rbzCCWCeZQUYc5vPeSHzpQqVz2ixLyE X-Gm-Gg: AZFdTZcHzmP/Cr81450vLdYH60nSX3uAR4ZoLbvMHewAVDcsiOtBHBBvqDZMNtkPX9r 7SOaAIpyYCfh6H6u/nTAF4wxmABFh+4AV+t41Cf1Fx+Hcxg3olZLroedU1JMlYO6+fSxo0lkGyk q2l0quodZRAK4R0jG7tXOMQ0p5u0MSOyGByJSDd//0tZ0FVUpplmN1ceGSEpqpy02BVfsdTrRQU hlYmlop328wPI/wt0V0bAWBf5BE+v12yddngnJIw8heTwzALxeVBT0qvb6zBuInrwkuKmdFA7Eu DOilkQgrbgjGgOyltBRGyHfOSxVIo1VikiUzmpWbs0JVwuqzmYnNk1o2IhKTKhyChPR+qa8DgaK WpRUc+B1FlavWcp0eUQ1Wl8euMo11GGz1thkxykJrIs/Ea5g3Ba15FO3VMdFYRU4MWf39Uw1rcD yjdFxYyYFI+qsCXfTcPIN04uM40KaXg4LhAA1gXo5JnKzGJhV5Vv0zRJoXJ8ujzmuEOB7v+cALN jjKb1jtQgEgJFRK/vjfj1oYLG3IlI2IBlFgw8WH1rieIhuviuirdiiKHzvi/I5aw6AjZaUemHQo sAEAI5qL/nLGgxjI/jtl6D0z3biyb+zGE57Wamlx9dbVsH0agoGcu01ubkiO X-Received: by 2002:a17:90b:17cd:b0:3b4:1926:9e9c with SMTP id 98e67ed59e1d1-3b41c8ff562mr44141556a91.30.1796275511954; Wed, 02 Dec 2026 21:25:11 -0800 (PST) Received: from localhost.localdomain ([64.118.140.61]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5c7649f12sm2518936a91.2.2026.12.02.21.25.08 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 02 Dec 2026 21:25:11 -0800 (PST) From: Ding Feng To: Miklos Szeredi , Amir Goldstein Cc: Ding Feng , Christian Brauner , Alexander Viro , Jan Kara , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: ovl: a write refused with EFBIG still clears the set-ID bits Date: Thu, 3 Dec 2026 13:25:06 +0800 Message-ID: <20261203052506.53945-1-dingf3ng@gmail.com> X-Mailer: git-send-email 2.55.0 X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi, On overlayfs, a write that the upper filesystem refuses still clears S_ISUID and S_ISGID. backing_file_write_iter() calls file_remove_privs() (fs/backing-file.c:305) before the backing file's write runs generic_write_checks(). ext4 and tmpfs check first, then strip, so a refused write leaves the mode alone. A 06777 root-owned file of 2048 bytes; uid 65534 with RLIMIT_FSIZE 1024 writes 10 bytes at offset 4096, which fails with EFBIG. On v7.4-rc5 (x86_64, QEMU): ext4 mode 6777 -> 6777 tmpfs mode 6777 -> 6777 overlayfs over ext4 mode 6777 -> 0777 It drops privilege, so it is no security problem, but overlayfs differs from the filesystems below it, and FUSE passthrough shares backing_file_write_iter(). Stripping after the write would open a window where a set-ID file has new content, so the fix I have in mind is the ext4 order: run generic_write_checks() on the overlay file before file_remove_privs(). Would you take a patch along those lines? ovl_fallocate() and ovl_copyfile() also strip before the lower call, but native ext4 fallocate does the same on a refused call, so I left them out here. Reproducer, run as root as ./refused_write_setid /mnt/ovl/file: /* * As root, create a 06777 file of 2048 bytes; as uid 65534 with RLIMIT_FSIZE 1024, write * 10 bytes at offset 4096, which fails with EFBIG; print the mode before and after. */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include int main(int argc, char **argv) { const char *path = argc > 1 ? argv[1] : "file"; struct rlimit rl = { 1024, RLIM_INFINITY }; char buf[2048]; struct stat before, after; int fd; fd = open(path, O_CREAT | O_RDWR | O_TRUNC, 0644); memset(buf, 'a', sizeof(buf)); pwrite(fd, buf, sizeof(buf), 0); fchmod(fd, 06777); close(fd); stat(path, &before); if (fork() == 0) { signal(SIGXFSZ, SIG_IGN); setrlimit(RLIMIT_FSIZE, &rl); if (setgid(65534) || setuid(65534)) _exit(1); fd = open(path, O_WRONLY); if (pwrite(fd, "xxxxxxxxxx", 10, 4096) < 0) perror("pwrite"); _exit(0); } wait(NULL); stat(path, &after); printf("%s: mode %04o -> %04o\n", path, before.st_mode & 07777, after.st_mode & 07777); return 0; } Thanks, Ding Feng