1. 12 3月, 2020 1 次提交
  2. 23 2月, 2020 1 次提交
  3. 21 2月, 2020 1 次提交
    • N
      net: netlink: cap max groups which will be considered in netlink_bind() · 3a20773b
      Nikolay Aleksandrov 提交于
      Since nl_groups is a u32 we can't bind more groups via ->bind
      (netlink_bind) call, but netlink has supported more groups via
      setsockopt() for a long time and thus nlk->ngroups could be over 32.
      Recently I added support for per-vlan notifications and increased the
      groups to 33 for NETLINK_ROUTE which exposed an old bug in the
      netlink_bind() code causing out-of-bounds access on archs where unsigned
      long is 32 bits via test_bit() on a local variable. Fix this by capping the
      maximum groups in netlink_bind() to BITS_PER_TYPE(u32), effectively
      capping them at 32 which is the minimum of allocated groups and the
      maximum groups which can be bound via netlink_bind().
      
      CC: Christophe Leroy <christophe.leroy@c-s.fr>
      CC: Richard Guy Briggs <rgb@redhat.com>
      Fixes: 4f520900 ("netlink: have netlink per-protocol bind function return an error code.")
      Reported-by: NErhard F. <erhard_f@mailbox.org>
      Signed-off-by: NNikolay Aleksandrov <nikolay@cumulusnetworks.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      3a20773b
  4. 18 2月, 2020 1 次提交
  5. 10 12月, 2019 1 次提交
  6. 14 10月, 2019 1 次提交
    • M
      genetlink: do not parse attributes for families with zero maxattr · cb0ce18a
      Michal Kubecek 提交于
      Commit c10e6cf8 ("net: genetlink: push attrbuf allocation and parsing
      to a separate function") moved attribute buffer allocation and attribute
      parsing from genl_family_rcv_msg_doit() into a separate function
      genl_family_rcv_msg_attrs_parse() which, unlike the previous code, calls
      __nlmsg_parse() even if family->maxattr is 0 (i.e. the family does its own
      parsing). The parser error is ignored and does not propagate out of
      genl_family_rcv_msg_attrs_parse() but an error message ("Unknown attribute
      type") is set in extack and if further processing generates no error or
      warning, it stays there and is interpreted as a warning by userspace.
      
      Dumpit requests are not affected as genl_family_rcv_msg_dumpit() bypasses
      the call of genl_family_rcv_msg_attrs_parse() if family->maxattr is zero.
      Move this logic inside genl_family_rcv_msg_attrs_parse() so that we don't
      have to handle it in each caller.
      
      v3: put the check inside genl_family_rcv_msg_attrs_parse()
      v2: adjust also argument of genl_family_rcv_msg_attrs_free()
      
      Fixes: c10e6cf8 ("net: genetlink: push attrbuf allocation and parsing to a separate function")
      Signed-off-by: NMichal Kubecek <mkubecek@suse.cz>
      Acked-by: NJiri Pirko <jiri@mellanox.com>
      Acked-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      cb0ce18a
  7. 09 10月, 2019 1 次提交
    • J
      net: genetlink: always allocate separate attrs for dumpit ops · ab5b526d
      Jiri Pirko 提交于
      Individual dumpit ops (start, dumpit, done) are locked by genl_lock
      if !family->parallel_ops. However, multiple
      genl_family_rcv_msg_dumpit() calls may in in flight in parallel.
      Each has a separate struct genl_dumpit_info allocated
      but they share the same family->attrbuf. Fix this by allocating separate
      memory for attrs for dumpit ops, for non-parallel_ops (for parallel_ops
      it is done already).
      
      Reported-by: syzbot+495688b736534bb6c6ad@syzkaller.appspotmail.com
      Reported-by: syzbot+ff59dc711f2cff879a05@syzkaller.appspotmail.com
      Reported-by: syzbot+dbe02e13bcce52bcf182@syzkaller.appspotmail.com
      Reported-by: syzbot+9cb7edb2906ea1e83006@syzkaller.appspotmail.com
      Fixes: bf813b0a ("net: genetlink: parse attrs and store in contect info struct during dumpit")
      Signed-off-by: NJiri Pirko <jiri@mellanox.com>
      Signed-off-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      ab5b526d
  8. 06 10月, 2019 5 次提交
  9. 15 6月, 2019 1 次提交
  10. 12 6月, 2019 1 次提交
  11. 31 5月, 2019 1 次提交
  12. 21 5月, 2019 2 次提交
  13. 20 5月, 2019 1 次提交
  14. 04 5月, 2019 1 次提交
  15. 28 4月, 2019 3 次提交
    • J
      genetlink: optionally validate strictly/dumps · ef6243ac
      Johannes Berg 提交于
      Add options to strictly validate messages and dump messages,
      sometimes perhaps validating dump messages non-strictly may
      be required, so add an option for that as well.
      
      Since none of this can really be applied to existing commands,
      set the options everwhere using the following spatch:
      
          @@
          identifier ops;
          expression X;
          @@
          struct genl_ops ops[] = {
          ...,
           {
                  .cmd = X,
          +       .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
                  ...
           },
          ...
          };
      
      For new commands one should just not copy the .validate 'opt-out'
      flags and thus get strict validation.
      Signed-off-by: NJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      ef6243ac
    • J
      netlink: make validation more configurable for future strictness · 8cb08174
      Johannes Berg 提交于
      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: NJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      8cb08174
    • M
      netlink: make nla_nest_start() add NLA_F_NESTED flag · ae0be8de
      Michal Kubecek 提交于
      Even if the NLA_F_NESTED flag was introduced more than 11 years ago, most
      netlink based interfaces (including recently added ones) are still not
      setting it in kernel generated messages. Without the flag, message parsers
      not aware of attribute semantics (e.g. wireshark dissector or libmnl's
      mnl_nlmsg_fprintf()) cannot recognize nested attributes and won't display
      the structure of their contents.
      
      Unfortunately we cannot just add the flag everywhere as there may be
      userspace applications which check nlattr::nla_type directly rather than
      through a helper masking out the flags. Therefore the patch renames
      nla_nest_start() to nla_nest_start_noflag() and introduces nla_nest_start()
      as a wrapper adding NLA_F_NESTED. The calls which add NLA_F_NESTED manually
      are rewritten to use nla_nest_start().
      
      Except for changes in include/net/netlink.h, the patch was generated using
      this semantic patch:
      
      @@ expression E1, E2; @@
      -nla_nest_start(E1, E2)
      +nla_nest_start_noflag(E1, E2)
      
      @@ expression E1, E2; @@
      -nla_nest_start_noflag(E1, E2 | NLA_F_NESTED)
      +nla_nest_start(E1, E2)
      Signed-off-by: NMichal Kubecek <mkubecek@suse.cz>
      Acked-by: NJiri Pirko <jiri@mellanox.com>
      Acked-by: NDavid Ahern <dsahern@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      ae0be8de
  16. 26 4月, 2019 1 次提交
  17. 13 4月, 2019 1 次提交
  18. 22 3月, 2019 2 次提交
    • J
      genetlink: make policy common to family · 3b0f31f2
      Johannes Berg 提交于
      Since maxattr is common, the policy can't really differ sanely,
      so make it common as well.
      
      The only user that did in fact manage to make a non-common policy
      is taskstats, which has to be really careful about it (since it's
      still using a common maxattr!). This is no longer supported, but
      we can fake it using pre_doit.
      
      This reduces the size of e.g. nl80211.o (which has lots of commands):
      
         text	   data	    bss	    dec	    hex	filename
       398745	  14323	   2240	 415308	  6564c	net/wireless/nl80211.o (before)
       397913	  14331	   2240	 414484	  65314	net/wireless/nl80211.o (after)
      --------------------------------
         -832      +8       0    -824
      
      Which is obviously just 8 bytes for each command, and an added 8
      bytes for the new policy pointer. I'm not sure why the ops list is
      counted as .text though.
      
      Most of the code transformations were done using the following spatch:
          @ops@
          identifier OPS;
          expression POLICY;
          @@
          struct genl_ops OPS[] = {
          ...,
           {
          -	.policy = POLICY,
           },
          ...
          };
      
          @@
          identifier ops.OPS;
          expression ops.POLICY;
          identifier fam;
          expression M;
          @@
          struct genl_family fam = {
                  .ops = OPS,
                  .maxattr = M,
          +       .policy = POLICY,
                  ...
          };
      
      This also gets rid of devlink_nl_cmd_region_read_dumpit() accessing
      the cb->data as ops, which we want to change in a later genl patch.
      Signed-off-by: NJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      3b0f31f2
    • Y
      genetlink: Fix a memory leak on error path · ceabee6c
      YueHaibing 提交于
      In genl_register_family(), when idr_alloc() fails,
      we forget to free the memory we possibly allocate for
      family->attrbuf.
      Reported-by: NHulk Robot <hulkci@huawei.com>
      Fixes: 2ae0f17d ("genetlink: use idr to track families")
      Signed-off-by: NYueHaibing <yuehaibing@huawei.com>
      Reviewed-by: NKirill Tkhai <ktkhai@virtuozzo.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      ceabee6c
  19. 22 2月, 2019 1 次提交
  20. 20 1月, 2019 1 次提交
  21. 15 12月, 2018 1 次提交
  22. 16 10月, 2018 1 次提交
    • D
      netlink: Add answer_flags to netlink_callback · 22e6c58b
      David Ahern 提交于
      With dump filtering we need a way to ensure the NLM_F_DUMP_FILTERED
      flag is set on a message back to the user if the data returned is
      influenced by some input attributes. Normally this can be done as
      messages are added to the skb, but if the filter results in no data
      being returned, the user could be confused as to why.
      
      This patch adds answer_flags to the netlink_callback allowing dump
      handlers to set the NLM_F_DUMP_FILTERED at a minimum in the
      NLMSG_DONE message ensuring the flag gets back to the user.
      
      The netlink_callback space is initialized to 0 via a memset in
      __netlink_dump_start, so init of the new answer_flags is covered.
      Signed-off-by: NDavid Ahern <dsahern@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      22e6c58b
  23. 09 10月, 2018 2 次提交
    • D
      netlink: Add new socket option to enable strict checking on dumps · 89d35528
      David Ahern 提交于
      Add a new socket option, NETLINK_DUMP_STRICT_CHK, that userspace
      can use via setsockopt to request strict checking of headers and
      attributes on dump requests.
      
      To get dump features such as kernel side filtering based on data in
      the header or attributes appended to the dump request, userspace
      must call setsockopt() for NETLINK_DUMP_STRICT_CHK and a non-zero
      value. Since the netlink sock and its flags are private to the
      af_netlink code, the strict checking flag is passed to dump handlers
      via a flag in the netlink_callback struct.
      
      For old userspace on new kernel there is no impact as all of the data
      checks in later patches are wrapped in a check on the new strict flag.
      
      For new userspace on old kernel, the setsockopt will fail and even if
      new userspace sets data in the headers and appended attributes the
      kernel will silently ignore it. Moving forward when the setsockopt
      succeeds, the new userspace on old kernel means the dump request can
      pass an attribute the kernel does not understand. The dump will then
      fail as the older kernel does not understand it.
      
      New userspace on new kernel setting the socket option gets the benefit
      of the improved data dump.
      
      Kernel side the NETLINK_DUMP_STRICT_CHK uapi is converted to a generic
      NETLINK_F_STRICT_CHK flag which can potentially be leveraged for tighter
      checking on the NEW, DEL, and SET commands.
      Signed-off-by: NDavid Ahern <dsahern@gmail.com>
      Acked-by: NChristian Brauner <christian@brauner.io>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      89d35528
    • D
      netlink: Pass extack to dump handlers · 4a19edb6
      David Ahern 提交于
      Declare extack in netlink_dump and pass to dump handlers via
      netlink_callback. Add any extack message after the dump_done_errno
      allowing error messages to be returned. This will be useful when
      strict checking is done on dump requests, returning why the dump
      fails EINVAL.
      Signed-off-by: NDavid Ahern <dsahern@gmail.com>
      Acked-by: NChristian Brauner <christian@brauner.io>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      4a19edb6
  24. 12 9月, 2018 1 次提交
  25. 06 9月, 2018 1 次提交
    • D
      netlink: Make groups check less stupid in netlink_bind() · 428f944b
      Dmitry Safonov 提交于
      As Linus noted, the test for 0 is needless, groups type can follow the
      usual kernel style and 8*sizeof(unsigned long) is BITS_PER_LONG:
      
      > The code [..] isn't technically incorrect...
      > But it is stupid.
      > Why stupid? Because the test for 0 is pointless.
      >
      > Just doing
      >        if (nlk->ngroups < 8*sizeof(groups))
      >                groups &= (1UL << nlk->ngroups) - 1;
      >
      > would have been fine and more understandable, since the "mask by shift
      > count" already does the right thing for a ngroups value of 0. Now that
      > test for zero makes me go "what's special about zero?". It turns out
      > that the answer to that is "nothing".
      [..]
      > The type of "groups" is kind of silly too.
      >
      > Yeah, "long unsigned int" isn't _technically_ wrong. But we normally
      > call that type "unsigned long".
      
      Cleanup my piece of pointlessness.
      
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Herbert Xu <herbert@gondor.apana.org.au>
      Cc: Steffen Klassert <steffen.klassert@secunet.com>
      Cc: netdev@vger.kernel.org
      Fairly-blamed-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NDmitry Safonov <dima@arista.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      428f944b
  26. 05 8月, 2018 1 次提交
    • D
      netlink: Don't shift on 64 for ngroups · 91874ecf
      Dmitry Safonov 提交于
      It's legal to have 64 groups for netlink_sock.
      
      As user-supplied nladdr->nl_groups is __u32, it's possible to subscribe
      only to first 32 groups.
      
      The check for correctness of .bind() userspace supplied parameter
      is done by applying mask made from ngroups shift. Which broke Android
      as they have 64 groups and the shift for mask resulted in an overflow.
      
      Fixes: 61f4b237 ("netlink: Don't shift with UB on nlk->ngroups")
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Herbert Xu <herbert@gondor.apana.org.au>
      Cc: Steffen Klassert <steffen.klassert@secunet.com>
      Cc: netdev@vger.kernel.org
      Cc: stable@vger.kernel.org
      Reported-and-Tested-by: NNathan Chancellor <natechancellor@gmail.com>
      Signed-off-by: NDmitry Safonov <dima@arista.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      91874ecf
  27. 02 8月, 2018 1 次提交
    • J
      netlink: Fix spectre v1 gadget in netlink_create() · bc5b6c0b
      Jeremy Cline 提交于
      'protocol' is a user-controlled value, so sanitize it after the bounds
      check to avoid using it for speculative out-of-bounds access to arrays
      indexed by it.
      
      This addresses the following accesses detected with the help of smatch:
      
      * net/netlink/af_netlink.c:654 __netlink_create() warn: potential
        spectre issue 'nlk_cb_mutex_keys' [w]
      
      * net/netlink/af_netlink.c:654 __netlink_create() warn: potential
        spectre issue 'nlk_cb_mutex_key_strings' [w]
      
      * net/netlink/af_netlink.c:685 netlink_create() warn: potential spectre
        issue 'nl_table' [w] (local cap)
      
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Signed-off-by: NJeremy Cline <jcline@redhat.com>
      Reviewed-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      bc5b6c0b
  28. 31 7月, 2018 1 次提交
  29. 30 7月, 2018 1 次提交
  30. 25 7月, 2018 1 次提交
  31. 29 6月, 2018 1 次提交
    • L
      Revert changes to convert to ->poll_mask() and aio IOCB_CMD_POLL · a11e1d43
      Linus Torvalds 提交于
      The poll() changes were not well thought out, and completely
      unexplained.  They also caused a huge performance regression, because
      "->poll()" was no longer a trivial file operation that just called down
      to the underlying file operations, but instead did at least two indirect
      calls.
      
      Indirect calls are sadly slow now with the Spectre mitigation, but the
      performance problem could at least be largely mitigated by changing the
      "->get_poll_head()" operation to just have a per-file-descriptor pointer
      to the poll head instead.  That gets rid of one of the new indirections.
      
      But that doesn't fix the new complexity that is completely unwarranted
      for the regular case.  The (undocumented) reason for the poll() changes
      was some alleged AIO poll race fixing, but we don't make the common case
      slower and more complex for some uncommon special case, so this all
      really needs way more explanations and most likely a fundamental
      redesign.
      
      [ This revert is a revert of about 30 different commits, not reverted
        individually because that would just be unnecessarily messy  - Linus ]
      
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Christoph Hellwig <hch@lst.de>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      a11e1d43