Skip to contentSkip to conversation

udf: shut up pointer cast warning

PATCH In review Arnd Bergmann 2 participants 3 messages Nov 9, 2021 – Nov 10, 2021 UDF filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 udf: shut up pointer cast warning

From: Arnd Bergmann <[email protected]>

On 32-bit architectures, the workaround of storing the directory position in the private_data pointer causes a warning, as loff_t does not fit in a pointer:

fs/udf/dir.c: In function 'udf_readdir':
fs/udf/dir.c:78:25: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
78 | if (ctx->pos != (uintptr_t)file->private_data) {
| ^
fs/udf/dir.c:211:30: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
211 | file->private_data = (void *)(uintptr_t)ctx->pos;
| ^

An extra cast to uintptr_t shuts up the warning. This is of course still broken if the position is ever beyond the first 2^32 bytes (4GB).

I have not found a clear information on whether directories this large are allowed on UDF, but it seems unlikely.

Fixes 39a464de961f ("udf: Fix crash after seekdir")
---
 fs/udf/dir.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/udf/dir.c +2 -2
index 8ae501d27eff..5aaa82be420a 100644
@@ -75,7 +75,7 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
 	 * identifying beginning of dir entry (names are under user control),
 	 * we need to scan the directory from the beginning.
 	 */
-	if (ctx->pos != (loff_t)file->private_data) {
+	if (ctx->pos != (uintptr_t)file->private_data) {
 		emit_pos = nf_pos;
 		nf_pos = 0;
 	}
@@ -208,7 +208,7 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
 
 out:
 	/* Store position where we've ended */
-	file->private_data = (void *)ctx->pos;
+	file->private_data = (void *)(uintptr_t)ctx->pos;
 	if (fibh.sbh != fibh.ebh)
 		brelse(fibh.ebh);
 	brelse(fibh.sbh);
Signature · 1 line
2.29.2
#1 lore raw
Quoted 14 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

On 32-bit architectures, the workaround of storing the directory position in the private_data pointer causes a warning, as loff_t does not fit in a pointer:

fs/udf/dir.c: In function 'udf_readdir':
fs/udf/dir.c:78:25: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
78 | if (ctx->pos != (uintptr_t)file->private_data) {
| ^
fs/udf/dir.c:211:30: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
211 | file->private_data = (void *)(uintptr_t)ctx->pos;
| ^

Quoted 8 lines

An extra cast to uintptr_t shuts up the warning. This is of course still broken if the position is ever beyond the first 2^32 bytes (4GB).

I have not found a clear information on whether directories this large are allowed on UDF, but it seems unlikely.

Fixes 39a464de961f ("udf: Fix crash after seekdir")

Thanks Arnd but the problem was actually (mostly theoretical) problem on 32-bita archs and furthermore I've realized it didn't completely fix the original problem either. Yesterday I've pushed a different fix to linux-next. So the warning should disappear.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#2 lore raw
Quoted 5 lines · Jan Kara

Thanks Arnd but the problem was actually (mostly theoretical) problem on 32-bita archs and furthermore I've realized it didn't completely fix the original problem either. Yesterday I've pushed a different fix to linux-next. So the warning should disappear.

Yes, I saw your new patch and it is definitely a better fix.

Thanks,

Arnd