diff mbox

mac80211: Fix the buffer length in debugfs for smps

Message ID 1388869583-2767-1-git-send-email-chaitanya.mgit@gmail.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Krishna Chaitanya Jan. 4, 2014, 9:06 p.m. UTC
This was blocking sending SMPS action frames 
through debugfs.

Signed-off-by: Chaitanya T K <chaitanya.mgit@gmail.com>
---
 net/mac80211/debugfs_netdev.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Johannes Berg Jan. 6, 2014, 2:48 p.m. UTC | #1
On Sun, 2014-01-05 at 02:36 +0530, Chaitanya T K wrote:
> This was blocking sending SMPS action frames 
> through debugfs.

I don't see any issue here, explain.

johannes

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Krishna Chaitanya Jan. 6, 2014, 3:05 p.m. UTC | #2
On Mon, Jan 6, 2014 at 8:18 PM, Johannes Berg <johannes@sipsolutions.net> wrote:
> On Sun, 2014-01-05 at 02:36 +0530, Chaitanya T K wrote:
>> This was blocking sending SMPS action frames
>> through debugfs.
>
> I don't see any issue here, explain.
>
> johannes
>
buflen includes the new line character as well, hence the comparison
strncmp fails for all combiantions.

echo "static" > ieee80211/phyX/netdev\:wlanX/smps
Then

buf=static\n
buflen=7

But the comparison is with "static" which doesn't include "\n"
hence the comparison fails.
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Johannes Berg Jan. 6, 2014, 3:15 p.m. UTC | #3
On Mon, 2014-01-06 at 20:35 +0530, Krishna Chaitanya wrote:
> On Mon, Jan 6, 2014 at 8:18 PM, Johannes Berg <johannes@sipsolutions.net> wrote:
> > On Sun, 2014-01-05 at 02:36 +0530, Chaitanya T K wrote:
> >> This was blocking sending SMPS action frames
> >> through debugfs.
> >
> > I don't see any issue here, explain.
> >
> > johannes
> >
> buflen includes the new line character as well, hence the comparison
> strncmp fails for all combiantions.
> 
> echo "static" > ieee80211/phyX/netdev\:wlanX/smps
> Then
> 
> buf=static\n
> buflen=7
> 
> But the comparison is with "static" which doesn't include "\n"
> hence the comparison fails.

Err, ok, so you can just do "echo -n static", right?

And then your patch breaks the way it currently works, which is about
the worst you can do.

johannes


--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Krishna Chaitanya Jan. 6, 2014, 3:32 p.m. UTC | #4
On Mon, Jan 6, 2014 at 8:45 PM, Johannes Berg <johannes@sipsolutions.net> wrote:
> On Mon, 2014-01-06 at 20:35 +0530, Krishna Chaitanya wrote:
>> On Mon, Jan 6, 2014 at 8:18 PM, Johannes Berg <johannes@sipsolutions.net> wrote:
>> > On Sun, 2014-01-05 at 02:36 +0530, Chaitanya T K wrote:
>> >> This was blocking sending SMPS action frames
>> >> through debugfs.
>> >
>> > I don't see any issue here, explain.
>> >
>> > johannes
>> >
>> buflen includes the new line character as well, hence the comparison
>> strncmp fails for all combiantions.
>>
>> echo "static" > ieee80211/phyX/netdev\:wlanX/smps
>> Then
>>
>> buf=static\n
>> buflen=7
>>
>> But the comparison is with "static" which doesn't include "\n"
>> hence the comparison fails.
>
> Err, ok, so you can just do "echo -n static", right?
>
> And then your patch breaks the way it currently works, which is about
> the worst you can do.
>
Ok, if one works other fails.

