x86: fix null pointer dereference in intel_get_extended_msrs()
PATCH 1/1 x86: fix null pointer dereference in intel_get_extended_msrs()
memset(&mc_ext, 0, ...)' leads to a buffer overflow and a subsequent null pointer dereference. Replace &mc_ext' with `mc_ext'.
--- xen/arch/x86/cpu/mcheck/mce_intel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/cpu/mcheck/mce_intel.c +1 -1
@@ -200,7 +200,7 @@ intel_get_extended_msrs(struct mcinfo_global *mig, struct mc_info *mi) }/* this function will called when CAP(9).MCG_EXT_P = 1 */ -memset (&mc_ext,0 ,sizeof (struct mcinfo_extended )); +memset (mc_ext,0 ,sizeof (struct mcinfo_extended )); mc_ext->common.type =MC_TYPE_EXTENDED ; mc_ext->common.size =sizeof (struct mcinfo_extended );
Signature · 1 line
1.7.10.4
Hazardous memset/memcpy idiom (was Re: [PATCH] x86: fix null pointer dereference in intel_get_extended_msrs())
Xi Wang writes ("[Xen-devel] [PATCH] x86: fix null pointer dereference in intel_get_extended_msrs()"):
Quoted 2 lines
memset(&mc_ext, 0, ...)' leads to a buffer overflow and a subsequent null pointer dereference. Replace&mc_ext' with `mc_ext'.
Really I think we shouldn't be writing out these kind of memsets. They're too error-prone. We should have a macro, perhaps like this:
#define FILLZERO(object) memset(&(object), 0, sizeof(object))
Likewise a copy macro.
Ian.
Hazardous memset/memcpy idiom (was Re: [PATCH] x86: fix null pointer dereference in intel_get_extended_msrs())
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Ian Jackson
Xi Wang writes ("[Xen-devel] [PATCH] x86: fix null pointer dereference in
intel_get_extended_msrs()"):Quoted 2 lines
memset(&mc_ext, 0, ...)' leads to a buffer overflow and a subsequent null pointer dereference. Replace&mc_ext' with `mc_ext'.
Quoted 6 lines
Really I think we shouldn't be writing out these kind of memsets. They're too error-prone. We should have a macro, perhaps like this:
#define FILLZERO(object) memset(&(object), 0, sizeof(object))Likewise a copy macro.
Unfortunately that wouldn't be usable in all cases (arrays passed to functions), and hence I'm not really confident this would be a good move. But yes, I considered what you suggest a number of times already, but dropped the idea each time because of its lack of general applicability.
I'm afraid we just have to live with the bad side effects of the power C provides.
Jan
Re: Hazardous memset/memcpy idiom (was Re: [PATCH] x86: fix null pointer dereference in intel_get_extended_msrs())
Quoted 13 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Ian Jackson
Xi Wang writes ("[Xen-devel] [PATCH] x86: fix null pointer dereference in
intel_get_extended_msrs()"):Quoted 2 lines
memset(&mc_ext, 0, ...)' leads to a buffer overflow and a subsequent null pointer dereference. Replace&mc_ext' with `mc_ext'.Quoted 6 lines
Really I think we shouldn't be writing out these kind of memsets. They're too error-prone. We should have a macro, perhaps like this:
#define FILLZERO(object) memset(&(object), 0, sizeof(object))Likewise a copy macro.
Quoted 8 lines
Unfortunately that wouldn't be usable in all cases (arrays passed to functions), and hence I'm not really confident this would be a good move. But yes, I considered what you suggest a number of times already, but dropped the idea each time because of its lack of general applicability.
I'm afraid we just have to live with the bad side effects of the power C provides.
In this specific case perhaps x86_mcinfo_reserve() should zero the buffer instead of each caller having to do the right thing? Most callers have a memset, a couple immediately fill in the buffer instead of zeroing it, but this isn't a hot path, is it?
Ian.
Re: Hazardous memset/memcpy idiom (was Re: [PATCH] x86: fix null pointer dereference in intel_get_extended_msrs())
Quoted 21 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 19 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Ian Jackson
Xi Wang writes ("[Xen-devel] [PATCH] x86: fix null pointer dereference in
intel_get_extended_msrs()"):Quoted 2 lines
memset(&mc_ext, 0, ...)' leads to a buffer overflow and a subsequent null pointer dereference. Replace&mc_ext' with `mc_ext'.Quoted 6 lines
Really I think we shouldn't be writing out these kind of memsets. They're too error-prone. We should have a macro, perhaps like this:
#define FILLZERO(object) memset(&(object), 0, sizeof(object))Likewise a copy macro.
Unfortunately that wouldn't be usable in all cases (arrays passed to functions), and hence I'm not really confident this would be a good move. But yes, I considered what you suggest a number of times already, but dropped the idea each time because of its lack of general applicability.
Quoted 7 lines
Quoted 2 lines
I'm afraid we just have to live with the bad side effects of the power C provides.
In this specific case perhaps
x86_mcinfo_reserve()should zero the buffer instead of each caller having to do the right thing? Most callers have a memset, a couple immediately fill in the buffer instead of zeroing it, but this isn't a hot path, is it?
Yes, I think we should. I'll prepare a patch. Nevertheless, the original patch is desirable to have as a separate one, as that's what I would prefer for backporting.
Jan
Hazardous memset/memcpy idiom (was Re: [PATCH] x86: fix null pointer dereference in intel_get_extended_msrs())
In reply to Jan BeulichJan Beulich writes ("Hazardous memset/memcpy idiom (was Re: [Xen-devel] [PATCH] x86: fix null pointer dereference in intel_get_extended_msrs())"):
Quoted 2 lines
Unfortunately that wouldn't be usable in all cases (arrays passed to functions),
#define FILLZERO_ARRAY(arrayobj, num_elements) \
(memset((arrayobj),0,sizeof((arrayobj)[0])*(num_elements)))And the fact that a macro isn't universally applicable isn't a reason not to replace an error-prone idiom in the very frequent cases where the macro would be applicable.
Ian.