Re: Avoid unprivileged splice(file->)/(->socket) pipe exclusion

2023-12-25 Thread Askar Safin
Hi, Ahelenia Ziemiańska! Thanks a lot for all this splice-related hard work!

In 
https://lore.kernel.org/lkml/CAHk-=wgG_2cmHgZwKjydi7=iimyhyn8aessnbm9xq9ufbau...@mail.gmail.com/
Linus said:
> I have grown to pretty much hate
> splice() over the years, just because it's been a constant source of
> sorrow in so many ways.

> It's just that it was never as lovely and as useful as it promised to
> be. So I'd actually be more than happy to just say "let's decommission
> splice entirely, just keeping the interfaces alive for backwards
> compatibility"

So probably we should do this as Linus suggested? I. e. fully remove
splice by replacing it with trivial read-write?

-- 
Askar Safin



Re: [PATCH v5 1/1] fs: Allow no_new_privs tasks to call chroot(2)

2021-03-26 Thread Askar Safin
Hi. Unprivileged users already can do chroot. He should simply create userns 
and then call "chroot" inside. As an LWN commenter noted, you can simply run 
"unshare -r /usr/sbin/chroot some-dir". (I recommend reading all comments: 
https://lwn.net/Articles/849125/ .)

Also: if you need chroot for path resolving only, consider openat2 with 
RESOLVE_IN_ROOT ( https://lwn.net/Articles/796868/ ).


==
Askar Safin
https://github.com/safinaskar


tty: typo in comments in drivers/tty/vt/keyboard.c

2016-11-07 Thread Askar Safin
Fixed typo in comments in drivers/tty/vt/keyboard.c

Signed-off-by: Askar Safin 
---
diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index 0f8caae..d5d81d4 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -1256,7 +1256,7 @@ static int emulate_raw(struct vc_data *vc, unsigned int 
keycode,
case KEY_SYSRQ:
/*
 * Real AT keyboards (that's what we're trying
-* to emulate here emit 0xe0 0x2a 0xe0 0x37 when
+* to emulate here) emit 0xe0 0x2a 0xe0 0x37 when
 * pressing PrtSc/SysRq alone, but simply 0x54
 * when pressing Alt+PrtSc/SysRq.
 */


tty: typo in comments in drivers/tty/vt/keyboard.c

2016-08-07 Thread Askar Safin
Signed-off-by: Askar Safin 
---
diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index 0f8caae..d5d81d4 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -1256,7 +1256,7 @@ static int emulate_raw(struct vc_data *vc, unsigned int 
keycode,
case KEY_SYSRQ:
/*
 * Real AT keyboards (that's what we're trying
-* to emulate here emit 0xe0 0x2a 0xe0 0x37 when
+* to emulate here) emit 0xe0 0x2a 0xe0 0x37 when
 * pressing PrtSc/SysRq alone, but simply 0x54
 * when pressing Alt+PrtSc/SysRq.
 */


TCP connections come in wrong order

2015-02-01 Thread Askar Safin
Consider the following code:

// C99, No error checking for simplicity

#include 
#include 
#include 

#include 
#include 
#include 

#include 

static int
tcp_connect_loop (const char *host, const char *protocol, struct addrinfo *res)
{
  for (; res != NULL; res = res->ai_next)
{
  int result = socket (res->ai_family, res->ai_socktype, res->ai_protocol);

  if (result != -1)
{
  if (connect (result, res->ai_addr, res->ai_addrlen) == 0)
{
  return result;
}

  close (result);
}
}

  // SOMEDAY: печатать больше инфы (то же для tcp_listen_loop)?
  errx (EXIT_FAILURE, "sh_tcp_connect: [%s]:%s: all structs returned by 
getaddrinfo failed", host, protocol);
}

int //@
sh_tcp_connect (const char *host, const char *protocol, int family)//@;
{
  struct addrinfo hints = {};

  hints.ai_family = family;
  hints.ai_socktype = SOCK_STREAM;

  struct addrinfo *res;

  getaddrinfo (host, protocol, &hints, &res);

  // POSIX 2013 says that now 'res' list contains at least one item

  int result;

  result = tcp_connect_loop (host, protocol, res);
  freeaddrinfo (res);

  return result;
}


static int
tcp_listen_loop (const char *protocol, struct addrinfo *res)
{
  for (; res != NULL; res = res->ai_next)
{
  int result = socket (res->ai_family, res->ai_socktype, res->ai_protocol);

  if (result != -1)
{
  const int on = 1;

  if (setsockopt (result, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) 
!= -1)
{
  if (bind (result, res->ai_addr, res->ai_addrlen) == 0)
{
  return result;
}
}

  close (result);
}
}

  errx (EXIT_FAILURE, "sh_tcp_listen: *:%s: all structs returned by getaddrinfo 
failed", protocol);
}

int //@
sh_tcp_listen (const char *protocol, int family)//@;
{
  struct addrinfo hints = {};

  hints.ai_flags = AI_PASSIVE;
  hints.ai_family = family;
  hints.ai_socktype = SOCK_STREAM;

  struct addrinfo *res;

  getaddrinfo (NULL, protocol, &hints, &res);

  int result;

  result = tcp_listen_loop (protocol, res);

  listen (result, 5);
  freeaddrinfo (res);
  return result;
}

#ifndef N
#define N 10
#endif

int
main (int argc, char *argv[])
{
  if (strcmp (argv[1], "-l") == 0)
{
  int l = sh_tcp_listen (argv[2], AF_INET);

  for (;;)
{
  int s = accept (l, NULL, NULL);
  if (s == -1)
{
  continue;
}
  char buf[1000];
  write (1, buf, read (s, buf, sizeof (buf)));
  close (s);
}
}
  else
{
  for (int i = 0; i != N; ++i)
{
  int s = sh_tcp_connect (argv[1], argv[2], AF_INET);
  dprintf (s, "%d\n", i);
  close (s);
}
}
  exit (EXIT_SUCCESS);
}

Compile this code as, for example, /tmp/x (again: this is C99), then run:

/tmp/x -l  > /tmp/ooo

This command will accept connections and write coming data to /tmp/ooo . Okey, 
then run in another terminal:

/tmp/x localhost 

This command will connect to localhost, write 0, then connect again, write 1, 
etc. Soon you will not have available ports, so /tmp/x will fail before it will 
perform all N connections, this is OK.
When this command complete, go to the first terminal and kill the program using 
Ctrl-C. Then look in /tmp/ooo and notice the last line, let's assume this is 
28290. Then compare /tmp/ooo with the right monotonic number sequence:

echo {0..28290} | tr ' ' '\n' | diff -ur - /tmp/ooo

With some luck you will notice that /tmp/ooo is wrong. For example, I got the 
following:

--- -   2015-02-02 00:24:35.606008461 +0300
+++ /tmp/ooo2015-02-02 00:09:25.002694629 +0300
@@ -7391,8 +7391,6 @@
 7390
 7391
 7392
-7393
-7394
 7395
 7396
 7397
@@ -7546,6 +7544,8 @@
 7545
 7546
 7547
+7393
+7394
 7548
 7549
 7550

If 'diff' doesn't report difference, then try again and again.

Is this a bug? I think that this is a bug.

Linux ideal-os 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt2-1 (2014-12-08) x86_64 
GNU/Linux
Debian 8.0 Jessie
GNU C Library (Debian GLIBC 2.19-13) stable release version 2.19, by Roland 
McGrath et al.
==
Askar Safin
http://vk.com/safinaskar
Kazan, Russia