linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mike Waychison <mikew-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
To: Greg KH <greg-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>,
	Olof Johansson <olofj-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
	Andi Kleen <andi-Vw/NltI1exuRpAAqCnN02g@public.gmane.org>,
	Alan Cox <alan-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>,
	Robert Lippert <rlippert-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
Cc: Jon Mayer <jonmayer-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
	Tony Luck <tony.luck-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
	Duncan Laurie <dlaurie-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
	Aaron Durbin <adurbin-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Tim Hockin <thockin-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
	David Hendrix <dhendrix-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
	linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH v2 6/5] Fix unaligned memory accesses in dmi-sysfs
Date: Fri, 25 Feb 2011 15:06:25 -0800	[thread overview]
Message-ID: <4D6835F1.2050304@google.com> (raw)
In-Reply-To: <20110223015307.13068.14063.stgit-tzAwxxnF6Tt6FDdRrpk8kO4/NqBCd+6Q@public.gmane.org>

DMI entries are arranged in memory back to back with no alignment
guarantees. This means that the struct dmi_header passed to callbacks
from dmi_walk() itself isn't byte aligned.  This causes problems on
architectures that expect aligned data, such as IA64.

The dmi-sysfs patchset introduced structure member accesses through
this passed in dmi_header.  Fix this by memcpy()ing the structures to
temporary locations on stack when inspecting/copying them.

Signed-off-by: Mike Waychison <mikew-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
Tested-by: Tony Luck <tony.luck-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
  dmi-sysfs.c |   28 +++++++++++++---------------
  1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/drivers/firmware/dmi-sysfs.c b/drivers/firmware/dmi-sysfs.c
index a5afd80..eb26d62 100644
--- a/drivers/firmware/dmi-sysfs.c
+++ b/drivers/firmware/dmi-sysfs.c
@@ -263,20 +263,16 @@ struct dmi_system_event_log {
  	u8	supported_log_type_descriptos[0];
  } __packed;

-static const struct dmi_system_event_log *to_sel(const struct 
dmi_header *dh)
-{
-	return (const struct dmi_system_event_log *)dh;
-}
-
  #define DMI_SYSFS_SEL_FIELD(_field) \
  static ssize_t dmi_sysfs_sel_##_field(struct dmi_sysfs_entry *entry, \
  				      const struct dmi_header *dh, \
  				      char *buf) \
  { \
-	const struct dmi_system_event_log *sel = to_sel(dh); \
-	if (sizeof(*sel) > dmi_entry_length(dh)) \
+	struct dmi_system_event_log sel; \
+	if (sizeof(sel) > dmi_entry_length(dh)) \
  		return -EIO; \
-	return sprintf(buf, "%u\n", sel->_field); \
+	memcpy(&sel, dh, sizeof(sel)); \
+	return sprintf(buf, "%u\n", sel._field); \
  } \
  static DMI_SYSFS_MAPPED_ATTR(sel, _field)

@@ -403,26 +399,28 @@ static ssize_t dmi_sel_raw_read_helper(struct 
dmi_sysfs_entry *entry,
  				       void *_state)
  {
  	struct dmi_read_state *state = _state;
-	const struct dmi_system_event_log *sel = to_sel(dh);
+	struct dmi_system_event_log sel;

-	if (sizeof(*sel) > dmi_entry_length(dh))
+	if (sizeof(sel) > dmi_entry_length(dh))
  		return -EIO;

-	switch (sel->access_method) {
+	memcpy(&sel, dh, sizeof(sel));
+
+	switch (sel.access_method) {
  	case DMI_SEL_ACCESS_METHOD_IO8:
  	case DMI_SEL_ACCESS_METHOD_IO2x8:
  	case DMI_SEL_ACCESS_METHOD_IO16:
-		return dmi_sel_raw_read_io(entry, sel, state->buf,
+		return dmi_sel_raw_read_io(entry, &sel, state->buf,
  					   state->pos, state->count);
  	case DMI_SEL_ACCESS_METHOD_PHYS32:
-		return dmi_sel_raw_read_phys32(entry, sel, state->buf,
+		return dmi_sel_raw_read_phys32(entry, &sel, state->buf,
  					       state->pos, state->count);
  	case DMI_SEL_ACCESS_METHOD_GPNV:
  		pr_info("dmi-sysfs: GPNV support missing.\n");
  		return -EIO;
  	default:
  		pr_info("dmi-sysfs: Unknown access method %02x\n",
-			sel->access_method);
+			sel.access_method);
  		return -EIO;
  	}
  }
@@ -595,7 +593,7 @@ static void __init dmi_sysfs_register_handle(const 
struct dmi_header *dh,
  	}

  	/* Set the key */
-	entry->dh = *dh;
+	memcpy(&entry->dh, dh, sizeof(*dh));
  	entry->instance = instance_counts[dh->type]++;
  	entry->position = position_count++;

  parent reply	other threads:[~2011-02-25 23:06 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-23  1:53 [PATCH v2 0/5] Exporting DMI entries via sysfs Mike Waychison
2011-02-23  1:53 ` [PATCH v2 1/5] firmware: Add DMI entry types to the headers Mike Waychison
2011-02-23  1:53 ` [PATCH v2 2/5] firmware: Basic dmi-sysfs support Mike Waychison
2011-02-23 19:43   ` Tony Luck
     [not found]     ` <AANLkTinjhY3oiFTq2xq4fwQ-mtLZ8ph435+nc5irM7wZ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-02-23 20:28       ` Mike Waychison
     [not found]         ` <AANLkTi=+-Wc0bWdpvR+X6UszLf7MXKYgi8Oo6anN-jR8-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-02-23 21:29           ` Tony Luck
     [not found]             ` <AANLkTi=dE5_VjJ+5H6cWf9nAtdkLiqhSXo6Gvd_uGQ25-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-02-25 19:58               ` Greg KH
2011-02-23  1:53 ` [PATCH v2 4/5] firmware: Expose DMI type 15 System Event Log Mike Waychison
2011-02-23  1:53 ` [PATCH v2 5/5] firmware: Add documentation for /sys/firmware/dmi Mike Waychison
     [not found] ` <20110223015307.13068.14063.stgit-tzAwxxnF6Tt6FDdRrpk8kO4/NqBCd+6Q@public.gmane.org>
2011-02-23  1:53   ` [PATCH v2 3/5] firmware: Break out system_event_log in dmi-sysfs Mike Waychison
2011-02-25 20:03   ` [PATCH v2 0/5] Exporting DMI entries via sysfs Greg KH
2011-02-25 23:06   ` Mike Waychison [this message]
     [not found]     ` <4D6835F1.2050304-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2011-02-25 23:20       ` [PATCH v2 6/5] Fix unaligned memory accesses in dmi-sysfs Greg KH
2011-02-25 23:41   ` [resend PATCH " Mike Waychison

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D6835F1.2050304@google.com \
    --to=mikew-hpiqsd4aklfqt0dzr+alfa@public.gmane.org \
    --cc=adurbin-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=alan-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org \
    --cc=andi-Vw/NltI1exuRpAAqCnN02g@public.gmane.org \
    --cc=dhendrix-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    --cc=dlaurie-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=greg-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org \
    --cc=jonmayer-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=olofj-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    --cc=rlippert-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=thockin-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=tony.luck-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).