06 Oct, 2020

1 commit

  • The rcu_read_lock() is not supposed to lock the kernel_sendmsg() API
    since it has the lock_sock() in qrtr_sendmsg() which will sleep. Hence,
    fix it by excluding the locking for kernel_sendmsg().

    While at it, let's also use radix_tree_deref_retry() to confirm the
    validity of the pointer returned by radix_tree_deref_slot() and use
    radix_tree_iter_resume() to resume iterating the tree properly before
    releasing the lock as suggested by Doug.

    Fixes: a7809ff90ce6 ("net: qrtr: ns: Protect radix_tree_deref_slot() using rcu read locks")
    Reported-by: Douglas Anderson
    Reviewed-by: Douglas Anderson
    Tested-by: Douglas Anderson
    Tested-by: Alex Elder
    Signed-off-by: Manivannan Sadhasivam
    Signed-off-by: David S. Miller

    Manivannan Sadhasivam
     

29 Sep, 2020

1 commit

  • The rcu read locks are needed to avoid potential race condition while
    dereferencing radix tree from multiple threads. The issue was identified
    by syzbot. Below is the crash report:

    =============================
    WARNING: suspicious RCU usage
    5.7.0-syzkaller #0 Not tainted
    -----------------------------
    include/linux/radix-tree.h:176 suspicious rcu_dereference_check() usage!

    other info that might help us debug this:

    rcu_scheduler_active = 2, debug_locks = 1
    2 locks held by kworker/u4:1/21:
    #0: ffff88821b097938 ((wq_completion)qrtr_ns_handler){+.+.}-{0:0}, at: spin_unlock_irq include/linux/spinlock.h:403 [inline]
    #0: ffff88821b097938 ((wq_completion)qrtr_ns_handler){+.+.}-{0:0}, at: process_one_work+0x6df/0xfd0 kernel/workqueue.c:2241
    #1: ffffc90000dd7d80 ((work_completion)(&qrtr_ns.work)){+.+.}-{0:0}, at: process_one_work+0x71e/0xfd0 kernel/workqueue.c:2243

    stack backtrace:
    CPU: 0 PID: 21 Comm: kworker/u4:1 Not tainted 5.7.0-syzkaller #0
    Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
    Workqueue: qrtr_ns_handler qrtr_ns_worker
    Call Trace:
    __dump_stack lib/dump_stack.c:77 [inline]
    dump_stack+0x1e9/0x30e lib/dump_stack.c:118
    radix_tree_deref_slot include/linux/radix-tree.h:176 [inline]
    ctrl_cmd_new_lookup net/qrtr/ns.c:558 [inline]
    qrtr_ns_worker+0x2aff/0x4500 net/qrtr/ns.c:674
    process_one_work+0x76e/0xfd0 kernel/workqueue.c:2268
    worker_thread+0xa7f/0x1450 kernel/workqueue.c:2414
    kthread+0x353/0x380 kernel/kthread.c:268

    Fixes: 0c2204a4ad71 ("net: qrtr: Migrate nameservice to kernel from userspace")
    Reported-and-tested-by: syzbot+0f84f6eed90503da72fc@syzkaller.appspotmail.com
    Signed-off-by: Manivannan Sadhasivam
    Signed-off-by: David S. Miller

    Manivannan Sadhasivam
     

10 Sep, 2020

