Commit graph

40 commits

Author SHA1 Message Date
Erik Karlsson
31c390727b file: strengthen exec access control
Do not allow setting environment variables if there is a session as
there is no access control for environment variables and allowing
arbitrary data into the environment is unsafe. Do not leak arguments
through unchecked if the size of the buffer for access checking the
whole command line is exceeded. Adjust the maximum number of allowed
arguments so it matches the actual implementation.

Signed-off-by: Erik Karlsson <erik.karlsson@genexis.eu>
2023-06-25 18:46:59 +02:00
Jo-Philipp Wich
9c6ba38287 treewide: adjust ubus object type names
Drop the historically inherited "luci-rpc-" prefix and replace it with a
more appropriate "rpcd-plugin-" string.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-12-08 20:09:24 +01:00
Jo-Philipp Wich
aaa08366e6 file: extend exec acl checks to commands with arguments
When the initial exec permission check on the executable path fails,
concatenate the command line with spaces and use the resulting string
as lookup path for a second exec permission check.

This allows for exec acls similar to this example:

    "file": {
        "/usr/bin/program --flag --option=1 arg *": [ "exec" ]
    }

The example above would allow executing `/usr/bin/program` with the
arguments `--flag`, `--option=1` and `arg` in exactly this order,
followed by any number of optional arguments as denoted by the
asterisk.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-12-11 09:13:05 +01:00
Yousong Zhou
90e40bd3d5 file: exec: properly free memory on error
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
[fix whitespace]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-29 09:26:18 +01:00
Jo-Philipp Wich
95f0973c34 file: increase minimum read buffer size to 4096 bytes
Some sysfs or proc files contain more than 128 byte of data, e.g. the
/proc/filesystems or /proc/mounts files.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-09-21 14:58:38 +02:00
Jo-Philipp Wich
69eeb1b480 file: refactor message parsing and permission checking
Refactor rpc_check_path() and wrap it with a macro to allow passing
different policies and permission names.

This allows using the function for non-read operations and simplifies
the message parsing code there.

Also change the stat and list methods to require "list" instead of
"read" permissions which is useful to allow browing the filesystem
without allowing read access to all files.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-09-08 18:29:18 +02:00
Jo-Philipp Wich
345363bf47 file: add remove operation
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-09-03 11:27:44 +02:00
Jo-Philipp Wich
821045f6ce file: add path based read/write/exec ACL checks
Introduce ACL checks to verify that the requested path may be read, written
or executed. This allows to restrict ubus file commands to specific paths.

To setup the required ACLs, the following ubus command may be used
on the command line:

ubus call session grant '{
  "ubus_rpc_session": "d41d8cd98f00b204e9800998ecf8427e",
  "scope": "file",
  "objects": [
    [ "/etc", "read" ],
    [ "/etc/*", "write" ],
    [ "/sbin/sysupgrade", "exec" ]
  ]
}'

The "read", "list", "stat" and "md5" procedures require "read" permissions,
the "write" procedure requires "write" permission and the "exec" procedure
requires "exec" permissions.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-09-01 18:29:03 +02:00
Jo-Philipp Wich
fb337e5a08 file: add stat() information to directory listings
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-09-01 18:29:03 +02:00
Jo-Philipp Wich
ffaa6132cb file: avoid closing stdio descriptors in rpc_file_exec_run
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-12-21 09:30:19 +01:00
Jo-Philipp Wich
67118a6b33 file: patch process stdin to /dev/null
This prevents broken pipe errors in executed child processes that
attempt to access stdin.

Suggested-by: Vytautas Virvičius <vy.virvicius@gmail.com>
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-12-21 09:18:23 +01:00
Jo-Philipp Wich
2e8106ac56 file: remove unused members from struct rpc_file_exec_context
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-12-21 09:00:48 +01:00
Jo-Philipp Wich
e5243c16eb file: rpc_file_exec_run: fix potential memory leak and integer overflow
- Store the realloc result in a separate pointer so that we can free
   the original on allocation failure
 - Use an explicit uint8_t for the argument vector length instead of
   "char" which might be signed or unsigned, depending on the arch
 - Bail out with an invalid argument error if the argument vector
   exceeds 255 items

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-12-21 09:00:20 +01:00
Jo-Philipp Wich
3aa81d0dfa file: access exec timeout via daemon ops structure
Since the plugin is not linked, but dlopen()'d with RTLD_LOCAL, we cannot
access global rpcd variables but need to access them via the common ops
structure symbol.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-11-28 12:12:04 +01:00
Jo-Philipp Wich
ccd7c0af75 treewide: rename exec_timeout to rpc_exec_timeout
Rename the extern int to denote a global symbol.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-11-28 12:07:58 +01:00
Jo-Philipp Wich
2cc4b998ec file: use global exec timeout instead of own hardcoded limit
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-11-22 14:28:29 +01:00
Luka Perkov
73aea9b8b6 file: add myself in Copyright header
Signed-off-by: Luka Perkov <luka@openwrt.org>
2016-04-12 17:15:27 +02:00
Luka Perkov
2350c6fa91 file: handle return output of b64_decode
Solve this compile warning:

file.c:300:16: error: comparison of unsigned expression < 0 is always false [-Werror,-Wtautological-compare]
                if (data_len < 0)

Signed-off-by: Luka Perkov <luka@openwrt.org>
2016-04-12 17:15:08 +02:00
Luka Perkov
c8c8f7d014 file: add append write support
Signed-off-by: Luka Perkov <luka@openwrt.org>
2016-04-12 17:14:42 +02:00
Luka Perkov
410802e106 file: be consistent with string termination character
Signed-off-by: Luka Perkov <luka@openwrt.org>
2015-07-15 00:21:39 +02:00
Luka Perkov
4db5df8a96 file: add support for setting mode when writing files
Signed-off-by: Luka Perkov <luka@openwrt.org>
2015-07-15 00:21:28 +02:00
Luka Perkov
fc895bb1e2 file: add support for base64
Signed-off-by: Luka Perkov <luka@openwrt.org>
2015-07-15 00:20:17 +02:00
Luka Perkov
9a6bfa110a file: add md5sum support
Signed-off-by: Luka Perkov <luka@openwrt.org>
2015-04-12 21:24:39 +02:00
John Crispin
311c85e7d9 properly handle return codes
Signed-off-by: John Crispin <blogic@openwrt.org>
2015-03-28 18:36:40 +01:00
Luka Perkov
361b823e8d file: free memory after opendir()
Signed-off-by: Luka Perkov <luka@openwrt.org>
2015-03-11 16:25:41 +01:00
Luka Perkov
b65f6a844f file: use blob_buf_free()
Signed-off-by: Luka Perkov <luka@openwrt.org>
2015-03-11 16:25:36 +01:00
Luka Perkov
e2d37b7e40 file: show "data" ubus parameter only when used
The ubus calls for file read, list and stat do not use data parameter, so lets
remove them to avoid confusion.

Signed-off-by: Luka Perkov <luka@openwrt.org>
2015-03-11 16:25:29 +01:00
Luka Perkov
4cc6a9deb8 fix segmentation fault when plugins are loaded
Function rpc_plugin_register_library() is modifying the struct's contents in
list_add() call. That said, the rpc_plugin struct should not be defined as
const. This caused segmentation fault when built on up-to-date Arch Linux.

Signed-off-by: Luka Perkov <luka@openwrt.org>
2014-01-29 13:29:57 +00:00
Luka Perkov
835b8b768d file: when writing a file make sure it's contents are stored
Fixes problems with ubi(fs).

Signed-off-by: Luka Perkov <luka@openwrt.org>
2014-01-29 13:29:48 +00:00
Luka Perkov
11f5072bb1 file: create a file on write if it does not exist
Signed-off-by: Luka Perkov <luka@openwrt.org>
2014-01-29 13:29:40 +00:00
Luka Perkov
ec21f653b9 fix whitespaces
Signed-off-by: Luka Perkov <luka@openwrt.org>
2014-01-29 13:29:32 +00:00
Jo-Philipp Wich
0c4e97b4e7 Extend copyright 2014-01-12 12:48:58 +00:00
Jo-Philipp Wich
e0afdb10ae Move includes into subdirectory 2013-09-04 12:46:11 +02:00
Jo-Philipp Wich
11f37e2889 Fold plugin specific headers files into the plugins .c file 2013-09-02 17:29:06 +02:00
Jo-Philipp Wich
07c2f0a9b1 Rename from "luci-rpcd" to "rpcd" 2013-09-02 17:23:30 +02:00
Jo-Philipp Wich
c849d04fc8 file: convert to plugin library 2013-09-02 15:23:09 +02:00
Jo-Philipp Wich
6a00d27ae5 file: properly use container_of() to not trip type safety warnings 2013-04-16 21:21:25 +02:00
Jo-Philipp Wich
dfa1d802b2 file: remove unused mode argument from exec procedure 2013-02-03 14:00:57 +01:00
Jo-Philipp Wich
bea6a81875 file: add exec method, rework read method 2013-01-31 22:19:22 +01:00
Jo-Philipp Wich
0607cfda5b initial commit 2013-01-26 15:29:09 +01:00