So instead why cant we use strlen(local_string)
instead of using buflen(remote). That way we can make sure we only
compare the characters we need and leave out the extra ones.
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Johannes Berg Jan. 6, 2014, 3:55 p.m. UTC | #5
On Mon, 2014-01-06 at 21:02 +0530, Krishna Chaitanya wrote:
> On Mon, Jan 6, 2014 at 8:45 PM, Johannes Berg <johannes@sipsolutions.net> wrote:
> > On Mon, 2014-01-06 at 20:35 +0530, Krishna Chaitanya wrote:
> >> On Mon, Jan 6, 2014 at 8:18 PM, Johannes Berg <johannes@sipsolutions.net> wrote:
> >> > On Sun, 2014-01-05 at 02:36 +0530, Chaitanya T K wrote:
> >> >> This was blocking sending SMPS action frames
> >> >> through debugfs.
> >> >
> >> > I don't see any issue here, explain.
> >> >
> >> > johannes
> >> >
> >> buflen includes the new line character as well, hence the comparison
> >> strncmp fails for all combiantions.
> >>
> >> echo "static" > ieee80211/phyX/netdev\:wlanX/smps
> >> Then
> >>
> >> buf=static\n
> >> buflen=7
> >>
> >> But the comparison is with "static" which doesn't include "\n"
> >> hence the comparison fails.
> >
> > Err, ok, so you can just do "echo -n static", right?
> >
> > And then your patch breaks the way it currently works, which is about
> > the worst you can do.
> >
> Ok, if one works other fails.
> 
> So instead why cant we use strlen(local_string)
> instead of using buflen(remote). That way we can make sure we only
> compare the characters we need and leave out the extra ones.

It wouldn't fix the problem and would introduce a buffer overflow bug.

johannes


--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Krishna Chaitanya Jan. 6, 2014, 4:46 p.m. UTC | #6
On Mon, Jan 6, 2014 at 9:25 PM, Johannes Berg <johannes@sipsolutions.net> wrote:
> On Mon, 2014-01-06 at 21:02 +0530, Krishna Chaitanya wrote:
>> On Mon, Jan 6, 2014 at 8:45 PM, Johannes Berg <johannes@sipsolutions.net> wrote:
>> > On Mon, 2014-01-06 at 20:35 +0530, Krishna Chaitanya wrote:
>> >> On Mon, Jan 6, 2014 at 8:18 PM, Johannes Berg <johannes@sipsolutions.net> wrote:
>> >> > On Sun, 2014-01-05 at 02:36 +0530, Chaitanya T K wrote:
>> >> >> This was blocking sending SMPS action frames
>> >> >> through debugfs.
>> >> >
>> >> > I don't see any issue here, explain.
>> >> >
>> >> > johannes
>> >> >
>> >> buflen includes the new line character as well, hence the comparison
>> >> strncmp fails for all combiantions.
>> >>
>> >> echo "static" > ieee80211/phyX/netdev\:wlanX/smps
>> >> Then
>> >>
>> >> buf=static\n
>> >> buflen=7
>> >>
>> >> But the comparison is with "static" which doesn't include "\n"
>> >> hence the comparison fails.
>> >
>> > Err, ok, so you can just do "echo -n static", right?
>> >
>> > And then your patch breaks the way it currently works, which is about
>> > the worst you can do.
>> >
>> Ok, if one works other fails.
>>
>> So instead why cant we use strlen(local_string)
>> instead of using buflen(remote). That way we can make sure we only
>> compare the characters we need and leave out the extra ones.
>
> It wouldn't fix the problem and would introduce a buffer overflow bug.
>
We can add some checks to make sure it doesn't overflow, but its not
worth it.

My intention is as most of the users are familiar with "echo" and
not "echo -n", its better to have a solution which works with "echo".

Also if we use buflen-1 and give "echo -n" it still works but problem is
it compares 1 less character.

Anyways either one is fine with me.

Thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c
index 04b5a14..1a8fa5f 100644
--- a/net/mac80211/debugfs_netdev.c
+++ b/net/mac80211/debugfs_netdev.c
@@ -265,7 +265,7 @@  static ssize_t ieee80211_if_parse_smps(struct ieee80211_sub_if_data *sdata,
 	enum ieee80211_smps_mode mode;
 
 	for (mode = 0; mode < IEEE80211_SMPS_NUM_MODES; mode++) {
-		if (strncmp(buf, smps_modes[mode], buflen) == 0) {
+		if (strncmp(buf, smps_modes[mode], buflen-1) == 0) {
 			int err = ieee80211_set_smps(sdata, mode);
 			if (!err)
 				return buflen;