1 commit

  • If skb_put_padto() returns an error, skb has been freed.
    Better not touch it anymore, as reported by syzbot [1]

    Note to qrtr maintainers : this suggests qrtr_sendmsg()
    should adjust sock_alloc_send_skb() second parameter
    to account for the potential added alignment to avoid
    reallocation.

    [1]

    BUG: KASAN: use-after-free in __skb_insert include/linux/skbuff.h:1907 [inline]
    BUG: KASAN: use-after-free in __skb_queue_before include/linux/skbuff.h:2016 [inline]
    BUG: KASAN: use-after-free in __skb_queue_tail include/linux/skbuff.h:2049 [inline]
    BUG: KASAN: use-after-free in skb_queue_tail+0x6b/0x120 net/core/skbuff.c:3146
    Write of size 8 at addr ffff88804d8ab3c0 by task syz-executor.4/4316

    CPU: 1 PID: 4316 Comm: syz-executor.4 Not tainted 5.9.0-rc4-syzkaller #0
    Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
    Call Trace:
    __dump_stack lib/dump_stack.c:77 [inline]
    dump_stack+0x1d6/0x29e lib/dump_stack.c:118
    print_address_description+0x66/0x620 mm/kasan/report.c:383
    __kasan_report mm/kasan/report.c:513 [inline]
    kasan_report+0x132/0x1d0 mm/kasan/report.c:530
    __skb_insert include/linux/skbuff.h:1907 [inline]
    __skb_queue_before include/linux/skbuff.h:2016 [inline]
    __skb_queue_tail include/linux/skbuff.h:2049 [inline]
    skb_queue_tail+0x6b/0x120 net/core/skbuff.c:3146
    qrtr_tun_send+0x1a/0x40 net/qrtr/tun.c:23
    qrtr_node_enqueue+0x44f/0xc00 net/qrtr/qrtr.c:364
    qrtr_bcast_enqueue+0xbe/0x140 net/qrtr/qrtr.c:861
    qrtr_sendmsg+0x680/0x9c0 net/qrtr/qrtr.c:960
    sock_sendmsg_nosec net/socket.c:651 [inline]
    sock_sendmsg net/socket.c:671 [inline]
    sock_write_iter+0x317/0x470 net/socket.c:998
    call_write_iter include/linux/fs.h:1882 [inline]
    new_sync_write fs/read_write.c:503 [inline]
    vfs_write+0xa96/0xd10 fs/read_write.c:578
    ksys_write+0x11b/0x220 fs/read_write.c:631
    do_syscall_64+0x31/0x70 arch/x86/entry/common.c:46
    entry_SYSCALL_64_after_hwframe+0x44/0xa9
    RIP: 0033:0x45d5b9
    Code: 5d b4 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 3d 01 f0 ff ff 0f 83 2b b4 fb ff c3 66 2e 0f 1f 84 00 00 00 00
    RSP: 002b:00007f84b5b81c78 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
    RAX: ffffffffffffffda RBX: 0000000000038b40 RCX: 000000000045d5b9
    RDX: 0000000000000055 RSI: 0000000020001240 RDI: 0000000000000003
    RBP: 00007f84b5b81ca0 R08: 0000000000000000 R09: 0000000000000000
    R10: 0000000000000000 R11: 0000000000000246 R12: 000000000000000f
    R13: 00007ffcbbf86daf R14: 00007f84b5b829c0 R15: 000000000118cf4c

    Allocated by task 4316:
    kasan_save_stack mm/kasan/common.c:48 [inline]
    kasan_set_track mm/kasan/common.c:56 [inline]
    __kasan_kmalloc+0x100/0x130 mm/kasan/common.c:461
    slab_post_alloc_hook+0x3e/0x290 mm/slab.h:518
    slab_alloc mm/slab.c:3312 [inline]
    kmem_cache_alloc+0x1c1/0x2d0 mm/slab.c:3482
    skb_clone+0x1b2/0x370 net/core/skbuff.c:1449
    qrtr_bcast_enqueue+0x6d/0x140 net/qrtr/qrtr.c:857
    qrtr_sendmsg+0x680/0x9c0 net/qrtr/qrtr.c:960
    sock_sendmsg_nosec net/socket.c:651 [inline]
    sock_sendmsg net/socket.c:671 [inline]
    sock_write_iter+0x317/0x470 net/socket.c:998
    call_write_iter include/linux/fs.h:1882 [inline]
    new_sync_write fs/read_write.c:503 [inline]
    vfs_write+0xa96/0xd10 fs/read_write.c:578
    ksys_write+0x11b/0x220 fs/read_write.c:631
    do_syscall_64+0x31/0x70 arch/x86/entry/common.c:46
    entry_SYSCALL_64_after_hwframe+0x44/0xa9

    Freed by task 4316:
    kasan_save_stack mm/kasan/common.c:48 [inline]
    kasan_set_track+0x3d/0x70 mm/kasan/common.c:56
    kasan_set_free_info+0x17/0x30 mm/kasan/generic.c:355
    __kasan_slab_free+0xdd/0x110 mm/kasan/common.c:422
    __cache_free mm/slab.c:3418 [inline]
    kmem_cache_free+0x82/0xf0 mm/slab.c:3693
    __skb_pad+0x3f5/0x5a0 net/core/skbuff.c:1823
    __skb_put_padto include/linux/skbuff.h:3233 [inline]
    skb_put_padto include/linux/skbuff.h:3252 [inline]
    qrtr_node_enqueue+0x62f/0xc00 net/qrtr/qrtr.c:360
    qrtr_bcast_enqueue+0xbe/0x140 net/qrtr/qrtr.c:861
    qrtr_sendmsg+0x680/0x9c0 net/qrtr/qrtr.c:960
    sock_sendmsg_nosec net/socket.c:651 [inline]
    sock_sendmsg net/socket.c:671 [inline]
    sock_write_iter+0x317/0x470 net/socket.c:998
    call_write_iter include/linux/fs.h:1882 [inline]
    new_sync_write fs/read_write.c:503 [inline]
    vfs_write+0xa96/0xd10 fs/read_write.c:578
    ksys_write+0x11b/0x220 fs/read_write.c:631
    do_syscall_64+0x31/0x70 arch/x86/entry/common.c:46
    entry_SYSCALL_64_after_hwframe+0x44/0xa9

    The buggy address belongs to the object at ffff88804d8ab3c0
    which belongs to the cache skbuff_head_cache of size 224
    The buggy address is located 0 bytes inside of
    224-byte region [ffff88804d8ab3c0, ffff88804d8ab4a0)
    The buggy address belongs to the page:
    page:00000000ea8cccfb refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff88804d8abb40 pfn:0x4d8ab
    flags: 0xfffe0000000200(slab)
    raw: 00fffe0000000200 ffffea0002237ec8 ffffea00029b3388 ffff88821bb66800
    raw: ffff88804d8abb40 ffff88804d8ab000 000000010000000b 0000000000000000
    page dumped because: kasan: bad access detected

    Fixes: ce57785bf91b ("net: qrtr: fix len of skb_put_padto in qrtr_node_enqueue")
    Signed-off-by: Eric Dumazet
    Reported-by: syzbot
    Cc: Carl Huang
    Cc: Wen Gong
    Cc: Bjorn Andersson
    Cc: Manivannan Sadhasivam
    Acked-by: Manivannan Sadhasivam
    Reviewed-by: Bjorn Andersson
    Signed-off-by: David S. Miller

    Eric Dumazet
     

