From: Jan Kara <jack@suse.cz>
To: <linux-fsdevel@vger.kernel.org>
Cc: Jan Kara <jack@suse.cz>
Subject: [PATCH 2/2] udf: Avoid confusion of missing and corrupted extended attributes
Date: Tue, 1 Sep 2026 11:12:26 +0200 [thread overview]
Message-ID: <20260901091256.1226297-4-jack@suse.cz> (raw)
In-Reply-To: <20260901091037.30587-1-jack@suse.cz>
udf_get_extendedattr() returns NULL either when extended attribute was
not found or when some corrupted attribute was found. Similarly
udf_add_extendedattr() returns NULL when extended attributes are
corrupted or when there's no space to insert the extended attribute.
Make both functions return proper error codes to discern these cases and
handle them in the callers.
Signed-off-by: Jan Kara <jack@suse.cz>
---
fs/udf/inode.c | 23 ++++++++++++++++-------
fs/udf/misc.c | 15 ++++++++-------
2 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index baf9845ac06b..8babc2fbce9a 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -1675,8 +1675,15 @@ static int udf_read_inode(struct inode *inode, bool hidden_inode)
struct deviceSpec *dsea =
(struct deviceSpec *)udf_get_extendedattr(inode, 12, 1);
- if (!dsea || !udf_device_spec_valid(dsea))
+ if (IS_ERR(dsea)) {
+ ret = PTR_ERR(dsea);
goto out;
+ }
+ /* Device inodes must have a device spec attribute */
+ if (!dsea || !udf_device_spec_valid(dsea)) {
+ ret = -EFSCORRUPTED;
+ goto out;
+ }
init_special_inode(inode, inode->i_mode,
MKDEV(le32_to_cpu(dsea->majorDeviceIdent),
le32_to_cpu(dsea->minorDeviceIdent)));
@@ -1836,13 +1843,19 @@ int udf_write_inode(struct inode *inode, struct writeback_control *wbc)
struct regid *eid;
struct deviceSpec *dsea =
(struct deviceSpec *)udf_get_extendedattr(inode, 12, 1);
+
+ /* Validity of extended attrs was checked on load */
+ if (WARN_ON_ONCE(IS_ERR(dsea))) {
+ err = PTR_ERR(dsea);
+ goto out_unlock;
+ }
if (!dsea) {
dsea = (struct deviceSpec *)
udf_add_extendedattr(inode,
sizeof(struct deviceSpec) +
sizeof(struct regid), 12, 0x3);
- if (!dsea) {
- err = -ENOSPC;
+ if (IS_ERR(dsea)) {
+ err = PTR_ERR(dsea);
goto out_unlock;
}
dsea->attrType = cpu_to_le32(12);
@@ -1852,10 +1865,6 @@ int udf_write_inode(struct inode *inode, struct writeback_control *wbc)
sizeof(struct regid));
dsea->impUseLength = cpu_to_le32(sizeof(struct regid));
}
- if (!udf_device_spec_valid(dsea)) {
- err = -EFSCORRUPTED;
- goto out_unlock;
- }
eid = (struct regid *)dsea->impUse;
memset(eid, 0, sizeof(*eid));
strcpy(eid->ident, UDF_ID_DEVELOPER);
diff --git a/fs/udf/misc.c b/fs/udf/misc.c
index 6928e378fbbd..a2084dfbfbd6 100644
--- a/fs/udf/misc.c
+++ b/fs/udf/misc.c
@@ -58,7 +58,7 @@ struct genericFormat *udf_add_extendedattr(struct inode *inode, uint32_t size,
cpu_to_le16(TAG_IDENT_EAHD) ||
le32_to_cpu(eahd->descTag.tagLocation) !=
iinfo->i_location.logicalBlockNum)
- return NULL;
+ return ERR_PTR(-EFSCORRUPTED);
} else {
struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
@@ -122,7 +122,7 @@ struct genericFormat *udf_add_extendedattr(struct inode *inode, uint32_t size,
return (struct genericFormat *)&ea[offset];
}
- return NULL;
+ return ERR_PTR(-ENOSPC);
}
struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type,
@@ -144,7 +144,7 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type,
cpu_to_le16(TAG_IDENT_EAHD) ||
le32_to_cpu(eahd->descTag.tagLocation) !=
iinfo->i_location.logicalBlockNum)
- return NULL;
+ return ERR_PTR(-EFSCORRUPTED);
if (type < 2048)
offset = sizeof(struct extendedAttrHeaderDesc);
@@ -153,16 +153,17 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type,
else
offset = le32_to_cpu(eahd->appAttrLocation);
- while (offset + sizeof(*gaf) < iinfo->i_lenEAttr) {
+ while (offset <
+ iinfo->i_lenEAttr - sizeof(struct genericFormat)) {
uint32_t attrLength;
gaf = (struct genericFormat *)&ea[offset];
attrLength = le32_to_cpu(gaf->attrLength);
/* Detect undersized elements and buffer overflows */
- if ((attrLength < sizeof(*gaf)) ||
- (attrLength > (iinfo->i_lenEAttr - offset)))
- break;
+ if (attrLength < sizeof(struct genericFormat) ||
+ attrLength > iinfo->i_lenEAttr - offset)
+ return ERR_PTR(-EFSCORRUPTED);
if (le32_to_cpu(gaf->attrType) == type &&
gaf->attrSubtype == subtype)
--
2.51.0
prev parent reply other threads:[~2026-09-01 9:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-01 9:12 [PATCH 0/2] udf: Fix handling of device spec attrs Jan Kara
2026-09-01 9:12 ` [PATCH 1/2] udf: validate the device specification EA before using it Jan Kara
2026-09-01 9:12 ` Jan Kara [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260901091256.1226297-4-jack@suse.cz \
--to=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox