Re: [RFC PATCH v1 04/10] net: qrtr: Report sender endpoint in aux data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Denis Kenzior <denkenz@xxxxxxxxx>
Date: Fri, 18 Oct 2024 13:18:22 -0500
> @@ -1234,6 +1247,78 @@ static int qrtr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
>  	return rc;
>  }
>  
> +static int qrtr_setsockopt(struct socket *sock, int level, int optname,
> +			   sockptr_t optval, unsigned int optlen)
> +{
> +	struct qrtr_sock *ipc = qrtr_sk(sock->sk);
> +	struct sock *sk = sock->sk;
> +	unsigned int val = 0;
> +	int rc = 0;
> +
> +	if (level != SOL_QRTR)
> +		return -ENOPROTOOPT;
> +
> +	if (optlen >= sizeof(val) &&
> +	    copy_from_sockptr(&val, optval, sizeof(val)))
> +		return -EFAULT;
> +
> +	lock_sock(sk);

This seems unnecessary to me.

sk_setsockopt(), do_ip_setsockopt(), and do_ipv6_setsockopt() do not
hold lock_sock() for assign_bit().

Also, QRTR_BIND_ENDPOINT in a later patch will not need lock_sock()
neither.  The value is u32, so you can use WRITE_ONCE() here and
READ_ONCE() in getsockopt().


> +
> +	switch (optname) {
> +	case QRTR_REPORT_ENDPOINT:
> +		assign_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags, val);
> +		break;
> +	default:
> +		rc = -ENOPROTOOPT;
> +	}
> +
> +	release_sock(sk);
> +
> +	return rc;
> +}
> +
> +static int qrtr_getsockopt(struct socket *sock, int level, int optname,
> +			   char __user *optval, int __user *optlen)
> +{
> +	struct qrtr_sock *ipc = qrtr_sk(sock->sk);
> +	struct sock *sk = sock->sk;
> +	unsigned int val;
> +	int len;
> +	int rc = 0;
> +
> +	if (level != SOL_QRTR)
> +		return -ENOPROTOOPT;
> +
> +	if (get_user(len, optlen))
> +		return -EFAULT;
> +
> +	if (len < sizeof(val))
> +		return -EINVAL;
> +
> +	lock_sock(sk);

Same remark.


> +
> +	switch (optname) {
> +	case QRTR_REPORT_ENDPOINT:
> +		val = test_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags);
> +		break;
> +	default:
> +		rc = -ENOPROTOOPT;
> +	}
> +
> +	release_sock(sk);
> +
> +	if (rc)
> +		return rc;
> +
> +	len = sizeof(int);
> +
> +	if (put_user(len, optlen) ||
> +	    copy_to_user(optval, &val, len))
> +		rc = -EFAULT;
> +
> +	return rc;
> +}
> +
>  static int qrtr_release(struct socket *sock)
>  {
>  	struct sock *sk = sock->sk;




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [Linux for Sparc]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux