18 Feb, 2017

1 commit

  • [ Upstream commit f1712c73714088a7252d276a57126d56c7d37e64 ]

    Zhang Yanmin reported crashes [1] and provided a patch adding a
    synchronize_rcu() call in can_rx_unregister()

    The main problem seems that the sockets themselves are not RCU
    protected.

    If CAN uses RCU for delivery, then sockets should be freed only after
    one RCU grace period.

    Recent kernels could use sock_set_flag(sk, SOCK_RCU_FREE), but let's
    ease stable backports with the following fix instead.

    [1]
    BUG: unable to handle kernel NULL pointer dereference at (null)
    IP: [] selinux_socket_sock_rcv_skb+0x65/0x2a0

    Call Trace:

    [] security_sock_rcv_skb+0x4c/0x60
    [] sk_filter+0x41/0x210
    [] sock_queue_rcv_skb+0x53/0x3a0
    [] raw_rcv+0x2a3/0x3c0
    [] can_rcv_filter+0x12b/0x370
    [] can_receive+0xd9/0x120
    [] can_rcv+0xab/0x100
    [] __netif_receive_skb_core+0xd8c/0x11f0
    [] __netif_receive_skb+0x24/0xb0
    [] process_backlog+0x127/0x280
    [] net_rx_action+0x33b/0x4f0
    [] __do_softirq+0x184/0x440
    [] do_softirq_own_stack+0x1c/0x30

    [] do_softirq.part.18+0x3b/0x40
    [] do_softirq+0x1d/0x20
    [] netif_rx_ni+0xe5/0x110
    [] slcan_receive_buf+0x507/0x520
    [] flush_to_ldisc+0x21c/0x230
    [] process_one_work+0x24f/0x670
    [] worker_thread+0x9d/0x6f0
    [] ? rescuer_thread+0x480/0x480
    [] kthread+0x12c/0x150
    [] ret_from_fork+0x3f/0x70

    Reported-by: Zhang Yanmin
    Signed-off-by: Eric Dumazet
    Acked-by: Oliver Hartkopp
    Signed-off-by: David S. Miller
    Signed-off-by: Greg Kroah-Hartman

    Eric Dumazet
     

09 Feb, 2017

1 commit

  • commit a06393ed03167771246c4c43192d9c264bc48412 upstream.

    When removing a bcm tx operation either a hrtimer or a tasklet might run.
    As the hrtimer triggers its associated tasklet and vice versa we need to
    take care to mutually terminate both handlers.

    Reported-by: Michael Josenhans
    Signed-off-by: Oliver Hartkopp
    Tested-by: Michael Josenhans
    Signed-off-by: Marc Kleine-Budde
    Signed-off-by: Greg Kroah-Hartman

    Oliver Hartkopp
     

07 Dec, 2016

1 commit


23 Nov, 2016

1 commit

  • Since commit 6f3b911d5f29b98 ("can: bcm: add support for CAN FD frames") the
    CAN broadcast manager supports CAN and CAN FD data frames.

    As these data frames are embedded in struct can[fd]_frames which have a
    different length the access to the provided array of CAN frames became
    dependend of op->cfsiz. By using a struct canfd_frame pointer for the array of
    CAN frames the new offset calculation based on op->cfsiz was accidently applied
    to CAN FD frame element lengths.

    This fix makes the pointer to the arrays of the different CAN frame types a
    void pointer so that the offset calculation in bytes accesses the correct CAN
    frame elements.

    Reference: http://marc.info/?l=linux-netdev&m=147980658909653

    Reported-by: Andrey Konovalov
    Signed-off-by: Oliver Hartkopp
    Tested-by: Andrey Konovalov
    Cc: linux-stable
    Signed-off-by: Marc Kleine-Budde

    Oliver Hartkopp
     

01 Nov, 2016

