6431 Commits

Author SHA1 Message Date
Kir Kolyshkin
a8cdd2be8d sched/headers: Move 'struct sched_param' out of uapi, to work around glibc/musl breakage
Both glibc and musl define 'struct sched_param' in sched.h, while kernel
has it in uapi/linux/sched/types.h, making it cumbersome to use
sched_getattr(2) or sched_setattr(2) from userspace.

For example, something like this:

	#include <sched.h>
	#include <linux/sched/types.h>

	struct sched_attr sa;

will result in "error: redefinition of ‘struct sched_param’" (note the
code doesn't need sched_param at all -- it needs struct sched_attr
plus some stuff from sched.h).

The situation is, glibc is not going to provide a wrapper for
sched_{get,set}attr, thus the need to include linux/sched_types.h
directly, which leads to the above problem.

Thus, the userspace is left with a few sub-par choices when it wants to
use e.g. sched_setattr(2), such as maintaining a copy of struct
sched_attr definition, or using some other ugly tricks.

OTOH, 'struct sched_param' is well known, defined in POSIX, and it won't
be ever changed (as that would break backward compatibility).

So, while 'struct sched_param' is indeed part of the kernel uapi,
exposing it the way it's done now creates an issue, and hiding it
(like this patch does) fixes that issue, hopefully without creating
another one: common userspace software rely on libc headers, and as
for "special" software (like libc), it looks like glibc and musl
do not rely on kernel headers for 'struct sched_param' definition
(but let's Cc their mailing lists in case it's otherwise).

The alternative to this patch would be to move struct sched_attr to,
say, linux/sched.h, or linux/sched/attr.h (the new file).

Oh, and here is the previous attempt to fix the issue:

  https://lore.kernel.org/all/20200528135552.GA87103@google.com/

While I support Linus arguments, the issue is still here
and needs to be fixed.

[ mingo: Linus is right, this shouldn't be needed - but on the other
         hand I agree that this header is not really helpful to
	 user-space as-is. So let's pretend that
	 <uapi/linux/sched/types.h> is only about sched_attr, and
	 call this commit a workaround for user-space breakage
	 that it in reality is ... Also, remove the Fixes tag. ]

Signed-off-by: Joe7500 <j7545032@gmail.com>
2025-08-24 00:20:35 +07:00
Lokesh Gidra
d0025e4ba4 BACKPORT: userfaultfd: add UFFD_USER_MODE_ONLY
Patch series "Control over userfaultfd kernel-fault handling", v6.

This patch series is split from [1].  The other series enables SELinux
support for userfaultfd file descriptors so that its creation and movement
can be controlled.

It has been demonstrated on various occasions that suspending kernel code
execution for an arbitrary amount of time at any access to userspace
memory (copy_from_user()/copy_to_user()/...) can be exploited to change
the intended behavior of the kernel.  For instance, handling page faults
in kernel-mode using userfaultfd has been exploited in [2, 3].  Likewise,
FUSE, which is similar to userfaultfd in this respect, has been exploited
in [4, 5] for similar outcome.

This small patch series adds a new flag to userfaultfd(2) that allows
callers to give up the ability to handle kernel-mode faults with the
resulting UFFD file object.  It then adds a 'user-mode only' option to the
unprivileged_userfaultfd sysctl knob to require unprivileged callers to
use this new flag.

The purpose of this new interface is to decrease the chance of an
unprivileged userfaultfd user taking advantage of userfaultfd to enhance
security vulnerabilities by lengthening the race window in kernel code.

[1] https://lore.kernel.org/lkml/20200211225547.235083-1-dancol@google.com/
[2] https://duasynt.com/blog/linux-kernel-heap-spray
[3] https://duasynt.com/blog/cve-2016-6187-heap-off-by-one-exploit
[4] https://googleprojectzero.blogspot.com/2016/06/exploiting-recursion-in-linux-kernel_20.html
[5] https://bugs.chromium.org/p/project-zero/issues/detail?id=808

This patch (of 2):

userfaultfd handles page faults from both user and kernel code.  Add a new
UFFD_USER_MODE_ONLY flag for userfaultfd(2) that makes the resulting
userfaultfd object refuse to handle faults from kernel mode, treating
these faults as if SIGBUS were always raised, causing the kernel code to
fail with EFAULT.

A future patch adds a knob allowing administrators to give some processes
the ability to create userfaultfd file objects only if they pass
UFFD_USER_MODE_ONLY, reducing the likelihood that these processes will
exploit userfaultfd's ability to delay kernel page faults to open timing
windows for future exploits.

Link: https://lkml.kernel.org/r/20201120030411.2690816-1-lokeshgidra@google.com
Link: https://lkml.kernel.org/r/20201120030411.2690816-2-lokeshgidra@google.com
Change-Id: I5c50a96f56c862cbbdb001acbe958c9f4c48023a
Signed-off-by: Daniel Colascione <dancol@google.com>
Signed-off-by: Lokesh Gidra <lokeshgidra@google.com>
Reviewed-by: Andrea Arcangeli <aarcange@redhat.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: <calin@google.com>
Cc: Daniel Colascione <dancol@dancol.org>
Cc: Eric Biggers <ebiggers@kernel.org>
Cc: Iurii Zaikin <yzaikin@google.com>
Cc: Jeff Vander Stoep <jeffv@google.com>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: "Joel Fernandes (Google)" <joel@joelfernandes.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Kalesh Singh <kaleshsingh@google.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
Cc: Nitin Gupta <nigupta@nvidia.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Shaohua Li <shli@fb.com>
Cc: Stephen Smalley <stephen.smalley.work@gmail.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2025-08-24 00:16:09 +07:00
Chung-Hsien Hsu
10b2c75769 nl80211: add WPA3 definition for SAE authentication
Add definition of WPA version 3 for SAE authentication.

Change-Id: I19ca34b8965168f011cc1352eba420f2d54b0258
Signed-off-by: Chung-Hsien Hsu <stanley.hsu@cypress.com>
Signed-off-by: Chi-Hsien Lin <chi-hsien.lin@cypress.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
2025-01-01 18:44:51 -05:00
John Galt
7e6c46b254 bpf: squash revert spoofing and some backports:
Squashed commit of the following:

commit 8ac5df9c8bc9575059fff6cea0c40463b96fc129
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:58:17 2024 -0500

    Revert "BACKPORT: bpf: add skb_load_bytes_relative helper"

    This reverts commit 029893dcc5d67af16fdf0723bacaae37ec567f67.

commit dbcbceafe848744ec188f74e87e9717916d359ea
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:58:13 2024 -0500

    Revert "BACKPORT: bpf: encapsulate verifier log state into a structure"

    This reverts commit d861145b97d247cbd9fe1400df52155f48639126.

commit 478f4dfee0406b54525e68764cc9ba48af1624fc
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:58:10 2024 -0500

    Revert "BACKPORT: bpf: Rename bpf_verifer_log"

    This reverts commit 5d088635de1bf2d6ae9ea94e3dd1c601d30c0cce.

