Skip to content

Commit 0b100c8

Browse files
committed
Merge remote-tracking branch 'remotes/dgilbert/tags/pull-migration-20200703a' into staging
virtiofsd+migration pull 2020-07-03 A couple of small migration fixes, and some capability rework for virtiofsd. Signed-off-by: Dr. David Alan Gilbert <[email protected]> # gpg: Signature made Fri 03 Jul 2020 16:26:35 BST # gpg: using RSA key 45F5C71B4A0CB7FB977A9FA90516331EBC5BFDE7 # gpg: Good signature from "Dr. David Alan Gilbert (RH2) <[email protected]>" [full] # Primary key fingerprint: 45F5 C71B 4A0C B7FB 977A 9FA9 0516 331E BC5B FDE7 * remotes/dgilbert/tags/pull-migration-20200703a: migration: Count new_dirty instead of real_dirty migration: postcopy take proper error return virtiofsd: Allow addition or removal of capabilities virtiofsd: Check capability calls virtiofsd: Terminate capability list Signed-off-by: Peter Maydell <[email protected]>
2 parents 21d0baf + fb61358 commit 0b100c8

File tree

6 files changed

+80
-13
lines changed

6 files changed

+80
-13
lines changed

docs/tools/virtiofsd.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ Options
5454
* flock|no_flock -
5555
Enable/disable flock. The default is ``no_flock``.
5656

57+
* modcaps=CAPLIST
58+
Modify the list of capabilities allowed; CAPLIST is a colon separated
59+
list of capabilities, each preceded by either + or -, e.g.
60+
''+sys_admin:-chown''.
61+
5762
* log_level=LEVEL -
5863
Print only log messages matching LEVEL or more severe. LEVEL is one of
5964
``err``, ``warn``, ``info``, or ``debug``. The default is ``info``.

