* [PATCH] netpoll: Fix device name check in netpoll_setup()
@ 2017-07-25 18:36 Matthias Kaehlcke
2017-07-26 18:44 ` Doug Anderson
2017-07-27 0:02 ` David Miller
0 siblings, 2 replies; 4+ messages in thread
From: Matthias Kaehlcke @ 2017-07-25 18:36 UTC (permalink / raw)
To: David S . Miller; +Cc: netdev, linux-kernel, Doug Anderson, Matthias Kaehlcke
Apparently netpoll_setup() assumes that netpoll.dev_name is a pointer
when checking if the device name is set:
if (np->dev_name) {
...
However the field is a character array, therefore the condition always
yields true. Check instead whether the first byte of the array has a
non-zero value.
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
net/core/netpoll.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index 8357f164c660..912731bed7b7 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -666,7 +666,7 @@ int netpoll_setup(struct netpoll *np)
int err;
rtnl_lock();
- if (np->dev_name) {
+ if (np->dev_name[0]) {
struct net *net = current->nsproxy->net_ns;
ndev = __dev_get_by_name(net, np->dev_name);
}
--
2.14.0.rc0.284.gd933b75aa4-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] netpoll: Fix device name check in netpoll_setup()
2017-07-25 18:36 [PATCH] netpoll: Fix device name check in netpoll_setup() Matthias Kaehlcke
@ 2017-07-26 18:44 ` Doug Anderson
2017-07-26 20:52 ` Cong Wang
2017-07-27 0:02 ` David Miller
1 sibling, 1 reply; 4+ messages in thread
From: Doug Anderson @ 2017-07-26 18:44 UTC (permalink / raw)
To: Matthias Kaehlcke; +Cc: David S . Miller, netdev, linux-kernel@vger.kernel.org
Hi,
On Tue, Jul 25, 2017 at 11:36 AM, Matthias Kaehlcke <mka@chromium.org> wrote:
> Apparently netpoll_setup() assumes that netpoll.dev_name is a pointer
> when checking if the device name is set:
>
> if (np->dev_name) {
> ...
>
> However the field is a character array, therefore the condition always
> yields true. Check instead whether the first byte of the array has a
> non-zero value.
>
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> ---
> net/core/netpoll.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/core/netpoll.c b/net/core/netpoll.c
> index 8357f164c660..912731bed7b7 100644
> --- a/net/core/netpoll.c
> +++ b/net/core/netpoll.c
> @@ -666,7 +666,7 @@ int netpoll_setup(struct netpoll *np)
> int err;
>
> rtnl_lock();
> - if (np->dev_name) {
> + if (np->dev_name[0]) {
> struct net *net = current->nsproxy->net_ns;
> ndev = __dev_get_by_name(net, np->dev_name);
> }
It's really up to the maintainer of the code, but my first instinct
here would be to instead remove the "if" test unless we really expect
dev->dev_name to be blank in lots of cases. It will slightly slow
down the error case but should avoid an "if" test in the non-error
case. By definition it should be safe since currently the "if" test
should always evaluate to true.
-Doug
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] netpoll: Fix device name check in netpoll_setup()
2017-07-26 18:44 ` Doug Anderson
@ 2017-07-26 20:52 ` Cong Wang
0 siblings, 0 replies; 4+ messages in thread
From: Cong Wang @ 2017-07-26 20:52 UTC (permalink / raw)
To: Doug Anderson
Cc: Matthias Kaehlcke, David S . Miller,
Linux Kernel Network Developers, linux-kernel@vger.kernel.org
On Wed, Jul 26, 2017 at 11:44 AM, Doug Anderson <dianders@chromium.org> wrote:
> Hi,
>
> On Tue, Jul 25, 2017 at 11:36 AM, Matthias Kaehlcke <mka@chromium.org> wrote:
>> Apparently netpoll_setup() assumes that netpoll.dev_name is a pointer
>> when checking if the device name is set:
>>
>> if (np->dev_name) {
>> ...
>>
>> However the field is a character array, therefore the condition always
>> yields true. Check instead whether the first byte of the array has a
>> non-zero value.
>>
>> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
>> ---
>> net/core/netpoll.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/net/core/netpoll.c b/net/core/netpoll.c
>> index 8357f164c660..912731bed7b7 100644
>> --- a/net/core/netpoll.c
>> +++ b/net/core/netpoll.c
>> @@ -666,7 +666,7 @@ int netpoll_setup(struct netpoll *np)
>> int err;
>>
>> rtnl_lock();
>> - if (np->dev_name) {
>> + if (np->dev_name[0]) {
>> struct net *net = current->nsproxy->net_ns;
>> ndev = __dev_get_by_name(net, np->dev_name);
>> }
>
> It's really up to the maintainer of the code, but my first instinct
> here would be to instead remove the "if" test unless we really expect
> dev->dev_name to be blank in lots of cases. It will slightly slow
> down the error case but should avoid an "if" test in the non-error
> case. By definition it should be safe since currently the "if" test
> should always evaluate to true.
>
netconsole could set this dev_name to empty via configfs,
so this patch is correct.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] netpoll: Fix device name check in netpoll_setup()
2017-07-25 18:36 [PATCH] netpoll: Fix device name check in netpoll_setup() Matthias Kaehlcke
2017-07-26 18:44 ` Doug Anderson
@ 2017-07-27 0:02 ` David Miller
1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2017-07-27 0:02 UTC (permalink / raw)
To: mka; +Cc: netdev, linux-kernel, dianders
From: Matthias Kaehlcke <mka@chromium.org>
Date: Tue, 25 Jul 2017 11:36:25 -0700
> Apparently netpoll_setup() assumes that netpoll.dev_name is a pointer
> when checking if the device name is set:
>
> if (np->dev_name) {
> ...
>
> However the field is a character array, therefore the condition always
> yields true. Check instead whether the first byte of the array has a
> non-zero value.
>
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
Applied, thanks a lot.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-07-27 0:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-25 18:36 [PATCH] netpoll: Fix device name check in netpoll_setup() Matthias Kaehlcke
2017-07-26 18:44 ` Doug Anderson
2017-07-26 20:52 ` Cong Wang
2017-07-27 0:02 ` David Miller
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).