1 commit

  • Andrey Konovalov reported an issue with proc_register in bcm.c.
    As suggested by Cong Wang this patch adds a lock_sock() protection and
    a check for unsuccessful proc_create_data() in bcm_connect().

    Reference: http://marc.info/?l=linux-netdev&m=147732648731237

    Reported-by: Andrey Konovalov
    Suggested-by: Cong Wang
    Signed-off-by: Oliver Hartkopp
    Acked-by: Cong Wang
    Tested-by: Andrey Konovalov
    Cc: linux-stable
    Signed-off-by: Marc Kleine-Budde

    Oliver Hartkopp
     

23 Jun, 2016

1 commit

  • The change to leave out procfs support in CAN when CONFIG_PROC_FS
    is not set was incomplete and leads to a build error:

    net/built-in.o: In function `can_init':
    :(.init.text+0x9858): undefined reference to `can_stat_update'
    ERROR: "can_stat_update" [net/can/can.ko] undefined!

    This tries a better approach, encapsulating all of the calls
    within IS_ENABLED(), so we also leave out the timer function
    from the object file.

    Signed-off-by: Arnd Bergmann
    Fixes: a20fadf85312 ("can: build proc support only if CONFIG_PROC_FS is activated")
    Signed-off-by: Marc Kleine-Budde

    Arnd Bergmann
     

17 Jun, 2016

5 commits

  • The programming API of the CAN_BCM depends on struct can_frame which is
    given as array directly behind the bcm_msg_head structure. To follow this
    schema for the CAN FD frames a new flag 'CAN_FD_FRAME' in the bcm_msg_head
    flags indicates that the concatenated CAN frame structures behind the
    bcm_msg_head are defined as struct canfd_frame.

    This patch adds the support to handle CAN and CAN FD frames on a per BCM-op
    base. Main changes:

    - generally use struct canfd_frames instead if struct can_frames
    - use canfd_frame.flags instead of can_frame.can_dlc for private BCM flags
    - make all CAN frame sizes depending on the new CAN_FD_FRAME flags
    - separate between CAN and CAN FD when sending/receiving frames

    Due to the dependence of the CAN_FD_FRAME flag the former binary interface
    for classic CAN frames remains stable.

    Signed-off-by: Oliver Hartkopp
    Signed-off-by: Marc Kleine-Budde

    Oliver Hartkopp
     
  • Signed-off-by: Oliver Hartkopp
    Signed-off-by: Marc Kleine-Budde

    Oliver Hartkopp
     
  • can_frame is the name of the struct can_frame which is not meant in
    the corrected comments.

    Signed-off-by: Oliver Hartkopp
    Signed-off-by: Marc Kleine-Budde

    Oliver Hartkopp
     
  • Signed-off-by: Oliver Hartkopp
    Signed-off-by: Marc Kleine-Budde

    Oliver Hartkopp
     
  • When building can subsystem with CONFIG_PROC_FS=n I detected some unused
    variables warning by using proc functions. In CAN the proc handling is
    nicely placed in one object file. This patch adds simple add a
    dependency on CONFIG_PROC_FS for CAN's proc.o file and corresponding
    static inline no-op functions.

    Signed-off-by: Alexander Aring
    Acked-by: Oliver Hartkopp
    [mkl: provide static inline noops instead of using #ifdefs]
    Signed-off-by: Marc Kleine-Budde

    Alexander Aring
     

05 Apr, 2016

1 commit

  • Currently, SOL_TIMESTAMPING can only be enabled using setsockopt.
    This is very costly when users want to sample writes to gather
    tx timestamps.

    Add support for enabling SO_TIMESTAMPING via control messages by
    using tsflags added in `struct sockcm_cookie` (added in the previous
    patches in this series) to set the tx_flags of the last skb created in
    a sendmsg. With this patch, the timestamp recording bits in tx_flags
    of the skbuff is overridden if SO_TIMESTAMPING is passed in a cmsg.

    Please note that this is only effective for overriding the recording
    timestamps flags. Users should enable timestamp reporting (e.g.,
    SOF_TIMESTAMPING_SOFTWARE | SOF_TIMESTAMPING_OPT_ID) using
    socket options and then should ask for SOF_TIMESTAMPING_TX_*
    using control messages per sendmsg to sample timestamps for each
    write.

    Signed-off-by: Soheil Hassas Yeganeh
    Acked-by: Willem de Bruijn
    Signed-off-by: David S. Miller

    Soheil Hassas Yeganeh
     

13 Oct, 2015

1 commit

  • The can subsystem communicates with user space using a bcm_msg_head
    header, which contains two timestamps. This is problematic for
    multiple reasons:

    a) The structure layout is currently incompatible between 64-bit
    user space and 32-bit user space, and cannot work in compat
    mode (other than x32).

    b) The timeval structure layout will change in 32-bit user
    space when we fix the y2038 overflow problem by redefining
    time_t to 64-bit, making new 32-bit user space incompatible
    with the current kernel interface.
    Cars last a long time and often use old kernels, so the actual
    users of this code are the most likely ones to migrate to y2038
    safe user space.

    This tries to work around part of the problem by changing the
    publicly visible user interface in the header, but not the binary
    interface. Fortunately, the values passed around in the structure
    are relative times and do not actually suffer from the y2038
    overflow, so 32-bit is enough here.

    We replace the use of 'struct timeval' with a newly defined
    'struct bcm_timeval' that uses the exact same binary layout
    as before and that still suffers from problem a) but not problem
    b).

    The downside of this approach is that any user space program
    that currently assigns a timeval structure to these members
    rather than writing the tv_sec/tv_usec portions individually
    will suffer a compile-time error when built with an updated
    kernel header. Fixing this error makes it work fine with old
    and new headers though.

    We could address problem a) by using '__u32' or 'int' members
    rather than 'long', but that would have a more significant
    downside in also breaking support for all existing 64-bit user
    binaries that might be using this interface, which is likely
    not acceptable.

    Signed-off-by: Arnd Bergmann
    Acked-by: Oliver Hartkopp
    Cc: linux-can@vger.kernel.org
    Cc: linux-api@vger.kernel.org
    Signed-off-by: Marc Kleine-Budde

    Arnd Bergmann
     

