diff options
author | Elena Reshetova <elena.reshetova@intel.com> | 2017-05-19 05:39:13 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2017-05-21 15:55:13 -0400 |
commit | 473e90b2e8356f084dcf9c815a5170d4d4925897 (patch) | |
tree | 59e060264aa0a1d6c3cc32a04dba8170bdceca56 | |
parent | 5f0744e50db1628d6de770b92278445b3de2779f (diff) |
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>
-rw-r--r-- | arch/x86/include/asm/amd_nb.h | 3 | ||||
-rw-r--r-- | 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 00c88a01301d..da181ad1d5f8 100644 --- a/arch/x86/include/asm/amd_nb.h +++ b/arch/x86/include/asm/amd_nb.h | |||
@@ -3,6 +3,7 @@ | |||
3 | 3 | ||
4 | #include <linux/ioport.h> | 4 | #include <linux/ioport.h> |
5 | #include <linux/pci.h> | 5 | #include <linux/pci.h> |
6 | #include <linux/refcount.h> | ||
6 | 7 | ||
7 | struct amd_nb_bus_dev_range { | 8 | struct amd_nb_bus_dev_range { |
8 | u8 bus; | 9 | u8 bus; |
@@ -55,7 +56,7 @@ struct threshold_bank { | |||
55 | struct threshold_block *blocks; | 56 | struct threshold_block *blocks; |
56 | 57 | ||
57 | /* initialized to the number of CPUs on the node sharing this bank */ | 58 | /* initialized to the number of CPUs on the node sharing this bank */ |
58 | atomic_t cpus; | 59 | refcount_t cpus; |
59 | }; | 60 | }; |
60 | 61 | ||
61 | struct amd_northbridge { | 62 | struct amd_northbridge { |
diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c index 6e4a047e4b68..41439ab41102 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) | |||
1202 | goto out; | 1202 | goto out; |
1203 | 1203 | ||
1204 | per_cpu(threshold_banks, cpu)[bank] = b; | 1204 | per_cpu(threshold_banks, cpu)[bank] = b; |
1205 | atomic_inc(&b->cpus); | 1205 | refcount_inc(&b->cpus); |
1206 | 1206 | ||
1207 | err = __threshold_add_blocks(b); | 1207 | err = __threshold_add_blocks(b); |
1208 | 1208 | ||
@@ -1225,7 +1225,7 @@ static int threshold_create_bank(unsigned int cpu, unsigned int bank) | |||
1225 | per_cpu(threshold_banks, cpu)[bank] = b; | 1225 | per_cpu(threshold_banks, cpu)[bank] = b; |
1226 | 1226 | ||
1227 | if (is_shared_bank(bank)) { | 1227 | if (is_shared_bank(bank)) { |
1228 | atomic_set(&b->cpus, 1); | 1228 | refcount_set(&b->cpus, 1); |
1229 | 1229 | ||
1230 | /* nb is already initialized, see above */ | 1230 | /* nb is already initialized, see above */ |
1231 | if (nb) { | 1231 | if (nb) { |
@@ -1289,7 +1289,7 @@ static void threshold_remove_bank(unsigned int cpu, int bank) | |||
1289 | goto free_out; | 1289 | goto free_out; |
1290 | 1290 | ||
1291 | if (is_shared_bank(bank)) { | 1291 | if (is_shared_bank(bank)) { |
1292 | if (!atomic_dec_and_test(&b->cpus)) { | 1292 | if (!refcount_dec_and_test(&b->cpus)) { |
1293 | __threshold_remove_blocks(b); | 1293 | __threshold_remove_blocks(b); |
1294 | per_cpu(threshold_banks, cpu)[bank] = NULL; | 1294 | per_cpu(threshold_banks, cpu)[bank] = NULL; |
1295 | return; | 1295 | return; |