From b482c393a2e64d8abf07041d96b6c7aa58858427 Mon Sep 17 00:00:00 2001
From: Anthony Iliopoulos <ailiop@suse.com>
Date: Tue, 18 Jan 2022 17:50:40 +0100
Subject: [PATCH] nvme: fix visibility of dev_attr_dhchap_ctrl_secret sysfs
attribute
Patch-mainline: not yet, fix for submitted nvme-auth
References: bsc#1194839
The attribute should not be accessible to userspace unless ctrl->opts
is initialized, otherwise accessing the attribute will trigger a null
ptr deref.
Signed-off-by: Anthony Iliopoulos <ailiop@suse.com>
Acked-by: Anthony Iliopoulos <ailiop@suse.com>
---
drivers/nvme/host/core.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index eb9a4fb91bc6..d9d99b874978 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3682,6 +3682,8 @@ static umode_t nvme_dev_attrs_are_visible(struct kobject *kobj,
#ifdef CONFIG_NVME_AUTH
if (a == &dev_attr_dhchap_secret.attr && !ctrl->opts)
return 0;
+ if (a == &dev_attr_dhchap_ctrl_secret.attr && !ctrl->opts)
+ return 0;
#endif
return a->mode;
--
2.34.1