All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Purdie <richard.purdie@linuxfoundation.org>
To: alex.kanavin@gmail.com, david.nystrom@est.tech
Cc: bitbake-devel@lists.openembedded.org
Subject: Re: [bitbake-devel] [PATCH [RFC] 1/2] utils: Add landlock_restrict_network function
Date: Sat, 13 Jun 2026 15:26:29 +0100	[thread overview]
Message-ID: <4c36de09175dced8cd0ede2b52208671b30695a0.camel@linuxfoundation.org> (raw)
In-Reply-To: <CANNYZj_gX=vNggcmyS0CtPoE+dYc0AjOf4=Z0QwcU46-Ccx4EA@mail.gmail.com>

On Sat, 2026-06-13 at 13:52 +0200, Alexander Kanavin via
lists.openembedded.org wrote:
> On Fri, 12 Jun 2026 at 14:01, David Nyström via
> lists.openembedded.org
> <david.nystrom=est.tech@lists.openembedded.org> wrote:
> > +def landlock_restrict_network():
> > +    """Block TCP bind/connect using Landlock LSM (ABI v4+, kernel
> > 6.7+).
> > +    Gracefully skipped on older kernels. Stacks with
> > disable_network()."""
> > +
> > +    NR_CREATE = 444  # landlock_create_ruleset
> > +    NR_SELF   = 446  # landlock_restrict_self
> > +    NET_TCP   = 0x3  # BIND_TCP | CONNECT_TCP
> > +
> > +    libc = ctypes.CDLL('libc.so.6')
> > +
> > +    abi = libc.syscall(NR_CREATE, 0, 0, 1)
> > +    if abi < 4:
> > +        return False
> > +
> > +    attr = struct.pack("QQ", 0, NET_TCP)
> > +    buf = ctypes.create_string_buffer(attr)
> > +    fd = libc.syscall(NR_CREATE, buf, len(attr), 0)
> > +    if fd < 0:
> > +        return False
> > +
> > +    libc.prctl(38, 1, 0, 0, 0)  # PR_SET_NO_NEW_PRIVS
> > +    r = libc.syscall(NR_SELF, fd, 0)
> > +    os.close(fd)
> > +    return r == 0
> 
> Far too many magic numbers. I would really want to do this with an
> API.
> 
> This also needs some kind of test, e.g. that the function indeed has
> the desired effect.

Unfortunately, to use tech like this, we do end up needing to do
something like that and utils.py already has quite a bit of it. The
plus side is that the kernel is really good about maintaining these
APIs so the numbers are unlikely to change.

I wouldn't take something like this unless there was a really good case
for using it. Network isolation in more builds probably is a strong
enough use case...

Cheers,

Richard


  reply	other threads:[~2026-06-13 14:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-12 11:38 [PATCH RFC 0/2] bitbake: Add basic landlock support David Nyström
2026-06-12 11:38 ` [PATCH [RFC] 1/2] utils: Add landlock_restrict_network function David Nyström
2026-06-13 11:52   ` [bitbake-devel] " Alexander Kanavin
2026-06-13 14:26     ` Richard Purdie [this message]
2026-06-15  8:28   ` Paul Barker
2026-07-17 18:11     ` David Nyström
2026-06-12 11:38 ` [PATCH [RFC] 2/2] bitbake-worker: Call landlock_restrict_network for tasks without network David Nyström
2026-06-15  8:30   ` [bitbake-devel] " Paul Barker
2026-07-16 15:44 ` [bitbake-devel] [PATCH RFC 0/2] bitbake: Add basic landlock support Richard Purdie
2026-07-16 15:50   ` David Nyström
2026-09-09 16:30     ` Richard Purdie
2026-09-11  7:52       ` David Nyström

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=4c36de09175dced8cd0ede2b52208671b30695a0.camel@linuxfoundation.org \
    --to=richard.purdie@linuxfoundation.org \
    --cc=alex.kanavin@gmail.com \
    --cc=bitbake-devel@lists.openembedded.org \
    --cc=david.nystrom@est.tech \
    /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.