* [PATCH 2/2] openvswitch: Fix condition check in output_userspace() by using nla_ok()
@ 2021-09-17 8:24 Jiasheng Jiang
2021-09-21 20:54 ` Pravin Shelar
0 siblings, 1 reply; 2+ messages in thread
From: Jiasheng Jiang @ 2021-09-17 8:24 UTC (permalink / raw)
To: pshelar, davem, kuba; +Cc: netdev, dev, linux-kernel, Jiasheng Jiang
Just using 'rem > 0' might be unsafe, so it's better
to use the nla_ok() instead.
Because we can see from the nla_next() that
'*remaining' might be smaller than 'totlen'. And nla_ok()
will avoid it happening.
For example, ovs_dp_process_packet() -> ovs_execute_actions()
-> do_execute_actions() -> output_userspace(), and attr comes
from OVS_CB(skb)->input_vport,which restores the received packet
from the user space.
Fixes: ccb1352e76cff0524e7ccb2074826a092dd13016
('net: Add Open vSwitch kernel components.')
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
net/openvswitch/actions.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
index c23537f..e8236dd 100644
--- a/net/openvswitch/actions.c
+++ b/net/openvswitch/actions.c
@@ -915,8 +915,7 @@ static int output_userspace(struct datapath *dp, struct sk_buff *skb,
upcall.cmd = OVS_PACKET_CMD_ACTION;
upcall.mru = OVS_CB(skb)->mru;
- for (a = nla_data(attr), rem = nla_len(attr); rem > 0;
- a = nla_next(a, &rem)) {
+ nla_for_each_nested(a, attr, rem) {
switch (nla_type(a)) {
case OVS_USERSPACE_ATTR_USERDATA:
upcall.userdata = a;
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 2/2] openvswitch: Fix condition check in output_userspace() by using nla_ok()
2021-09-17 8:24 [PATCH 2/2] openvswitch: Fix condition check in output_userspace() by using nla_ok() Jiasheng Jiang
@ 2021-09-21 20:54 ` Pravin Shelar
0 siblings, 0 replies; 2+ messages in thread
From: Pravin Shelar @ 2021-09-21 20:54 UTC (permalink / raw)
To: Jiasheng Jiang
Cc: David S. Miller, Jakub Kicinski, Linux Kernel Network Developers,
ovs dev, LKML
On Fri, Sep 17, 2021 at 1:25 AM Jiasheng Jiang <jiasheng@iscas.ac.cn> wrote:
>
> Just using 'rem > 0' might be unsafe, so it's better
> to use the nla_ok() instead.
> Because we can see from the nla_next() that
> '*remaining' might be smaller than 'totlen'. And nla_ok()
> will avoid it happening.
> For example, ovs_dp_process_packet() -> ovs_execute_actions()
> -> do_execute_actions() -> output_userspace(), and attr comes
> from OVS_CB(skb)->input_vport,which restores the received packet
> from the user space.
>
> Fixes: ccb1352e76cff0524e7ccb2074826a092dd13016
> ('net: Add Open vSwitch kernel components.')
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
> net/openvswitch/actions.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
> index c23537f..e8236dd 100644
> --- a/net/openvswitch/actions.c
> +++ b/net/openvswitch/actions.c
> @@ -915,8 +915,7 @@ static int output_userspace(struct datapath *dp, struct sk_buff *skb,
> upcall.cmd = OVS_PACKET_CMD_ACTION;
> upcall.mru = OVS_CB(skb)->mru;
>
> - for (a = nla_data(attr), rem = nla_len(attr); rem > 0;
> - a = nla_next(a, &rem)) {
> + nla_for_each_nested(a, attr, rem) {
> switch (nla_type(a)) {
> case OVS_USERSPACE_ATTR_USERDATA:
> upcall.userdata = a;
These nl-attributes are built and verified at time of OVS flow
install, so the rest of checks in nla_ok, is not required.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-09-21 20:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-17 8:24 [PATCH 2/2] openvswitch: Fix condition check in output_userspace() by using nla_ok() Jiasheng Jiang
2021-09-21 20:54 ` Pravin Shelar
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).