commit 7bc7c24beb82168b49337530cb56b5dfeeafe19a
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:58:07 2024 -0500

    Revert "BACKPORT: bpf: btf: Introduce BPF Type Format (BTF)"

    This reverts commit 93d34e26514b4d9d15fd176706f57634b2e97485.

commit 7106457ba90a459b6241fdd44df658c1b52c0e4b
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:58:03 2024 -0500

    Revert "bpf: Update logging functions to work with BTF"

    This reverts commit 97e6c528eb2f76c58a3b6a4c1e7fbeafcd97633a.

commit 08e68c7ba56f5e78fd1afcd5a2164716a75b0fe3
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:58:00 2024 -0500

    Revert "bpf: btf: Validate type reference"

    This reverts commit c7b7eecbc1134e5d8865af2cc0692fc7156175d5.

commit 7763cf0831970a64ed62f9b7362fca02ab6e83f1
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:57:51 2024 -0500

    Revert "bpf: btf: Check members of struct/union"

    This reverts commit 9a77b51cad6f04866ca067ca0e70a89b9f59ed56.

commit eb033235f666b5f66995f4cf89702de7ab4721f8
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:57:47 2024 -0500

    Revert "bpf: btf: Add pretty print capability for data with BTF type info"

    This reverts commit 745692103435221d6e39bc177811769995540525.

commit c32995674ace91e06c591d2f63177585e81adc75
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:57:43 2024 -0500

    Revert "BACKPORT: bpf: btf: Add BPF_BTF_LOAD command"

    This reverts commit 4e0afd38e20e5aa2df444361309bc07251ca6b2a.

commit 1310bc8d4aca0015c8723e7624121eddf76b3244
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:57:38 2024 -0500

    Revert "bpf: btf: Add BPF_OBJ_GET_INFO_BY_FD support to BTF fd"

    This reverts commit d4b5d76d9101b97e6fe5181bcefe7f601ed19926.

commit 881a49445608712bdb0a0f0c959838bdbc725f62
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:57:34 2024 -0500

    Revert "BACKPORT: bpf: btf: Clean up btf.h in uapi"

    This reverts commit 26b661822933d41b3feb59bb284334bfbbc82af4.

commit e2109fd858ebd5fe392c8bf579b9350fbca35a35
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:57:29 2024 -0500

    Revert "bpf: btf: Avoid WARN_ON when CONFIG_REFCOUNT_FULL=y"

    This reverts commit 9abf878903404e649fef4ad0b189eec1c13d29fe.

commit 088a7d9137f03da4e0fc1d72add3901823081ccd
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:57:23 2024 -0500

    Revert "bpf: Fix compiler warning on info.map_ids for 32bit platform"

    This reverts commit a3a278e1f6cf167d538ac52f4ad60bb9cf8d4129.

commit 6e14aed6b63f2b266982454d83678445c062cf39
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:57:13 2024 -0500

    Revert "bpf: btf: Change how section is supported in btf_header"

    This reverts commit 4b60ffd683eb623a184b46761777838d7c49e707.

commit 151a60855c23bf0317734031481d779efb369d6c
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:57:08 2024 -0500

    Revert "bpf: btf: Check array->index_type"

    This reverts commit b00e10f1a073fadce178b6fb62496722e16db303.

commit 49775e9074a54ac5f60f518e6fc5a26172996eae
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:57:01 2024 -0500

    Revert "bpf: btf: Remove unused bits from uapi/linux/btf.h"

    This reverts commit c90c6ad34f7a8f565f351d21c2d5b9706838767d.

commit b6d6c6ab28e4b018da6ce9e64125e63f4191d3d9
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:56:58 2024 -0500

    Revert "bpf: btf: Avoid variable length array"

    This reverts commit fe7d1f7750242e77a73839d173ac36c3e39d4171.

commit a45bedecb9b1175fef96f2d64fba2d61777dbf35
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:56:49 2024 -0500

    Revert "bpf: btf: avoid -Wreturn-type warning"

    This reverts commit 78214f1e390bf1d69d9ae4ee80072ac85c34619e.

commit 445efb8465b9fa5706d81098417f15656265322e
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:56:46 2024 -0500

    Revert "bpf: btf: Check array t->size"

    This reverts commit aed532e7466f77885a362e4b863bf90c41e834ba.

commit 8aada590d525de735cf39196d88722e727c141e9
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:56:42 2024 -0500

    Revert "bpf: btf: Ensure t->type == 0 for BTF_KIND_FWD"

    This reverts commit 8c8b601dcc2e62e1276b73dfee8b49e40fb65944.

commit ed67ad09e866c9c30897488088bbb4555ea3dc80
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:56:38 2024 -0500

    Revert "bpf: btf: Fix bitfield extraction for big endian"

    This reverts commit b0696a226c52868d64963f01665dd1a640a92f2b.

commit 5cc64db782daf86cdf7ac77133ca94181bb29146
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:56:35 2024 -0500

    Revert "bpf: btf: Clean up BTF_INT_BITS() in uapi btf.h"

    This reverts commit 0f008594540b09c667ea88fc87cf289b8db334da.

commit 3a5c6b9010426449c08ecdcc10e758431b1e515f
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:56:31 2024 -0500

    Revert "bpf: btf: Ensure the member->offset is in the right order"

    This reverts commit c5e361ecd6d45a7cdbffda02e4691a7a37198bdd.

commit bd6173c1ac458b08d6cedaf06e6e53c93e6b0cc5
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:56:26 2024 -0500

    Revert "bpf: fix bpf_skb_load_bytes_relative pkt length check"

    This reverts commit 9ea14969874cd7896588df435c890f6f2f547821.

commit 0b61d26b25a65d9ded4611426c6da9c78e41567c
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:56:22 2024 -0500

    Revert "bpf: btf: Fix end boundary calculation for type section"

    This reverts commit 08ef221c7fb604cb60c490fa999ec7254d492f05.

commit 72fb2b9bb5b90f60ab71915fe4e57eeee3308163
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:56:18 2024 -0500

    Revert "bpf: btf: Fix a missing check bug"

    This reverts commit 594687e3e01e26086f3b0173e5eda9b9f0b672f8.

commit 575a34ceba4013ad0230038f29f6ea0b3ba41a7e
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:56:15 2024 -0500

    Revert "bpf, btf: fix a missing check bug in btf_parse"

    This reverts commit 6bf31bbc438663756e92fb0aad4f5a35fd730fb0.

commit bcca98c0bc5e19b38af3ddcd0feee80ad26e1f96
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:56:11 2024 -0500

    Revert "bpf: fix BTF limits"

    This reverts commit e351b26ae671dfacd82f27c1c5f66cf8089d930d.

commit f71c484e340041d8828c94b39a233ea587d8cc09
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:56:07 2024 -0500

    Revert "bpf/btf: Fix BTF verification of enum members in struct/union"

    This reverts commit 861e65b744c171d59850e61a01715f194f25e45c.

commit eca310722a2624d33cd49884aa18c36d435b10f8
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:56:02 2024 -0500

    Revert "bpf: btf: fix truncated last_member_type_id in btf_struct_resolve"

    This reverts commit d6cd1eac41b10e606ec7f445162a0617c01be973.

