Skip to content

Commit 6a9d552

Browse files
seanyoungmchehab
authored andcommitted
media: rc: bpf attach/detach requires write permission
Note that bpf attach/detach also requires CAP_NET_ADMIN. Cc: stable@vger.kernel.org Signed-off-by: Sean Young <sean@mess.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
1 parent f66556c commit 6a9d552

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

drivers/media/rc/bpf-lirc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ int lirc_prog_attach(const union bpf_attr *attr, struct bpf_prog *prog)
253253
if (attr->attach_flags)
254254
return -EINVAL;
255255

256-
rcdev = rc_dev_get_from_fd(attr->target_fd);
256+
rcdev = rc_dev_get_from_fd(attr->target_fd, true);
257257
if (IS_ERR(rcdev))
258258
return PTR_ERR(rcdev);
259259

@@ -278,7 +278,7 @@ int lirc_prog_detach(const union bpf_attr *attr)
278278
if (IS_ERR(prog))
279279
return PTR_ERR(prog);
280280

281-
rcdev = rc_dev_get_from_fd(attr->target_fd);
281+
rcdev = rc_dev_get_from_fd(attr->target_fd, true);
282282
if (IS_ERR(rcdev)) {
283283
bpf_prog_put(prog);
284284
return PTR_ERR(rcdev);
@@ -303,7 +303,7 @@ int lirc_prog_query(const union bpf_attr *attr, union bpf_attr __user *uattr)
303303
if (attr->query.query_flags)
304304
return -EINVAL;
305305

306-
rcdev = rc_dev_get_from_fd(attr->query.target_fd);
306+
rcdev = rc_dev_get_from_fd(attr->query.target_fd, false);
307307
if (IS_ERR(rcdev))
308308
return PTR_ERR(rcdev);
309309

drivers/media/rc/lirc_dev.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ void __exit lirc_dev_exit(void)
814814
unregister_chrdev_region(lirc_base_dev, RC_DEV_MAX);
815815
}
816816

817-
struct rc_dev *rc_dev_get_from_fd(int fd)
817+
struct rc_dev *rc_dev_get_from_fd(int fd, bool write)
818818
{
819819
struct fd f = fdget(fd);
820820
struct lirc_fh *fh;
@@ -828,6 +828,9 @@ struct rc_dev *rc_dev_get_from_fd(int fd)
828828
return ERR_PTR(-EINVAL);
829829
}
830830

831+
if (write && !(f.file->f_mode & FMODE_WRITE))
832+
return ERR_PTR(-EPERM);
833+
831834
fh = f.file->private_data;
832835
dev = fh->rc;
833836

drivers/media/rc/rc-core-priv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void lirc_raw_event(struct rc_dev *dev, struct ir_raw_event ev);
325325
void lirc_scancode_event(struct rc_dev *dev, struct lirc_scancode *lsc);
326326
int lirc_register(struct rc_dev *dev);
327327
void lirc_unregister(struct rc_dev *dev);
328-
struct rc_dev *rc_dev_get_from_fd(int fd);
328+
struct rc_dev *rc_dev_get_from_fd(int fd, bool write);
329329
#else
330330
static inline int lirc_dev_init(void) { return 0; }
331331
static inline void lirc_dev_exit(void) {}

0 commit comments

Comments
 (0)