From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f180.google.com (mail-yw1-f180.google.com [209.85.128.180]) (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 48F13481FD0 for ; Tue, 19 May 2026 11:04:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779188670; cv=none; b=daITM3lG1uZdjt7c+0h6MES1j/FMA9qnCjAsilF4Kg65lEIO7+ARbPWpil/mv+l/uhu2A7fEyG1MFwuxxLE7IfbBrjjW0+sU8uLVDW2I9pRk6amPVm0+wACB0AmPGpeSPBJdMfrNkyihXYkYTIqmPdM1aRJGL0QWMAg6OIK2Eqc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779188670; c=relaxed/simple; bh=FA07lT6C4tTEVDxKP6sBgKRYzFaomS+7kWG4YIRtUto=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QIgcaTw3bUuY2vWatXUPw8X0sjgZBpQdV7/DjT6opFSTtVKHnEwnzHbCInvXQBqL0uz5KsSrN3yPyzZkw133ehmnq+OthGJWaplOC7QzSNZgn9wy65YvVVRWb77eBWxGobavCZAKNzpKfCfYCfxnYq5Uv9x5O53Y7Ms2bSxmTNU= 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=EqKQ+dCT; arc=none smtp.client-ip=209.85.128.180 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="EqKQ+dCT" Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-7bd6f65c781so26141257b3.1 for ; Tue, 19 May 2026 04:04:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779188666; x=1779793466; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PuiWRQBqdRLNOxJ2VaNl5btGp2aiulYiXmdelCaoF30=; b=EqKQ+dCTBmNawz3z4SNN2PCQdPqfGOKoY4u3jlk9tk9yyloS9Hg7V4Fdoq46lOgU1g BbQXAZrdhp3bgnLqzYO1kOUNUNz5ks/lexZ4j6Be2QLer0JXWnZs3AF1IsE9yXlmchyp IVSCpmY8japnhq8lQpqJ/QJryl8/p0F2af3+8aPnA0vCSBaff3PBp8O2PFvwbUUWuCf1 byC2sPBomdbQvV1JUdU0/Unb0yPzOZlBys0UOvvYTVXG8wcqUoI8EQVds6DRvq4ONaJ0 5+t+lVUcE39RusMUF5fyG6giQ7uUWSVhpAAS7c/yPqU+t3iL/K3edERyK0gYgUP4mtup 7phw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779188666; x=1779793466; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=PuiWRQBqdRLNOxJ2VaNl5btGp2aiulYiXmdelCaoF30=; b=DKfRUvbOOPhWsIy1sikmVF470hjrr7Rci6iGHuo6DwPJqrVnUHAgK1hLCqq1xLioPt 7rgevej97fMUtQ4p8GFbeCUVl3YiETOKP66Gwft34ToMAFoDKcdPF/7p97ebf8r5ATMd pnxq5IgKszBVAJpwVHXqeeUbk/O6nRH49y4Tr3xAyahbZke1KD5GOHFcJvsfvNoXG/Rt 20QE6T2FzdKEG0d+is3onkJdivh1HwRd7n2c6GmSpj/mQ5Ur67rrbQhNPd67sCv3VZr/ zQ1nTZhvlAr9wwHL2j9NTtB2rZD4lNFJ5GCAQP5X2YCP1pV/8dPYuKt+f/yVRJ39RJ8D 1xkQ== X-Forwarded-Encrypted: i=1; AFNElJ+9zl9chOUaN7UM7dNGkgzQbq5xRnoerg9tmj9MYXvmUa8+7vPP6UcGCmUm1FbMGIruMacxzKVb9hWvXmE=@vger.kernel.org X-Gm-Message-State: AOJu0YzwDfSBGdL+DO3bgXJ9wCDtcGjUwsCU3tv7jSSFp7rkL+yTWhPk 0Mwtxv+DvokT+CBpMEmpP69R/9mLRPSCjjoDaLpsA334GEL/LZkvSIEg X-Gm-Gg: Acq92OFBcXCuGuxJLohjTsf3l24CJi1tSWON+QGe5BKCo93hprOuBBsUkk71Wn+Fvfa Jgiv9u7vthDMzE3r3UKKNRuakJOcZVRMNB/I4kZteqNZROJyzDGiba6XMFoEl9YF/lWX7BK3+tO dX9pCKSVvh/BhxGTVJZMdj+axhBed7tJBszCJZkae6Xwvbg9gg3WMIn4mb259javnaNFSAqgDvN ZPWnTM9lQ6h8DnUjMbx/0XcJNDR6XKIOk3FSqmbKuq4rcuUCeHGBgs7o08431NObYroTS8W2fPi rdEju2kB8bmwm7kE2Jt3Bi070d/SD4an+l5tPDDRMj+gDyXv/d1V01TkHcM3fFIbrYD16HDlvXp FWLqaU6gE8hhx71i4D8kqnzEhzf6XfRvVxvRMcCEpQfbcL+trcAt2vvsHt7ejyKEfgYxtv70JvD SPdyJ6OBv/twRlLv+67clo4m9scKxQaBS74S9Jb+De7rKmWOcXAHXeW+HghZMrMzG9+5E6tPC72 stTZ3El2NdvbKoSMzmQ X-Received: by 2002:a05:690c:e1cc:20b0:7c7:df46:3e2b with SMTP id 00721157ae682-7c7e7e1c3c2mr143911227b3.16.1779188666185; Tue, 19 May 2026 04:04:26 -0700 (PDT) Received: from server0 (c-68-48-65-54.hsd1.mi.comcast.net. [68.48.65.54]) by smtp.gmail.com with ESMTPSA id 00721157ae682-7cc9bc0ccf7sm35206827b3.25.2026.05.19.04.04.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2026 04:04:25 -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 v2 2/3] ocfs2: reject dinodes whose i_rdev disagrees with the file type Date: Tue, 19 May 2026 07:04:03 -0400 Message-ID: <20260519110404.1803902-3-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260519110404.1803902-1-michael.bommarito@gmail.com> References: <20260519110404.1803902-1-michael.bommarito@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit id1.dev1.i_rdev is the device-number arm of the ocfs2_dinode id1 union. It is only meaningful for character and block device inodes. For any other user-visible file type the on-disk value must be zero. ocfs2_populate_inode() currently copies id1.dev1.i_rdev into inode->i_rdev before the S_IFMT switch decides whether the inode is a special file. A non-device inode with a non-zero i_rdev can therefore publish stale or attacker-controlled device state into the in-core inode. System inodes legitimately use other arms of the same union, so keep the cross-check restricted to non-system inodes. Factor that predicate into a helper and use it in both the normal validator and online filecheck path; filecheck reports the malformed dinode through OCFS2_FILECHECK_ERR_INVALIDINO instead of ocfs2_error(). Fixes: b657c95c1108 ("ocfs2: Wrap inode block reads in a dedicated function.") Cc: stable@vger.kernel.org Signed-off-by: Michael Bommarito Assisted-by: Claude:claude-opus-4-7 --- fs/ocfs2/inode.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c index e149ccbdc03ce..992980ea98046 100644 --- a/fs/ocfs2/inode.c +++ b/fs/ocfs2/inode.c @@ -72,6 +72,16 @@ static bool ocfs2_valid_inode_mode(umode_t mode) return fs_umode_to_ftype(mode) != FT_UNKNOWN; } +static bool ocfs2_dinode_has_unexpected_rdev(struct ocfs2_dinode *di) +{ + umode_t mode = le16_to_cpu(di->i_mode); + + if (le32_to_cpu(di->i_flags) & OCFS2_SYSTEM_FL) + return false; + + return !S_ISCHR(mode) && !S_ISBLK(mode) && di->id1.dev1.i_rdev != 0; +} + void ocfs2_set_inode_flags(struct inode *inode) { unsigned int flags = OCFS2_I(inode)->ip_attr; @@ -1518,6 +1528,41 @@ int ocfs2_validate_inode_block(struct super_block *sb, goto bail; } + /* + * id1.dev1.i_rdev is the device-number arm of the id1 union and + * is only meaningful for character and block device inodes. For + * any other regular user-visible file type the on-disk value + * must be zero. ocfs2_populate_inode() currently runs + * + * inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev)); + * + * unconditionally, before the S_IFMT switch decides whether the + * inode is a special file. As a result, an i_rdev value present + * on a non-device inode is silently published into the in-core + * inode; a subsequent forced re-read or in-core mode mutation + * (cluster peer with raw write access to the shared LUN, + * on-disk corruption, or a separately forged dinode) can then + * expose the attacker-controlled device number to + * init_special_inode() without ever showing an unusual i_mode + * at validation time. + * + * System inodes (OCFS2_SYSTEM_FL) legitimately use the bitmap1 + * and journal1 arms of the same union (allocator i_used / + * i_total counters and the journal ij_flags / + * ij_recovery_generation pair); those bytes are not an i_rdev + * and must not be checked here. Restrict the cross-check to + * non-system inodes, which is the full attacker-controllable + * surface. + */ + if (ocfs2_dinode_has_unexpected_rdev(di)) { + rc = ocfs2_error(sb, + "Invalid dinode #%llu: non-device mode 0%o with i_rdev %llu\n", + (unsigned long long)bh->b_blocknr, + le16_to_cpu(di->i_mode), + (unsigned long long)le64_to_cpu(di->id1.dev1.i_rdev)); + goto bail; + } + if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_DATA_FL) { struct ocfs2_inline_data *data = &di->id2.i_data; @@ -1657,6 +1702,16 @@ static int ocfs2_filecheck_validate_inode_block(struct super_block *sb, (unsigned long long)bh->b_blocknr, le16_to_cpu(di->i_mode)); rc = -OCFS2_FILECHECK_ERR_INVALIDINO; + goto bail; + } + + if (ocfs2_dinode_has_unexpected_rdev(di)) { + mlog(ML_ERROR, + "Filecheck: invalid dinode #%llu: non-device mode 0%o with i_rdev %llu\n", + (unsigned long long)bh->b_blocknr, + le16_to_cpu(di->i_mode), + (unsigned long long)le64_to_cpu(di->id1.dev1.i_rdev)); + rc = -OCFS2_FILECHECK_ERR_INVALIDINO; } bail: -- 2.53.0