commit caae5c99a3ca7bed0e318b31b6aa7ca8260a1c52
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:55:58 2024 -0500

    Revert "BACKPORT: net: bpf: rename ndo_xdp to ndo_bpf"

    This reverts commit 2a1ddcb6a384745195d57b4e4cdda2a55d2cbe47.

commit f90bdcdaa095a4f10268bb740470a3e0893be21b
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:55:54 2024 -0500

    Revert "BACKPORT: bpf: offload: add infrastructure for loading programs for a specific netdev"

    This reverts commit a9516d402726094eafccce26a99cf5110d188be9.

commit c6e0ce9019c06d9a45c030a2bc38eed320afd45a
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:55:50 2024 -0500

    Revert "bpf: offload: rename the ifindex field"

    This reverts commit 36bc9c7351a1dc78b3e71571998af381e876b4cb.

commit 88b6a4d41b69df804b846a8ebdca410517e08343
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:55:46 2024 -0500

    Revert "BACKPORT: bpf: Check attach type at prog load time"

    This reverts commit fe5a0d514e4970d86983458136d4a2f6caeee365.

commit 9ccfaa66a5ea042331f0aacdb3667e23c8ed363e
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:55:43 2024 -0500

    Revert "BACKPORT: bpf: introduce BPF_PROG_QUERY command"

    This reverts commit a5720688858170f1054f9549b5a628db1c252a88.

commit adab2743b3fa0853d0351b33b0a286de745025e5
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:55:37 2024 -0500

    Revert "BACKPORT: bpf: Hooks for sys_bind"

    This reverts commit e484887c7e7aa026521ddc1773233368a6304b24.

commit d462e09db98ad89b3a836f9b9a925812b0d8cfe7
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:55:33 2024 -0500

    Revert "BACKPORT: net: Introduce __inet_bind() and __inet6_bind"

    This reverts commit 41a3131c3e94c28fd084dd6f4358baee3824fd17.

commit cdf7f55dc65b4bdf7ecfc924be77c6a039709b3d
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:55:29 2024 -0500

    Revert "BACKPORT: bpf: Hooks for sys_connect"

    This reverts commit f26fe7233e2885ef489707ab5a5a5dda9f081b80.

commit 97685d5058f76ba4ea6dd2db157f4537f3a8953d
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:55:23 2024 -0500

    Revert "BACKPORT: bpf: Post-hooks for sys_bind"

    This reverts commit 284ac5bc7c70dac338301445e94e1ad40fb40fdb.

commit d03d9c05036d3109eae643f473cc5a5ad0a80721
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:55:19 2024 -0500

    Revert "kernel: bpf: devmap: Create __dev_map_alloc_node"

    This reverts commit db726149fa9abfd1ca9add3e2db6b1524f7e90a3.

commit 8c34bcb3e4c6630799764871b4af2e5f9344a371
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:55:15 2024 -0500

    Revert "BACKPORT: xdp: Add devmap_hash map type for looking up devices by hashed index"

    This reverts commit c4d4e1d201d8433e06b2ac66041d7105095a0204.

commit ef277c7b3a08fd59943eb2b47af64afc513de008
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:55:11 2024 -0500

    Revert "BACKPORT: devmap: Allow map lookups from eBPF"

    This reverts commit 24d196375871c72de0de977de79afede5a7d1780.

commit 4fcd87869c55c28ed59bff916d640147601816d2
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:55:07 2024 -0500

    Revert "gen_headers_{arm, arm64}: Add btf.h to the list"

    This reverts commit 37edfe7c90bac355885ffec3327b338a34619792.

commit b89560e0b405b58ecc5fc12c15ad4f56147760d6
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:55:03 2024 -0500

    Revert "syscall: Fake uname to 4.19 for bpfloader/netd"

    This reverts commit 186e74af61269602d0c068d98928b1f25e03eba2.

commit fd49f8c35eb7875d6810a5a52877ebc59bfd4530
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:54:59 2024 -0500

    Revert "syscall: Fake uname to 4.19 also for netbpfload"

    This reverts commit 34b9a1ab387d7dc83ede613b2c12b3741ea08edb.

commit b853fcf2ff892664d0ff522ca7fd530bc94c023e
Author: John Galt <johngaltfirstrun@gmail.com>
Date:   Fri Dec 13 07:54:53 2024 -0500

    Revert "syscall: Increase bpf fake uname to 5.4"

    This reverts commit 9cdc014e11b410a7f03d8c968a35ee0dd6a28fff.
2025-01-01 18:14:02 -05:00
balgxmr
bb43b90fab Merge branch 'linux-4.14.y' of https://github.com/openela/kernel-lts into fourteen 2024-10-12 20:06:00 -05:00
Paolo Pisati
1ac49c559c m68k: amiga: Turn off Warp1260 interrupts during boot
commit 1d8491d3e726984343dd8c3cdbe2f2b47cfdd928 upstream.

On an Amiga 1200 equipped with a Warp1260 accelerator, an interrupt
storm coming from the accelerator board causes the machine to crash in
local_irq_enable() or auto_irq_enable().  Disabling interrupts for the
Warp1260 in amiga_parse_bootinfo() fixes the problem.

Link: https://lore.kernel.org/r/ZkjwzVwYeQtyAPrL@amaterasu.local
Cc: stable <stable@kernel.org>
Signed-off-by: Paolo Pisati <p.pisati@gmail.com>
Reviewed-by: Michael Schmitz <schmitzmic@gmail.com>
Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
Link: https://lore.kernel.org/r/20240601153254.186225-1-p.pisati@gmail.com
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 296185ef87e6184e364bd9e7c983089b8e606a55)
Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
2024-10-10 10:27:23 +00:00
John Galt
8007673cc8 include/uapi/usb/video: drop uvc-new structs 2024-08-13 15:19:24 -05:00
Yumi Yukimura
bb6386976e usb: gadget: function: Import uvc from android13-5.10
* Taken as of HEAD 8b3b0f2a448982699cfd8f529e86d474a58c8214
  ("ANDROID: Pixel: Add missing symbol to symbol list")

* Place it in a subfolder, to avoid conflicts when merging upstream

Change-Id: If00e90a06ec5b234c9eb4032d6b6fa5c98fb6055
2024-08-13 15:19:23 -05:00
balgxmr
0fb6d25210 Merge branch 'linux-4.14.y' of https://github.com/openela/kernel-lts into fourteen 2024-08-09 14:23:24 -05:00
Matthias Goergens
bee6efedbf hugetlb_encode.h: fix undefined behaviour (34 << 26)
commit 710bb68c2e3a24512e2d2bae470960d7488e97b1 upstream.

Left-shifting past the size of your datatype is undefined behaviour in C.
The literal 34 gets the type `int`, and that one is not big enough to be
left shifted by 26 bits.

An `unsigned` is long enough (on any machine that has at least 32 bits for
their ints.)

For uniformity, we mark all the literals as unsigned.  But it's only
really needed for HUGETLB_FLAG_ENCODE_16GB.

Thanks to Randy Dunlap for an initial review and suggestion.

