linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: mcchou@chromium.org
To: linux-bluetooth@vger.kernel.org
Cc: luiz.von.dentz@intel.com, josephsih@chromium.org,
	Miao-chen Chou <mcchou@chromium.org>
Subject: [PATCH 2/2] monitor/rfcomm: Fix a potential memory access issue
Date: Fri,  2 Dec 2016 18:08:32 -0800	[thread overview]
Message-ID: <1480730912-41560-1-git-send-email-mcchou@chromium.org> (raw)
In-Reply-To: <CABBYNZ+_=ihEO+sVwUV-w5eNOs2FB=7OpjMPTdik_jLHCR29Jw@mail.gmail.com>

From: Miao-chen Chou <mcchou@chromium.org>

This patch introduces a temp variable to prevent the access to an unaligned
struct member. Since the struct rfcomm_rpn is used from PDU, enforcing alignment
is not a solution due to padding.
---
 monitor/rfcomm.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/monitor/rfcomm.c b/monitor/rfcomm.c
index b32ad40..7f1f23e 100644
--- a/monitor/rfcomm.c
+++ b/monitor/rfcomm.c
@@ -199,6 +199,7 @@ static inline bool mcc_rpn(struct rfcomm_frame *rfcomm_frame, uint8_t indent)
 {
 	struct l2cap_frame *frame = &rfcomm_frame->l2cap_frame;
 	struct rfcomm_rpn rpn;
+	uint16_t pm;

 	if (!l2cap_frame_get_u8(frame, &rpn.dlci))
 		return false;
@@ -235,8 +236,11 @@ static inline bool mcc_rpn(struct rfcomm_frame *rfcomm_frame, uint8_t indent)
 		GET_RPN_RTCI(rpn.io), GET_RPN_RTCO(rpn.io), rpn.xon,
 		rpn.xoff);

-	if (!l2cap_frame_get_le16(frame, &rpn.pm))
+	/* prevent unaligned memory access */
+	pm = rpn.pm;
+	if (!l2cap_frame_get_le16(frame, &pm))
 		return false;
+	rpn.pm = pm;

 	print_field("%*cpm 0x%04x", indent, ' ', rpn.pm);

@@ -265,6 +269,7 @@ static inline bool mcc_pn(struct rfcomm_frame *rfcomm_frame, uint8_t indent)
 {
 	struct l2cap_frame *frame = &rfcomm_frame->l2cap_frame;
 	struct rfcomm_pn pn;
+	uint16_t mtu;

 	/* rfcomm_pn struct is defined in rfcomm.h */

@@ -284,8 +289,11 @@ static inline bool mcc_pn(struct rfcomm_frame *rfcomm_frame, uint8_t indent)
 	if (!l2cap_frame_get_u8(frame, &pn.ack_timer))
 		return false;

-	if (!l2cap_frame_get_le16(frame, &pn.mtu))
+	/* prevent unaligned memory access */
+	mtu = pn.mtu;
+	if (!l2cap_frame_get_le16(frame, &mtu))
 		return false;
+	pn.mtu = mtu;

 	if (!l2cap_frame_get_u8(frame, &pn.max_retrans))
 		return false;
--
2.8.0.rc3.226.g39d4020


  reply	other threads:[~2016-12-03  2:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-19  1:32 [PATCH] monitor/rfcomm: Fix a potential memory access issue mcchou
2016-11-21 10:06 ` Luiz Augusto von Dentz
2016-11-21 10:18   ` Luiz Augusto von Dentz
2016-12-03  2:08     ` mcchou [this message]
2016-12-07 14:12       ` [PATCH 2/2] " Luiz Augusto von Dentz
2016-12-07 20:27         ` Miao-chen Chou
2016-12-07 21:07           ` Johan Hedberg
2016-12-07 23:20             ` Miao-chen Chou

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=1480730912-41560-1-git-send-email-mcchou@chromium.org \
    --to=mcchou@chromium.org \
    --cc=josephsih@chromium.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.von.dentz@intel.com \
    /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).