18 Aug, 2020

1 commit

  • Passing large uint32 sockaddr_qrtr.port numbers for port allocation
    triggers a warning within idr_alloc() since the port number is cast
    to int, and thus interpreted as a negative number. This leads to
    the rejection of such valid port numbers in qrtr_port_assign() as
    idr_alloc() fails.

    To avoid the problem, switch to idr_alloc_u32() instead.

    Fixes: bdabad3e363d ("net: Add Qualcomm IPC router")
    Reported-by: syzbot+f31428628ef672716ea8@syzkaller.appspotmail.com
    Signed-off-by: Necip Fazil Yildiran
    Reviewed-by: Dmitry Vyukov
    Signed-off-by: David S. Miller

    Necip Fazil Yildiran
     

26 Jul, 2020

1 commit

  • The UDP reuseport conflict was a little bit tricky.

    The net-next code, via bpf-next, extracted the reuseport handling
    into a helper so that the BPF sk lookup code could invoke it.

    At the same time, the logic for reuseport handling of unconnected
    sockets changed via commit efc6b6f6c3113e8b203b9debfb72d81e0f3dcace
    which changed the logic to carry on the reuseport result into the
    rest of the lookup loop if we do not return immediately.

    This requires moving the reuseport_has_conns() logic into the callers.

    While we are here, get rid of inline directives as they do not belong
    in foo.c files.

    The other changes were cases of more straightforward overlapping
    modifications.

    Signed-off-by: David S. Miller

    David S. Miller
     

25 Jul, 2020

1 commit

  • We have to detach sock from socket in qrtr_release(),
    otherwise skb->sk may still reference to this socket
    when the skb is released in tun->queue, particularly
    sk->sk_wq still points to &sock->wq, which leads to
    a UAF.

    Reported-and-tested-by: syzbot+6720d64f31c081c2f708@syzkaller.appspotmail.com
    Fixes: 28fb4e59a47d ("net: qrtr: Expose tunneling endpoint to user space")
    Cc: Bjorn Andersson
    Cc: Eric Dumazet
    Signed-off-by: Cong Wang
    Reviewed-by: Eric Dumazet
    Signed-off-by: David S. Miller

    Cong Wang
     

20 Jul, 2020

1 commit


01 Jul, 2020