Link: https://lkml.kernel.org/r/20220905031904.150925-1-matthias.goergens@gmail.com
Signed-off-by: Matthias Goergens <matthias.goergens@gmail.com>
Acked-by: Randy Dunlap <rdunlap@infradead.org>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Muchun Song <songmuchun@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
[cmllamas: fix trivial conflict due to missing page encondigs]
Signed-off-by: Carlos Llamas <cmllamas@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit a33d99c8b213d16ad61bc68cb17aad1e2f484192)
Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
2024-08-08 15:52:17 +00:00
Anshuman Khandual
06d15f1e6c mm/hugetlb: add mmap() encodings for 32MB and 512MB page sizes
ARM64 architecture also supports 32MB and 512MB HugeTLB page sizes.  This
just adds mmap() system call argument encoding for them.

Link: http://lkml.kernel.org/r/1537841300-6979-1-git-send-email-anshuman.khandual@arm.com
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
Acked-by: Punit Agrawal <punit.agrawal@arm.com>
Acked-by: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 20916d4636a9b3c1bf562b305f91d126771edaf9)
Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
2024-08-08 15:52:17 +00:00
balgxmr
a3e27025de Merge branch 'linux-4.14.y' of https://github.com/openela/kernel-lts into fourteen 2024-06-07 18:31:44 -05:00
Lukasz Pawelczyk
aaeb687490 netfilter: xt_owner: Add supplementary groups option
[ Upstream commit ea6cc2fd8a2b89ab6dcd096ba6dbc1ecbdf26564 ]

The XT_OWNER_SUPPL_GROUPS flag causes GIDs specified with XT_OWNER_GID
to be also checked in the supplementary groups of a process.

f_cred->group_info cannot be modified during its lifetime and f_cred
holds a reference to it so it's safe to use.

Signed-off-by: Lukasz Pawelczyk <l.pawelczyk@samsung.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Stable-dep-of: 7ae836a3d630 ("netfilter: xt_owner: Fix for unsafe access of sk->sk_socket")
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
2024-05-06 14:36:42 +00:00
Toke Høiland-Jørgensen
60d8ed2059 BACKPORT: devmap: Allow map lookups from eBPF
We don't currently allow lookups into a devmap from eBPF, because the map
lookup returns a pointer directly to the dev->ifindex, which shouldn't be
modifiable from eBPF.

However, being able to do lookups in devmaps is useful to know (e.g.)
whether forwarding to a specific interface is enabled. Currently, programs
work around this by keeping a shadow map of another type which indicates
whether a map index is valid.

Since we now have a flag to make maps read-only from the eBPF side, we can
simply lift the lookup restriction if we make sure this flag is always set.

Change-Id: I42b1430605c6837710fd903a0c8abf2c7dc13f16
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
2024-03-29 20:47:39 -05:00
Toke Høiland-Jørgensen
ea91631118 BACKPORT: xdp: Add devmap_hash map type for looking up devices by hashed index
A common pattern when using xdp_redirect_map() is to create a device map
where the lookup key is simply ifindex. Because device maps are arrays,
this leaves holes in the map, and the map has to be sized to fit the
largest ifindex, regardless of how many devices actually are actually
needed in the map.

This patch adds a second type of device map where the key is looked up
using a hashmap, instead of being used as an array index. This allows maps
to be densely packed, so they can be smaller.

Change-Id: I6155de499a47fb45bac1a39319f0ad979032fd6d
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Acked-by: Yonghong Song <yhs@fb.com>
Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
2024-03-29 20:47:18 -05:00
Andrey Ignatov
760bd1980b BACKPORT: bpf: Post-hooks for sys_bind
"Post-hooks" are hooks that are called right before returning from
sys_bind. At this time IP and port are already allocated and no further
changes to `struct sock` can happen before returning from sys_bind but
BPF program has a chance to inspect the socket and change sys_bind
result.

Specifically it can e.g. inspect what port was allocated and if it
doesn't satisfy some policy, BPF program can force sys_bind to fail and
return EPERM to user.

Another example of usage is recording the IP:port pair to some map to
use it in later calls to sys_connect. E.g. if some TCP server inside
cgroup was bound to some IP:port_n, it can be recorded to a map. And
later when some TCP client inside same cgroup is trying to connect to
127.0.0.1:port_n, BPF hook for sys_connect can override the destination
and connect application to IP:port_n instead of 127.0.0.1:port_n. That
helps forcing all applications inside a cgroup to use desired IP and not
break those applications if they e.g. use localhost to communicate
between each other.

== Implementation details ==

Post-hooks are implemented as two new attach types
`BPF_CGROUP_INET4_POST_BIND` and `BPF_CGROUP_INET6_POST_BIND` for
existing prog type `BPF_PROG_TYPE_CGROUP_SOCK`.

Separate attach types for IPv4 and IPv6 are introduced to avoid access
to IPv6 field in `struct sock` from `inet_bind()` and to IPv4 field from
`inet6_bind()` since those fields might not make sense in such cases.

Change-Id: Ibef21eed069c37684321b2401e5bb52f689ab8e7
Signed-off-by: Andrey Ignatov <rdna@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
2024-03-29 20:47:11 -05:00
Andrey Ignatov
a91b401218 BACKPORT: bpf: Hooks for sys_connect
== The problem ==

See description of the problem in the initial patch of this patch set.

== The solution ==

The patch provides much more reliable in-kernel solution for the 2nd
part of the problem: making outgoing connecttion from desired IP.

It adds new attach types `BPF_CGROUP_INET4_CONNECT` and
`BPF_CGROUP_INET6_CONNECT` for program type
`BPF_PROG_TYPE_CGROUP_SOCK_ADDR` that can be used to override both
source and destination of a connection at connect(2) time.

Local end of connection can be bound to desired IP using newly
introduced BPF-helper `bpf_bind()`. It allows to bind to only IP though,
and doesn't support binding to port, i.e. leverages
`IP_BIND_ADDRESS_NO_PORT` socket option. There are two reasons for this:
* looking for a free port is expensive and can affect performance
  significantly;
* there is no use-case for port.

As for remote end (`struct sockaddr *` passed by user), both parts of it
can be overridden, remote IP and remote port. It's useful if an
application inside cgroup wants to connect to another application inside
same cgroup or to itself, but knows nothing about IP assigned to the
cgroup.

Support is added for IPv4 and IPv6, for TCP and UDP.

IPv4 and IPv6 have separate attach types for same reason as sys_bind
hooks, i.e. to prevent reading from / writing to e.g. user_ip6 fields
when user passes sockaddr_in since it'd be out-of-bound.

== Implementation notes ==

The patch introduces new field in `struct proto`: `pre_connect` that is
a pointer to a function with same signature as `connect` but is called
before it. The reason is in some cases BPF hooks should be called way
before control is passed to `sk->sk_prot->connect`. Specifically
`inet_dgram_connect` autobinds socket before calling
`sk->sk_prot->connect` and there is no way to call `bpf_bind()` from
hooks from e.g. `ip4_datagram_connect` or `ip6_datagram_connect` since
it'd cause double-bind. On the other hand `proto.pre_connect` provides a
flexible way to add BPF hooks for connect only for necessary `proto` and
call them at desired time before `connect`. Since `bpf_bind()` is
allowed to bind only to IP and autobind in `inet_dgram_connect` binds
only port there is no chance of double-bind.