13 Jul, 2015

1 commit

  • Commit 514ac99c64b "can: fix multiple delivery of a single CAN frame for
    overlapping CAN filters" requires the skb->tstamp to be set to check for
    identical CAN skbs.

    Without timestamping to be required by user space applications this timestamp
    was not generated which lead to commit 36c01245eb8 "can: fix loss of CAN frames
    in raw_rcv" - which forces the timestamp to be set in all CAN related skbuffs
    by introducing several __net_timestamp() calls.

    This forces e.g. out of tree drivers which are not using alloc_can{,fd}_skb()
    to add __net_timestamp() after skbuff creation to prevent the frame loss fixed
    in mainline Linux.

    This patch removes the timestamp dependency and uses an atomic counter to
    create an unique identifier together with the skbuff pointer.

    Btw: the new skbcnt element introduced in struct can_skb_priv has to be
    initialized with zero in out-of-tree drivers which are not using
    alloc_can{,fd}_skb() too.

    Signed-off-by: Oliver Hartkopp
    Cc: linux-stable
    Signed-off-by: Marc Kleine-Budde

    Oliver Hartkopp
     

24 Jun, 2015

1 commit


22 Jun, 2015

1 commit

  • As reported by Manfred Schlaegl here

    http://marc.info/?l=linux-netdev&m=143482089824232&w=2

    commit 514ac99c64b "can: fix multiple delivery of a single CAN frame for
    overlapping CAN filters" requires the skb->tstamp to be set to check for
    identical CAN skbs.

    As net timestamping is influenced by several players (netstamp_needed and
    netdev_tstamp_prequeue) Manfred missed a proper timestamp which leads to
    CAN frame loss.

    As skb timestamping became now mandatory for CAN related skbs this patch
    makes sure that received CAN skbs always have a proper timestamp set.
    Maybe there's a better solution in the future but this patch fixes the
    CAN frame loss so far.

    Reported-by: Manfred Schlaegl
    Signed-off-by: Oliver Hartkopp
    Cc: linux-stable
    Signed-off-by: Marc Kleine-Budde

    Oliver Hartkopp
     

