io_uring: fix xa_alloc_cycle() error return value check
Jens Axboe
maintainerPATCH 1/1 io_uring: fix xa_alloc_cycle() error return value check
We currently check for ret != 0 to indicate error, but '1' is a valid return and just indicates that the allocation succeeded with a wrap. Correct the check to be for < 0, like it was before the xarray conversion.
---
fs/io_uring.c +1 -1
@@ -9843,7 +9843,7 @@ static int io_register_personality(struct io_ring_ctx *ctx) ret =xa_alloc_cyclic (&ctx->personalities, &id, (void *)creds,XA_LIMIT (0 ,USHRT_MAX ), &ctx->pers_next,GFP_KERNEL ); -if (!ret) +if (ret <0 )return id;put_cred (creds);return ret;
Signature · 1 line
Jens Axboe
Jens Axboe
maintainerQuoted 8 lines · Jens Axboe
We currently check for ret != 0 to indicate error, but '1' is a valid return and just indicates that the allocation succeeded with a wrap. Correct the check to be for < 0, like it was before the xarray conversion.
Fixes 61cf93700fe6 ("io_uring: Convert personality_idr to XArray")Signed-off-by Jens Axboe <[email protected]>
Gah, included a debug patch, not the fix. Here's the right one.
fs/io_uring.c +5 -4
@@ -9843,10 +9843,11 @@ static int io_register_personality(struct io_ring_ctx *ctx) ret =xa_alloc_cyclic (&ctx->personalities, &id, (void *)creds,XA_LIMIT (0 ,USHRT_MAX ), &ctx->pers_next,GFP_KERNEL ); -if (!ret) -return id; -put_cred (creds); -return ret; +if (ret <0 ) { +put_cred (creds); +return ret; + } +return id; } static int io_register_restrictions(struct io_ring_ctx *ctx, void __user *arg,
Signature · 1 line
Jens Axboe
fs/io_uring.c static int io_register_personality(struct io_ring_ctx *ctx) · line 9851
Quoted 12 lines · Jens Axboe
fs/io_uring.c +5
-4ret =xa_alloc_cyclic (&ctx->personalities, &id, (void *)creds,XA_LIMIT (0 ,USHRT_MAX ), &ctx->pers_next,GFP_KERNEL ); -if (!ret) -return id; -put_cred (creds); -return ret; +if (ret <0 ) { +put_cred (creds); +return ret; + } +return id; }
Wouldn't you rather:
if (ret >= 0) return id; put_cred(creds); return ret;
?
Jens Axboe
maintainerQuoted 16 lines · Matthew Wilcox
fs/io_uring.c static int io_register_personality(struct io_ring_ctx *ctx) · line 9851
Quoted 12 lines · Jens Axboe
fs/io_uring.c +5
-4ret =xa_alloc_cyclic (&ctx->personalities, &id, (void *)creds,XA_LIMIT (0 ,USHRT_MAX ), &ctx->pers_next,GFP_KERNEL ); -if (!ret) -return id; -put_cred (creds); -return ret; +if (ret <0 ) { +put_cred (creds); +return ret; + } +return id; }Wouldn't you rather:
Quoted 4 lines
if (ret >= 0) return id; put_cred(creds); return ret;
Don't really feel that strongly, I tend to like to do the error path like that unless it's a hot path. But I can go either way, if someone else feels strongly about it :-)
Signature · 1 line
Jens Axboe