bpf_bind() sets `force_bind_address_no_port` to bind to only IP despite
of value of `bind_address_no_port` socket field.

bpf_bind() sets `with_lock` to `false` when calling to __inet_bind()
and __inet6_bind() since all call-sites, where bpf_bind() is called,
already hold socket lock.

Change-Id: I03eb513369c630b203466621d1fbdb9b29c8333c
Signed-off-by: Andrey Ignatov <rdna@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
2024-03-29 20:47:10 -05:00
Andrey Ignatov
90533685ef BACKPORT: bpf: Hooks for sys_bind
== The problem ==

There is a use-case when all processes inside a cgroup should use one
single IP address on a host that has multiple IP configured.  Those
processes should use the IP for both ingress and egress, for TCP and UDP
traffic. So TCP/UDP servers should be bound to that IP to accept
incoming connections on it, and TCP/UDP clients should make outgoing
connections from that IP. It should not require changing application
code since it's often not possible.

Currently it's solved by intercepting glibc wrappers around syscalls
such as `bind(2)` and `connect(2)`. It's done by a shared library that
is preloaded for every process in a cgroup so that whenever TCP/UDP
server calls `bind(2)`, the library replaces IP in sockaddr before
passing arguments to syscall. When application calls `connect(2)` the
library transparently binds the local end of connection to that IP
(`bind(2)` with `IP_BIND_ADDRESS_NO_PORT` to avoid performance penalty).

Shared library approach is fragile though, e.g.:
* some applications clear env vars (incl. `LD_PRELOAD`);
* `/etc/ld.so.preload` doesn't help since some applications are linked
  with option `-z nodefaultlib`;
* other applications don't use glibc and there is nothing to intercept.

== The solution ==

The patch provides much more reliable in-kernel solution for the 1st
part of the problem: binding TCP/UDP servers on desired IP. It does not
depend on application environment and implementation details (whether
glibc is used or not).

It adds new eBPF program type `BPF_PROG_TYPE_CGROUP_SOCK_ADDR` and
attach types `BPF_CGROUP_INET4_BIND` and `BPF_CGROUP_INET6_BIND`
(similar to already existing `BPF_CGROUP_INET_SOCK_CREATE`).

The new program type is intended to be used with sockets (`struct sock`)
in a cgroup and provided by user `struct sockaddr`. Pointers to both of
them are parts of the context passed to programs of newly added types.

The new attach types provides hooks in `bind(2)` system call for both
IPv4 and IPv6 so that one can write a program to override IP addresses
and ports user program tries to bind to and apply such a program for
whole cgroup.

== Implementation notes ==

[1]
Separate attach types for `AF_INET` and `AF_INET6` are added
intentionally to prevent reading/writing to offsets that don't make
sense for corresponding socket family. E.g. if user passes `sockaddr_in`
it doesn't make sense to read from / write to `user_ip6[]` context
fields.

[2]
The write access to `struct bpf_sock_addr_kern` is implemented using
special field as an additional "register".

There are just two registers in `sock_addr_convert_ctx_access`: `src`
with value to write and `dst` with pointer to context that can't be
changed not to break later instructions. But the fields, allowed to
write to, are not available directly and to access them address of
corresponding pointer has to be loaded first. To get additional register
the 1st not used by `src` and `dst` one is taken, its content is saved
to `bpf_sock_addr_kern.tmp_reg`, then the register is used to load
address of pointer field, and finally the register's content is restored
from the temporary field after writing `src` value.

Change-Id: I47b4cd565cb7cd3bcf3ecf80ddf2586ee81868fb
Signed-off-by: Andrey Ignatov <rdna@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
2024-03-29 20:47:10 -05:00
Alexei Starovoitov
ecf5f40d12 BACKPORT: bpf: introduce BPF_PROG_QUERY command
introduce BPF_PROG_QUERY command to retrieve a set of either
attached programs to given cgroup or a set of effective programs
that will execute for events within a cgroup

Change-Id: I05e0ed5f6eddc30f4a18216d4541448816fd1ae5
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
for cgroup bits
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
2024-03-29 20:47:10 -05:00
Andrey Ignatov
140bf99a1f BACKPORT: bpf: Check attach type at prog load time
== The problem ==

There are use-cases when a program of some type can be attached to
multiple attach points and those attach points must have different
permissions to access context or to call helpers.

E.g. context structure may have fields for both IPv4 and IPv6 but it
doesn't make sense to read from / write to IPv6 field when attach point
is somewhere in IPv4 stack.

Same applies to BPF-helpers: it may make sense to call some helper from
some attach point, but not from other for same prog type.

== The solution ==

Introduce `expected_attach_type` field in in `struct bpf_attr` for
`BPF_PROG_LOAD` command. If scenario described in "The problem" section
is the case for some prog type, the field will be checked twice:

1) At load time prog type is checked to see if attach type for it must
   be known to validate program permissions correctly. Prog will be
   rejected with EINVAL if it's the case and `expected_attach_type` is
   not specified or has invalid value.

2) At attach time `attach_type` is compared with `expected_attach_type`,
   if prog type requires to have one, and, if they differ, attach will
   be rejected with EINVAL.

The `expected_attach_type` is now available as part of `struct bpf_prog`
in both `bpf_verifier_ops->is_valid_access()` and
`bpf_verifier_ops->get_func_proto()` () and can be used to check context
accesses and calls to helpers correspondingly.

Initially the idea was discussed by Alexei Starovoitov <ast@fb.com> and
Daniel Borkmann <daniel@iogearbox.net> here:
https://marc.info/?l=linux-netdev&m=152107378717201&w=2

Change-Id: Idead9c9cb4251bf5bd843b68bcb83072d5746226
Signed-off-by: Andrey Ignatov <rdna@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
2024-03-29 20:47:10 -05:00
Jakub Kicinski
9d28c6d8c9 bpf: offload: rename the ifindex field
bpf_target_prog seems long and clunky, rename it to prog_ifindex.
We don't want to call this field just ifindex, because maps
may need a similar field in the future and bpf_attr members for
programs and maps are unnamed.

Change-Id: I5473ea6721193bcf616ac3a1056c808446af9c8d
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
2024-03-29 20:47:10 -05:00
Jakub Kicinski
bada3d2e21 BACKPORT: bpf: offload: add infrastructure for loading programs for a specific netdev
The fact that we don't know which device the program is going
to be used on is quite limiting in current eBPF infrastructure.
We have to reverse or limit the changes which kernel makes to
the loaded bytecode if we want it to be offloaded to a networking
device.  We also have to invent new APIs for debugging and
troubleshooting support.

Make it possible to load programs for a specific netdev.  This
helps us to bring the debug information closer to the core
eBPF infrastructure (e.g. we will be able to reuse the verifer
log in device JIT).  It allows device JITs to perform translation
on the original bytecode.