2 commits

  • This code assumes that the user passed in enough data for a
    qrtr_hdr_v1 or qrtr_hdr_v2 struct, but it's not necessarily true. If
    the buffer is too small then it will read beyond the end.

    Reported-by: Manivannan Sadhasivam
    Reported-by: syzbot+b8fe393f999a291a9ea6@syzkaller.appspotmail.com
    Fixes: 194ccc88297a ("net: qrtr: Support decoding incoming v2 packets")
    Signed-off-by: Dan Carpenter
    Signed-off-by: David S. Miller

    Dan Carpenter
     
  • The flow is allocated in qrtr_tx_wait, but not freed when qrtr node
    is released. (*slot) becomes NULL after radix_tree_iter_delete is
    called in __qrtr_node_release. The fix is to save (*slot) to a
    vairable and then free it.

    This memory leak is catched when kmemleak is enabled in kernel,
    the report looks like below:

    unreferenced object 0xffffa0de69e08420 (size 32):
    comm "kworker/u16:3", pid 176, jiffies 4294918275 (age 82858.876s)
    hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 28 84 e0 69 de a0 ff ff ........(..i....
    28 84 e0 69 de a0 ff ff 03 00 00 00 00 00 00 00 (..i............
    backtrace:
    [] qrtr_node_enqueue+0x38e/0x400 [qrtr]
    [] qrtr_sendmsg+0x1e0/0x2a0 [qrtr]
    [] sock_sendmsg+0x5b/0x60
    [] qmi_send_message.isra.3+0xbe/0x110 [qmi_helpers]
    [] qmi_send_request+0x1c/0x20 [qmi_helpers]

    Signed-off-by: Carl Huang
    Signed-off-by: David S. Miller

    Carl Huang
     

14 Jun, 2020

1 commit

  • Since commit 84af7a6194e4 ("checkpatch: kconfig: prefer 'help' over
    '---help---'"), the number of '---help---' has been gradually
    decreasing, but there are still more than 2400 instances.

    This commit finishes the conversion. While I touched the lines,
    I also fixed the indentation.

    There are a variety of indentation styles found.

    a) 4 spaces + '---help---'
    b) 7 spaces + '---help---'
    c) 8 spaces + '---help---'
    d) 1 space + 1 tab + '---help---'
    e) 1 tab + '---help---' (correct indentation)
    f) 1 tab + 1 space + '---help---'
    g) 1 tab + 2 spaces + '---help---'

    In order to convert all of them to 1 tab + 'help', I ran the
    following commend:

    $ find . -name 'Kconfig*' | xargs sed -i 's/^[[:space:]]*---help---/\thelp/'

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     

01 Jun, 2020

1 commit

  • xdp_umem.c had overlapping changes between the 64-bit math fix
    for the calculation of npgs and the removal of the zerocopy
    memory type which got rid of the chunk_size_nohdr member.

    The mlx5 Kconfig conflict is a case where we just take the
    net-next copy of the Kconfig entry dependency as it takes on
    the ESWITCH dependency by one level of indirection which is
    what the 'net' conflicting change is trying to ensure.

    Signed-off-by: David S. Miller

    David S. Miller
     

31 May, 2020

1 commit

  • A null pointer dereference in qrtr_ns_data_ready() is seen if a client
    opens a qrtr socket before qrtr_ns_init() can bind to the control port.
    When the control port is bound, the ENETRESET error will be broadcasted
    and clients will close their sockets. This results in DEL_CLIENT
    packets being sent to the ns and qrtr_ns_data_ready() being called
    without the workqueue being allocated.

    Allocate the workqueue before setting sk_data_ready and binding to the
    control port. This ensures that the work and workqueue structs are
    allocated and initialized before qrtr_ns_data_ready can be called.

    Fixes: 0c2204a4ad71 ("net: qrtr: Migrate nameservice to kernel from userspace")
    Signed-off-by: Chris Lew
    Reviewed-by: Bjorn Andersson
    Reviewed-by: Manivannan Sadhasivam
    Signed-off-by: David S. Miller

    Chris Lew
     

25 May, 2020

1 commit


22 May, 2020

1 commit

  • Once the traversal of the list is completed with list_for_each_entry(),
    the iterator (node) will point to an invalid object. So passing this to
    qrtr_local_enqueue() which is outside of the iterator block is erroneous
    eventhough the object is not used.

    So fix this by passing NULL to qrtr_local_enqueue().

    Fixes: bdabad3e363d ("net: Add Qualcomm IPC router")
    Reported-by: kbuild test robot
    Reported-by: Julia Lawall
    Signed-off-by: Manivannan Sadhasivam
    Reviewed-by: Bjorn Andersson
    Signed-off-by: David S. Miller

    Manivannan Sadhasivam
     

