lkml.org 
[lkml]   [2021]   [May]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH AUTOSEL 5.12 085/116] flow_dissector: Fix out-of-bounds warning in __skb_flow_bpf_to_target()
    Date
    From: "Gustavo A. R. Silva" <gustavoars@kernel.org>

    [ Upstream commit 1e3d976dbb23b3fce544752b434bdc32ce64aabc ]

    Fix the following out-of-bounds warning:

    net/core/flow_dissector.c:835:3: warning: 'memcpy' offset [33, 48] from the object at 'flow_keys' is out of the bounds of referenced subobject 'ipv6_src' with type '__u32[4]' {aka 'unsigned int[4]'} at offset 16 [-Warray-bounds]

    The problem is that the original code is trying to copy data into a
    couple of struct members adjacent to each other in a single call to
    memcpy(). So, the compiler legitimately complains about it. As these
    are just a couple of members, fix this by copying each one of them in
    separate calls to memcpy().

    This helps with the ongoing efforts to globally enable -Warray-bounds
    and get us closer to being able to tighten the FORTIFY_SOURCE routines
    on memcpy().

    Link: https://github.com/KSPP/linux/issues/109
    Reported-by: kernel test robot <lkp@intel.com>
    Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Sasha Levin <sashal@kernel.org>
    ---
    net/core/flow_dissector.c | 6 ++++--
    1 file changed, 4 insertions(+), 2 deletions(-)

    diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
    index a96a4f5de0ce..3f36b04d86a0 100644
    --- a/net/core/flow_dissector.c
    +++ b/net/core/flow_dissector.c
    @@ -828,8 +828,10 @@ static void __skb_flow_bpf_to_target(const struct bpf_flow_keys *flow_keys,
    key_addrs = skb_flow_dissector_target(flow_dissector,
    FLOW_DISSECTOR_KEY_IPV6_ADDRS,
    target_container);
    - memcpy(&key_addrs->v6addrs, &flow_keys->ipv6_src,
    - sizeof(key_addrs->v6addrs));
    + memcpy(&key_addrs->v6addrs.src, &flow_keys->ipv6_src,
    + sizeof(key_addrs->v6addrs.src));
    + memcpy(&key_addrs->v6addrs.dst, &flow_keys->ipv6_dst,
    + sizeof(key_addrs->v6addrs.dst));
    key_control->addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
    }

    --
    2.30.2
    \
     
     \ /
      Last update: 2021-05-05 18:40    [W:4.161 / U:0.072 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site