__bpf_prog_get() when called to get a reference for an attachment
point will now refuse to give it if program has a device assigned.
Following patches will add a version of that function which passes
the expected netdev in. @type argument in __bpf_prog_get() is
renamed to attach_type to make it clearer that it's only set on
attachment.

All calls to ndo_bpf are protected by rtnl, only verifier callbacks
are not.  We need a wait queue to make sure netdev doesn't get
destroyed while verifier is still running and calling its driver.

Change-Id: Iba7b96574abc005ad3351d6db2528eb534e47561
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Simon Horman <simon.horman@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
2024-03-29 20:47:10 -05:00
Alexei Starovoitov
f09a67e582 bpf: fix BTF limits
[ Upstream commit a0791f0df7d212c245761538b17a9ea93607b667 ]

vmlinux BTF has more than 64k types.
Its string section is also at the offset larger than 64k.
Adjust both limits to make in-kernel BTF verifier successfully parse in-kernel BTF.

Fixes: 69b693f0aefa ("bpf: btf: Introduce BPF Type Format (BTF)")
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
2024-03-29 20:47:09 -05:00
Martin KaFai Lau
0c5fb6c25b bpf: btf: Clean up BTF_INT_BITS() in uapi btf.h
This patch shrinks the BTF_INT_BITS() mask.  The current
btf_int_check_meta() ensures the nr_bits of an integer
cannot exceed 64.  Hence, it is mostly an uapi cleanup.

The actual btf usage (i.e. seq_show()) is also modified
to use u8 instead of u16.  The verification (e.g. btf_int_check_meta())
path stays as is to deal with invalid BTF situation.

Fixes: 69b693f0aefa ("bpf: btf: Introduce BPF Type Format (BTF)")
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
2024-03-29 20:47:09 -05:00
Martin KaFai Lau
8ab7d84711 bpf: btf: Remove unused bits from uapi/linux/btf.h
This patch does the followings:
1. Limit BTF_MAX_TYPES and BTF_MAX_NAME_OFFSET to 64k.  We can
   raise it later.

2. Remove the BTF_TYPE_PARENT and BTF_STR_TBL_ELF_ID.  They are
   currently encoded at the highest bit of a u32.
   It is because the current use case does not require supporting
   parent type (i.e type_id referring to a type in another BTF file).
   It also does not support referring to a string in ELF.

   The BTF_TYPE_PARENT and BTF_STR_TBL_ELF_ID checks are replaced
   by BTF_TYPE_ID_CHECK and BTF_STR_OFFSET_CHECK which are
   defined in btf.c instead of uapi/linux/btf.h.

3. Limit the BTF_INFO_KIND from 5 bits to 4 bits which is enough.
   There is unused bits headroom if we ever needed it later.

4. The root bit in BTF_INFO is also removed because it is not
   used in the current use case.

5. Remove BTF_INT_VARARGS since func type is not supported now.
   The BTF_INT_ENCODING is limited to 4 bits instead of 8 bits.

The above can be added back later because the verifier
ensures the unused bits are zeros.

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
2024-03-29 20:47:08 -05:00
Martin KaFai Lau
f987bdbadc bpf: btf: Change how section is supported in btf_header
There are currently unused section descriptions in the btf_header.  Those
sections are here to support future BTF use cases.  For example, the
func section (func_off) is to support function signature (e.g. the BPF
prog function signature).

Instead of spelling out all potential sections up-front in the btf_header.
This patch makes changes to btf_header such that extending it (e.g. adding
a section) is possible later.  The unused ones can be removed for now and
they can be added back later.

This patch:
1. adds a hdr_len to the btf_header.  It will allow adding
sections (and other info like parent_label and parent_name)
later.  The check is similar to the existing bpf_attr.
If a user passes in a longer hdr_len, the kernel
ensures the extra tailing bytes are 0.

2. allows the section order in the BTF object to be
different from its sec_off order in btf_header.

3. each sec_off is followed by a sec_len.  It must not have gap or
overlapping among sections.

The string section is ensured to be at the end due to the 4 bytes
alignment requirement of the type section.

The above changes will allow enough flexibility to
add new sections (and other info) to the btf_header later.

This patch also removes an unnecessary !err check
at the end of btf_parse().

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
2024-03-29 20:47:08 -05:00
Martin KaFai Lau
55fd1e0672 BACKPORT: bpf: btf: Clean up btf.h in uapi
This patch cleans up btf.h in uapi:
1) Rename "name" to "name_off" to better reflect it is an offset to the
   string section instead of a char array.
2) Remove unused value BTF_FLAGS_COMPR and BTF_MAGIC_SWAP

Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
Change-Id: I480706c7a099a26b52b050f1e51e3408eabfed20
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
2024-03-29 20:47:08 -05:00
Martin KaFai Lau
1269666cd4 BACKPORT: bpf: btf: Add BPF_BTF_LOAD command
This patch adds a BPF_BTF_LOAD command which
1) loads and verifies the BTF (implemented in earlier patches)
2) returns a BTF fd to userspace.  In the next patch, the
   BTF fd can be specified during BPF_MAP_CREATE.

It currently limits to CAP_SYS_ADMIN.

Change-Id: Id826446740838918cc317c75d0ccb6038842e933
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Alexei Starovoitov <ast@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
2024-03-29 20:47:08 -05:00
Martin KaFai Lau
1e85e9cd95 BACKPORT: bpf: btf: Introduce BPF Type Format (BTF)
This patch introduces BPF type Format (BTF).

BTF (BPF Type Format) is the meta data format which describes
the data types of BPF program/map.  Hence, it basically focus
on the C programming language which the modern BPF is primary
using.  The first use case is to provide a generic pretty print
capability for a BPF map.

BTF has its root from CTF (Compact C-Type format).  To simplify
the handling of BTF data, BTF removes the differences between
small and big type/struct-member.  Hence, BTF consistently uses u32
instead of supporting both "one u16" and "two u32 (+padding)" in
describing type and struct-member.

It also raises the number of types (and functions) limit
from 0x7fff to 0x7fffffff.

Due to the above changes,  the format is not compatible to CTF.
Hence, BTF starts with a new BTF_MAGIC and version number.

