@@ -203,7 +203,7 @@ static ssize_t fuse_buf_fd_to_fd(const struct fuse_buf *dst, size_t dst_off,
static ssize_t fuse_buf_copy_one(fuse_req_t req,
const struct fuse_buf *dst, size_t dst_off,
const struct fuse_buf *src, size_t src_off,
- size_t len)
+ size_t len, bool dropped_cap_fsetid)
{
int src_is_fd = src->flags & FUSE_BUF_IS_FD;
int dst_is_fd = dst->flags & FUSE_BUF_IS_FD;
@@ -211,7 +211,8 @@ static ssize_t fuse_buf_copy_one(fuse_req_t req,
int dst_is_phys = src->flags & FUSE_BUF_PHYS_ADDR;
if (src_is_phys && !src_is_fd && dst_is_fd) {
- return fuse_virtio_write(req, dst, dst_off, src, src_off, len);
+ return fuse_virtio_write(req, dst, dst_off, src, src_off, len,
+ dropped_cap_fsetid);
}
assert(!src_is_phys && !dst_is_phys);
if (!src_is_fd && !dst_is_fd) {
@@ -267,7 +268,7 @@ static int fuse_bufvec_advance(struct fuse_bufvec *bufv, size_t len)
}
ssize_t fuse_buf_copy(fuse_req_t req, struct fuse_bufvec *dstv,
- struct fuse_bufvec *srcv)
+ struct fuse_bufvec *srcv, bool dropped_cap_fsetid)
{
size_t copied = 0, i;
@@ -309,7 +310,8 @@ ssize_t fuse_buf_copy(fuse_req_t req, struct fuse_bufvec *dstv,
dst_len = dst->size - dstv->off;
len = min_size(src_len, dst_len);
- res = fuse_buf_copy_one(req, dst, dstv->off, src, srcv->off, len);
+ res = fuse_buf_copy_one(req, dst, dstv->off, src, srcv->off, len,
+ dropped_cap_fsetid);
if (res < 0) {
if (!copied) {
return res;
@@ -718,10 +718,14 @@ size_t fuse_buf_size(const struct fuse_bufvec *bufv);
* @param req The request this copy is part of
* @param dst destination buffer vector
* @param src source buffer vector
+ * @param dropped_cap_fsetid Caller has dropped CAP_FSETID. If work is handed
+ * over to a different thread/process, CAP_FSETID needs to be dropped
+ * there as well.
* @return actual number of bytes copied or -errno on error
*/
ssize_t fuse_buf_copy(fuse_req_t req,
- struct fuse_bufvec *dst, struct fuse_bufvec *src);
+ struct fuse_bufvec *dst, struct fuse_bufvec *src,
+ bool dropped_cap_fsetid);
/**
* Memory buffer iterator
@@ -2029,9 +2029,13 @@ int64_t fuse_virtio_io(struct fuse_session *se, VhostUserFSSlaveMsg *msg,
* @param src The source (memory) buffer
* @param src_off The GPA
* @param len Length in bytes
+ * @param dropped_cap_fsetid Caller dropped CAP_FSETID. If it is being handed
+ * over to different thread/process, CAP_FSETID needs to be dropped
+ * before write.
*/
ssize_t fuse_virtio_write(fuse_req_t req, const struct fuse_buf *dst,
size_t dst_off, const struct fuse_buf *src,
- size_t src_off, size_t len);
+ size_t src_off, size_t len,
+ bool dropped_cap_fsetid);
#endif /* FUSE_LOWLEVEL_H_ */
@@ -1189,7 +1189,7 @@ int64_t fuse_virtio_io(struct fuse_session *se, VhostUserFSSlaveMsg *msg,
*/
ssize_t fuse_virtio_write(fuse_req_t req, const struct fuse_buf *dst,
size_t dst_off, const struct fuse_buf *src,
- size_t src_off, size_t len)
+ size_t src_off, size_t len, bool dropped_cap_fsetid)
{
VhostUserFSSlaveMsg msg = { 0 };
@@ -1205,6 +1205,9 @@ ssize_t fuse_virtio_write(fuse_req_t req, const struct fuse_buf *dst,
msg.c_offset[0] = (uintptr_t)src->mem + src_off;
msg.len[0] = len;
msg.flags[0] = VHOST_USER_FS_FLAG_MAP_W;
+ if (dropped_cap_fsetid) {
+ msg.gen_flags |= VHOST_USER_FS_GENFLAG_DROP_FSETID;
+ }
int64_t result = fuse_virtio_io(req->se, &msg, dst->fd);
fuse_log(FUSE_LOG_DEBUG, "%s: result=%ld\n", __func__, result);
@@ -2135,7 +2135,7 @@ static void lo_write_buf(fuse_req_t req, fuse_ino_t ino,
}
}
- res = fuse_buf_copy(req, &out_buf, in_buf);
+ res = fuse_buf_copy(req, &out_buf, in_buf, fi->kill_priv);
if (res < 0) {
fuse_reply_err(req, -res);
} else {