Linux Trace Kernel
 help / color / mirror / Atom feed
From: Gabriele Monaco <gmonaco@redhat.com>
To: wen.yang@linux.dev
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v6 9/9] selftests/ftrace: Walk up to find test.d/functions when a subdirectory is passed
Date: Mon, 24 Aug 2026 12:08:25 +0200	[thread overview]
Message-ID: <f70d634ff65d6b1bd61c4ae517cf522881a23c61.camel@redhat.com> (raw)
In-Reply-To: <20260820165819.5CCC71F00A3A@smtp.kernel.org>

On Thu, 2026-08-20 at 16:58 +0000, sashiko-bot@kernel.org wrote:
> > +  if [ -n "$OPT_TEST_DIR" ]; then
> > +    # Walk up from OPT_TEST_DIR to find the nearest ancestor that contains
> > +    # test.d/functions.  This allows a monitor subdirectory (e.g.
> > +    # verification/test.d/tlob/) to be passed directly without placing a
> > +    # dummy functions shim in each new subdirectory.
> > +    # Security: only walk within directories owned by root or the current
> > user
> > +    # to prevent sourcing a functions file planted in a world-writable
> > ancestor.
> > +    dir=$(realpath "$OPT_TEST_DIR" 2>/dev/null || echo "$OPT_TEST_DIR")
> > +    while [ "$dir" != "/" ] && [ "$dir" != "//" ]; do
> > +      if [ -f "$dir/test.d/functions" ]; then
> > +        # Verify the directory is not world-writable to prevent LPE.
> > +        dirperms=$(stat -c "%a" "$dir" 2>/dev/null || stat -f "%Lp" "$dir"
> > 2>/dev/null)
> > +        case "$dirperms" in
> > +          *2|*3|*6|*7) ;; # world-writable: skip this candidate
> > +          *)
> > +            TOP_DIR=$dir
> 
> [Severity: High]
> Does this logic actually check directory ownership as mentioned in the
> comments?
> 
> It appears the code only checks if the directory is world-writable, but omits
> validating that it is owned by root or the current user. An attacker could
> potentially create a directory with standard 0755 permissions, plant a
> malicious test.d/functions script, and if a privileged user or automated test
> harness runs ftracetest against a subdirectory, the script would traverse up
> and source the payload.

I'm wondering if this is a broad example of root can shoot themselves in the
foot.
This is a selftest run by a root user, I believe they are responsible to
validate what's running isn't malicious.

I cannot picture a case where a path is commonly world writable here. I would
keep things simple and perhaps walk up at a maximum of 4-5 levels
(tools/testing/selftests/verification/test.d), to kinda make sure we never go
out of the repository.

You cannot really rely on git (may run from a tarball) or other static methods,
but I believe 4-5 levels up will cover us just fine.

In my opinion all this stat/dirperms thing is rarely useful, you could just
write the concern in a *brief* comment, saying we trust 4-5 level ups are still
in the repo and we trust the repo, just to make AIs happy.

What do you think?

Gabriele

> Additionally, if the stat command fails for any reason, dirperms will be
> empty.
> Would an empty string match the *) fallback case and cause the script to
> silently
> fail open, accepting even a world-writable directory?
> 
> > +            TEST_DIR=$TOP_DIR/test.d
> > +            break
> > +            ;;
> > +        esac
> > +      fi
> > +      dir=$(dirname "$dir")
> > +    done
> >    fi
> >  }


  reply	other threads:[~2026-08-24 10:08 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-20 16:45 [PATCH v6 0/9] rv: Add task latency over budget RV monitor wen.yang
2026-08-20 16:45 ` [PATCH v6 1/9] rv: Introduce DA_MON_ALLOCATION_STRATEGY wen.yang
2026-08-20 16:45 ` [PATCH v6 2/9] rv: Add generic uprobe infrastructure for RV monitors wen.yang
2026-08-20 16:59   ` sashiko-bot
2026-08-20 16:45 ` [PATCH v6 3/9] rv: Add tlob model DOT file wen.yang
2026-08-20 16:53   ` sashiko-bot
2026-08-20 16:45 ` [PATCH v6 4/9] rv: Fix ha_invariant_passed_ns silent bypass of invariant check wen.yang
2026-08-20 16:58   ` sashiko-bot
2026-08-20 16:45 ` [PATCH v6 5/9] rv: Make da_monitor_reset_hook and EVENT_NONE_LBL overridable wen.yang
2026-08-20 16:59   ` sashiko-bot
2026-08-20 16:45 ` [PATCH v6 6/9] rv: Add tlob hybrid automaton monitor wen.yang
2026-08-20 17:03   ` sashiko-bot
2026-08-20 16:45 ` [PATCH v6 7/9] rv: Add KUnit tests for the tlob monitor wen.yang
2026-08-20 16:45 ` [PATCH v6 8/9] selftests/verification: Add tlob selftests wen.yang
2026-08-20 16:56   ` sashiko-bot
2026-08-20 16:45 ` [PATCH v6 9/9] selftests/ftrace: Walk up to find test.d/functions when a subdirectory is passed wen.yang
2026-08-20 16:58   ` sashiko-bot
2026-08-24 10:08     ` Gabriele Monaco [this message]
2026-08-24 19:35       ` Steven Rostedt

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=f70d634ff65d6b1bd61c4ae517cf522881a23c61.camel@redhat.com \
    --to=gmonaco@redhat.com \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=wen.yang@linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox