From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (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 4C26634F279 for ; Mon, 27 Apr 2026 16:20:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777306845; cv=none; b=ojt76aHBtJTi6zokHDO0HWSpI6w0Dse6e4qd/UIZVzloJ7Gx1feBUDYhGJ2oLQZKkIxGPWT/cn12yoEZJ3AdP1q9kftkC0Ls+rtKo+slbrmxk1cwscSho5P7WuBNDm9J4jO7UaCPNQ84iGwAY5DPULmwugMi23DQPx84HJRXLCA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777306845; c=relaxed/simple; bh=WroDfzPqTURMv0iDm0VUPBMyksj/JhESZ+u0Y7pNEqM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=WRVJmUtS9tSGfXo1vVIfv3JWZrxsh7qD/3w4bco8vjaEWm8Ku6hmhDDJHcNVNERu1AlgKFXcZ8P+K4ahqVZop2OeVUsCX7OkJN5nkCakzy1Cl1f+oa6cXyUP7Mr0D4//RWTqYsmGNdw5xDgsLlopKIu5yIH5NtFv3V2X4GY+hqQ= 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=Rq7lY7ac; arc=none smtp.client-ip=209.85.216.54 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="Rq7lY7ac" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-35da2d35eccso7067976a91.0 for ; Mon, 27 Apr 2026 09:20:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777306843; x=1777911643; 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=vxA6MQ5WVPMH6RM+iJNh6xzquK0b80JHF1z9HxjdUkE=; b=Rq7lY7ac3FJm1V+qUxlnkjICvMkJ8ez9vfJiCrYTnGvpFe99cKwZ/unM9qz3aU0Y0a uid2n+rY9hLk3JwBi9Ug58REYW0e80VIpexqoxXMVFZInRtuHv1YzizxJL4BJASkUYuu +pR5LPlApMiI+tUvg8nSEcVLA3ug/oTYqE8PREw3talb9h2K+S+461uaxj5RwU4HyGXP D7B2g2VAgq6VSGbsEKZIFyta2aiYeMU2r3yi5o/yVcabhCga6n+M5zaPeKpnymjH/iK2 Dfut8/RL+r3lU9kIZuPVgUEHvNEZH3tjQyRj/TEfM70qcT2wegpAWVOqMtJHDi69Q1kY WrfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777306843; x=1777911643; 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=vxA6MQ5WVPMH6RM+iJNh6xzquK0b80JHF1z9HxjdUkE=; b=ZoILHEkZDNnxFtHkASP3H3eJqPk9AgdA2KuajGEq8aTvSv6r2f0/0Eb1UKyWShQhuA yJjw9DE+tKMai3WO51loqlqhba8CqXOR88Xkrqxx/HrKscauLDNked4Fzgb0XJtiO+ql fki4uYkBILX+ySt4JUXtk12Xo+fgovYCUoa+QmwiFJK9iwMXjIHzDHB6A4lGvr0tCOlz UfFZ3/rliFNab7sgW/Vz+FSNzjQnQQvhH1TlP93SuoUhg/HJSPhKCJ3CLAStrYCQswFP VUB74wf6VwB16/p7DT6f14rZfhE5ss0ewtPycud5kE3SF1joAEAM9ZE1cspgjbMYFWH4 mTAg== X-Forwarded-Encrypted: i=1; AFNElJ8zlsbPRiXayVq4h1ahH8W2QijIE+jYvctnhFdeya0twltkAd+Ku6MzMj+7fftP9RGmmWJ6bKZW0ouBAVE=@vger.kernel.org X-Gm-Message-State: AOJu0YxiwKrGbNweWx868eVAmt5lplK9l9UaREB2INw6OUVDsF23guW1 CRv3EMjg8vn/o2kNA5uZXJTuLiNdu62xSmpFM2ziNE02UB6a2hw18a/2 X-Gm-Gg: AeBDiesS3L6hmQart/igw0XM6tmlllevp9cYX5eUEoB+NCqxQhHYRD7/hJtD1BsQWaH +AifLo/Y7kHEz4/Zx5V6u12DgT6XdNzno1IN9hLmRGQ4MtFBGdnIi5TVTVPS6F1OQQVBfITgExx KDWEAFJjtkbsZ2/0MC2EYt+KvOq4FnzX+QtZgDdcazKYkcuoMLxwlC9iW5wnoHKahxt3XVLmx7a X4TfmCzuUe/DdrEMN0fWR3aFVGL5oG5FvzZMm0Mhc0KYQ1mbkLcFrzcwRgL5JtNbjV08VO2oSXw Jb4Z881Nm9nOCU/n6gWQh5MwFEFlm77LKBd7MK6L7d2uGlyLHawY7iwb6JH5Noa2HjEsfW5lmsD D2O8oiEz6U1NEQXUwun7C5o28mmlyfB31mB36cT5y38wDz/6q/ITLK91EdVzKVxVrMnsvLomx2C b9WjDkGLmtA10LcGRkV2Mt0rUl4pnwmmRfg4jJQwfR X-Received: by 2002:a17:90a:d4f:b0:362:ef3a:a153 with SMTP id 98e67ed59e1d1-362ef3aa62cmr9842448a91.12.1777306843438; Mon, 27 Apr 2026 09:20:43 -0700 (PDT) Received: from vini ([2401:4900:8fca:e7b6:f223:6319:a79e:7616]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b5fab28e35sm307352625ad.64.2026.04.27.09.20.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2026 09:20:43 -0700 (PDT) From: Vineet Agarwal To: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, libaokun1@huawei.com, jack@suse.cz, ojaswin@linux.ibm.com, ritesh.list@gmail.com, yi.zhang@huawei.com, Vineet Agarwal Subject: [PATCH] ext4: avoid BUG_ON() in ext4_get_inline_entry() Date: Mon, 27 Apr 2026 21:50:20 +0530 Message-ID: <20260427162020.49723-1-agarwal.vineet2006@gmail.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Corrupted inline directory metadata can cause offset to exceed the inline data size through rec_len processing in empty_inline_dir(). This triggers BUG_ON() in ext4_get_inline_entry(), causing a kernel panic before ext4_check_dir_entry() can handle the corruption gracefully. Replace BUG_ON() with a NULL return and handle the invalid offset in the caller by emitting a warning and exiting safely. This prevents a kernel panic from corrupted inline directory metadata. Signed-off-by: Vineet Agarwal --- fs/ext4/inline.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index 8045e4ff270c..bca9936ed6d0 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -1718,7 +1718,8 @@ ext4_get_inline_entry(struct inode *inode, { void *inline_pos; - BUG_ON(offset > ext4_get_inline_size(inode)); + if (offset > ext4_get_inline_size(inode)) + return NULL; if (offset < EXT4_MIN_INLINE_DATA_SIZE) { inline_pos = (void *)ext4_raw_inode(iloc)->i_block; @@ -1773,6 +1774,12 @@ bool empty_inline_dir(struct inode *dir, int *has_inline_data) while (offset < inline_len) { de = ext4_get_inline_entry(dir, &iloc, offset, &inline_pos, &inline_size); + if (!de) { + ext4_warning(dir->i_sb, + "bad inline directory (dir #%llu) - invalid offset", + dir->i_ino); + goto out; + } if (ext4_check_dir_entry(dir, NULL, de, iloc.bh, inline_pos, inline_size, offset)) { -- 2.54.0