aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-05-24 12:26:13 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-05-24 12:26:13 +0200
commiteace8bb509d05bd888a3718fd6b8ecbc40ddd373 (patch)
tree6554619a732ec153b1a589124da54caeee76d404
parent0563fdf8ca1be4ead824153e7411ab5fe99d1d2c (diff)
downloadpatches-eace8bb509d05bd888a3718fd6b8ecbc40ddd373.tar.gz
readfile patchs so I don't loose them again...
-rw-r--r--0001-readfile-implement-readfile-syscall.patch135
-rw-r--r--0002-readfile-add-test_readfile.c.patch80
-rw-r--r--series2
3 files changed, 217 insertions, 0 deletions
diff --git a/0001-readfile-implement-readfile-syscall.patch b/0001-readfile-implement-readfile-syscall.patch
new file mode 100644
index 00000000000000..1fe832ed0ab1b1
--- /dev/null
+++ b/0001-readfile-implement-readfile-syscall.patch
@@ -0,0 +1,135 @@
+From 5bb274ae162250fad4f4f441a4c75c47ebede90d Mon Sep 17 00:00:00 2001
+From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Date: Tue, 3 Mar 2020 15:05:49 +0100
+Subject: [PATCH 1/2] readfile: implement readfile syscall
+
+It's a tiny syscall, meant to allow a user to do a single "open this
+file, read into this buffer, and close the file" all in a single shot.
+
+Should be good for reading "tiny" files like sysfs, procfs, and other
+"small" files.
+
+There is no restarting the syscall, am trying to keep it simple. At
+least for now.
+
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ arch/x86/entry/syscalls/syscall_32.tbl | 1 +
+ arch/x86/entry/syscalls/syscall_64.tbl | 1 +
+ fs/open.c | 50 ++++++++++++++++++++++++++
+ include/linux/syscalls.h | 2 ++
+ include/uapi/asm-generic/unistd.h | 4 ++-
+ 5 files changed, 57 insertions(+), 1 deletion(-)
+
+diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl
+index 54581ac671b4..a10438d5e5ec 100644
+--- a/arch/x86/entry/syscalls/syscall_32.tbl
++++ b/arch/x86/entry/syscalls/syscall_32.tbl
+@@ -442,3 +442,4 @@
+ 435 i386 clone3 sys_clone3
+ 437 i386 openat2 sys_openat2
+ 438 i386 pidfd_getfd sys_pidfd_getfd
++439 i386 readfile sys_readfile
+diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl
+index 37b844f839bc..ffcc8bed83fb 100644
+--- a/arch/x86/entry/syscalls/syscall_64.tbl
++++ b/arch/x86/entry/syscalls/syscall_64.tbl
+@@ -359,6 +359,7 @@
+ 435 common clone3 sys_clone3
+ 437 common openat2 sys_openat2
+ 438 common pidfd_getfd sys_pidfd_getfd
++439 common readfile sys_readfile
+
+ #
+ # x32-specific system call numbers start at 512 to avoid cache impact
+diff --git a/fs/open.c b/fs/open.c
+index 719b320ede52..94d1633c94bb 100644
+--- a/fs/open.c
++++ b/fs/open.c
+@@ -1339,3 +1339,53 @@ int stream_open(struct inode *inode, struct file *filp)
+ }
+
+ EXPORT_SYMBOL(stream_open);
++
++static struct file *readfile_open(int dfd, const char __user *filename,
++ struct open_flags *op)
++{
++ struct filename *tmp;
++ struct file *f;
++
++ tmp = getname(filename);
++ if (IS_ERR(tmp))
++ return (struct file *)tmp;
++
++ f = do_filp_open(dfd, tmp, op);
++ if (!IS_ERR(f))
++ fsnotify_open(f);
++
++ putname(tmp);
++ return f;
++}
++
++SYSCALL_DEFINE5(readfile, int, dfd, const char __user *, filename,
++ char __user *, buffer, size_t, bufsize, int, flags)
++{
++ struct open_flags op;
++ struct open_how how;
++ struct file *file;
++ loff_t pos = 0;
++ int retval;
++
++ /* Mask off all O_ flags as we only want to read from the file */
++ flags &= ~(VALID_OPEN_FLAGS);
++ flags |= O_RDONLY | O_LARGEFILE;
++
++ how = build_open_how(flags, 0000);
++ retval = build_open_flags(&how, &op);
++ if (retval)
++ return retval;
++
++ file = readfile_open(dfd, filename, &op);
++ if (IS_ERR(file))
++ return PTR_ERR(file);
++
++// retval = ksys_read(fd, buffer, bufsize);
++// __close_fd(current->files, fd);
++
++ retval = kernel_read(file, buffer, bufsize, &pos);
++
++ filp_close(file, NULL);
++
++ return retval;
++}
+diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
+index 1815065d52f3..3a636a913437 100644
+--- a/include/linux/syscalls.h
++++ b/include/linux/syscalls.h
+@@ -1003,6 +1003,8 @@ asmlinkage long sys_pidfd_send_signal(int pidfd, int sig,
+ siginfo_t __user *info,
+ unsigned int flags);
+ asmlinkage long sys_pidfd_getfd(int pidfd, int fd, unsigned int flags);
++asmlinkage long sys_readfile(int dfd, const char __user *filename,
++ char __user *buffer, size_t bufsize, int flags);
+
+ /*
+ * Architecture-specific system calls
+diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h
+index 3a3201e4618e..31f84500915d 100644
+--- a/include/uapi/asm-generic/unistd.h
++++ b/include/uapi/asm-generic/unistd.h
+@@ -855,9 +855,11 @@ __SYSCALL(__NR_clone3, sys_clone3)
+ __SYSCALL(__NR_openat2, sys_openat2)
+ #define __NR_pidfd_getfd 438
+ __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd)
++#define __NR_readfile 439
++__SYSCALL(__NR_readfile, sys_readfile)
+
+ #undef __NR_syscalls
+-#define __NR_syscalls 439
++#define __NR_syscalls 440
+
+ /*
+ * 32 bit systems traditionally used different
+--
+2.26.2
+
diff --git a/0002-readfile-add-test_readfile.c.patch b/0002-readfile-add-test_readfile.c.patch
new file mode 100644
index 00000000000000..cb1deca510b20c
--- /dev/null
+++ b/0002-readfile-add-test_readfile.c.patch
@@ -0,0 +1,80 @@
+From 4c20f7981f2ceff4d47fd6d36a12e66785e2107f Mon Sep 17 00:00:00 2001
+From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Date: Sun, 8 Mar 2020 09:54:45 +0100
+Subject: [PATCH 2/2] readfile: add test_readfile.c
+
+---
+ test_readfile.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++
+ 1 file changed, 61 insertions(+)
+ create mode 100644 test_readfile.c
+
+diff --git a/test_readfile.c b/test_readfile.c
+new file mode 100644
+index 000000000000..e9fdf999ba91
+--- /dev/null
++++ b/test_readfile.c
+@@ -0,0 +1,61 @@
++// SPDX-License-Identifier: GPL-2.0
++#include <stdlib.h>
++#include <stdio.h>
++#include <linux/types.h>
++#include <sys/syscall.h>
++#include <fcntl.h>
++
++#include <assert.h>
++#include <dirent.h>
++#include <limits.h>
++#include <stdio.h>
++#include <string.h>
++#include <sys/types.h>
++#include <sys/stat.h>
++#include <fcntl.h>
++#include <unistd.h>
++
++
++#define NR_readfile 439
++
++#define TEST_FILE1 "/sys/devices/system/cpu/vulnerabilities/meltdown"
++#define TEST_FILE2 "/sys/devices/system/cpu/vulnerabilities/spectre_v1"
++#define TEST_FILE3 "/proc/self/maps"
++#define TEST_FILE4 "/sys/kernel/debug/usb/devices"
++
++static int sys_readfile(int fd, const char *filename, char *buffer,
++ size_t bufsize, int flags)
++{
++ return syscall(NR_readfile, fd, filename, buffer, bufsize, flags);
++}
++
++void readfile(const char *filename)
++{
++ int root_fd;
++ char buffer[16000];
++ int retval;
++
++ memset(buffer, 0x00, sizeof(buffer));
++
++ root_fd = open("/", O_DIRECTORY);
++ if (root_fd == -1) {
++ printf("error with root_fd\n");
++ return;
++ }
++
++ retval = sys_readfile(root_fd, filename, &buffer[0], sizeof(buffer), 0);
++ printf("filename=%s\n retval=%d\n buffer='%s'\n",
++ filename, retval, &buffer[0]);
++
++ close(root_fd);
++}
++
++int main(void)
++{
++ readfile(TEST_FILE1);
++ readfile(TEST_FILE2);
++ readfile(TEST_FILE3);
++ readfile(TEST_FILE4);
++ return 0;
++}
++
+--
+2.26.2
+
diff --git a/series b/series
index dbb51a2009a906..0a3b895a3dda97 100644
--- a/series
+++ b/series
@@ -1,4 +1,6 @@
#
+0001-readfile-implement-readfile-syscall.patch
+0002-readfile-add-test_readfile.c.patch
0001-bpf-explicitly-memset-the-bpf_attr-structure.patch
0002-bpf-explicitly-memset-some-bpf-info-structures-decla.patch
0001-tty-serial-samsung_tty-build-it-for-any-platform.patch