This patch does the first verification pass to the BTF.  The first
pass checks:
1. meta-data size (e.g. It does not go beyond the total btf's size)
2. name_offset is valid
3. Each BTF_KIND (e.g. int, enum, struct....) does its
   own check of its meta-data.

Some other checks, like checking a struct's member is referring
to a valid type, can only be done in the second pass.  The second
verification pass will be implemented in the next patch.

Change-Id: Ic3a57709c16c02059438f5b1b85ccc94466f2db3
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Alexei Starovoitov <ast@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
2024-03-29 20:47:07 -05:00
Daniel Borkmann
dfe923e71f BACKPORT: bpf: add skb_load_bytes_relative helper
This adds a small BPF helper similar to bpf_skb_load_bytes() that
is able to load relative to mac/net header offset from the skb's
linear data. Compared to bpf_skb_load_bytes(), it takes a fifth
argument namely start_header, which is either BPF_HDR_START_MAC
or BPF_HDR_START_NET. This allows for a more flexible alternative
compared to LD_ABS/LD_IND with negative offset. It's enabled for
tc BPF programs as well as sock filter program types where it's
mainly useful in reuseport programs to ease access to lower header
data.

Reference: https://lists.iovisor.org/pipermail/iovisor-dev/2017-March/000698.html
Change-Id: I8edf5b01aa2cc08876fb579437816838339bf798
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
2024-03-29 20:46:37 -05:00
Martin KaFai Lau
aee61bff27 BACKPORT: bpf: Use char in prog and map name
Instead of u8, use char for prog and map name.  It can avoid the
userspace tool getting compiler's signess warning.  The
bpf_prog_aux, bpf_map, bpf_attr, bpf_prog_info and
bpf_map_info are changed.

Change-Id: I599a8f1eccb0d63aa8d680b771fff1580c69cf75
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Cc: Jakub Kicinski <jakub.kicinski@netronome.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@fb.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
2024-03-29 20:44:27 -05:00
Martin KaFai Lau
a969bdaac3 BACKPORT: bpf: Add map_name to bpf_map_info
This patch allows userspace to specify a name for a map
during BPF_MAP_CREATE.

The map's name can later be exported to user space
via BPF_OBJ_GET_INFO_BY_FD.

Change-Id: I96b8d74b09c14f2413d421bba61cfa63d1730bc3
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Alexei Starovoitov <ast@fb.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
2024-03-29 20:44:27 -05:00
Martin KaFai Lau
5b72a5869e BACKPORT: bpf: Add name, load_time, uid and map_ids to bpf_prog_info
The patch adds name and load_time to struct bpf_prog_aux.  They
are also exported to bpf_prog_info.

The bpf_prog's name is passed by userspace during BPF_PROG_LOAD.
The kernel only stores the first (BPF_PROG_NAME_LEN - 1) bytes
and the name stored in the kernel is always \0 terminated.

The kernel will reject name that contains characters other than
isalnum() and '_'.  It will also reject name that is not null
terminated.

The existing 'user->uid' of the bpf_prog_aux is also exported to
the bpf_prog_info as created_by_uid.

The existing 'used_maps' of the bpf_prog_aux is exported to
the newly added members 'nr_map_ids' and 'map_ids' of
the bpf_prog_info.  On the input, nr_map_ids tells how
big the userspace's map_ids buffer is.  On the output,
nr_map_ids tells the exact user_map_cnt and it will only
copy up to the userspace's map_ids buffer is allowed.

Change-Id: I85270047bd427a4f00259541a08868df62168959
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Alexei Starovoitov <ast@fb.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
2024-03-29 20:44:15 -05:00
balgxmr
19ed78a215 Merge branch 'linux-4.14.y' of https://github.com/openela/kernel-lts into fourteen 2024-03-29 20:27:56 -05:00
Pablo Neira Ayuso
a057d02cf8 netfilter: nft_compat: reject unused compat flag
[ Upstream commit 292781c3c5485ce33bd22b2ef1b2bed709b4d672 ]

Flag (1 << 0) is ignored is set, never used, reject it it with EINVAL
instead.

Fixes: 0ca743a559 ("netfilter: nf_tables: add compatibility layer for x_tables")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 56fb2bf4ab8c91a2e078553497b6c5b2f1dac699)
Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
2024-03-08 08:21:36 +00:00
Qu Wenruo
7b51f7d400 btrfs: defrag: reject unknown flags of btrfs_ioctl_defrag_range_args
commit 173431b274a9a54fc10b273b46e67f46bcf62d2e upstream.

Add extra sanity check for btrfs_ioctl_defrag_range_args::flags.

This is not really to enhance fuzzing tests, but as a preparation for
future expansion on btrfs_ioctl_defrag_range_args.

In the future we're going to add new members, allowing more fine tuning
for btrfs defrag.  Without the -ENONOTSUPP error, there would be no way
to detect if the kernel supports those new defrag features.

CC: stable@vger.kernel.org # 4.14+
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit f084057282bc5f45e5f50a4b226244a30666422d)
Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
2024-03-08 08:21:29 +00:00
balgxmr
6f806db393 Merge branch 'upstream-linux-4.14.y' of https://android.googlesource.com/kernel/common into fourteen 2023-11-08 10:28:18 -05:00
Pablo Neira Ayuso
c6fc37a301 gtp: uapi: fix GTPA_MAX
[ Upstream commit adc8df12d91a2b8350b0cd4c7fec3e8546c9d1f8 ]

Subtract one to __GTPA_MAX, otherwise GTPA_MAX is off by 2.

Fixes: 459aa660eb ("gtp: add initial driver for datapath of GPRS Tunneling Protocol (GTP-U)")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-08 11:21:06 +01:00
balgxmr
bc2672d1f9 Merge branch 'upstream-linux-4.14.y' of https://android.googlesource.com/kernel/common into rebaseee 2023-10-12 09:43:53 -05:00
Rob Clark
b5239cce0f dma-buf/sync_file: Fix docs syntax
[ Upstream commit 05d56d8079d510a2994039470f65bea85f0075ee ]

Fixes the warning:

  include/uapi/linux/sync_file.h:77: warning: Function parameter or member 'num_fences' not described in 'sync_file_info'

Fixes: 2d75c88fef ("staging/android: refactor SYNC IOCTLs")
Signed-off-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Randy Dunlap <rdunlap@infradead.org>
Link: https://lore.kernel.org/r/20230724145000.125880-1-robdclark@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-09-23 10:46:58 +02:00
balgxmr
4e32a36c52 Merge branch 'android-4.14-stable' of https://android.googlesource.com/kernel/common into rebase-chp 2023-08-11 14:27:33 -05:00
balgxmr
2aa4212b1a Merge branch 'upstream-linux-4.14.y' of https://android.googlesource.com/kernel/common into rebase-chp 2023-08-11 13:51:03 -05:00
Bart Van Assche
d554350f5b block: Fix a source code comment in include/uapi/linux/blkzoned.h
[ Upstream commit e0933b526fbfd937c4a8f4e35fcdd49f0e22d411 ]

Fix the symbolic names for zone conditions in the blkzoned.h header
file.

Cc: Hannes Reinecke <hare@suse.de>
Cc: Damien Le Moal <dlemoal@kernel.org>
Fixes: 6a0cb1bc10 ("block: Implement support for zoned block devices")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Link: https://lore.kernel.org/r/20230706201422.3987341-1-bvanassche@acm.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-08-11 11:33:51 +02:00
Marek Vasut
6839df85db media: videodev2.h: Fix struct v4l2_input tuner index comment
[ Upstream commit 26ae58f65e64fa7ba61d64bae752e59e08380c6a ]

VIDIOC_ENUMINPUT documentation describes the tuner field of
struct v4l2_input as index:

Documentation/userspace-api/media/v4l/vidioc-enuminput.rst
"
* - __u32
  - ``tuner``
  - Capture devices can have zero or more tuners (RF demodulators).
    When the ``type`` is set to ``V4L2_INPUT_TYPE_TUNER`` this is an
    RF connector and this field identifies the tuner. It corresponds
    to struct :c:type:`v4l2_tuner` field ``index``. For
    details on tuners see :ref:`tuner`.