09 Jun, 2015

1 commit

  • Similar to referencing iptables rules by their line number this UID allows to
    reference created routing jobs, e.g. to alter configured data modifications.

    The UID is an optional non-zero value which can be provided at routing job
    creation time. When the UID is set the UID replaces the data modification
    configuration as job identification attribute e.g. at job removal time.

    Signed-off-by: Oliver Hartkopp
    Signed-off-by: Marc Kleine-Budde

    Oliver Hartkopp
     

11 May, 2015

1 commit


01 Apr, 2015

2 commits

  • The CAN_RAW socket can set multiple CAN identifier specific filters that lead
    to multiple filters in the af_can.c filter processing. These filters are
    indenpendent from each other which leads to logical OR'ed filters when applied.

    This socket option joines the given CAN filters in the way that only CAN frames
    are passed to user space that matched *all* given CAN filters. The semantic for
    the applied filters is therefore changed to a logical AND.

    This is useful especially when the filterset is a combination of filters where
    the CAN_INV_FILTER flag is set in order to notch single CAN IDs or CAN ID
    ranges from the incoming traffic.

    As the raw_rcv() function is executed from NET_RX softirq the introduced
    variables are implemented as per-CPU variables to avoid extensive locking at
    CAN frame reception time.

    Signed-off-by: Oliver Hartkopp
    Signed-off-by: Marc Kleine-Budde

    Oliver Hartkopp
     
  • The CAN_RAW socket can set multiple CAN identifier specific filters that lead
    to multiple filters in the af_can.c filter processing. These filters are
    indenpendent from each other which leads to logical OR'ed filters when applied.

    This patch makes sure that every CAN frame which is filtered for a specific
    socket is only delivered once to the user space. This is independent from the
    number of matching CAN filters of this socket.

    As the raw_rcv() function is executed from NET_RX softirq the introduced
    variables are implemented as per-CPU variables to avoid extensive locking at
    CAN frame reception time.

    Signed-off-by: Oliver Hartkopp
    Signed-off-by: Marc Kleine-Budde

    Oliver Hartkopp
     

10 Mar, 2015

1 commit


09 Mar, 2015

1 commit

  • When accessing CAN network interfaces with AF_PACKET sockets e.g. by dhclient
    this can lead to a skb_under_panic due to missing skb initialisations.

    Add the missing initialisations at the CAN skbuff creation times on driver
    level (rx path) and in the network layer (tx path).

    Reported-by: Austin Schuh
    Reported-by: Daniel Steer
    Signed-off-by: Oliver Hartkopp
    Cc: linux-stable
    Signed-off-by: Marc Kleine-Budde

    Oliver Hartkopp
     

03 Mar, 2015

1 commit

  • After TIPC doesn't depend on iocb argument in its internal
    implementations of sendmsg() and recvmsg() hooks defined in proto
    structure, no any user is using iocb argument in them at all now.
    Then we can drop the redundant iocb argument completely from kinds of
    implementations of both sendmsg() and recvmsg() in the entire
    networking stack.

    Cc: Christoph Hellwig
    Suggested-by: Al Viro
    Signed-off-by: Ying Xue
    Signed-off-by: David S. Miller

    Ying Xue
     

02 Mar, 2015

1 commit


18 Jan, 2015

