Skip to content

Commit 9b286ef

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull trivial vfs updates from Al Viro: "A few cleanups + Neil's namespace_unlock() optimization" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: exec: make prepare_bprm_creds static genheaders: %-<width>s had been there since v6; %-*s - since v7 VFS: use synchronize_rcu_expedited() in namespace_unlock() iov_iter: reduce code duplication
2 parents 47f3f4e + e4f2283 commit 9b286ef

5 files changed

Lines changed: 38 additions & 50 deletions

File tree

‎fs/exec.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,7 @@ EXPORT_SYMBOL(finalize_exec);
14021402
* Or, if exec fails before, free_bprm() should release ->cred and
14031403
* and unlock.
14041404
*/
1405-
int prepare_bprm_creds(struct linux_binprm *bprm)
1405+
static int prepare_bprm_creds(struct linux_binprm *bprm)
14061406
{
14071407
if (mutex_lock_interruptible(&current->signal->cred_guard_mutex))
14081408
return -ERESTARTNOINTR;

‎fs/namespace.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ static void namespace_unlock(void)
13601360
if (likely(hlist_empty(&head)))
13611361
return;
13621362

1363-
synchronize_rcu();
1363+
synchronize_rcu_expedited();
13641364

13651365
group_pin_kill(&head);
13661366
}

‎include/linux/binfmts.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ extern int transfer_args_to_stack(struct linux_binprm *bprm,
139139
extern int bprm_change_interp(const char *interp, struct linux_binprm *bprm);
140140
extern int copy_strings_kernel(int argc, const char *const *argv,
141141
struct linux_binprm *bprm);
142-
extern int prepare_bprm_creds(struct linux_binprm *bprm);
143142
extern void install_exec_creds(struct linux_binprm *bprm);
144143
extern void set_binfmt(struct linux_binfmt *new);
145144
extern ssize_t read_code(struct file *, unsigned long, loff_t, size_t);

‎lib/iov_iter.c‎

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -561,13 +561,20 @@ static size_t copy_pipe_to_iter(const void *addr, size_t bytes,
561561
return bytes;
562562
}
563563

564+
static __wsum csum_and_memcpy(void *to, const void *from, size_t len,
565+
__wsum sum, size_t off)
566+
{
567+
__wsum next = csum_partial_copy_nocheck(from, to, len, 0);
568+
return csum_block_add(sum, next, off);
569+
}
570+
564571
static size_t csum_and_copy_to_pipe_iter(const void *addr, size_t bytes,
565572
__wsum *csum, struct iov_iter *i)
566573
{
567574
struct pipe_inode_info *pipe = i->pipe;
568575
size_t n, r;
569576
size_t off = 0;
570-
__wsum sum = *csum, next;
577+
__wsum sum = *csum;
571578
int idx;
572579

573580
if (!sanity(i))
@@ -579,8 +586,7 @@ static size_t csum_and_copy_to_pipe_iter(const void *addr, size_t bytes,
579586
for ( ; n; idx = next_idx(idx, pipe), r = 0) {
580587
size_t chunk = min_t(size_t, n, PAGE_SIZE - r);
581588
char *p = kmap_atomic(pipe->bufs[idx].page);
582-
next = csum_partial_copy_nocheck(addr, p + r, chunk, 0);
583-
sum = csum_block_add(sum, next, off);
589+
sum = csum_and_memcpy(p + r, addr, chunk, sum, off);
584590
kunmap_atomic(p);
585591
i->idx = idx;
586592
i->iov_offset = r + chunk;
@@ -1401,17 +1407,15 @@ size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum,
14011407
err ? v.iov_len : 0;
14021408
}), ({
14031409
char *p = kmap_atomic(v.bv_page);
1404-
next = csum_partial_copy_nocheck(p + v.bv_offset,
1405-
(to += v.bv_len) - v.bv_len,
1406-
v.bv_len, 0);
1410+
sum = csum_and_memcpy((to += v.bv_len) - v.bv_len,
1411+
p + v.bv_offset, v.bv_len,
1412+
sum, off);
14071413
kunmap_atomic(p);
1408-
sum = csum_block_add(sum, next, off);
14091414
off += v.bv_len;
14101415
}),({
1411-
next = csum_partial_copy_nocheck(v.iov_base,
1412-
(to += v.iov_len) - v.iov_len,
1413-
v.iov_len, 0);
1414-
sum = csum_block_add(sum, next, off);
1416+
sum = csum_and_memcpy((to += v.iov_len) - v.iov_len,
1417+
v.iov_base, v.iov_len,
1418+
sum, off);
14151419
off += v.iov_len;
14161420
})
14171421
)
@@ -1445,17 +1449,15 @@ bool csum_and_copy_from_iter_full(void *addr, size_t bytes, __wsum *csum,
14451449
0;
14461450
}), ({
14471451
char *p = kmap_atomic(v.bv_page);
1448-
next = csum_partial_copy_nocheck(p + v.bv_offset,
1449-
(to += v.bv_len) - v.bv_len,
1450-
v.bv_len, 0);
1452+
sum = csum_and_memcpy((to += v.bv_len) - v.bv_len,
1453+
p + v.bv_offset, v.bv_len,
1454+
sum, off);
14511455
kunmap_atomic(p);
1452-
sum = csum_block_add(sum, next, off);
14531456
off += v.bv_len;
14541457
}),({
1455-
next = csum_partial_copy_nocheck(v.iov_base,
1456-
(to += v.iov_len) - v.iov_len,
1457-
v.iov_len, 0);
1458-
sum = csum_block_add(sum, next, off);
1458+
sum = csum_and_memcpy((to += v.iov_len) - v.iov_len,
1459+
v.iov_base, v.iov_len,
1460+
sum, off);
14591461
off += v.iov_len;
14601462
})
14611463
)
@@ -1493,17 +1495,15 @@ size_t csum_and_copy_to_iter(const void *addr, size_t bytes, void *csump,
14931495
err ? v.iov_len : 0;
14941496
}), ({
14951497
char *p = kmap_atomic(v.bv_page);
1496-
next = csum_partial_copy_nocheck((from += v.bv_len) - v.bv_len,
1497-
p + v.bv_offset,
1498-
v.bv_len, 0);
1498+
sum = csum_and_memcpy(p + v.bv_offset,
1499+
(from += v.bv_len) - v.bv_len,
1500+
v.bv_len, sum, off);
14991501
kunmap_atomic(p);
1500-
sum = csum_block_add(sum, next, off);
15011502
off += v.bv_len;
15021503
}),({
1503-
next = csum_partial_copy_nocheck((from += v.iov_len) - v.iov_len,
1504-
v.iov_base,
1505-
v.iov_len, 0);
1506-
sum = csum_block_add(sum, next, off);
1504+
sum = csum_and_memcpy(v.iov_base,
1505+
(from += v.iov_len) - v.iov_len,
1506+
v.iov_len, sum, off);
15071507
off += v.iov_len;
15081508
})
15091509
)

