net: make ->{get,set}sockopt in proto_ops optional

Just check for a NULL method instead of wiring up
sock_no_{get,set}sockopt.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Christoph Hellwig 2020-07-17 08:23:31 +02:00 committed by David S. Miller
parent 3021ad5299
commit a44d9e7210
26 changed files with 11 additions and 73 deletions

View File

@ -335,7 +335,6 @@ static const struct proto_ops alg_proto_ops = {
.ioctl = sock_no_ioctl, .ioctl = sock_no_ioctl,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.getsockopt = sock_no_getsockopt,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,
.sendpage = sock_no_sendpage, .sendpage = sock_no_sendpage,
.sendmsg = sock_no_sendmsg, .sendmsg = sock_no_sendmsg,

View File

@ -361,11 +361,9 @@ static struct proto_ops algif_aead_ops = {
.ioctl = sock_no_ioctl, .ioctl = sock_no_ioctl,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.getsockopt = sock_no_getsockopt,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,
.bind = sock_no_bind, .bind = sock_no_bind,
.accept = sock_no_accept, .accept = sock_no_accept,
.setsockopt = sock_no_setsockopt,
.release = af_alg_release, .release = af_alg_release,
.sendmsg = aead_sendmsg, .sendmsg = aead_sendmsg,
@ -454,11 +452,9 @@ static struct proto_ops algif_aead_ops_nokey = {
.ioctl = sock_no_ioctl, .ioctl = sock_no_ioctl,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.getsockopt = sock_no_getsockopt,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,
.bind = sock_no_bind, .bind = sock_no_bind,
.accept = sock_no_accept, .accept = sock_no_accept,
.setsockopt = sock_no_setsockopt,
.release = af_alg_release, .release = af_alg_release,
.sendmsg = aead_sendmsg_nokey, .sendmsg = aead_sendmsg_nokey,

View File

@ -279,10 +279,8 @@ static struct proto_ops algif_hash_ops = {
.ioctl = sock_no_ioctl, .ioctl = sock_no_ioctl,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.getsockopt = sock_no_getsockopt,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,
.bind = sock_no_bind, .bind = sock_no_bind,
.setsockopt = sock_no_setsockopt,
.release = af_alg_release, .release = af_alg_release,
.sendmsg = hash_sendmsg, .sendmsg = hash_sendmsg,
@ -383,10 +381,8 @@ static struct proto_ops algif_hash_ops_nokey = {
.ioctl = sock_no_ioctl, .ioctl = sock_no_ioctl,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.getsockopt = sock_no_getsockopt,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,
.bind = sock_no_bind, .bind = sock_no_bind,
.setsockopt = sock_no_setsockopt,
.release = af_alg_release, .release = af_alg_release,
.sendmsg = hash_sendmsg_nokey, .sendmsg = hash_sendmsg_nokey,

View File

@ -101,11 +101,9 @@ static struct proto_ops algif_rng_ops = {
.ioctl = sock_no_ioctl, .ioctl = sock_no_ioctl,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.getsockopt = sock_no_getsockopt,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,
.bind = sock_no_bind, .bind = sock_no_bind,
.accept = sock_no_accept, .accept = sock_no_accept,
.setsockopt = sock_no_setsockopt,
.sendmsg = sock_no_sendmsg, .sendmsg = sock_no_sendmsg,
.sendpage = sock_no_sendpage, .sendpage = sock_no_sendpage,

View File

@ -188,11 +188,9 @@ static struct proto_ops algif_skcipher_ops = {
.ioctl = sock_no_ioctl, .ioctl = sock_no_ioctl,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.getsockopt = sock_no_getsockopt,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,
.bind = sock_no_bind, .bind = sock_no_bind,
.accept = sock_no_accept, .accept = sock_no_accept,
.setsockopt = sock_no_setsockopt,
.release = af_alg_release, .release = af_alg_release,
.sendmsg = skcipher_sendmsg, .sendmsg = skcipher_sendmsg,
@ -281,11 +279,9 @@ static struct proto_ops algif_skcipher_ops_nokey = {
.ioctl = sock_no_ioctl, .ioctl = sock_no_ioctl,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.getsockopt = sock_no_getsockopt,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,
.bind = sock_no_bind, .bind = sock_no_bind,
.accept = sock_no_accept, .accept = sock_no_accept,
.setsockopt = sock_no_setsockopt,
.release = af_alg_release, .release = af_alg_release,
.sendmsg = skcipher_sendmsg_nokey, .sendmsg = skcipher_sendmsg_nokey,

View File

@ -738,8 +738,6 @@ static const struct proto_ops base_sock_ops = {
.recvmsg = sock_no_recvmsg, .recvmsg = sock_no_recvmsg,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.setsockopt = sock_no_setsockopt,
.getsockopt = sock_no_getsockopt,
.connect = sock_no_connect, .connect = sock_no_connect,
.socketpair = sock_no_socketpair, .socketpair = sock_no_socketpair,
.accept = sock_no_accept, .accept = sock_no_accept,

View File

@ -1110,8 +1110,6 @@ static const struct proto_ops pppoe_ops = {
.poll = datagram_poll, .poll = datagram_poll,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.setsockopt = sock_no_setsockopt,
.getsockopt = sock_no_getsockopt,
.sendmsg = pppoe_sendmsg, .sendmsg = pppoe_sendmsg,
.recvmsg = pppoe_recvmsg, .recvmsg = pppoe_recvmsg,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,

View File

@ -618,8 +618,6 @@ static const struct proto_ops pptp_ops = {
.getname = pptp_getname, .getname = pptp_getname,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.setsockopt = sock_no_setsockopt,
.getsockopt = sock_no_getsockopt,
.sendmsg = sock_no_sendmsg, .sendmsg = sock_no_sendmsg,
.recvmsg = sock_no_recvmsg, .recvmsg = sock_no_recvmsg,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,

View File

@ -1714,8 +1714,6 @@ int sock_no_getname(struct socket *, struct sockaddr *, int);
int sock_no_ioctl(struct socket *, unsigned int, unsigned long); int sock_no_ioctl(struct socket *, unsigned int, unsigned long);
int sock_no_listen(struct socket *, int); int sock_no_listen(struct socket *, int);
int sock_no_shutdown(struct socket *, int); int sock_no_shutdown(struct socket *, int);
int sock_no_getsockopt(struct socket *, int , int, char __user *, int __user *);
int sock_no_setsockopt(struct socket *, int, int, char __user *, unsigned int);
int sock_no_sendmsg(struct socket *, struct msghdr *, size_t); int sock_no_sendmsg(struct socket *, struct msghdr *, size_t);
int sock_no_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t len); int sock_no_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t len);
int sock_no_recvmsg(struct socket *, struct msghdr *, size_t, int); int sock_no_recvmsg(struct socket *, struct msghdr *, size_t, int);

View File

@ -1917,8 +1917,6 @@ static const struct proto_ops atalk_dgram_ops = {
#endif #endif
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.setsockopt = sock_no_setsockopt,
.getsockopt = sock_no_getsockopt,
.sendmsg = atalk_sendmsg, .sendmsg = atalk_sendmsg,
.recvmsg = atalk_recvmsg, .recvmsg = atalk_recvmsg,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,

View File

@ -182,8 +182,6 @@ static const struct proto_ops bnep_sock_ops = {
.recvmsg = sock_no_recvmsg, .recvmsg = sock_no_recvmsg,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.setsockopt = sock_no_setsockopt,
.getsockopt = sock_no_getsockopt,
.connect = sock_no_connect, .connect = sock_no_connect,
.socketpair = sock_no_socketpair, .socketpair = sock_no_socketpair,
.accept = sock_no_accept, .accept = sock_no_accept,

View File

@ -185,8 +185,6 @@ static const struct proto_ops cmtp_sock_ops = {
.recvmsg = sock_no_recvmsg, .recvmsg = sock_no_recvmsg,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.setsockopt = sock_no_setsockopt,
.getsockopt = sock_no_getsockopt,
.connect = sock_no_connect, .connect = sock_no_connect,
.socketpair = sock_no_socketpair, .socketpair = sock_no_socketpair,
.accept = sock_no_accept, .accept = sock_no_accept,

View File

@ -233,8 +233,6 @@ static const struct proto_ops hidp_sock_ops = {
.recvmsg = sock_no_recvmsg, .recvmsg = sock_no_recvmsg,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.setsockopt = sock_no_setsockopt,
.getsockopt = sock_no_getsockopt,
.connect = sock_no_connect, .connect = sock_no_connect,
.socketpair = sock_no_socketpair, .socketpair = sock_no_socketpair,
.accept = sock_no_accept, .accept = sock_no_accept,

View File

@ -981,7 +981,6 @@ static const struct proto_ops caif_seqpacket_ops = {
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.setsockopt = setsockopt, .setsockopt = setsockopt,
.getsockopt = sock_no_getsockopt,
.sendmsg = caif_seqpkt_sendmsg, .sendmsg = caif_seqpkt_sendmsg,
.recvmsg = caif_seqpkt_recvmsg, .recvmsg = caif_seqpkt_recvmsg,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,
@ -1002,7 +1001,6 @@ static const struct proto_ops caif_stream_ops = {
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.setsockopt = setsockopt, .setsockopt = setsockopt,
.getsockopt = sock_no_getsockopt,
.sendmsg = caif_stream_sendmsg, .sendmsg = caif_stream_sendmsg,
.recvmsg = caif_stream_recvmsg, .recvmsg = caif_stream_recvmsg,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,

View File

@ -1648,8 +1648,6 @@ static const struct proto_ops bcm_ops = {
.gettstamp = sock_gettstamp, .gettstamp = sock_gettstamp,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.setsockopt = sock_no_setsockopt,
.getsockopt = sock_no_getsockopt,
.sendmsg = bcm_sendmsg, .sendmsg = bcm_sendmsg,
.recvmsg = bcm_recvmsg, .recvmsg = bcm_recvmsg,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,

View File

@ -2783,20 +2783,6 @@ int sock_no_shutdown(struct socket *sock, int how)
} }
EXPORT_SYMBOL(sock_no_shutdown); EXPORT_SYMBOL(sock_no_shutdown);
int sock_no_setsockopt(struct socket *sock, int level, int optname,
char __user *optval, unsigned int optlen)
{
return -EOPNOTSUPP;
}
EXPORT_SYMBOL(sock_no_setsockopt);
int sock_no_getsockopt(struct socket *sock, int level, int optname,
char __user *optval, int __user *optlen)
{
return -EOPNOTSUPP;
}
EXPORT_SYMBOL(sock_no_getsockopt);
int sock_no_sendmsg(struct socket *sock, struct msghdr *m, size_t len) int sock_no_sendmsg(struct socket *sock, struct msghdr *m, size_t len)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;

View File

@ -3734,8 +3734,6 @@ static const struct proto_ops pfkey_ops = {
.ioctl = sock_no_ioctl, .ioctl = sock_no_ioctl,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.setsockopt = sock_no_setsockopt,
.getsockopt = sock_no_getsockopt,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,
.sendpage = sock_no_sendpage, .sendpage = sock_no_sendpage,

View File

@ -921,8 +921,6 @@ static const struct proto_ops llcp_rawsock_ops = {
.ioctl = sock_no_ioctl, .ioctl = sock_no_ioctl,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.setsockopt = sock_no_setsockopt,
.getsockopt = sock_no_getsockopt,
.sendmsg = sock_no_sendmsg, .sendmsg = sock_no_sendmsg,
.recvmsg = llcp_sock_recvmsg, .recvmsg = llcp_sock_recvmsg,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,

View File

@ -276,8 +276,6 @@ static const struct proto_ops rawsock_ops = {
.ioctl = sock_no_ioctl, .ioctl = sock_no_ioctl,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.setsockopt = sock_no_setsockopt,
.getsockopt = sock_no_getsockopt,
.sendmsg = rawsock_sendmsg, .sendmsg = rawsock_sendmsg,
.recvmsg = rawsock_recvmsg, .recvmsg = rawsock_recvmsg,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,
@ -296,8 +294,6 @@ static const struct proto_ops rawsock_raw_ops = {
.ioctl = sock_no_ioctl, .ioctl = sock_no_ioctl,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.setsockopt = sock_no_setsockopt,
.getsockopt = sock_no_getsockopt,
.sendmsg = sock_no_sendmsg, .sendmsg = sock_no_sendmsg,
.recvmsg = rawsock_recvmsg, .recvmsg = rawsock_recvmsg,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,

View File

@ -4503,8 +4503,6 @@ static const struct proto_ops packet_ops_spkt = {
.gettstamp = sock_gettstamp, .gettstamp = sock_gettstamp,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.setsockopt = sock_no_setsockopt,
.getsockopt = sock_no_getsockopt,
.sendmsg = packet_sendmsg_spkt, .sendmsg = packet_sendmsg_spkt,
.recvmsg = packet_recvmsg, .recvmsg = packet_recvmsg,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,

View File

@ -439,8 +439,6 @@ const struct proto_ops phonet_dgram_ops = {
.ioctl = pn_socket_ioctl, .ioctl = pn_socket_ioctl,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.setsockopt = sock_no_setsockopt,
.getsockopt = sock_no_getsockopt,
.sendmsg = pn_socket_sendmsg, .sendmsg = pn_socket_sendmsg,
.recvmsg = sock_common_recvmsg, .recvmsg = sock_common_recvmsg,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,

View File

@ -1208,8 +1208,6 @@ static const struct proto_ops qrtr_proto_ops = {
.gettstamp = sock_gettstamp, .gettstamp = sock_gettstamp,
.poll = datagram_poll, .poll = datagram_poll,
.shutdown = sock_no_shutdown, .shutdown = sock_no_shutdown,
.setsockopt = sock_no_setsockopt,
.getsockopt = sock_no_getsockopt,
.release = qrtr_release, .release = qrtr_release,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,
.sendpage = sock_no_sendpage, .sendpage = sock_no_sendpage,

View File

@ -1742,6 +1742,9 @@ static int smc_setsockopt(struct socket *sock, int level, int optname,
/* generic setsockopts reaching us here always apply to the /* generic setsockopts reaching us here always apply to the
* CLC socket * CLC socket
*/ */
if (unlikely(!smc->clcsock->ops->setsockopt))
rc = -EOPNOTSUPP;
else
rc = smc->clcsock->ops->setsockopt(smc->clcsock, level, optname, rc = smc->clcsock->ops->setsockopt(smc->clcsock, level, optname,
optval, optlen); optval, optlen);
if (smc->clcsock->sk->sk_err) { if (smc->clcsock->sk->sk_err) {
@ -1808,6 +1811,8 @@ static int smc_getsockopt(struct socket *sock, int level, int optname,
smc = smc_sk(sock->sk); smc = smc_sk(sock->sk);
/* socket options apply to the CLC socket */ /* socket options apply to the CLC socket */
if (unlikely(!smc->clcsock->ops->getsockopt))
return -EOPNOTSUPP;
return smc->clcsock->ops->getsockopt(smc->clcsock, level, optname, return smc->clcsock->ops->getsockopt(smc->clcsock, level, optname,
optval, optlen); optval, optlen);
} }

View File

@ -2131,6 +2131,8 @@ int __sys_setsockopt(int fd, int level, int optname, char __user *optval,
if (level == SOL_SOCKET && !sock_use_custom_sol_socket(sock)) if (level == SOL_SOCKET && !sock_use_custom_sol_socket(sock))
err = sock_setsockopt(sock, level, optname, optval, optlen); err = sock_setsockopt(sock, level, optname, optval, optlen);
else if (unlikely(!sock->ops->setsockopt))
err = -EOPNOTSUPP;
else else
err = sock->ops->setsockopt(sock, level, optname, optval, err = sock->ops->setsockopt(sock, level, optname, optval,
optlen); optlen);
@ -2175,6 +2177,8 @@ int __sys_getsockopt(int fd, int level, int optname, char __user *optval,
if (level == SOL_SOCKET) if (level == SOL_SOCKET)
err = sock_getsockopt(sock, level, optname, optval, optlen); err = sock_getsockopt(sock, level, optname, optval, optlen);
else if (unlikely(!sock->ops->getsockopt))
err = -EOPNOTSUPP;
else else
err = sock->ops->getsockopt(sock, level, optname, optval, err = sock->ops->getsockopt(sock, level, optname, optval,
optlen); optlen);

View File

@ -714,8 +714,6 @@ static const struct proto_ops unix_stream_ops = {
#endif #endif
.listen = unix_listen, .listen = unix_listen,
.shutdown = unix_shutdown, .shutdown = unix_shutdown,
.setsockopt = sock_no_setsockopt,
.getsockopt = sock_no_getsockopt,
.sendmsg = unix_stream_sendmsg, .sendmsg = unix_stream_sendmsg,
.recvmsg = unix_stream_recvmsg, .recvmsg = unix_stream_recvmsg,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,
@ -741,8 +739,6 @@ static const struct proto_ops unix_dgram_ops = {
#endif #endif
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = unix_shutdown, .shutdown = unix_shutdown,
.setsockopt = sock_no_setsockopt,
.getsockopt = sock_no_getsockopt,
.sendmsg = unix_dgram_sendmsg, .sendmsg = unix_dgram_sendmsg,
.recvmsg = unix_dgram_recvmsg, .recvmsg = unix_dgram_recvmsg,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,
@ -767,8 +763,6 @@ static const struct proto_ops unix_seqpacket_ops = {
#endif #endif
.listen = unix_listen, .listen = unix_listen,
.shutdown = unix_shutdown, .shutdown = unix_shutdown,
.setsockopt = sock_no_setsockopt,
.getsockopt = sock_no_getsockopt,
.sendmsg = unix_seqpacket_sendmsg, .sendmsg = unix_seqpacket_sendmsg,
.recvmsg = unix_seqpacket_recvmsg, .recvmsg = unix_seqpacket_recvmsg,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,

View File

@ -1202,8 +1202,6 @@ static const struct proto_ops vsock_dgram_ops = {
.ioctl = sock_no_ioctl, .ioctl = sock_no_ioctl,
.listen = sock_no_listen, .listen = sock_no_listen,
.shutdown = vsock_shutdown, .shutdown = vsock_shutdown,
.setsockopt = sock_no_setsockopt,
.getsockopt = sock_no_getsockopt,
.sendmsg = vsock_dgram_sendmsg, .sendmsg = vsock_dgram_sendmsg,
.recvmsg = vsock_dgram_recvmsg, .recvmsg = vsock_dgram_recvmsg,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,