1 commit

  • Contrary to common expectations for an "int" return, these functions
    return only a positive value -- if used correctly they cannot even
    return 0 because the message header will necessarily be in the skb.

    This makes the very common pattern of

    if (genlmsg_end(...) < 0) { ... }

    be a whole bunch of dead code. Many places also simply do

    return nlmsg_end(...);

    and the caller is expected to deal with it.

    This also commonly (at least for me) causes errors, because it is very
    common to write

    if (my_function(...))
    /* error condition */

    and if my_function() does "return nlmsg_end()" this is of course wrong.

    Additionally, there's not a single place in the kernel that actually
    needs the message length returned, and if anyone needs it later then
    it'll be very easy to just use skb->len there.

    Remove this, and make the functions void. This removes a bunch of dead
    code as described above. The patch adds lines because I did

    - return nlmsg_end(...);
    + nlmsg_end(...);
    + return 0;

    I could have preserved all the function's return values by returning
    skb->len, but instead I've audited all the places calling the affected
    functions and found that none cared. A few places actually compared
    the return value with < 0 with no change in behaviour, so I opted for the more
    efficient version.

    One instance of the error I've made numerous times now is also present
    in net/phonet/pn_netlink.c in the route_dumpit() function - it didn't
    check for
    Signed-off-by: David S. Miller

    Johannes Berg
     

08 Dec, 2014