08 May, 2020

2 commits

  • IPC Router protocol is also used by external modems for exchanging the QMI
    messages. Hence, it doesn't always depend on Qualcomm platforms. One such
    instance is the QCA6390 WLAN device connected to x86 machine.

    Reviewed-by: Bjorn Andersson
    Signed-off-by: Manivannan Sadhasivam
    Signed-off-by: David S. Miller

    Manivannan Sadhasivam
     
  • MHI is the transport layer used for communicating to the external modems.
    Hence, this commit adds MHI transport layer support to QRTR for
    transferring the QMI messages over IPC Router.

    Reviewed-by: Bjorn Andersson
    Signed-off-by: Manivannan Sadhasivam
    Signed-off-by: David S. Miller

    Manivannan Sadhasivam
     

23 Apr, 2020

1 commit

  • Add tracepoint support for QRTR with NS as the first candidate. Later on
    this can be extended to core QRTR and transport drivers.

    The trace_printk() used in NS has been replaced by tracepoints.

    Signed-off-by: Manivannan Sadhasivam
    Signed-off-by: David S. Miller

    Manivannan Sadhasivam
     

10 Apr, 2020

1 commit

  • If the local node id(qrtr_local_nid) is not modified after its
    initialization, it equals to the broadcast node id(QRTR_NODE_BCAST).
    So the messages from local node should not be taken as broadcast
    and keep the process going to send them out anyway.

    The definitions are as follow:
    static unsigned int qrtr_local_nid = NUMA_NO_NODE;

    Fixes: fdf5fd397566 ("net: qrtr: Broadcast messages only from control port")
    Signed-off-by: Wang Wenhu
    Signed-off-by: David S. Miller

    Wang Wenhu
     

04 Mar, 2020

2 commits

  • The 2 second delay before calling qrtr_ns_init() meant that the remote
    processors would register as endpoints in qrtr and the say_hello() call
    would therefor broadcast the outgoing HELLO to them. With the HELLO
    handshake corrected this delay is no longer needed.

    Reviewed-by: Manivannan Sadhasivam
    Tested-by: Manivannan Sadhasivam
    Signed-off-by: Bjorn Andersson
    Signed-off-by: David S. Miller

    Bjorn Andersson
     
  • Lost in the translation from the user space implementation was the
    detail that HELLO mesages must be exchanged between each node pair. As
    such the incoming HELLO must be replied to.

    Similar to the previous implementation no effort is made to prevent two
    Linux boxes from continuously sending HELLO messages back and forth,
    this is left to a follow up patch.

    say_hello() is moved, to facilitate the new call site.

    Fixes: 0c2204a4ad71 ("net: qrtr: Migrate nameservice to kernel from userspace")
    Reviewed-by: Manivannan Sadhasivam
    Tested-by: Manivannan Sadhasivam
    Signed-off-by: Bjorn Andersson
    Signed-off-by: David S. Miller

    Bjorn Andersson
     

27 Feb, 2020

1 commit


25 Feb, 2020

1 commit


22 Feb, 2020

2 commits

  • In order to start the QRTR nameservice, the local node ID needs to be
    valid. Hence, fix it to 1. Previously, the node ID was configured through
    a userspace tool before starting the nameservice daemon. Since we have now
    integrated the nameservice handling to kernel, this change is necessary
    for making it functional.

    Signed-off-by: Manivannan Sadhasivam
    Signed-off-by: David S. Miller

    Manivannan Sadhasivam
     
  • The QRTR nameservice has been maintained in userspace for some time. This
    commit migrates it to Linux kernel. This change is required in order to
    eliminate the need of starting a userspace daemon for making the WiFi
    functional for ath11k based devices. Since the QRTR NS is not usually
    packed in most of the distros, users need to clone, build and install it
    to get the WiFi working. It will become a hassle when the user doesn't
    have any other source of network connectivity.

    Signed-off-by: Manivannan Sadhasivam
    Signed-off-by: David S. Miller

    Manivannan Sadhasivam
     

15 Jan, 2020

5 commits

  • Rather than enqueuing messages and scheduling a worker to deliver them
    to the individual sockets we can now, thanks to the previous work, move
    this directly into the endpoint callback.

    This saves us a context switch per incoming message and removes the
    possibility of an opportunistic suspend to happen between the message is
    coming from the endpoint until it ends up in the socket's receive
    buffer.

    Signed-off-by: Bjorn Andersson
    Signed-off-by: David S. Miller

    Bjorn Andersson
     
  • The important part of qrtr_port_lookup() wrt synchronization is that the
    function returns a reference counted struct qrtr_sock, or fail.

    As such we need only to ensure that an decrement of the object's
    refcount happens inbetween the finding of the object in the idr and
    qrtr_port_lookup()'s own increment of the object.

    By using RCU and putting a synchronization point after we remove the
    mapping from the idr, but before it can be released we achieve this -
    with the benefit of not having to hold the mutex in qrtr_port_lookup().

    Signed-off-by: Bjorn Andersson
    Signed-off-by: David S. Miller

    Bjorn Andersson
     
  • Move operations on the qrtr_nodes radix tree under a separate spinlock
    and make the qrtr_nodes tree GFP_ATOMIC, to allow operation from atomic
    context in a subsequent patch.

    Signed-off-by: Bjorn Andersson
    Signed-off-by: David S. Miller

    Bjorn Andersson
     
  • In order to prevent overconsumption of resources on the remote side QRTR
    implements a flow control mechanism.

    The mechanism works by the sender keeping track of the number of
    outstanding unconfirmed messages that has been transmitted to a
    particular node/port pair.

    Upon count reaching a low watermark (L) the confirm_rx bit is set in the
    outgoing message and when the count reaching a high watermark (H)
    transmission will be blocked upon the reception of a resume_tx message
    from the remote, that resets the counter to 0.

    This guarantees that there will be at most 2H - L messages in flight.
    Values chosen for L and H are 5 and 10 respectively.

    Signed-off-by: Bjorn Andersson
    Signed-off-by: David S. Miller

    Bjorn Andersson
     
  • The confirm-rx bit is used to implement a per port flow control, in
    order to make sure that no messages are dropped due to resource
    exhaustion. Move the resume-tx transmission to recvmsg to only confirm
    messages as they are consumed by the application.

    Signed-off-by: Bjorn Andersson
    Signed-off-by: David S. Miller

    Bjorn Andersson
     

06 Jan, 2020

1 commit

  • The len used for skb_put_padto is wrong, it need to add len of hdr.

    In qrtr_node_enqueue, local variable size_t len is assign with
    skb->len, then skb_push(skb, sizeof(*hdr)) will add skb->len with
    sizeof(*hdr), so local variable size_t len is not same with skb->len
    after skb_push(skb, sizeof(*hdr)).

    Then the purpose of skb_put_padto(skb, ALIGN(len, 4)) is to add add
    pad to the end of the skb's data if skb->len is not aligned to 4, but
    unfortunately it use len instead of skb->len, at this line, skb->len
    is 32 bytes(sizeof(*hdr)) more than len, for example, len is 3 bytes,
    then skb->len is 35 bytes(3 + 32), and ALIGN(len, 4) is 4 bytes, so
    __skb_put_padto will do nothing after check size(35) < len(4), the
    correct value should be 36(sizeof(*hdr) + ALIGN(len, 4) = 32 + 4),
    then __skb_put_padto will pass check size(35) < len(36) and add 1 byte
    to the end of skb's data, then logic is correct.

    function of skb_push:
    void *skb_push(struct sk_buff *skb, unsigned int len)
    {
    skb->data -= len;
    skb->len += len;
    if (unlikely(skb->data < skb->head))
    skb_under_panic(skb, len, __builtin_return_address(0));
    return skb->data;
    }

    function of skb_put_padto
    static inline int skb_put_padto(struct sk_buff *skb, unsigned int len)
    {
    return __skb_put_padto(skb, len, true);
    }

    function of __skb_put_padto
    static inline int __skb_put_padto(struct sk_buff *skb, unsigned int len,
    bool free_on_error)
    {
    unsigned int size = skb->len;

    if (unlikely(size < len)) {
    len -= size;
    if (__skb_pad(skb, len, free_on_error))
    return -ENOMEM;
    __skb_put(skb, len);
    }
    return 0;
    }

    Signed-off-by: Carl Huang
    Signed-off-by: Wen Gong
    Signed-off-by: David S. Miller

    Carl Huang
     

31 Oct, 2019

1 commit


22 Sep, 2019

1 commit

  • As the endpoint is unregistered there might still be work pending to
    handle incoming messages, which will result in a use after free
    scenario. The plan is to remove the rx_worker, but until then (and for
    stable@) ensure that the work is stopped before the node is freed.

    Fixes: bdabad3e363d ("net: Add Qualcomm IPC router")
    Cc: stable@vger.kernel.org
    Signed-off-by: Bjorn Andersson
    Signed-off-by: Jakub Kicinski

    Bjorn Andersson
     

12 Sep, 2019

1 commit


05 Jun, 2019

1 commit

  • Based on 1 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license version 2 and
    only version 2 as published by the free software foundation this
    program is distributed in the hope that it will be useful but
    without any warranty without even the implied warranty of
    merchantability or fitness for a particular purpose see the gnu
    general public license for more details

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-only

    has been chosen to replace the boilerplate/reference in 294 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Allison Randal
    Reviewed-by: Alexios Zavras
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190529141900.825281744@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

22 May, 2019

1 commit

  • Pull networking fixes from David Miller:

    1) Clear up some recent tipc regressions because of registration
    ordering. Fix from Junwei Hu.

    2) tipc's TLV_SET() can read past the end of the supplied buffer during
    the copy. From Chris Packham.

    3) ptp example program doesn't match the kernel, from Richard Cochran.

    4) Outgoing message type fix in qrtr, from Bjorn Andersson.

    5) Flow control regression in stmmac, from Tan Tee Min.

    6) Fix inband autonegotiation in phylink, from Russell King.

    7) Fix sk_bound_dev_if handling in rawv6_bind(), from Mike Manning.

    8) Fix usbnet crash after disconnect, from Kloetzke Jan.

    * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net: (21 commits)
    usbnet: fix kernel crash after disconnect
    selftests: fib_rule_tests: use pre-defined DEV_ADDR
    net-next: net: Fix typos in ip-sysctl.txt
    ipv6: Consider sk_bound_dev_if when binding a raw socket to an address
    net: phylink: ensure inband AN works correctly
    usbnet: ipheth: fix racing condition
    net: stmmac: dma channel control register need to be init first
    net: stmmac: fix ethtool flow control not able to get/set
    net: qrtr: Fix message type of outgoing packets
    networking: : fix typos in code comments
    ptp: Fix example program to match kernel.
    fddi: fix typos in code comments
    selftests: fib_rule_tests: enable forwarding before ipv4 from/iif test
    selftests: fib_rule_tests: fix local IPv4 address typo
    tipc: Avoid copying bytes beyond the supplied data
    2/2] net: xilinx_emaclite: use readx_poll_timeout() in mdio wait function
    1/2] net: axienet: use readx_poll_timeout() in mdio wait function
    vlan: Mark expected switch fall-through
    macvlan: Mark expected switch fall-through
    net/mlx4_en: ethtool, Remove unsupported SFP EEPROM high pages query
    ...

    Linus Torvalds
     

21 May, 2019

2 commits

  • Add SPDX license identifiers to all Make/Kconfig files which:

    - Have no license information of any form

    These files fall under the project license, GPL v2 only. The resulting SPDX
    license identifier is:

    GPL-2.0-only

    Signed-off-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     
  • QRTR packets has a message type in the header, which is repeated in the
    control header. For control packets we therefor copy the type from
    beginning of the outgoing payload and use that as message type.

    For non-control messages an endianness fix introduced in v5.2-rc1 caused the
    type to be 0, rather than QRTR_TYPE_DATA, causing all messages to be dropped by
    the receiver. Fix this by converting and using qrtr_type, which will remain
    QRTR_TYPE_DATA for non-control messages.

    Fixes: 8f5e24514cbd ("net: qrtr: use protocol endiannes variable")
    Signed-off-by: Bjorn Andersson
    Signed-off-by: David S. Miller

    Bjorn Andersson
     

12 May, 2019

1 commit

  • sparse was unable to verify endiannes correctness due to reassignment
    from le32_to_cpu to the same variable - fix this warning up by providing
    a proper __le32 type and initializing it. This is not actually fixing
    any bug - rather just addressing the sparse warning.

    Signed-off-by: Nicholas Mc Guire
    Signed-off-by: David S. Miller

    Nicholas Mc Guire
     

28 Apr, 2019

1 commit

  • We currently have two levels of strict validation:

    1) liberal (default)
    - undefined (type >= max) & NLA_UNSPEC attributes accepted
    - attribute length >= expected accepted
    - garbage at end of message accepted
    2) strict (opt-in)
    - NLA_UNSPEC attributes accepted
    - attribute length >= expected accepted

    Split out parsing strictness into four different options:
    * TRAILING - check that there's no trailing data after parsing
    attributes (in message or nested)
    * MAXTYPE - reject attrs > max known type
    * UNSPEC - reject attributes with NLA_UNSPEC policy entries
    * STRICT_ATTRS - strictly validate attribute size

    The default for future things should be *everything*.
    The current *_strict() is a combination of TRAILING and MAXTYPE,
    and is renamed to _deprecated_strict().
    The current regular parsing has none of this, and is renamed to
    *_parse_deprecated().

    Additionally it allows us to selectively set one of the new flags
    even on old policies. Notably, the UNSPEC flag could be useful in
    this case, since it can be arranged (by filling in the policy) to
    not be an incompatible userspace ABI change, but would then going
    forward prevent forgetting attribute entries. Similar can apply
    to the POLICY flag.

    We end up with the following renames:
    * nla_parse -> nla_parse_deprecated
    * nla_parse_strict -> nla_parse_deprecated_strict
    * nlmsg_parse -> nlmsg_parse_deprecated
    * nlmsg_parse_strict -> nlmsg_parse_deprecated_strict
    * nla_parse_nested -> nla_parse_nested_deprecated
    * nla_validate_nested -> nla_validate_nested_deprecated

    Using spatch, of course:
    @@
    expression TB, MAX, HEAD, LEN, POL, EXT;
    @@
    -nla_parse(TB, MAX, HEAD, LEN, POL, EXT)
    +nla_parse_deprecated(TB, MAX, HEAD, LEN, POL, EXT)

    @@
    expression NLH, HDRLEN, TB, MAX, POL, EXT;
    @@
    -nlmsg_parse(NLH, HDRLEN, TB, MAX, POL, EXT)
    +nlmsg_parse_deprecated(NLH, HDRLEN, TB, MAX, POL, EXT)

    @@
    expression NLH, HDRLEN, TB, MAX, POL, EXT;
    @@
    -nlmsg_parse_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
    +nlmsg_parse_deprecated_strict(NLH, HDRLEN, TB, MAX, POL, EXT)

    @@
    expression TB, MAX, NLA, POL, EXT;
    @@
    -nla_parse_nested(TB, MAX, NLA, POL, EXT)
    +nla_parse_nested_deprecated(TB, MAX, NLA, POL, EXT)

    @@
    expression START, MAX, POL, EXT;
    @@
    -nla_validate_nested(START, MAX, POL, EXT)
    +nla_validate_nested_deprecated(START, MAX, POL, EXT)

    @@
    expression NLH, HDRLEN, MAX, POL, EXT;
    @@
    -nlmsg_validate(NLH, HDRLEN, MAX, POL, EXT)
    +nlmsg_validate_deprecated(NLH, HDRLEN, MAX, POL, EXT)

    For this patch, don't actually add the strict, non-renamed versions
    yet so that it breaks compile if I get it wrong.

    Also, while at it, make nla_validate and nla_parse go down to a
    common __nla_validate_parse() function to avoid code duplication.

    Ultimately, this allows us to have very strict validation for every
    new caller of nla_parse()/nlmsg_parse() etc as re-introduced in the
    next patch, while existing things will continue to work as is.

    In effect then, this adds fully strict validation for any new command.

    Signed-off-by: Johannes Berg
    Signed-off-by: David S. Miller

    Johannes Berg
     

20 Apr, 2019

1 commit

  • The SIOCGSTAMP/SIOCGSTAMPNS ioctl commands are implemented by many
    socket protocol handlers, and all of those end up calling the same
    sock_get_timestamp()/sock_get_timestampns() helper functions, which
    results in a lot of duplicate code.

    With the introduction of 64-bit time_t on 32-bit architectures, this
    gets worse, as we then need four different ioctl commands in each
    socket protocol implementation.

    To simplify that, let's add a new .gettstamp() operation in
    struct proto_ops, and move ioctl implementation into the common
    sock_ioctl()/compat_sock_ioctl_trans() functions that these all go
    through.

    We can reuse the sock_get_timestamp() implementation, but generalize
    it so it can deal with both native and compat mode, as well as
    timeval and timespec structures.

    Acked-by: Stefan Schmidt
    Acked-by: Neil Horman
    Acked-by: Marc Kleine-Budde
    Link: https://lore.kernel.org/lkml/CAK8P3a038aDQQotzua_QtKGhq8O9n+rdiz2=WDCp82ys8eUT+A@mail.gmail.com/
    Signed-off-by: Arnd Bergmann
    Acked-by: Willem de Bruijn
    Signed-off-by: David S. Miller

    Arnd Bergmann