"

Drivers I could find also use the 'tuner' field as an index, e.g.:
drivers/media/pci/bt8xx/bttv-driver.c bttv_enum_input()
drivers/media/usb/go7007/go7007-v4l2.c vidioc_enum_input()

However, the UAPI comment claims this field is 'enum v4l2_tuner_type':
include/uapi/linux/videodev2.h

This field being 'enum v4l2_tuner_type' is unlikely as it seems to be
never used that way in drivers, and documentation confirms it. It seem
this comment got in accidentally in the commit which this patch fixes.
Fix the UAPI comment to stop confusion.

This was pointed out by Dmitry while reviewing VIDIOC_ENUMINPUT
support for strace.

Fixes: 6016af82ea ("[media] v4l2: use __u32 rather than enums in ioctl() structs")
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-08-11 11:33:39 +02:00
Michael Schmitz
6c849cda76 block: change all __u32 annotations to __be32 in affs_hardblocks.h
commit 95a55437dc49fb3342c82e61f5472a71c63d9ed0 upstream.

The Amiga partition parser module uses signed int for partition sector
address and count, which will overflow for disks larger than 1 TB.

Use u64 as type for sector address and size to allow using disks up to
2 TB without LBD support, and disks larger than 2 TB with LBD. The RBD
format allows to specify disk sizes up to 2^128 bytes (though native
OS limitations reduce this somewhat, to max 2^68 bytes), so check for
u64 overflow carefully to protect against overflowing sector_t.

This bug was reported originally in 2012, and the fix was created by
the RDB author, Joanne Dow <jdow@earthlink.net>. A patch had been
discussed and reviewed on linux-m68k at that time but never officially
submitted (now resubmitted as patch 1 of this series).

Patch 3 (this series) adds additional error checking and warning
messages. One of the error checks now makes use of the previously
unused rdb_CylBlocks field, which causes a 'sparse' warning
(cast to restricted __be32).

Annotate all 32 bit fields in affs_hardblocks.h as __be32, as the
on-disk format of RDB and partition blocks is always big endian.

Reported-by: Martin Steigerwald <Martin@lichtvoll.de>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=43511
Fixes: 1da177e4c3 ("Linux-2.6.12-rc2")
Message-ID: <201206192146.09327.Martin@lichtvoll.de>
Cc: <stable@vger.kernel.org> # 5.2
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
Link: https://lore.kernel.org/r/20230620201725.7020-3-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-08-11 11:33:38 +02:00
Alessio Balsini
084b16d264 BACKPORT: ANDROID: fuse/passthrough: API V2 with __u32 open argument
The initial FUSE passthrough interface has the issue of introducing an
ioctl which receives as a parameter a data structure containing a
pointer. What happens is that, depending on the architecture, the size
of this struct might change, and especially for 32-bit userspace running
on 64-bit kernel, the size mismatch results into different a single
ioctl the behavior of which depends on the data that is passed (e.g.,
with an enum). This is just a poor ioctl design as mentioned by Arnd
Bergmann [1].

Introduce the new FUSE_PASSTHROUGH_OPEN ioctl which only gets the fd of
the lower file system, which is a fixed-size __u32, dropping the
confusing fuse_passthrough_out data structure.

[1] https://lore.kernel.org/lkml/CAK8P3a2K2FzPvqBYL9W=Yut58SFXyetXwU4Fz50G5O3TsS0pPQ@mail.gmail.com/

Bug: 175195837
Signed-off-by: Alessio Balsini <balsini@google.com>
Change-Id: I486d71cbe20f3c0c87544fa75da4e2704fe57c7c
[cyberknight777: backport to 4.14]
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
Signed-off-by: onettboots <blackcocopet@gmail.com>
2023-08-09 18:16:06 -05:00
Daeho Jeong
e494455484 f2fs: introduce F2FS_IOC_START_ATOMIC_REPLACE
introduce a new ioctl to replace the whole content of a file atomically,
which means it induces truncate and content update at the same time.
We can start it with F2FS_IOC_START_ATOMIC_REPLACE and complete it with
F2FS_IOC_COMMIT_ATOMIC_WRITE. Or abort it with
F2FS_IOC_ABORT_ATOMIC_WRITE.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-08-09 17:46:59 -05:00
balgxmr
06d0ea64ab Merge tag 'LA.UM.9.1.r1-13700-SMxxx0.QSSI13.0' of https://git.codelinaro.org/clo/la/kernel/msm-4.14 into rebase
"LA.UM.9.1.r1-13700-SMxxx0.QSSI13.0"
2023-08-09 17:00:20 -05:00
balgxmr
434f599332 Merge branch 'upstream-linux-4.14.y' of https://android.googlesource.com/kernel/common into rebase 2023-08-09 16:44:33 -05:00
Greg Kroah-Hartman
26537ae6e9 Merge 4.14.319 into android-4.14-stable
Changes in 4.14.319
	power: supply: ab8500: Fix external_power_changed race
	power: supply: bq27xxx: Use mod_delayed_work() instead of cancel() + schedule()
	ARM: dts: vexpress: add missing cache properties
	power: supply: Ratelimit no data debug output
	regulator: Fix error checking for debugfs_create_dir
	power: supply: Fix logic checking if system is running from battery
	MIPS: Alchemy: fix dbdma2
	mips: Move initrd_start check after initrd address sanitisation.
	xen/blkfront: Only check REQ_FUA for writes
	ocfs2: fix use-after-free when unmounting read-only filesystem
	ocfs2: check new file size on fallocate call
	nios2: dts: Fix tse_mac "max-frame-size" property
	nilfs2: fix incomplete buffer cleanup in nilfs_btnode_abort_change_key()
	nilfs2: fix possible out-of-bounds segment allocation in resize ioctl
	net: usb: qmi_wwan: add support for Compal RXM-G1
	Remove DECnet support from kernel
	USB: serial: option: add Quectel EM061KGL series
	netfilter: nfnetlink: skip error delivery on batch in case of ENOMEM
	ping6: Fix send to link-local addresses with VRF.
	IB/isert: Fix dead lock in ib_isert
	IB/isert: Fix possible list corruption in CMA handler
	IB/isert: Fix incorrect release of isert connection
	sctp: fix an error code in sctp_sf_eat_auth()
	igb: fix nvm.ops.read() error handling
	drm/nouveau/dp: check for NULL nv_connector->native_mode
	net: lapbether: only support ethernet devices
	net: tipc: resize nlattr array to correct size
	selftests/ptp: Fix timestamp printf format for PTP_SYS_OFFSET
	neighbour: Remove unused inline function neigh_key_eq16()
	neighbour: delete neigh_lookup_nodev as not used
	powerpc: Fix defconfig choice logic when cross compiling
	mmc: block: ensure error propagation for non-blk
	Linux 4.14.319

Change-Id: I86bdcfa1df827dd0feed2b0bb8957c23e8f8bd5d
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-06-21 16:19:38 +00:00