2 commits

  • Fix various spelling errors in the comments of the CAN modules.

    Signed-off-by: Jeremiah Mahler
    Acked-by: Oliver Hartkopp
    Signed-off-by: Marc Kleine-Budde

    Jeremiah Mahler
     
  • Several CAN modules use a design pattern with a banner[] variable at the
    top which defines a string that is used once during init to print the
    banner. The string is also embedded with KERN_INFO which makes it
    printk() specific.

    Improve the code by eliminating the banner[] variable and moving the
    string to where it is printed. Then switch from printk(KERN_INFO to
    pr_info() for the lines that were changed.

    Signed-off-by: Jeremiah Mahler
    Acked-by: Oliver Hartkopp
    Signed-off-by: Marc Kleine-Budde

    Jeremiah Mahler
     

24 Nov, 2014

2 commits


19 May, 2014

2 commits


25 Apr, 2014

1 commit

  • It is possible by passing a netlink socket to a more privileged
    executable and then to fool that executable into writing to the socket
    data that happens to be valid netlink message to do something that
    privileged executable did not intend to do.

    To keep this from happening replace bare capable and ns_capable calls
    with netlink_capable, netlink_net_calls and netlink_ns_capable calls.
    Which act the same as the previous calls except they verify that the
    opener of the socket had the desired permissions as well.

    Reported-by: Andy Lutomirski
    Signed-off-by: "Eric W. Biederman"
    Signed-off-by: David S. Miller

    Eric W. Biederman
     

03 Mar, 2014

1 commit

  • In commit e2d265d3b587 (canfd: add support for CAN FD in CAN_RAW sockets)
    CAN FD frames with a payload length up to 8 byte are passed to legacy
    sockets where the CAN FD support was not enabled by the application.

    After some discussions with developers at a fair this well meant feature
    leads to confusion as no clean switch for CAN / CAN FD is provided to the
    application programmer. Additionally a compatibility like this for legacy
    CAN_RAW sockets requires some compatibility handling for the sending, e.g.
    make CAN2.0 frames a CAN FD frame with BRS at transmission time (?!?).

    This will become a mess when people start to develop applications with
    real CAN FD hardware. This patch reverts the bad compatibility code
    together with the documentation describing the removed feature.

    Acked-by: Stephane Grosjean
    Signed-off-by: Oliver Hartkopp
    Signed-off-by: Marc Kleine-Budde

    Oliver Hartkopp
     

31 Jan, 2014

2 commits

  • linux-can-fixes-for-3.14-20140129

    Marc Kleine-Budde says:

    ====================
    Arnd Bergmann provides a fix for the flexcan driver, enabling compilation on
    all combinations of big and little endian on ARM and PowerPc. A patch by Ira W.
    Snyder fixes uninitialized variable warnings in the janz-ican3 driver.
    Rostislav Lisovy contributes a patch to propagate the SO_PRIORITY of raw
    sockets to skbs.
    ====================

    Signed-off-by: David S. Miller

    David S. Miller
     
  • Self generated skbuffs in net/can/bcm.c are setting a skb->sk reference but
    no explicit destructor which is enforced since Linux 3.11 with commit
    376c7311bdb6 (net: add a temporary sanity check in skb_orphan()).

    This patch adds some helper functions to make sure that a destructor is
    properly defined when a sock reference is assigned to a CAN related skb.
    To create an unshared skb owned by the original sock a common helper function
    has been introduced to replace open coded functions to create CAN echo skbs.

    Signed-off-by: Oliver Hartkopp
    Tested-by: Andre Naujoks
    Reviewed-by: Eric Dumazet
    Signed-off-by: David S. Miller

    Oliver Hartkopp
     

30 Jan, 2014

1 commit

  • This allows controlling certain queueing disciplines by setting the
    socket's SO_PRIORITY option.

    For example, with the default pfifo_fast queueing discipline, which
    provides three priorities, socket priority TC_PRIO_CONTROL means
    higher than default and TC_PRIO_BULK means lower than default.

    Signed-off-by: Rostislav Lisovy
    Signed-off-by: Michal Sojka
    Acked-by: Oliver Hartkopp
    Signed-off-by: Marc Kleine-Budde

    Rostislav Lisovy
     

19 Jan, 2014

1 commit

  • This is a follow-up patch to f3d3342602f8bc ("net: rework recvmsg
    handler msg_name and msg_namelen logic").

    DECLARE_SOCKADDR validates that the structure we use for writing the
    name information to is not larger than the buffer which is reserved
    for msg->msg_name (which is 128 bytes). Also use DECLARE_SOCKADDR
    consistently in sendmsg code paths.

    Signed-off-by: Steffen Hurrle
    Suggested-by: Hannes Frederic Sowa
    Acked-by: Hannes Frederic Sowa
    Signed-off-by: David S. Miller

    Steffen Hurrle
     

15 Jan, 2014

1 commit


21 Dec, 2013

1 commit

  • In commit be286bafe1f4069094865264f29805854c5788bf ("can: gw: add a variable
    limit for CAN frame routings") the detection of the frame routing has been
    changed. The former solution required dev->header_ops to be unused (== NULL).

    I missed to remove the obsolete checks in the original commit - so here it is.

    Signed-off-by: Oliver Hartkopp
    Signed-off-by: Marc Kleine-Budde

    Oliver Hartkopp
     

16 Nov, 2013

1 commit

  • Pull trivial tree updates from Jiri Kosina:
    "Usual earth-shaking, news-breaking, rocket science pile from
    trivial.git"

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial: (23 commits)
    doc: usb: Fix typo in Documentation/usb/gadget_configs.txt
    doc: add missing files to timers/00-INDEX
    timekeeping: Fix some trivial typos in comments
    mm: Fix some trivial typos in comments
    irq: Fix some trivial typos in comments
    NUMA: fix typos in Kconfig help text
    mm: update 00-INDEX
    doc: Documentation/DMA-attributes.txt fix typo
    DRM: comment: `halve' -> `half'
    Docs: Kconfig: `devlopers' -> `developers'
    doc: typo on word accounting in kprobes.c in mutliple architectures
    treewide: fix "usefull" typo
    treewide: fix "distingush" typo
    mm/Kconfig: Grammar s/an/a/
    kexec: Typo s/the/then/
    Documentation/kvm: Update cpuid documentation for steal time and pv eoi
    treewide: Fix common typo in "identify"
    __page_to_pfn: Fix typo in comment
    Correct some typos for word frequency
    clk: fixed-factor: Fix a trivial typo
    ...

    Linus Torvalds