diff mbox series

[6/8] cachefiles: Modify inappropriate error return value in cachefiles_daemon_secctx()

Message ID 20240821024301.1058918-7-wozizhi@huawei.com (mailing list archive)
State New
Headers show
Series netfs/cachefiles: Some bugfixes | expand

Commit Message

Zizhi Wo Aug. 21, 2024, 2:42 a.m. UTC
In cachefiles_daemon_secctx(), if it is detected that secctx has been
written to the cache, the error code returned is -EINVAL, which is
inappropriate and does not distinguish the situation well.

Like cachefiles_daemon_dir(), fix this issue by return -EEXIST to the user
if it has already been defined once.

Fixes: 8667d434b2a9 ("cachefiles: Register a miscdev and parse commands over it")
Signed-off-by: Zizhi Wo <wozizhi@huawei.com>
---
 fs/cachefiles/daemon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Howells Oct. 10, 2024, 11:31 a.m. UTC | #1
Zizhi Wo <wozizhi@huawei.com> wrote:

> In cachefiles_daemon_secctx(), if it is detected that secctx has been
> written to the cache, the error code returned is -EINVAL, which is
> inappropriate and does not distinguish the situation well.

I disagree: it is an invalid parameter, not an already extant file, and a
message is logged for clarification.  I'd prefer to avoid filesystem errors as
we are also doing filesystem operations.

David
Zizhi Wo Oct. 10, 2024, 11:47 a.m. UTC | #2
在 2024/10/10 19:31, David Howells 写道:
> Zizhi Wo <wozizhi@huawei.com> wrote:
> 
>> In cachefiles_daemon_secctx(), if it is detected that secctx has been
>> written to the cache, the error code returned is -EINVAL, which is
>> inappropriate and does not distinguish the situation well.
> 
> I disagree: it is an invalid parameter, not an already extant file, and a
> message is logged for clarification.  I'd prefer to avoid filesystem errors as
> we are also doing filesystem operations.
> 
> David
> 
> 

Alright, what I originally intended was to differentiate the error codes
between cases where no arguments are specified and where cache->secctx
already exists.

Thanks,
Zizhi Wo
diff mbox series

Patch

diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
index 89b11336a836..59e576951c68 100644
--- a/fs/cachefiles/daemon.c
+++ b/fs/cachefiles/daemon.c
@@ -587,7 +587,7 @@  static int cachefiles_daemon_secctx(struct cachefiles_cache *cache, char *args)
 
 	if (cache->secctx) {
 		pr_err("Second security context specified\n");
-		return -EINVAL;
+		return -EEXIST;
 	}
 
 	secctx = kstrdup(args, GFP_KERNEL);