include/exec/ram_addr.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,7 @@ static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start,
442442
static inline
443443
uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,
444444
ram_addr_t start,
445-
ram_addr_t length,
446-
uint64_t *real_dirty_pages)
445+
ram_addr_t length)
447446
{
448447
ram_addr_t addr;
449448
unsigned long word = BIT_WORD((start + rb->offset) >> TARGET_PAGE_BITS);
@@ -469,7 +468,6 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,
469468
if (src[idx][offset]) {
470469
unsigned long bits = atomic_xchg(&src[idx][offset], 0);
471470
unsigned long new_dirty;
472-
*real_dirty_pages += ctpopl(bits);
473471
new_dirty = ~dest[k];
474472
dest[k] |= bits;
475473
new_dirty &= bits;
@@ -502,7 +500,6 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,
502500
start + addr + offset,
503501
TARGET_PAGE_SIZE,
504502
DIRTY_MEMORY_MIGRATION)) {
505-
*real_dirty_pages += 1;
506503
long k = (start + addr) >> TARGET_PAGE_BITS;
507504
if (!test_and_set_bit(k, dest)) {
508505
num_dirty++;

migration/postcopy-ram.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ bool postcopy_ram_supported_by_host(MigrationIncomingState *mis)
389389
*/
390390
if (munlockall()) {
391391
error_report("%s: munlockall: %s", __func__, strerror(errno));
392-
return -1;
392+
goto out;
393393
}
394394

395395
/*

migration/ram.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -859,9 +859,11 @@ static inline bool migration_bitmap_clear_dirty(RAMState *rs,
859859
/* Called with RCU critical section */
860860
static void ramblock_sync_dirty_bitmap(RAMState *rs, RAMBlock *rb)
861861
{
862-
rs->migration_dirty_pages +=
863-
cpu_physical_memory_sync_dirty_bitmap(rb, 0, rb->used_length,
864-
&rs->num_dirty_pages_period);
862+
uint64_t new_dirty_pages =
863+
cpu_physical_memory_sync_dirty_bitmap(rb, 0, rb->used_length);
864+
865+
rs->migration_dirty_pages += new_dirty_pages;
866+
rs->num_dirty_pages_period += new_dirty_pages;
865867
}
866868

867869
/**

tools/virtiofsd/helper.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ void fuse_cmdline_help(void)
174174
" default: no_writeback\n"
175175
" -o xattr|no_xattr enable/disable xattr\n"
176176
" default: no_xattr\n"
177+
" -o modcaps=CAPLIST Modify the list of capabilities\n"
178+
" e.g. -o modcaps=+sys_admin:-chown\n"
177179
" --rlimit-nofile=<num> set maximum number of file descriptors\n"
178180
" (0 leaves rlimit unchanged)\n"
179181
" default: min(1000000, fs.file-max - 16384)\n"

tools/virtiofsd/passthrough_ll.c

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ struct lo_data {
145145
int posix_lock;
146146
int xattr;
147147
char *source;
148+
char *modcaps;
148149
double timeout;
149150
int cache;
150151
int timeout_set;
@@ -170,6 +171,7 @@ static const struct fuse_opt lo_opts[] = {
170171
{ "no_posix_lock", offsetof(struct lo_data, posix_lock), 0 },
171172
{ "xattr", offsetof(struct lo_data, xattr), 1 },
172173
{ "no_xattr", offsetof(struct lo_data, xattr), 0 },
174+
{ "modcaps=%s", offsetof(struct lo_data, modcaps), 0 },
173175
{ "timeout=%lf", offsetof(struct lo_data, timeout), 0 },
174176
{ "timeout=", offsetof(struct lo_data, timeout_set), 1 },
175177
{ "cache=none", offsetof(struct lo_data, cache), CACHE_NONE },
@@ -2570,9 +2572,11 @@ static void setup_mounts(const char *source)
25702572

25712573
/*
25722574
* Only keep whitelisted capabilities that are needed for file system operation
2575+
* The (possibly NULL) modcaps_in string passed in is free'd before exit.
25732576
*/
2574-
static void setup_capabilities(void)
2577+
static void setup_capabilities(char *modcaps_in)
25752578
{
2579+
char *modcaps = modcaps_in;
25762580
pthread_mutex_lock(&cap.mutex);
25772581
capng_restore_state(&cap.saved);
25782582

@@ -2589,7 +2593,7 @@ static void setup_capabilities(void)
25892593
*/
25902594
capng_setpid(syscall(SYS_gettid));
25912595
capng_clear(CAPNG_SELECT_BOTH);
2592-
capng_updatev(CAPNG_ADD, CAPNG_PERMITTED | CAPNG_EFFECTIVE,
2596+
if (capng_updatev(CAPNG_ADD, CAPNG_PERMITTED | CAPNG_EFFECTIVE,
25932597
CAP_CHOWN,
25942598
CAP_DAC_OVERRIDE,
25952599
CAP_DAC_READ_SEARCH,
@@ -2598,10 +2602,67 @@ static void setup_capabilities(void)
25982602
CAP_SETGID,
25992603
CAP_SETUID,
26002604
CAP_MKNOD,
2601-
CAP_SETFCAP);
2602-
capng_apply(CAPNG_SELECT_BOTH);
2605+
CAP_SETFCAP,
2606+
-1)) {
2607+
fuse_log(FUSE_LOG_ERR, "%s: capng_updatev failed\n", __func__);
2608+
exit(1);
2609+
}
2610+
2611+
/*
2612+
* The modcaps option is a colon separated list of caps,
2613+
* each preceded by either + or -.
2614+
*/
2615+
while (modcaps) {
2616+
capng_act_t action;
2617+
int cap;
2618+
2619+
char *next = strchr(modcaps, ':');
2620+
if (next) {
2621+
*next = '\0';
2622+
next++;
2623+
}
2624+
2625+
switch (modcaps[0]) {
2626+
case '+':
2627+
action = CAPNG_ADD;
2628+
break;
2629+
2630+
case '-':
2631+
action = CAPNG_DROP;
2632+
break;
2633+
2634+
default:
2635+
fuse_log(FUSE_LOG_ERR,
2636+
"%s: Expecting '+'/'-' in modcaps but found '%c'\n",
2637+
__func__, modcaps[0]);
2638+
exit(1);
2639+
}
2640+
cap = capng_name_to_capability(modcaps + 1);
2641+
if (cap < 0) {
2642+
fuse_log(FUSE_LOG_ERR, "%s: Unknown capability '%s'\n", __func__,
2643+
modcaps);
2644+
exit(1);
2645+
}
2646+
if (capng_update(action, CAPNG_PERMITTED | CAPNG_EFFECTIVE, cap)) {
2647+
fuse_log(FUSE_LOG_ERR, "%s: capng_update failed for '%s'\n",
2648+
__func__, modcaps);
2649+
exit(1);
2650+
}
2651+
2652+
modcaps = next;
2653+
}
2654+
g_free(modcaps_in);
2655+
2656+
if (capng_apply(CAPNG_SELECT_BOTH)) {
2657+
fuse_log(FUSE_LOG_ERR, "%s: capng_apply failed\n", __func__);
2658+
exit(1);
2659+
}
26032660

26042661
cap.saved = capng_save_state();
2662+
if (!cap.saved) {
2663+
fuse_log(FUSE_LOG_ERR, "%s: capng_save_state failed\n", __func__);
2664+
exit(1);
2665+
}
26052666
pthread_mutex_unlock(&cap.mutex);
26062667
}
26072668

@@ -2615,7 +2676,7 @@ static void setup_sandbox(struct lo_data *lo, struct fuse_session *se,
26152676
setup_namespaces(lo, se);
26162677
setup_mounts(lo->source);
26172678
setup_seccomp(enable_syslog);
2618-
setup_capabilities();
2679+
setup_capabilities(g_strdup(lo->modcaps));
26192680
}
26202681

26212682
/* Set the maximum number of open file descriptors */

0 commit comments

Comments
 (0)