From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13CFC2E7F38 for ; Sun, 17 May 2026 11:10:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779016235; cv=none; b=uNrdypILxeNuhYReqKJcVF5AfTfouq81/OGMFOlQg+y+sQ7LiLpnUc2VMgtSVjhy22GAFI6c5BOoOwJ0xsz/BqiWR1eVFimgt6daEC6isnOisGw+NX5GyY0t7f0mynMDz9jwgYSBcypA57i2SKJ4MTDadklmr1HmB92XpZyF2Nk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779016235; c=relaxed/simple; bh=WSAeD9+GINAzh16KM2LUaC6xph/bYkCKYNODz21UYmg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ku1BBS13T1++URuFaYANuKWbLtSoDqJuRek71LPgt7EodWo7BYC1IWv1Gowk8ndanwJiLO87urGJs6xpIzM7z2xms54jZuVX2jyFTyNJS7VfSMBYFoNQpvOOMVcEkHf+E9o3PixzI7zkEmEDHj1S0X7P++tPtzW6NN6y18JLwzA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=m5bBGAts; arc=none smtp.client-ip=209.85.160.172 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.b="m5bBGAts" Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-50e63771eb0so17984151cf.3 for ; Sun, 17 May 2026 04:10:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779016233; x=1779621033; 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; bh=Pt++DOA6Wc2HF8ky6f3A8ACPhJyI14sNysUPXV2Ffo4=; b=m5bBGAtse5lrwNlkTUdq0iDZacuzY1HL6Yqf98QDiLACGwF677LJ6FD7sdyTAyeE0r kohyr43wDut2HNSAw3FMJKH+rox4S2NyNKVGjzkFUjwK4thT3zUdNIXCeV7Xc0RktzkC vCp33qVli2b16Rg9OjPErrab+wnkprWVsNo8gda3UQZacMYHO5W4wAg+xnNJTEJMHn05 dRGsCO1buyiG1XIYNX07+zQCOtLNz9T6fzGBHVVWpPmxWDUX6ricO/jEubaEp9N0C/YP 2Js7Ig+TcnBFgD5rGpzZj6VhiKOuThPgX8ehTY/FjzJG8koahD2CuXMDK5AMsHSVba3U aifg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779016233; x=1779621033; 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; bh=Pt++DOA6Wc2HF8ky6f3A8ACPhJyI14sNysUPXV2Ffo4=; b=KPkOXYHkTfkj3SXdn00pfhIksI2YA2Zoi7YkZ/Zrm6X7+62VY5USs8v50pzAChKzlu Tn6Y2Q5MClIBnKZmP49iKdKovw/UyAAFxci5iExJCpTsOGdwWXqc6iGPnIKVb0s6CX8r K58SVab6lEkTnZSMv70CLyp1gfC3qzu+5QbGeAtBNrgqiOiiY2apNJwvNWUq+wj7RRJL pgicVTFmJHz6EDiZvlWCpIGxzB3YE4MFgJygUddREH+mbr9sownpQVQ7uDZ6074/XyUa Zh2a+eZBYEb2q5TA4SppAr5s152hKb7Jpf61bmxnWdNo+SUfEnRcV0SvczvRwXsPtfeH oP3g== X-Forwarded-Encrypted: i=1; AFNElJ/WFu0cBZSXOCFHp7EfQFQlf8KDBTfRR4tPy+q9D8lTAeybHdaJ/IslG77L5XgpNk2AuQP9SJMObRPIcZY=@vger.kernel.org X-Gm-Message-State: AOJu0YxY9TMTnwe4q2aXFx1JWl9E1jLMNtUL52iiKDJ090UmCSnqkWNH iSoteENEPUF1+lkvRzEU1UozfngbW/I+PyYeL9rULgqFngr1NkivdzGz X-Gm-Gg: Acq92OHc8Z0KQhSRHzvwmaPKKTy6PQkRYB1Fqe4I7NHOzn1cngxwQMHLPjWnfCo106n ht/I7KjA9nZFpepxhN/aAVQ4NMISxkr4I2iQy6Cxp5cYSiDyvG5k0L02QMUcfjdH4rIwwpybUJZ BGzUbF7Dc2bZyoeRdu1swh/mi8WuS57KIWGYFigfXwgpNMsdzEITvPzdiXGzyoX/yW9eZ/Z8KQw vFB6NjCDLRahRTcyD9ANarsv5TM/uUTV+Q5worbvqXS0KqWG4xvsU3I2zzs10PwEtYrInOIaK6i yjm2CJHNZxBlXLO25TeCjP2vVgI4V46CFuOfx9fENXvFdjWKZxDOl6VP3mbvBEYAKSFkWUzj03I nMAK7+v3utLSwIqVwXpa8CprBsad3v78S4IAQm2UgUic/7+AsbAKN0KVJA1y4EfHXlrKN1Wptv/ eIUlHOVg0iHEPAkCajDyf35bt7mhtvcjbURZHO+uOdcCS0u3nhtW+MgFYDDiZo1afahNv3cl7w+ dzTRychI1KXOOPZc2yih8mNLOGA44pQQ8Q3k80fMiJpBHRdjuivHCTHMyXmttJf X-Received: by 2002:a05:622a:996:b0:50f:de06:45e2 with SMTP id d75a77b69052e-5165a0d077bmr145323161cf.31.1779016232644; Sun, 17 May 2026 04:10:32 -0700 (PDT) Received: from server0.tail6e7dd.ts.net (c-68-48-65-54.hsd1.mi.comcast.net. [68.48.65.54]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-516456df09csm100306651cf.13.2026.05.17.04.10.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 May 2026 04:10:31 -0700 (PDT) From: Michael Bommarito To: Joseph Qi , Mark Fasheh , Joel Becker Cc: ZhengYuan Huang , ocfs2-devel@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 0/3] ocfs2: harden inode validators against forged metadata Date: Sun, 17 May 2026 07:10:11 -0400 Message-ID: <20260517111015.3187935-1-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit This series adds three structural checks to ocfs2_validate_inode_block() that catch attacker-controlled bytes in a freshly read dinode before ocfs2_populate_inode() copies them verbatim into the in-core inode. All three checks fire on the mount, lookup, and read-after-cache-invalidation paths and reject the block with ocfs2_error(), the same error-propagation mechanism the existing suballoc-slot, inline-data, chain-list, and refcount checks use. Direction ========= This continues the validator-hardening direction visible in the recent in-flight ocfs2_validate_inode_block hardening series, e.g. ZhengYuan Huang's "ocfs2: revalidate the journal dinode before toggling dirty" (<20260512024115.4036371-1-gality369@gmail.com>), "ocfs2: add extent tree depth validation" (<20260416110229.3283682-1-gality369@gmail.com>), and "ocfs2: add extent list validation v2" (<20260423094116.876696-1-gality369@gmail.com>). Each of those adds a per-field invariant check against bytes that downstream code paths trust unconditionally. The three checks in this series cover three more fields whose attacker-controlled values currently propagate into VFS-visible state without question: i_mode (type bits and reserved bits), i_rdev (cross-checked against the file type), and the i_size / i_clusters pairing for regular files on non-sparse volumes (patch 3 is gated on !ocfs2_sparse_alloc(); sparse- allocation mounts legitimately commit i_size > 0 with i_clusters == 0 via ocfs2_zero_extend()). Threat model ============ The validator is the chokepoint that protects ocfs2_populate_inode() from a malformed dinode whether the malformation got there via: (1) An attacker-supplied disk image mounted by a privileged user. The mount path runs every dinode through this validator before any unprivileged user opens a file on the volume. This is the same threat model the existing inline-data, refcount, and chain-list checks in this function were written for. (2) A compromised cluster peer with raw write access to the shared block device. OCFS2 is a clustered filesystem; the on-disk blocks behind bh->b_data live on shared storage that other cluster nodes can write. The local node's cache-eviction re-read runs the newly fetched block through this validator before ocfs2_populate_inode() runs again. Oracle's BlockErrorDetection design document scopes the existing CRC32 + Hamming integrity primitive explicitly as defense against memory and wire corruption, not as authentication of peer writes; the field-level validators are therefore the kernel-side defense whichever path produced the forged block. The three checks in this series are deliberately structural: they each express an invariant mkfs.ocfs2 and the kernel maintain unconditionally, and they reject any dinode whose header violates that invariant before its bytes propagate to the in-core inode. Scope note: these checks block forge patterns that touch i_mode (outside the canonical envelope), i_rdev (on a non-device file), or the i_size / i_clusters pair (regular file with size but no extents, on non-sparse volumes only). A forger who keeps the dinode within these structural envelopes (for example, flipping only the permission bits and uid/gid on a regular file that already has clusters allocated) can still produce a dinode that satisfies the field-level invariants; closing that residual class is outside the scope of this hardening series. Validation ========== Each patch builds on top of the previous one against mainline; the series as a whole builds clean against v7.1-rc1 with zero new warnings. checkpatch --strict reports 0 errors, 0 warnings, 0 checks for each patch. The series was exercised on a two-node QEMU cluster (virtio-blk shared LUN with share-rw=on, both nodes joining the same o2cb cluster, mounted ocfs2 with metaecc): - Pre-series baseline: a peer-node raw-write forge that adds S_ISUID and flips uid/gid to 0 on a regular file is accepted by the existing validator chain; the unprivileged user on the victim node exec()s the file and gains euid=0. This confirms the cluster-peer write primitive is reachable in today's mainline. Per the Scope note above, this particular forge stays within the structural envelope these patches enforce and is NOT blocked by them; closing it requires the out-of-scope keyed-integrity work. - Post-series, structural-variant forge: a peer-node forge that, in addition to the setuid + uid/gid changes, stores i_rdev = MKDEV(1,1) on the same regular-file dinode (the cleanest cluster-context attacker primitive patch 2 catches) is rejected by ocfs2_validate_inode_block() with ocfs2_error "non-device mode 0104755 with i_rdev N". The buffer-head propagates -EFSCORRUPTED to ocfs2_read_locked_inode and the user-visible result is Permission denied on subsequent stat / open / exec of the forged file. Analogous post-series forge variants that flip i_mode outside the canonical envelope, or that set i_size > 0 with i_clusters == 0 on a non-inline regular file mounted from a non-sparse volume, are rejected by patches 1 and 3 respectively. A separate cluster regression (mount, peer-write a regular file, drop_caches on the second node, read it back) runs clean post-series, so the checks do not regress normal operation. In-tree selftests under tools/testing/selftests/ that reference fs/ocfs2/inode.c or any changed symbol were checked; no matching selftests exist for ocfs2_validate_inode_block(), which is consistent with OCFS2 having no in-tree selftest coverage. The subsystem's standard regression coverage is xfstests (the generic fs group) plus ocfs2-test, both out of tree. Those were not run as part of this series; a full xfstests pass before merge is recommended and I am happy to run a representative subset and report results if reviewers would find it useful. Patches ======= Michael Bommarito (3): ocfs2: reject dinodes with non-canonical i_mode type or stray bits ocfs2: reject dinodes whose i_rdev disagrees with the file type ocfs2: reject regular files with non-zero i_size and zero i_clusters fs/ocfs2/inode.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) -- 2.53.0