All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@kernel.org>
To: stable@vger.kernel.org
Cc: linux-mm@kvack.org, bpf@vger.kernel.org, x86@kernel.org,
	linux-kernel@vger.kernel.org,
	"Masami Hiramatsu" <mhiramat@kernel.org>,
	"Tsahee Zidenberg" <tsahee@annapurnalabs.com>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Christoph Hellwig" <hch@lst.de>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Mahé Tardy" <mahe.tardy@isovalent.com>,
	linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH stable 5.4 0/8] bpf: Fix bpf_probe_read/bpf_probe_read_str helpers
Date: Mon, 22 May 2023 22:33:44 +0200	[thread overview]
Message-ID: <20230522203352.738576-1-jolsa@kernel.org> (raw)

hi,
we see broken access to user space with bpf_probe_read/bpf_probe_read_str
helpers on arm64 with 5.4 kernel. The problem is that both helpers try to
read user memory by calling probe_kernel_read, which seems to work on x86
but fails on arm64.

There are several fixes after v5.4 to address this issue.

There was an attempt to fix that in past [1], but it deviated far from
upstream changes.

This patchset tries to follow the upstream changes with 2 notable exceptions:

   1) bpf: Add probe_read_{user, kernel} and probe_read_{user, kernel}_str helpers

      - this upsgream patch adds new helpers, which we don't need to do,
        we just need following functions (and related helper's glue):

          bpf_probe_read_kernel_common
          bpf_probe_read_kernel_str_common

        that implement bpf_probe_read* helpers and receive fix in next
        patch below, ommiting any other hunks

   2) bpf: rework the compat kernel probe handling

      - taking only fixes for functions and realted helper's glue that we took
        from patch above, ommiting any other hunks


It's possible to add new helpers and keep the patches closer to upstream,
but I thought trying this way first as RFC without adding any new helpers
into stable kernel, which might possibly end up later with additional fixes.

Also I'm sending this as RFC, because I might be missing some mm related
dependency change, that I'm not aware of.

We tested new kernel with our use case on arm64 and x86.

thanks,
jirka


[1] https://yhbt.net/lore/all/YHGMFzQlHomDtZYG@kroah.com/t/
---
Andrii Nakryiko (1):
      bpf: bpf_probe_read_kernel_str() has to return amount of data read on success

Christoph Hellwig (4):
      maccess: clarify kerneldoc comments
      maccess: rename strncpy_from_unsafe_user to strncpy_from_user_nofault
      maccess: rename strncpy_from_unsafe_strict to strncpy_from_kernel_nofault
      bpf: rework the compat kernel probe handling

Daniel Borkmann (3):
      uaccess: Add strict non-pagefault kernel-space read function
      bpf: Add probe_read_{user, kernel} and probe_read_{user, kernel}_str helpers
      bpf: Restrict bpf_probe_read{, str}() only to archs where they work

 arch/arm/Kconfig            |   1 +
 arch/arm64/Kconfig          |   1 +
 arch/x86/Kconfig            |   1 +
 arch/x86/mm/Makefile        |   2 +-
 arch/x86/mm/maccess.c       |  43 ++++++++++++++++++++++++++++++++++++++
 include/linux/uaccess.h     |   8 +++++--
 init/Kconfig                |   3 +++
 kernel/trace/bpf_trace.c    | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------------------
 kernel/trace/trace_kprobe.c |   2 +-
 mm/maccess.c                |  63 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 10 files changed, 207 insertions(+), 57 deletions(-)
 create mode 100644 arch/x86/mm/maccess.c

WARNING: multiple messages have this Message-ID (diff)
From: Jiri Olsa <jolsa@kernel.org>
To: stable@vger.kernel.org
Cc: linux-mm@kvack.org, bpf@vger.kernel.org, x86@kernel.org,
	linux-kernel@vger.kernel.org,
	"Masami Hiramatsu" <mhiramat@kernel.org>,
	"Tsahee Zidenberg" <tsahee@annapurnalabs.com>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Christoph Hellwig" <hch@lst.de>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Mahé Tardy" <mahe.tardy@isovalent.com>,
	linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH stable 5.4 0/8] bpf: Fix bpf_probe_read/bpf_probe_read_str helpers
Date: Mon, 22 May 2023 22:33:44 +0200	[thread overview]
Message-ID: <20230522203352.738576-1-jolsa@kernel.org> (raw)

hi,
we see broken access to user space with bpf_probe_read/bpf_probe_read_str
helpers on arm64 with 5.4 kernel. The problem is that both helpers try to
read user memory by calling probe_kernel_read, which seems to work on x86
but fails on arm64.

There are several fixes after v5.4 to address this issue.

There was an attempt to fix that in past [1], but it deviated far from
upstream changes.

