linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] x86, cacheinfo: dereferences before check
@ 2010-06-01  7:11 Dan Carpenter
  2010-06-01  8:23 ` Borislav Petkov
  0 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2010-06-01  7:11 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Ingo Molnar, H. Peter Anvin, x86, Borislav Petkov, Dave Jones,
	linux-kernel, kernel-janitors

This moves a couple dereferences after the checks in
show_cache_disable() and store_cache_disable().  These were introduced
fairly recently in 9350f982e4: "x86, cacheinfo: Reorganize AMD L3 cache
structure"

Signed-off-by: Dan Carpenter <error27@gmail.com>

diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
index 33eae20..1725a0e 100644
--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
@@ -399,12 +399,13 @@ amd_check_l3_disable(int index, struct _cpuid4_info_regs *this_leaf)
 static ssize_t show_cache_disable(struct _cpuid4_info *this_leaf, char *buf,
 				  unsigned int slot)
 {
-	struct pci_dev *dev = this_leaf->l3->dev;
+	struct pci_dev *dev;
 	unsigned int reg = 0;
 
 	if (!this_leaf->l3 || !this_leaf->l3->can_disable)
 		return -EINVAL;
 
+	dev = this_leaf->l3->dev;
 	if (!dev)
 		return -EINVAL;
 
@@ -456,7 +457,7 @@ static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,
 				   const char *buf, size_t count,
 				   unsigned int slot)
 {
-	struct pci_dev *dev = this_leaf->l3->dev;
+	struct pci_dev *dev;
 	int cpu = cpumask_first(to_cpumask(this_leaf->shared_cpu_map));
 	unsigned long val = 0;
 
@@ -469,6 +470,7 @@ static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,
 	if (!capable(CAP_SYS_ADMIN))
 		return -EPERM;
 
+	dev = this_leaf->l3->dev;
 	if (!dev)
 		return -EINVAL;
 

^ permalink raw reply related	[flat|nested] 6+ messages in thread
* intel_cacheinfo: potential NULL dereference?
@ 2010-06-22 11:18 Jiri Slaby
  2010-06-22 11:20 ` Jiri Slaby
  0 siblings, 1 reply; 6+ messages in thread
From: Jiri Slaby @ 2010-06-22 11:18 UTC (permalink / raw)
  To: borislav.petkov; +Cc: H. Peter Anvin, x86, Linux kernel mailing list

Hi,

commit 9350f982 changed the code so it looks like:
static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,
                                   const char *buf, size_t count,
                                   unsigned int slot)
{
        struct pci_dev *dev = this_leaf->l3->dev;   <<1>>
        int cpu = cpumask_first(to_cpumask(this_leaf->shared_cpu_map));
        unsigned long val = 0;

#define SUBCACHE_MASK   (3UL << 20)
#define SUBCACHE_INDEX  0xfff

        if (!this_leaf->l3 || !this_leaf->l3->can_disable)  <<2>>
                return -EINVAL;

Stanse found, that this_leaf->l3 is dereferenced at <<1>>, but checked
for being NULL at <<2>>. Is the check superfluous or the dev assignment
should go after the check?

thanks,
--
js

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-06-22 19:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-01  7:11 [patch] x86, cacheinfo: dereferences before check Dan Carpenter
2010-06-01  8:23 ` Borislav Petkov
2010-06-02 16:09   ` [PATCH] x86, cacheinfo: Carve out L3 cache slot accessors Borislav Petkov
2010-06-02 16:18   ` [PATCH -v2] " Borislav Petkov
2010-06-10  0:10     ` [tip:x86/cpu] " tip-bot for Borislav Petkov
  -- strict thread matches above, loose matches on Subject: below --
2010-06-22 11:18 intel_cacheinfo: potential NULL dereference? Jiri Slaby
2010-06-22 11:20 ` Jiri Slaby
2010-06-22 13:08   ` Borislav Petkov
2010-06-22 14:11     ` Jiri Slaby
2010-06-22 17:09       ` H. Peter Anvin
2010-06-22 19:19         ` Borislav Petkov
2010-06-22 19:45           ` [PATCH -v2] x86, cacheinfo: Carve out L3 cache slot accessors Borislav Petkov

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).