summaryrefslogtreecommitdiff
path: root/net/mctp
AgeCommit message (Collapse)AuthorFilesLines
2022-04-14Merge tag 'v5.15.34' into dev-5.15Joel Stanley1-1/+1
This is the 5.15.34 stable release Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-04-13mctp: Fix check for dev_hard_header() resultMatt Johnston1-1/+1
[ Upstream commit 60be976ac45137657b7b505d7e0d44d0e51accb7 ] dev_hard_header() returns the length of the header, so we need to test for negative errors rather than non-zero. Fixes: 889b7da23abf ("mctp: Add initial routing framework") Signed-off-by: Matt Johnston <matt@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-03-18mctp: Avoid warning if unregister notifies twiceMatt Johnston1-4/+4
Previously if an unregister notify handler ran twice (waiting for netdev to be released) it would print a warning in mctp_unregister() every subsequent time the unregister notify occured. Instead we only need to worry about the case where a mctp_ptr is set on an unknown device type. OpenBMC-Staging-Count: 1 Signed-off-by: Matt Johnston <matt@codeconstruct.com.au> Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Fix warnings reported by clang-analyzerMatt Johnston2-2/+1
net/mctp/device.c:140:11: warning: Assigned value is garbage or undefined [clang-analyzer-core.uninitialized.Assign] mcb->idx = idx; - Not a real problem due to how the callback runs, fix the warning. net/mctp/route.c:458:4: warning: Value stored to 'msk' is never read [clang-analyzer-deadcode.DeadStores] msk = container_of(key->sk, struct mctp_sock, sk); - 'msk' dead assignment can be removed here. OpenBMC-Staging-Count: 1 Signed-off-by: Matt Johnston <matt@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 8d783197f06d905e5e7a89342e815ef5aeaa1731) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Fix incorrect netdev unref for extended addrMatt Johnston1-6/+2
In the extended addressing local route output codepath dev_get_by_index_rcu() doesn't take a dev_hold() so we shouldn't dev_put(). OpenBMC-Staging-Count: 1 Signed-off-by: Matt Johnston <matt@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit e297db3eadd7809170aea627ed3d9f714fa3da2d) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: make __mctp_dev_get() take a refcount holdMatt Johnston3-5/+22
Previously there was a race that could allow the mctp_dev refcount to hit zero: rcu_read_lock(); mdev = __mctp_dev_get(dev); // mctp_unregister() happens here, mdev->refs hits zero mctp_dev_hold(dev); rcu_read_unlock(); Now we make __mctp_dev_get() take the hold itself. It is safe to test against the zero refcount because __mctp_dev_get() is called holding rcu_read_lock and mctp_dev uses kfree_rcu(). OpenBMC-Staging-Count: 1 Reported-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Matt Johnston <matt@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit dc121c0084910db985cf1c8ba6fce5d8c307cc02) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: add address validity checking for packet receiveJeremy Kerr1-0/+11
This change adds some basic sanity checks for the source and dest headers of packets on initial receive. OpenBMC-Staging-Count: 1 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: Jakub Kicinski <kuba@kernel.org> (cherry picked from commit 86cdfd63f25dc1c8f241ee70c58da3c10472b76e) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: replace mctp_address_ok with more fine-grained helpersJeremy Kerr3-3/+3
Currently, we have mctp_address_ok(), which checks if an EID is in the "valid" range of 8-254 inclusive. However, 0 and 255 may also be valid addresses, depending on context. 0 is the NULL EID, which may be set when physical addressing is used. 255 is valid as a destination address for broadcasts. This change renames mctp_address_ok to mctp_address_unicast, and adds similar helpers for broadcast and null EIDs, which will be used in an upcoming commit. OpenBMC-Staging-Count: 1 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: Jakub Kicinski <kuba@kernel.org> (cherry picked from commit cb196b725936f6b776ad1d073f66fbe92aa798fa) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: fix use after freeTom Rix1-5/+6
Clang static analysis reports this problem route.c:425:4: warning: Use of memory after it is freed trace_mctp_key_acquire(key); ^~~~~~~~~~~~~~~~~~~~~~~~~~~ When mctp_key_add() fails, key is freed but then is later used in trace_mctp_key_acquire(). Add an else statement to use the key only when mctp_key_add() is successful. OpenBMC-Staging-Count: 1 Fixes: 4f9e1ba6de45 ("mctp: Add tracepoints for tag/key handling") Signed-off-by: Tom Rix <trix@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 7e5b6a5c8c44310784c88c1c198dde79f6402f7b) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Add SIOCMCTP{ALLOC,DROP}TAG ioctls for tag controlMatt Johnston2-54/+249
This change adds a couple of new ioctls for mctp sockets: SIOCMCTPALLOCTAG and SIOCMCTPDROPTAG. These ioctls provide facilities for explicit allocation / release of tags, overriding the automatic allocate-on-send/release-on-reply and timeout behaviours. This allows userspace more control over messages that may not fit a simple request/response model. In order to indicate a pre-allocated tag to the sendmsg() syscall, we introduce a new flag to the struct sockaddr_mctp.smctp_tag value: MCTP_TAG_PREALLOC. Additional changes from Jeremy Kerr <jk@codeconstruct.com.au>. Contains a fix that was: Reported-by: kernel test robot <lkp@intel.com> OpenBMC-Staging-Count: 1 Signed-off-by: Matt Johnston <matt@codeconstruct.com.au> Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 63ed1aab3d40aa61aaa66819bdce9377ac7f40fa) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Allow keys matching any local addressJeremy Kerr2-2/+10
Currently, we require an exact match on an incoming packet's dest address, and the key's local_addr field. In a future change, we may want to set up a key before packets are routed, meaning we have no local address to match on. This change allows key lookups to match on local_addr = MCTP_ADDR_ANY. OpenBMC-Staging-Count: 1 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 0de55a7d1133d0ab1acad5d91eea6ccd8cf6d448) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Add helper for address match checkingJeremy Kerr1-5/+3
Currently, we have a couple of paths that check that an EID matches, or the match value is MCTP_ADDR_ANY. Rather than open coding this, add a little helper. OpenBMC-Staging-Count: 1 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 8069b22d656f6e1922352bff90ab78e6fab73779) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: tests: Add key state testsJeremy Kerr1-0/+137
This change adds a few more tests to check the key/tag lookups on route input. We add a specific entry to the keys lists, route a packet with specific header values, and check for key match/mismatch. OpenBMC-Staging-Count: 1 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit c5755214623dd7aaafc5204458a0a30b7469850c) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: tests: Rename FL_T macro to FL_TOJeremy Kerr1-6/+6
This is a definition for the tag-owner flag, which has TO as a standard abbreviation. We'll want to add a helper for the actual tag value in a future change. OpenBMC-Staging-Count: 1 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 62a2b005c6d639b6bd7a63fe2f0a96eaf06f0057) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: test: zero out sockaddrMatt Johnston1-1/+1
MCTP now requires that padding bytes are zero. OpenBMC-Staging-Count: 1 Signed-off-by: Matt Johnston <matt@codeconstruct.com.au> Fixes: 1e4b50f06d97 ("mctp: handle the struct sockaddr_mctp padding fields") Link: https://lore.kernel.org/r/20220110021806.2343023-1-matt@codeconstruct.com.au Signed-off-by: Jakub Kicinski <kuba@kernel.org> (cherry picked from commit 9d5e9e549ba4a02e515001a41c2b0a30ccd5f477) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Remove only static neighbour on RTM_DELNEIGHGagan Kumar1-4/+5
Add neighbour source flag in mctp_neigh_remove(...) to allow removal of only static neighbours. This should be a no-op change and might be useful later when mctp can have MCTP_NEIGH_DISCOVER neighbours. OpenBMC-Staging-Count: 1 Signed-off-by: Gagan Kumar <gagan1kumar.cs@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit ae81de737885820616f9c67c2e7935998b523d58) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: emit RTM_NEWADDR and RTM_DELADDRMatt Johnston1-5/+48
Userspace can receive notification of MCTP address changes via RTNLGRP_MCTP_IFADDR rtnetlink multicast group. OpenBMC-Staging-Count: 1 Signed-off-by: Matt Johnston <matt@codeconstruct.com.au> Link: https://lore.kernel.org/r/20211220023104.1965509-1-matt@codeconstruct.com.au Signed-off-by: Jakub Kicinski <kuba@kernel.org> (cherry picked from commit dbcefdeb2a58039f4c81d0361056fbdd9be906a1) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Remove redundant if statementsXu Wang1-2/+1
The 'if (dev)' statement already move into dev_{put , hold}, so remove redundant if statements. OpenBMC-Staging-Count: 1 Signed-off-by: Xu Wang <vulab@iscas.ac.cn> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit d9e56d1839fa40dbaab640ec205390826bddf8ae) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: remove unnecessary check before calling kfree_skb()Yang Yingliang2-5/+2
The skb will be checked inside kfree_skb(), so remove the outside check. OpenBMC-Staging-Count: 1 Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> Link: https://lore.kernel.org/r/20211130031243.768823-1-yangyingliang@huawei.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> (cherry picked from commit 5cfe53cfeb1c05b73e5f2e09d7fe3140b17c1204) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: test: fix skb free in test device txJeremy Kerr1-1/+1
In our test device, we're currently freeing skbs in the transmit path with kfree(), rather than kfree_skb(). This change uses the correct kfree_skb() instead. OpenBMC-Staging-Count: 1 Fixes: ded21b722995 ("mctp: Add test utils") Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit d8519565447078f141c58ba4193d820f2cdf1914) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp/test: Update refcount checking in route fragment testsJeremy Kerr1-5/+0
In 99ce45d5e, we moved a route refcount decrement from mctp_do_fragment_route into the caller. This invalidates the assumption that the route test makes about refcount behaviour, so the route tests fail. This change fixes the test case to suit the new refcount behaviour. OpenBMC-Staging-Count: 1 Fixes: 99ce45d5e7db ("mctp: Implement extended addressing") Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit f6ef47e5bdc6f652176e433b02317fc83049f8d7) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: handle the struct sockaddr_mctp_ext padding fieldEugene Syromiatnikov1-1/+10
struct sockaddr_mctp_ext.__smctp_paddin0 has to be checked for being set to zero, otherwise it cannot be utilised in the future. OpenBMC-Staging-Count: 1 Fixes: 99ce45d5e7dbde39 ("mctp: Implement extended addressing") Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com> Acked-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: Jakub Kicinski <kuba@kernel.org> (cherry picked from commit e9ea574ec1c27e555e7f78cbbcd28af91889d529) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Pass flow data & flow release events to driversJeremy Kerr2-2/+104
Now that we have an extension for MCTP data in skbs, populate the flow when a key has been created for the packet, and add a device driver operation to inform of flow destruction. Includes a fix for a warning with test builds: Reported-by: kernel test robot <lkp@intel.com> OpenBMC-Staging-Count: 1 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 67737c457281dd199ceb9e31b6ba7efd3bfe566d) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Add flow extension to skbJeremy Kerr1-1/+6
This change adds a new skb extension for MCTP, to represent a request/response flow. The intention is to use this in a later change to allow i2c controllers to correctly configure a multiplexer over a flow. Since we have a cleanup function in the core path (if an extension is present), we'll need to make CONFIG_MCTP a bool, rather than a tristate. Includes a fix for a build warning with clang: Reported-by: kernel test robot <lkp@intel.com> OpenBMC-Staging-Count: 1 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 78476d315e190533757ab894255c4f2c2f254bce) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Return new key from mctp_alloc_local_tagJeremy Kerr1-12/+16
In a future change, we will want the key available for future use after allocating a new tag. This change returns the key from mctp_alloc_local_tag, rather than just key->tag. OpenBMC-Staging-Count: 1 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 212c10c3c658b191c18ecdf80efb742f9bce5205) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Implement extended addressingJeremy Kerr2-35/+149
This change allows an extended address struct - struct sockaddr_mctp_ext - to be passed to sendmsg/recvmsg. This allows userspace to specify output ifindex and physical address information (for sendmsg) or receive the input ifindex/physaddr for incoming messages (for recvmsg). This is typically used by userspace for MCTP address discovery and assignment operations. The extended addressing facility is conditional on a new sockopt: MCTP_OPT_ADDR_EXT; userspace must explicitly enable addressing before the kernel will consume/populate the extended address data. Includes a fix for an uninitialised var: Reported-by: kernel test robot <lkp@intel.com> Backport: exclude SOL_MPTCP OpenBMC-Staging-Count: 1 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 99ce45d5e7dbde399997a630f45ac9f654fa4bcc) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Avoid leak of mctp_sk_keyMatt Johnston1-0/+4
mctp_key_alloc() returns a key already referenced. The mctp_route_input() path receives a packet for a bind socket and allocates a key. It passes the key to mctp_key_add() which takes a refcount and adds the key to lists. mctp_route_input() should then release its own refcount when setting the key pointer to NULL. In the mctp_alloc_local_tag() path (for mctp_local_output()) we similarly need to unref the key before returning (mctp_reserve_tag() takes a refcount and adds the key to lists). OpenBMC-Staging-Count: 1 Fixes: 73c618456dc5 ("mctp: locking, lifetime and validity changes for sk_keys") Signed-off-by: Matt Johnston <matt@codeconstruct.com.au> Reviewed-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 0b93aed2842d950e8d2625e975e5a57febeff33d) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Add input reassembly testsJeremy Kerr1-0/+134
Add multi-packet route input tests, for message reassembly. These will feed packets to be received by a bound socket, or dropped. OpenBMC-Staging-Count: 1 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 1e5e9250d4224e3ed77846bd8d29ac66fbe6f05d) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Add route input to socket testsJeremy Kerr1-0/+132
Add a few tests for single-packet route inputs, testing the mctp_route_input function. OpenBMC-Staging-Count: 1 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 8892c0490779d6de921eb684e5504708fdbbcb68) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Add packet rx testsJeremy Kerr1-3/+64
Add a few tests for the initial packet ingress through mctp_pkttype_receive function; mainly packet header sanity checks. Full input routing checks will be added as a separate change. OpenBMC-Staging-Count: 1 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit b504db408c34e01d791f69c61ee256a8c7eec62f) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Add test utilsJeremy Kerr3-0/+90
Add a new object for shared test utilities OpenBMC-Staging-Count: 1 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit ded21b72299529cc143a4213ea0ec4b0c620b8eb) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Add initial test structure and fragmentation testJeremy Kerr3-0/+227
This change adds the first kunit test for the mctp subsystem, and an initial test for the fragmentation path. We're adding tests under a new net/mctp/test/ directory. Incorporates a fix for module configs: Reported-by: kernel test robot <lkp@intel.com> OpenBMC-Staging-Count: 1 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 161eba50e183ed4ca20f6d8dec19bdc526d2b2b9) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Warn if pointer is set for a wrong dev typeMatt Johnston1-7/+24
Should not occur but is a sanity check. May help tracking down Trinity reported issue https://lore.kernel.org/lkml/20210913030701.GA5926@xsang-OptiPlex-9020/ OpenBMC-Staging-Count: 1 Signed-off-by: Matt Johnston <matt@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 7b1871af75f30d9d88184fff42698718fa157dcf) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Set route MTU via netlinkMatt Johnston1-1/+13
A route's RTAX_MTU can be set in nested RTAX_METRICS OpenBMC-Staging-Count: 1 Signed-off-by: Matt Johnston <matt@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 6183569db80eedc648b584a658e6b898d43650cb) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Do inits as a subsys_initcallJeremy Kerr1-1/+1
In a future change, we'll want to provide a registration call for mctp-specific devices. This requires us to have the networks established before device driver inits, so run the core init as a subsys_initcall. OpenBMC-Staging-Count: 1 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 97f09abffcb967144ed01fe9d09d0fba499ffc6f) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Add tracepoints for tag/key handlingJeremy Kerr2-1/+17
The tag allocation, release and bind events are somewhat opaque outside the kernel; this change adds a few tracepoints to assist in instrumentation and debugging. OpenBMC-Staging-Count: 1 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 4f9e1ba6de45aa8797a83f1fe5b82ec4bac16899) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Implement a timeout for tagsJeremy Kerr2-0/+52
Currently, a MCTP (local-eid,remote-eid,tag) tuple is allocated to a socket on send, and only expires when the socket is closed. This change introduces a tag timeout, freeing the tuple after a fixed expiry - currently six seconds. This is greater than (but close to) the max response timeout in upper-layer bindings. OpenBMC-Staging-Count: 1 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 7b14e15ae6f4850392800482efb54d5cf4ae300c) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Add refcounts to mctp_devJeremy Kerr3-13/+20
Currently, we tie the struct mctp_dev lifetime to the underlying struct net_device, and hold/put that device as a proxy for a separate mctp_dev refcount. This works because we're not holding any references to the mctp_dev that are different from the netdev lifetime. In a future change we'll break that assumption though, as we'll need to hold mctp_dev references in a workqueue, which might live past the netdev unregister notification. In order to support that, this change introduces a refcount on the mctp_dev, currently taken by the net_device->mctp_ptr reference, and released on netdev unregister events. We can then use this for future references that might outlast the net device. OpenBMC-Staging-Count: 1 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 43f55f23f70881e9c397557f15c8090b368d0af2) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: locking, lifetime and validity changes for sk_keysJeremy Kerr2-38/+94
We will want to invalidate sk_keys in a future change, which will require a boolean flag to mark invalidated items in the socket & net namespace lists. We'll also need to take a reference to keys, held over non-atomic contexts, so we need a refcount on keys also. This change adds a validity flag (currently always true) and refcount to struct mctp_sk_key. With a refcount on the keys, using RCU no longer makes much sense; we have exact indications on the lifetime of keys. So, we also change the RCU list traversal to a locked implementation. OpenBMC-Staging-Count: 1 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 73c618456dc5cf2acb597256d633060cf75de8d6) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Allow local delivery to the null EIDJeremy Kerr1-0/+23
We may need to receive packets addressed to the null EID (==0), but addressed to us at the physical layer. This change adds a lookup for local routes when we see a packet addressed to EID 0, and a local phys address. OpenBMC-Staging-Count: 1 Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 1f6c77ac9e6ecef152fd5df94c4b3c346adb197a) Signed-off-by: Joel Stanley <joel@jms.id.au>
2022-03-18mctp: Allow MCTP on tun devicesMatt Johnston2-7/+13
Allowing TUN is useful for testing, to route packets to userspace or to tunnel between machines. OpenBMC-Staging-Count: 1 Signed-off-by: Matt Johnston <matt@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit f364dd71d92fe6722fe5d47803be974dc0c40762) Signed-off-by: Joel Stanley <joel@jms.id.au>
2021-12-08mctp: Don't let RTM_DELROUTE delete local routesMatt Johnston1-4/+5
[ Upstream commit 76d001603c509562181f3787a7065b8e163bc7b9 ] We need to test against the existing route type, not the rtm_type in the netlink request. Fixes: 83f0a0b7285b ("mctp: Specify route types, require rtm_type in RTM_*ROUTE messages") Signed-off-by: Matt Johnston <matt@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-11-18mctp: handle the struct sockaddr_mctp padding fieldsEugene Syromiatnikov1-0/+13
commit 1e4b50f06d970d8da3474d2a0354450416710bda upstream. In order to have the padding fields actually usable in the future, there have to be checks that user space doesn't supply non-zero garbage there. It is also worth setting these padding fields to zero, unless it is known that they have been already zeroed. Cc: stable@vger.kernel.org # v5.15 Fixes: 5a20dd46b8b84593 ("mctp: Be explicit about struct sockaddr_mctp padding") Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com> Acked-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-09-08mctp: perform route destruction under RCU read lockJeremy Kerr1-0/+2
The kernel test robot reports: [ 843.509974][ T345] ============================= [ 843.524220][ T345] WARNING: suspicious RCU usage [ 843.538791][ T345] 5.14.0-rc2-00606-g889b7da23abf #1 Not tainted [ 843.553617][ T345] ----------------------------- [ 843.567412][ T345] net/mctp/route.c:310 RCU-list traversed in non-reader section!! - we're missing the rcu read lock acquire around the destruction path. This change adds the acquire/release - the path is already atomic, and we're using the _rcu list iterators. Reported-by: kernel test robot <oliver.sang@intel.com> Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net>
2021-08-12mctp: Specify route types, require rtm_type in RTM_*ROUTE messagesJeremy Kerr1-5/+22
This change adds a 'type' attribute to routes, which can be parsed from a RTM_NEWROUTE message. This will help to distinguish local vs. peer routes in a future change. This means userspace will need to set a correct rtm_type in RTM_NEWROUTE and RTM_DELROUTE messages; we currently only accept RTN_UNICAST. Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Link: https://lore.kernel.org/r/20210810023834.2231088-1-jk@codeconstruct.com.au Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2021-08-05mctp: remove duplicated assignment of pointer hdrColin Ian King1-1/+0
The pointer hdr is being initialized and also re-assigned with the same value from the call to function mctp_hdr. Static analysis reports that the initializated value is unused. The second assignment is duplicated and can be removed. Addresses-Coverity: ("Unused value"). Signed-off-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: David S. Miller <davem@davemloft.net>
2021-07-29mctp: Allow per-netns default networksMatt Johnston3-1/+18
Currently we have a compile-time default network (MCTP_INITIAL_DEFAULT_NET). This change introduces a default_net field on the net namespace, allowing future configuration for new interfaces. Signed-off-by: Matt Johnston <matt@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net>
2021-07-29mctp: Add dest neighbour lladdr to route outputMatt Johnston1-2/+8
Now that we have a neighbour implementation, hook it up to the output path to set the dest hardware address for outgoing packets. Signed-off-by: Matt Johnston <matt@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net>
2021-07-29mctp: Implement message fragmentation & reassemblyJeremy Kerr2-41/+339
This change implements MCTP fragmentation (based on route & device MTU), and corresponding reassembly. The MCTP specification only allows for fragmentation on the originating message endpoint, and reassembly on the destination endpoint - intermediate nodes do not need to reassemble/refragment. Consequently, we only fragment in the local transmit path, and reassemble locally-bound packets. Messages are required to be in-order, so we simply cancel reassembly on out-of-order or missing packets. In the fragmentation path, we just break up the message into MTU-sized fragments; the skb structure is a simple copy for now, which we can later improve with a shared data implementation. For reassembly, we keep track of incoming message fragments using the existing tag infrastructure, allocating a key on the (src,dest,tag) tuple, and reassembles matching fragments into a skb->frag_list. Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net>
2021-07-29mctp: Populate socket implementationJeremy Kerr2-10/+419
Start filling-out the socket syscalls: bind, sendmsg & recvmsg. This requires an input route implementation, so we add to mctp_route_input, allowing lookups on binds & message tags. This just handles single-packet messages at present, we will add fragmentation in a future change. Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net>