‎scripts/selinux/genheaders/genheaders.c‎

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ struct security_class_mapping {
1919
#include "classmap.h"
2020
#include "initial_sid_to_string.h"
2121

22-
#define max(x, y) (((int)(x) > (int)(y)) ? x : y)
23-
2422
const char *progname;
2523

2624
static void usage(void)
@@ -46,11 +44,9 @@ static char *stoupperx(const char *s)
4644

4745
int main(int argc, char *argv[])
4846
{
49-
int i, j, k;
47+
int i, j;
5048
int isids_len;
5149
FILE *fout;
52-
const char *needle = "SOCKET";
53-
char *substr;
5450

5551
progname = argv[0];
5652

@@ -80,30 +76,25 @@ int main(int argc, char *argv[])
8076

8177
for (i = 0; secclass_map[i].name; i++) {
8278
struct security_class_mapping *map = &secclass_map[i];
83-
fprintf(fout, "#define SECCLASS_%s", map->name);
84-
for (j = 0; j < max(1, 40 - strlen(map->name)); j++)
85-
fprintf(fout, " ");
86-
fprintf(fout, "%2d\n", i+1);
79+
fprintf(fout, "#define SECCLASS_%-39s %2d\n", map->name, i+1);
8780
}
8881

8982
fprintf(fout, "\n");
9083

9184
for (i = 1; i < isids_len; i++) {
9285
const char *s = initial_sid_to_string[i];
93-
fprintf(fout, "#define SECINITSID_%s", s);
94-
for (j = 0; j < max(1, 40 - strlen(s)); j++)
95-
fprintf(fout, " ");
96-
fprintf(fout, "%2d\n", i);
86+
fprintf(fout, "#define SECINITSID_%-39s %2d\n", s, i);
9787
}
9888
fprintf(fout, "\n#define SECINITSID_NUM %d\n", i-1);
9989
fprintf(fout, "\nstatic inline bool security_is_socket_class(u16 kern_tclass)\n");
10090
fprintf(fout, "{\n");
10191
fprintf(fout, "\tbool sock = false;\n\n");
10292
fprintf(fout, "\tswitch (kern_tclass) {\n");
10393
for (i = 0; secclass_map[i].name; i++) {
94+
static char s[] = "SOCKET";
10495
struct security_class_mapping *map = &secclass_map[i];
105-
substr = strstr(map->name, needle);
106-
if (substr && strcmp(substr, needle) == 0)
96+
int len = strlen(map->name), l = sizeof(s) - 1;
97+
if (len >= l && memcmp(map->name + len - l, s, l) == 0)
10798
fprintf(fout, "\tcase SECCLASS_%s:\n", map->name);
10899
}
109100
fprintf(fout, "\t\tsock = true;\n");
@@ -129,17 +120,15 @@ int main(int argc, char *argv[])
129120

130121
for (i = 0; secclass_map[i].name; i++) {
131122
struct security_class_mapping *map = &secclass_map[i];
123+
int len = strlen(map->name);
132124
for (j = 0; map->perms[j]; j++) {
133125
if (j >= 32) {
134126
fprintf(stderr, "Too many permissions to fit into an access vector at (%s, %s).\n",
135127
map->name, map->perms[j]);
136128
exit(5);
137129
}
138-
fprintf(fout, "#define %s__%s", map->name,
139-
map->perms[j]);
140-
for (k = 0; k < max(1, 40 - strlen(map->name) - strlen(map->perms[j])); k++)
141-
fprintf(fout, " ");
142-
fprintf(fout, "0x%08xU\n", (1<<j));
130+
fprintf(fout, "#define %s__%-*s 0x%08xU\n", map->name,
131+
39-len, map->perms[j], 1U<<j);
143132
}
144133
}
145134

0 commit comments

Comments
 (0)