From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796275513; b=KUvVcyKJsYKvcGHIC9Wcs4HvuaX92IprB8KTNgLkbaosSVghPMr1uqNwP/296+eN9jP5 02QimikvLS4hzeRZ3G46qvPNZyJ2NQRpqLzrZxMaGmVyG/lZnEXJ6FC2WE4TqP0bWfpjY MjyjWK2YFl/BNtN3UOey8LqlSVOO+DShAxpqwTbOIFZ2NS3AVxAF7e12k6cYD0wxVIoP+ QH+mxB+0pSIZalfCW6JwL2h0HYHgbQmyR9J5Y9tXUvJLjh3wstsEZDi6dSOzcEnq/MKSa hmDReXhgadB5kqhXlAnJM1mJJCP5QautVDNP7GFk+O5nuwLHeUCL3Km1W9vhPs//VPw== 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=1M901S52xpq6oxmvSkon0hFHPrpqBEhUuNbM5brhGJ9Ig1Zk1KHCB3WSHCbGGB7nCUrt j5t7Rn9LUU9gLr15AuqHFPLtn00dclKLM3hfxInwfXy4jUKYcm2W5E3kWO+txxJp8gG4V T6e0F5oN00gSQchHpVgp+qtMzF9ydNKv77k52oQTPOT6uD5/LQvwl0/0y+pQq4OK2j1MH eKR/4Qxg7Ky+waJPrVCkjzCBoCWlwjlgS1rK1O4bXxm31nx4gajBBsA8LkRAN/JyBUY5i xhv1MiD/HnSsWTrmcOtOXcEh/gCPHWr6InS2tlD7bmxUh3KdXjX6ZC7MKZb+Tz5CFpg== 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.180 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 D8AAC606A322 for ; Thu, 3 Dec 2026 05:25:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D8AAC606A322 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-f180.google.com with SMTP id 41be03b00d2f7-cc4aa18f9afso5787045a12.3 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=ZtK1at+HJ2SM//tGa3vrAEzeUB2HuCHqowboSab2pXElV8b9kBtZMaB8g3s05RvtXu 9N5a+5b/GUOMH2zJz5ojssHEBZOanmmP5YBzf1PW85timPeMw66wHRONYg5Ox0MNLXu0 Tr1GFudXV6W9dc2DGlHb9d1S2G8szqtmQpYuZXMkz4I9BY2zd4Vpmq/ACv6lWo4KuTeR ficwcr38Tzz31QUeto/xWYQDK0VXkcrsPznU1R7UuzghRS9QC7eyH3n5YHCY4DrkZjvB EQ+kIljJNLTwGtPNipddcvrVPCe1y6z/OLlV4l4akeaiIQ+laeDBWFtlp/TXeYI4zAgB EfcA== X-Forwarded-Encrypted: i=1; AL+hErGyM9DOrm5iAyvh/sJM5DDtJxyVMSdwh/JNu/ky2yvbGWue+TMJPUtusiPkJkWBfu9FigHQdERxYiiVvPYc@vger.kernel.org X-Gm-Message-State: APuU4Z+MNwDL01SCy0hiBNPfj8Nz6yqt4laRLRzwqi2L1sN1a12kfXSb 5LrMOLk2Z/zxZfmJnjmGVfxivn3hlIzmWVHqPoYc64vbfMsLdBLwjWUr X-Gm-Gg: AZFdTZdq32dQ7BMGR7l2Gnbeev/hirRR9Y+EG6z6Qja6dkeHOBfWsQ69MB0FXjO2EO2 sDNo1Fni5fHgKdsS9EgNhIQ1vCKaYF1AvDuOkV4utOFrwMb1buOBp0XtnidHTplxfjC1hVqhcgZ xyLP4NLuCzAE7oG+Sm12DMIZjBj9Ng5u/g09aQncrMRfcjVnVNn0GboHISPRRj6rjg7Se2wVgfl RKWhLuz6Ctb5USEK61QhBxn2/jAlw0y9SCiCSW9oxsM8hLjcavFEGUdJ8JG9BLCZs8ma7MH1/l0 m8jR8nO6pPmAOaCa+K1DBLuDTio8OquvMDxBXqetaTUfenK+E6SBymQkIuF5nAGvFpUH05wzHsh TfjYMo89EaiHyDFTJnBgNnve4CUpuK9VTGQjcpmrybh+ktxNoX3xS/Ynuvsr1S6Eqb3hWp0Mbw/ i5k8mzTeCsZHMKgFbJgP19oOFCAQ8HcJxB0RrU0h/YdYHhscBWLhErh1Vjwj6indBbBY504QrB9 Q3oEP2IyO6gG1pJwmRkASHDL3Z6viy6TdYcVTi3JWyz1HVXCS8/k7SExDxTYhz3epOKJwH3xqFn dAcxFoI+NpSRH8Epjwed/8nWIN3Daom2zF79mM8tGD1QLSuy27bHmz1Lcm8f 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-unionfs@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