diff mbox series

[v5,12/25] powerpc/secvar: Warn when PAGE_SIZE is smaller than max object size

Message ID 20230131063928.388035-13-ajd@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series pSeries dynamic secure boot secvar interface + platform keyring loading | expand

Commit Message

Andrew Donnellan Jan. 31, 2023, 6:39 a.m. UTC
Due to sysfs constraints, when writing to a variable, we can only handle
writes of up to PAGE_SIZE.

It's possible that the maximum object size is larger than PAGE_SIZE, in
which case, print a warning on boot so that the user is aware.

Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Signed-off-by: Russell Currey <ruscur@russell.cc>

---

v3: New patch (ajd)
---
 arch/powerpc/kernel/secvar-sysfs.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Stefan Berger Jan. 31, 2023, 3:57 p.m. UTC | #1
On 1/31/23 01:39, Andrew Donnellan wrote:
> Due to sysfs constraints, when writing to a variable, we can only handle
> writes of up to PAGE_SIZE.
> 
> It's possible that the maximum object size is larger than PAGE_SIZE, in
> which case, print a warning on boot so that the user is aware.
> 
> Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
> Signed-off-by: Russell Currey <ruscur@russell.cc>
> 
> ---
> 
> v3: New patch (ajd)
> ---
>   arch/powerpc/kernel/secvar-sysfs.c | 9 +++++++++
>   1 file changed, 9 insertions(+)
> 
> diff --git a/arch/powerpc/kernel/secvar-sysfs.c b/arch/powerpc/kernel/secvar-sysfs.c
> index 2cbc60b37e4e..9b6be63b7b36 100644
> --- a/arch/powerpc/kernel/secvar-sysfs.c
> +++ b/arch/powerpc/kernel/secvar-sysfs.c
> @@ -223,6 +223,7 @@ static int secvar_sysfs_load_static(void)
>   
>   static int secvar_sysfs_init(void)
>   {
> +	u64 max_size;
>   	int rc;
>   
>   	if (!secvar_ops) {
> @@ -272,6 +273,14 @@ static int secvar_sysfs_init(void)
>   		goto err;
>   	}
>   
> +	// Due to sysfs limitations, we will only ever get a write buffer of
> +	// up to 1 page in size. Print a warning if this is potentially going
> +	// to cause problems, so that the user is aware.
> +	secvar_ops->max_size(&max_size);
> +	if (max_size > PAGE_SIZE)
> +		pr_warn_ratelimited("PAGE_SIZE (%lu) is smaller than maximum object size (%llu), writes are limited to PAGE_SIZE\n",
> +				    PAGE_SIZE, max_size);
> +
>   	return 0;
>   err:
>   	kobject_put(secvar_kobj);

Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
diff mbox series

Patch

diff --git a/arch/powerpc/kernel/secvar-sysfs.c b/arch/powerpc/kernel/secvar-sysfs.c
index 2cbc60b37e4e..9b6be63b7b36 100644
--- a/arch/powerpc/kernel/secvar-sysfs.c
+++ b/arch/powerpc/kernel/secvar-sysfs.c
@@ -223,6 +223,7 @@  static int secvar_sysfs_load_static(void)
 
 static int secvar_sysfs_init(void)
 {
+	u64 max_size;
 	int rc;
 
 	if (!secvar_ops) {
@@ -272,6 +273,14 @@  static int secvar_sysfs_init(void)
 		goto err;
 	}
 
+	// Due to sysfs limitations, we will only ever get a write buffer of
+	// up to 1 page in size. Print a warning if this is potentially going
+	// to cause problems, so that the user is aware.
+	secvar_ops->max_size(&max_size);
+	if (max_size > PAGE_SIZE)
+		pr_warn_ratelimited("PAGE_SIZE (%lu) is smaller than maximum object size (%llu), writes are limited to PAGE_SIZE\n",
+				    PAGE_SIZE, max_size);
+
 	return 0;
 err:
 	kobject_put(secvar_kobj);