* [patch] [IrDA]: small read past the end of array in debug code
@ 2013-04-17 7:10 Dan Carpenter
2013-04-19 21:33 ` David Miller
0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2013-04-17 7:10 UTC (permalink / raw)
To: Samuel Ortiz; +Cc: David S. Miller, netdev, kernel-janitors
The "reason" can come from skb->data[] and it hasn't been capped so it
can be from 0-255 instead of just 0-6. For example in irlmp_state_dtr()
the code does:
reason = skb->data[3];
...
irlmp_disconnect_indication(self, reason, skb);
Also LMREASON has a couple other values which don't have entries in the
irlmp_reasons[] array. And 0xff is a valid reason as well which means
"unknown".
So far as I can see we don't actually care about "reason" except for in
the debug code.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/include/net/irda/irlmp.h b/include/net/irda/irlmp.h
index f741091..f132924 100644
--- a/include/net/irda/irlmp.h
+++ b/include/net/irda/irlmp.h
@@ -256,7 +256,8 @@ static inline __u32 irlmp_get_daddr(const struct lsap_cb *self)
return (self && self->lap) ? self->lap->daddr : 0;
}
-extern const char *irlmp_reasons[];
+const char *irlmp_reason_str(LM_REASON reason);
+
extern int sysctl_discovery_timeout;
extern int sysctl_discovery_slots;
extern int sysctl_discovery;
diff --git a/net/irda/irlmp.c b/net/irda/irlmp.c
index 6115a44..1064621 100644
--- a/net/irda/irlmp.c
+++ b/net/irda/irlmp.c
@@ -66,8 +66,15 @@ const char *irlmp_reasons[] = {
"LM_LAP_RESET",
"LM_INIT_DISCONNECT",
"ERROR, NOT USED",
+ "UNKNOWN",
};
+const char *irlmp_reason_str(LM_REASON reason)
+{
+ reason = min_t(size_t, reason, ARRAY_SIZE(irlmp_reasons) - 1);
+ return irlmp_reasons[reason];
+}
+
/*
* Function irlmp_init (void)
*
@@ -747,7 +754,8 @@ void irlmp_disconnect_indication(struct lsap_cb *self, LM_REASON reason,
{
struct lsap_cb *lsap;
- IRDA_DEBUG(1, "%s(), reason=%s\n", __func__, irlmp_reasons[reason]);
+ IRDA_DEBUG(1, "%s(), reason=%s [%d]\n", __func__,
+ irlmp_reason_str(reason), reason);
IRDA_ASSERT(self != NULL, return;);
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return;);
diff --git a/net/irda/iriap.c b/net/irda/iriap.c
index 29340a9..e1b37f5 100644
--- a/net/irda/iriap.c
+++ b/net/irda/iriap.c
@@ -303,7 +303,8 @@ static void iriap_disconnect_indication(void *instance, void *sap,
{
struct iriap_cb *self;
- IRDA_DEBUG(4, "%s(), reason=%s\n", __func__, irlmp_reasons[reason]);
+ IRDA_DEBUG(4, "%s(), reason=%s [%d]\n", __func__,
+ irlmp_reason_str(reason), reason);
self = instance;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [patch] [IrDA]: small read past the end of array in debug code
2013-04-17 7:10 [patch] [IrDA]: small read past the end of array in debug code Dan Carpenter
@ 2013-04-19 21:33 ` David Miller
2013-04-20 20:39 ` Dan Carpenter
0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2013-04-19 21:33 UTC (permalink / raw)
To: dan.carpenter; +Cc: samuel, netdev, kernel-janitors
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Wed, 17 Apr 2013 10:10:38 +0300
> The "reason" can come from skb->data[] and it hasn't been capped so it
> can be from 0-255 instead of just 0-6. For example in irlmp_state_dtr()
> the code does:
>
> reason = skb->data[3];
> ...
> irlmp_disconnect_indication(self, reason, skb);
>
> Also LMREASON has a couple other values which don't have entries in the
> irlmp_reasons[] array. And 0xff is a valid reason as well which means
> "unknown".
>
> So far as I can see we don't actually care about "reason" except for in
> the debug code.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Applied but please put the subsystem prefix outside of [] which get
stripped by git am and other tools. I fixed it up to be "irda: ".
Thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] [IrDA]: small read past the end of array in debug code
2013-04-19 21:33 ` David Miller
@ 2013-04-20 20:39 ` Dan Carpenter
2013-04-22 18:02 ` Ben Hutchings
0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2013-04-20 20:39 UTC (permalink / raw)
To: David Miller; +Cc: samuel, netdev, kernel-janitors
On Fri, Apr 19, 2013 at 05:33:29PM -0400, David Miller wrote:
> From: Dan Carpenter <dan.carpenter@oracle.com>
> Date: Wed, 17 Apr 2013 10:10:38 +0300
>
> > The "reason" can come from skb->data[] and it hasn't been capped so it
> > can be from 0-255 instead of just 0-6. For example in irlmp_state_dtr()
> > the code does:
> >
> > reason = skb->data[3];
> > ...
> > irlmp_disconnect_indication(self, reason, skb);
> >
> > Also LMREASON has a couple other values which don't have entries in the
> > irlmp_reasons[] array. And 0xff is a valid reason as well which means
> > "unknown".
> >
> > So far as I can see we don't actually care about "reason" except for in
> > the debug code.
> >
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> Applied but please put the subsystem prefix outside of [] which get
> stripped by git am and other tools. I fixed it up to be "irda: ".
>
Sorry about that. I won't do it again.
It's weird because the prefix was cut and pasted from an earlier
commit. Also [media] and [SCSI] use square brackets in their
subsystems. I tried some experiments with "git am" and you're right
that "git am" always strips out the square bracket stuff. Odd.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] [IrDA]: small read past the end of array in debug code
2013-04-20 20:39 ` Dan Carpenter
@ 2013-04-22 18:02 ` Ben Hutchings
0 siblings, 0 replies; 4+ messages in thread
From: Ben Hutchings @ 2013-04-22 18:02 UTC (permalink / raw)
To: Dan Carpenter; +Cc: David Miller, samuel, netdev, kernel-janitors
On Sat, 2013-04-20 at 23:39 +0300, Dan Carpenter wrote:
> On Fri, Apr 19, 2013 at 05:33:29PM -0400, David Miller wrote:
> > From: Dan Carpenter <dan.carpenter@oracle.com>
> > Date: Wed, 17 Apr 2013 10:10:38 +0300
> >
> > > The "reason" can come from skb->data[] and it hasn't been capped so it
> > > can be from 0-255 instead of just 0-6. For example in irlmp_state_dtr()
> > > the code does:
> > >
> > > reason = skb->data[3];
> > > ...
> > > irlmp_disconnect_indication(self, reason, skb);
> > >
> > > Also LMREASON has a couple other values which don't have entries in the
> > > irlmp_reasons[] array. And 0xff is a valid reason as well which means
> > > "unknown".
> > >
> > > So far as I can see we don't actually care about "reason" except for in
> > > the debug code.
> > >
> > > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> >
> > Applied but please put the subsystem prefix outside of [] which get
> > stripped by git am and other tools. I fixed it up to be "irda: ".
> >
>
> Sorry about that. I won't do it again.
>
> It's weird because the prefix was cut and pasted from an earlier
> commit. Also [media] and [SCSI] use square brackets in their
> subsystems. I tried some experiments with "git am" and you're right
> that "git am" always strips out the square bracket stuff. Odd.
The -k option suppresses this behaviour, but then it will also keep
[PATCH]. It's a shame there's no option to strip just \[PATCH[^]]*\]
Ben.
--
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-04-22 18:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-17 7:10 [patch] [IrDA]: small read past the end of array in debug code Dan Carpenter
2013-04-19 21:33 ` David Miller
2013-04-20 20:39 ` Dan Carpenter
2013-04-22 18:02 ` Ben Hutchings
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).