This patchset tries to follow the upstream changes with 2 notable exceptions:

   1) bpf: Add probe_read_{user, kernel} and probe_read_{user, kernel}_str helpers

      - this upsgream patch adds new helpers, which we don't need to do,
        we just need following functions (and related helper's glue):

          bpf_probe_read_kernel_common
          bpf_probe_read_kernel_str_common

        that implement bpf_probe_read* helpers and receive fix in next
        patch below, ommiting any other hunks

   2) bpf: rework the compat kernel probe handling

      - taking only fixes for functions and realted helper's glue that we took
        from patch above, ommiting any other hunks


It's possible to add new helpers and keep the patches closer to upstream,
but I thought trying this way first as RFC without adding any new helpers
into stable kernel, which might possibly end up later with additional fixes.

Also I'm sending this as RFC, because I might be missing some mm related
dependency change, that I'm not aware of.

We tested new kernel with our use case on arm64 and x86.

thanks,
jirka


[1] https://yhbt.net/lore/all/YHGMFzQlHomDtZYG@kroah.com/t/
---
Andrii Nakryiko (1):
      bpf: bpf_probe_read_kernel_str() has to return amount of data read on success

Christoph Hellwig (4):
      maccess: clarify kerneldoc comments
      maccess: rename strncpy_from_unsafe_user to strncpy_from_user_nofault
      maccess: rename strncpy_from_unsafe_strict to strncpy_from_kernel_nofault
      bpf: rework the compat kernel probe handling

Daniel Borkmann (3):
      uaccess: Add strict non-pagefault kernel-space read function
      bpf: Add probe_read_{user, kernel} and probe_read_{user, kernel}_str helpers
      bpf: Restrict bpf_probe_read{, str}() only to archs where they work

 arch/arm/Kconfig            |   1 +
 arch/arm64/Kconfig          |   1 +
 arch/x86/Kconfig            |   1 +
 arch/x86/mm/Makefile        |   2 +-
 arch/x86/mm/maccess.c       |  43 ++++++++++++++++++++++++++++++++++++++
 include/linux/uaccess.h     |   8 +++++--
 init/Kconfig                |   3 +++
 kernel/trace/bpf_trace.c    | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------------------
 kernel/trace/trace_kprobe.c |   2 +-
 mm/maccess.c                |  63 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 10 files changed, 207 insertions(+), 57 deletions(-)
 create mode 100644 arch/x86/mm/maccess.c

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

             reply	other threads:[~2023-05-22 20:34 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-22 20:33 Jiri Olsa [this message]
2023-05-22 20:33 ` [RFC PATCH stable 5.4 0/8] bpf: Fix bpf_probe_read/bpf_probe_read_str helpers Jiri Olsa
2023-05-22 20:33 ` [RFC PATCH stable 5.4 1/8] uaccess: Add strict non-pagefault kernel-space read function Jiri Olsa
2023-05-22 20:33   ` Jiri Olsa
2023-05-22 20:33 ` [RFC PATCH stable 5.4 2/8] bpf: Add probe_read_{user, kernel} and probe_read_{user, kernel}_str helpers Jiri Olsa
2023-05-22 20:33   ` Jiri Olsa
2023-05-22 20:33 ` [RFC PATCH stable 5.4 3/8] bpf: Restrict bpf_probe_read{, str}() only to archs where they work Jiri Olsa
2023-05-22 20:33   ` Jiri Olsa
2023-05-22 20:33 ` [RFC PATCH stable 5.4 4/8] maccess: clarify kerneldoc comments Jiri Olsa
2023-05-22 20:33   ` Jiri Olsa
2023-05-22 20:33 ` [RFC PATCH stable 5.4 5/8] maccess: rename strncpy_from_unsafe_user to strncpy_from_user_nofault Jiri Olsa
2023-05-22 20:33   ` Jiri Olsa
2023-05-22 20:33 ` [RFC PATCH stable 5.4 6/8] maccess: rename strncpy_from_unsafe_strict to strncpy_from_kernel_nofault Jiri Olsa
2023-05-22 20:33   ` Jiri Olsa
2023-05-22 20:33 ` [RFC PATCH stable 5.4 7/8] bpf: rework the compat kernel probe handling Jiri Olsa
2023-05-22 20:33   ` Jiri Olsa
2023-05-22 20:33 ` [RFC PATCH stable 5.4 8/8] bpf: bpf_probe_read_kernel_str() has to return amount of data read on success Jiri Olsa
2023-05-22 20:33   ` Jiri Olsa
2023-05-26 18:54 ` [RFC PATCH stable 5.4 0/8] bpf: Fix bpf_probe_read/bpf_probe_read_str helpers Greg KH
2023-05-26 18:54   ` Greg KH
2023-05-28 20:02   ` Jiri Olsa
2023-05-28 20:02     ` Jiri Olsa
2023-05-29  8:37     ` Greg KH
2023-05-29  8:37       ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230522203352.738576-1-jolsa@kernel.org \
    --to=jolsa@kernel.org \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=hch@lst.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mahe.tardy@isovalent.com \
    --cc=mhiramat@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tsahee@annapurnalabs.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.