* [PATCH] x86: convert threshold_bank.cpus from atomic_t to refcount_t
@ 2017-04-20 13:38 Elena Reshetova
2017-04-26 10:18 ` Borislav Petkov
2017-05-21 19:59 ` [tip:ras/core] x86/mce: Convert " tip-bot for Elena Reshetova
0 siblings, 2 replies; 3+ messages in thread
From: Elena Reshetova @ 2017-04-20 13:38 UTC (permalink / raw)
To: bp; +Cc: linux-kernel, dwindsor, ishkamiel, keescook, Elena Reshetova
refcount_t type and corresponding API should be
used instead of atomic_t when the variable is used as
a reference counter. This allows to avoid accidental
refcounter overflows that might lead to use-after-free
situations.
Suggested-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
Reviewed-by: Hans Liljestrand <ishkamiel@gmail.com>
Reviewed-by: David Windsor <dwindsor@gmail.com>
---
arch/x86/include/asm/amd_nb.h | 3 ++-
arch/x86/kernel/cpu/mcheck/mce_amd.c | 6 +++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/arch/x86/include/asm/amd_nb.h b/arch/x86/include/asm/amd_nb.h
index 00c88a0..da181ad 100644
--- a/arch/x86/include/asm/amd_nb.h
+++ b/arch/x86/include/asm/amd_nb.h
@@ -3,6 +3,7 @@
#include <linux/ioport.h>
#include <linux/pci.h>
+#include <linux/refcount.h>
struct amd_nb_bus_dev_range {
u8 bus;
@@ -55,7 +56,7 @@ struct threshold_bank {
struct threshold_block *blocks;
/* initialized to the number of CPUs on the node sharing this bank */
- atomic_t cpus;
+ refcount_t cpus;
};
struct amd_northbridge {
diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c
index 524cc57..cfe0838 100644
--- a/arch/x86/kernel/cpu/mcheck/mce_amd.c
+++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c
@@ -1202,7 +1202,7 @@ static int threshold_create_bank(unsigned int cpu, unsigned int bank)
goto out;
per_cpu(threshold_banks, cpu)[bank] = b;
- atomic_inc(&b->cpus);
+ refcount_inc(&b->cpus);
err = __threshold_add_blocks(b);
@@ -1225,7 +1225,7 @@ static int threshold_create_bank(unsigned int cpu, unsigned int bank)
per_cpu(threshold_banks, cpu)[bank] = b;
if (is_shared_bank(bank)) {
- atomic_set(&b->cpus, 1);
+ refcount_set(&b->cpus, 1);
/* nb is already initialized, see above */
if (nb) {
@@ -1289,7 +1289,7 @@ static void threshold_remove_bank(unsigned int cpu, int bank)
goto free_out;
if (is_shared_bank(bank)) {
- if (!atomic_dec_and_test(&b->cpus)) {
+ if (!refcount_dec_and_test(&b->cpus)) {
__threshold_remove_blocks(b);
per_cpu(threshold_banks, cpu)[bank] = NULL;
return;
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] x86: convert threshold_bank.cpus from atomic_t to refcount_t
2017-04-20 13:38 [PATCH] x86: convert threshold_bank.cpus from atomic_t to refcount_t Elena Reshetova
@ 2017-04-26 10:18 ` Borislav Petkov
2017-05-21 19:59 ` [tip:ras/core] x86/mce: Convert " tip-bot for Elena Reshetova
1 sibling, 0 replies; 3+ messages in thread
From: Borislav Petkov @ 2017-04-26 10:18 UTC (permalink / raw)
To: Elena Reshetova; +Cc: linux-kernel, dwindsor, ishkamiel, keescook
On Thu, Apr 20, 2017 at 04:38:56PM +0300, Elena Reshetova wrote:
> refcount_t type and corresponding API should be
> used instead of atomic_t when the variable is used as
> a reference counter. This allows to avoid accidental
> refcounter overflows that might lead to use-after-free
> situations.
>
> Suggested-by: Kees Cook <keescook@chromium.org>
> Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
> Reviewed-by: Hans Liljestrand <ishkamiel@gmail.com>
> Reviewed-by: David Windsor <dwindsor@gmail.com>
> ---
> arch/x86/include/asm/amd_nb.h | 3 ++-
> arch/x86/kernel/cpu/mcheck/mce_amd.c | 6 +++---
> 2 files changed, 5 insertions(+), 4 deletions(-)
Applied, thanks.
--
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tip:ras/core] x86/mce: Convert threshold_bank.cpus from atomic_t to refcount_t
2017-04-20 13:38 [PATCH] x86: convert threshold_bank.cpus from atomic_t to refcount_t Elena Reshetova
2017-04-26 10:18 ` Borislav Petkov
@ 2017-05-21 19:59 ` tip-bot for Elena Reshetova
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Elena Reshetova @ 2017-05-21 19:59 UTC (permalink / raw)
To: linux-tip-commits
Cc: dwindsor, ishkamiel, bp, mingo, hpa, tony.luck, linux-kernel,
keescook, linux-edac, Yazen.Ghannam, elena.reshetova, tglx
Commit-ID: 473e90b2e8356f084dcf9c815a5170d4d4925897
Gitweb: http://git.kernel.org/tip/473e90b2e8356f084dcf9c815a5170d4d4925897
Author: Elena Reshetova <elena.reshetova@intel.com>
AuthorDate: Fri, 19 May 2017 11:39:13 +0200
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Sun, 21 May 2017 21:55:13 +0200
x86/mce: Convert threshold_bank.cpus from atomic_t to refcount_t
The refcount_t type and corresponding API should be used instead
of atomic_t when the variable is used as a reference counter. This
allows to avoid accidental refcounter overflows that might lead to
use-after-free situations.
Suggested-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Hans Liljestrand <ishkamiel@gmail.com>
Reviewed-by: David Windsor <dwindsor@gmail.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Yazen Ghannam <Yazen.Ghannam@amd.com>
Cc: linux-edac <linux-edac@vger.kernel.org>
Link: http://lkml.kernel.org/r/1492695536-5947-1-git-send-email-elena.reshetova@intel.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
arch/x86/include/asm/amd_nb.h | 3 ++-
arch/x86/kernel/cpu/mcheck/mce_amd.c | 6 +++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/arch/x86/include/asm/amd_nb.h b/arch/x86/include/asm/amd_nb.h
index 00c88a0..da181ad 100644
--- a/arch/x86/include/asm/amd_nb.h
+++ b/arch/x86/include/asm/amd_nb.h
@@ -3,6 +3,7 @@
#include <linux/ioport.h>
#include <linux/pci.h>
+#include <linux/refcount.h>
struct amd_nb_bus_dev_range {
u8 bus;
@@ -55,7 +56,7 @@ struct threshold_bank {
struct threshold_block *blocks;
/* initialized to the number of CPUs on the node sharing this bank */
- atomic_t cpus;
+ refcount_t cpus;
};
struct amd_northbridge {
diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c
index 6e4a047..41439ab 100644
--- a/arch/x86/kernel/cpu/mcheck/mce_amd.c
+++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c
@@ -1202,7 +1202,7 @@ static int threshold_create_bank(unsigned int cpu, unsigned int bank)
goto out;
per_cpu(threshold_banks, cpu)[bank] = b;
- atomic_inc(&b->cpus);
+ refcount_inc(&b->cpus);
err = __threshold_add_blocks(b);
@@ -1225,7 +1225,7 @@ static int threshold_create_bank(unsigned int cpu, unsigned int bank)
per_cpu(threshold_banks, cpu)[bank] = b;
if (is_shared_bank(bank)) {
- atomic_set(&b->cpus, 1);
+ refcount_set(&b->cpus, 1);
/* nb is already initialized, see above */
if (nb) {
@@ -1289,7 +1289,7 @@ static void threshold_remove_bank(unsigned int cpu, int bank)
goto free_out;
if (is_shared_bank(bank)) {
- if (!atomic_dec_and_test(&b->cpus)) {
+ if (!refcount_dec_and_test(&b->cpus)) {
__threshold_remove_blocks(b);
per_cpu(threshold_banks, cpu)[bank] = NULL;
return;
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-05-21 20:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-20 13:38 [PATCH] x86: convert threshold_bank.cpus from atomic_t to refcount_t Elena Reshetova
2017-04-26 10:18 ` Borislav Petkov
2017-05-21 19:59 ` [tip:ras/core] x86/mce: Convert " tip-bot for Elena Reshetova
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).