Skip to contentSkip to conversation

efi: READ_ONCE rng seed size before munmap

PATCH Applied Jason A. Donenfeld 4 participants 7 messages Feb 17, 2020 – Feb 26, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi: READ_ONCE rng seed size before munmap

This function is consistent with using size instead of seed->size (except for one place that this patch fixes), but it reads seed->size without using READ_ONCE, which means the compiler might still do something unwanted. So, this commit simply adds the READ_ONCE wrapper.

---
 drivers/firmware/efi/efi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/firmware/efi/efi.c +2 -2
index 621220ab3d0e..21ea99f65113 100644
@@ -552,7 +552,7 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz,
 
 		seed = early_memremap(efi.rng_seed, sizeof(*seed));
 		if (seed != NULL) {
-			size = seed->size;
+			size = READ_ONCE(seed->size);
 			early_memunmap(seed, sizeof(*seed));
 		} else {
 			pr_err("Could not map UEFI random seed!\n");
@@ -562,7 +562,7 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz,
 					      sizeof(*seed) + size);
 			if (seed != NULL) {
 				pr_notice("seeding entropy pool\n");
-				add_bootloader_randomness(seed->bits, seed->size);
+				add_bootloader_randomness(seed->bits, size);
 				early_memunmap(seed, sizeof(*seed) + size);
 			} else {
 				pr_err("Could not map UEFI random seed!\n");
Signature · 1 line
2.25.0
maintainer
#1 lore raw
Quoted 10 lines · Jason A. Donenfeld

This function is consistent with using size instead of seed->size (except for one place that this patch fixes), but it reads seed->size without using READ_ONCE, which means the compiler might still do something unwanted. So, this commit simply adds the READ_ONCE wrapper.

Thanks Jason

I've queued this in efi/urgent with a fixes: tag rather than a cc:
stable, since it only applies clean to v5.4 and later. We'll need a backport to 4.14 and 4.19 as well, which has a trivial conflict (s/add_bootloader_randomness/add_device_randomness/) but we'll need to wait for this patch to hit Linus's tree first.

Quoted 29 lines
---
 drivers/firmware/efi/efi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/firmware/efi/efi.c +2 -3
index 621220ab3d0e..21ea99f65113 100644
@@ -552,7 +552,7 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz,
 
                seed = early_memremap(efi.rng_seed, sizeof(*seed));
                if (seed != NULL) {
-                       size = seed->size;
+                       size = READ_ONCE(seed->size);
                        early_memunmap(seed, sizeof(*seed));
                } else {
                        pr_err("Could not map UEFI random seed!\n");
@@ -562,7 +562,7 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz,
                                              sizeof(*seed) + size);
                        if (seed != NULL) {
                                pr_notice("seeding entropy pool\n");
-                               add_bootloader_randomness(seed->bits, seed->size);
+                               add_bootloader_randomness(seed->bits, size);
                                early_memunmap(seed, sizeof(*seed) + size);
                        } else {
                                pr_err("Could not map UEFI random seed!\n");
--

2.25.0

#2 lore raw
Quoted 8 lines · Ard Biesheuvel
Quoted 7 lines · Jason A. Donenfeld

This function is consistent with using size instead of seed->size (except for one place that this patch fixes), but it reads seed->size without using READ_ONCE, which means the compiler might still do something unwanted. So, this commit simply adds the READ_ONCE wrapper.

Quoted 8 lines
Quoted 3 lines

Thanks Jason

I've queued this in efi/urgent with a fixes: tag rather than a cc:
stable, since it only applies clean to v5.4 and later.

Why do that? That just makes it harder for me to know to pick it up for 5.4 and newer.

Quoted 4 lines

We'll need a
backport to 4.14 and 4.19 as well, which has a trivial conflict (s/add_bootloader_randomness/add_device_randomness/) but we'll need to wait for this patch to hit Linus's tree first.

Ok, if you are going to send it on to me for stable, that's fine, but usually you can just wait for the rejection notices for older kernels before having to worry about this. In other words, you are doing more work than you have to here :)

thanks,

greg k-h

maintainer
#3 lore raw
Quoted 27 lines · Greg KH
Quoted 8 lines · Ard Biesheuvel
Quoted 7 lines · Jason A. Donenfeld

This function is consistent with using size instead of seed->size (except for one place that this patch fixes), but it reads seed->size without using READ_ONCE, which means the compiler might still do something unwanted. So, this commit simply adds the READ_ONCE wrapper.

Quoted 8 lines
Quoted 3 lines

Thanks Jason

I've queued this in efi/urgent with a fixes: tag rather than a cc:
stable, since it only applies clean to v5.4 and later.

Why do that? That just makes it harder for me to know to pick it up for 5.4 and newer.

Quoted 4 lines

We'll need a
backport to 4.14 and 4.19 as well, which has a trivial conflict (s/add_bootloader_randomness/add_device_randomness/) but we'll need to wait for this patch to hit Linus's tree first.

Quoted 5 lines

Ok, if you are going to send it on to me for stable, that's fine, but usually you can just wait for the rejection notices for older kernels before having to worry about this. In other words, you are doing more work than you have to here :)

So just

without any context is your preferred method?

#4 lore raw
Quoted 34 lines · Ard Biesheuvel
Quoted 27 lines · Greg KH
Quoted 8 lines · Ard Biesheuvel
Quoted 7 lines · Jason A. Donenfeld

This function is consistent with using size instead of seed->size (except for one place that this patch fixes), but it reads seed->size without using READ_ONCE, which means the compiler might still do something unwanted. So, this commit simply adds the READ_ONCE wrapper.

Quoted 8 lines
Quoted 3 lines

Thanks Jason

I've queued this in efi/urgent with a fixes: tag rather than a cc:
stable, since it only applies clean to v5.4 and later.

Why do that? That just makes it harder for me to know to pick it up for 5.4 and newer.

Quoted 4 lines

We'll need a
backport to 4.14 and 4.19 as well, which has a trivial conflict (s/add_bootloader_randomness/add_device_randomness/) but we'll need to wait for this patch to hit Linus's tree first.

Quoted 5 lines

Ok, if you are going to send it on to me for stable, that's fine, but usually you can just wait for the rejection notices for older kernels before having to worry about this. In other words, you are doing more work than you have to here :)

Quoted 5 lines

So just

without any context is your preferred method?

If you can provide a "Fixes:" tag showing what commit it does fix, that's even better as that way I _know_ to try to apply it to older kernels and if it fails, you will get an email saying it failed. With just a cc: stable, I do a "best guess" and don't work very hard if older kernels do not apply as I don't know if it is relevant or not.

thanks,

greg k-h

maintainer
#5 lore raw
Quoted 40 lines · Greg KH
Quoted 38 lines · Ard Biesheuvel
Quoted 27 lines · Greg KH
Quoted 8 lines · Ard Biesheuvel
Quoted 7 lines · Jason A. Donenfeld

This function is consistent with using size instead of seed->size (except for one place that this patch fixes), but it reads seed->size without using READ_ONCE, which means the compiler might still do something unwanted. So, this commit simply adds the READ_ONCE wrapper.

Quoted 8 lines
Quoted 3 lines

Thanks Jason

I've queued this in efi/urgent with a fixes: tag rather than a cc:
stable, since it only applies clean to v5.4 and later.

Why do that? That just makes it harder for me to know to pick it up for 5.4 and newer.

Quoted 4 lines

We'll need a
backport to 4.14 and 4.19 as well, which has a trivial conflict (s/add_bootloader_randomness/add_device_randomness/) but we'll need to wait for this patch to hit Linus's tree first.

Quoted 5 lines

Ok, if you are going to send it on to me for stable, that's fine, but usually you can just wait for the rejection notices for older kernels before having to worry about this. In other words, you are doing more work than you have to here :)

So just

Quoted 8 lines
Quoted 1 line

without any context is your preferred method?

If you can provide a "Fixes:" tag showing what commit it does fix, that's even better as that way I _know_ to try to apply it to older kernels and if it fails, you will get an email saying it failed. With just a cc: stable, I do a "best guess" and don't work very hard if older kernels do not apply as I don't know if it is relevant or not.

OK, will do.

#6 lore raw
In reply to Jason A. Donenfeld
The following commit has been merged into the efi/urgent branch of tip:

The following commit has been merged into the efi/urgent branch of tip:

Commit-ID:     be36f9e7517e17810ec369626a128d7948942259
Gitweb:        https://git.kernel.org/tip/be36f9e7517e17810ec369626a128d7948942259
Author:        Jason A. Donenfeld <[email protected]>
AuthorDate:    Fri, 21 Feb 2020 09:48:49 +01:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Wed, 26 Feb 2020 15:31:43 +01:00

efi: READ_ONCE rng seed size before munmap

This function is consistent with using size instead of seed->size (except for one place that this patch fixes), but it reads seed->size without using READ_ONCE, which means the compiler might still do something unwanted. So, this commit simply adds the READ_ONCE wrapper.

---
 drivers/firmware/efi/efi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/firmware/efi/efi.c +2 -2
index 621220a..21ea99f 100644
@@ -552,7 +552,7 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz,
 
 		seed = early_memremap(efi.rng_seed, sizeof(*seed));
 		if (seed != NULL) {
-			size = seed->size;
+			size = READ_ONCE(seed->size);
 			early_memunmap(seed, sizeof(*seed));
 		} else {
 			pr_err("Could not map UEFI random seed!\n");
@@ -562,7 +562,7 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz,
 					      sizeof(*seed) + size);
 			if (seed != NULL) {
 				pr_notice("seeding entropy pool\n");
-				add_bootloader_randomness(seed->bits, seed->size);
+				add_bootloader_randomness(seed->bits, size);
 				early_memunmap(seed, sizeof(*seed) + size);
 			} else {
 				pr_err("Could not map UEFI random seed!\n");