Skip to content

Commit

Permalink
Merge branch 'sk-const'
Browse files Browse the repository at this point in the history
Guillaume Nault says:

====================
net: Mark the sk parameter of routing functions as 'const'.

The sk_getsecid security hook prevents the use of a const sk pointer in
several routing functions. Since this hook should only read sk data,
make its sk argument const (patch 1), then constify the sk parameter of
various routing functions (patches 2-4).

Build-tested with make allmodconfig.
====================

Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
davem330 committed Jul 14, 2023
2 parents def3833 + dc4c399 commit f63cfa1
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 29 deletions.
4 changes: 2 additions & 2 deletions drivers/net/ppp/pptp.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ static void del_chan(struct pppox_sock *sock)
spin_unlock(&chan_lock);
}

static struct rtable *pptp_route_output(struct pppox_sock *po,
static struct rtable *pptp_route_output(const struct pppox_sock *po,
struct flowi4 *fl4)
{
struct sock *sk = &po->sk;
const struct sock *sk = &po->sk;
struct net *net;

net = sock_net(sk);
Expand Down
10 changes: 4 additions & 6 deletions include/linux/icmpv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,10 @@ extern void icmpv6_param_prob_reason(struct sk_buff *skb,

struct flowi6;
struct in6_addr;
extern void icmpv6_flow_init(struct sock *sk,
struct flowi6 *fl6,
u8 type,
const struct in6_addr *saddr,
const struct in6_addr *daddr,
int oif);

void icmpv6_flow_init(const struct sock *sk, struct flowi6 *fl6, u8 type,
const struct in6_addr *saddr,
const struct in6_addr *daddr, int oif);

static inline void icmpv6_param_prob(struct sk_buff *skb, u8 code, int pos)
{
Expand Down
2 changes: 1 addition & 1 deletion include/linux/lsm_hook_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ LSM_HOOK(int, 0, sk_alloc_security, struct sock *sk, int family, gfp_t priority)
LSM_HOOK(void, LSM_RET_VOID, sk_free_security, struct sock *sk)
LSM_HOOK(void, LSM_RET_VOID, sk_clone_security, const struct sock *sk,
struct sock *newsk)
LSM_HOOK(void, LSM_RET_VOID, sk_getsecid, struct sock *sk, u32 *secid)
LSM_HOOK(void, LSM_RET_VOID, sk_getsecid, const struct sock *sk, u32 *secid)
LSM_HOOK(void, LSM_RET_VOID, sock_graft, struct sock *sk, struct socket *parent)
LSM_HOOK(int, 0, inet_conn_request, const struct sock *sk, struct sk_buff *skb,
struct request_sock *req)
Expand Down
5 changes: 3 additions & 2 deletions include/linux/security.h
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,8 @@ int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u
int security_sk_alloc(struct sock *sk, int family, gfp_t priority);
void security_sk_free(struct sock *sk);
void security_sk_clone(const struct sock *sk, struct sock *newsk);
void security_sk_classify_flow(struct sock *sk, struct flowi_common *flic);
void security_sk_classify_flow(const struct sock *sk,
struct flowi_common *flic);
void security_req_classify_flow(const struct request_sock *req,
struct flowi_common *flic);
void security_sock_graft(struct sock*sk, struct socket *parent);
Expand Down Expand Up @@ -1597,7 +1598,7 @@ static inline void security_sk_clone(const struct sock *sk, struct sock *newsk)
{
}

static inline void security_sk_classify_flow(struct sock *sk,
static inline void security_sk_classify_flow(const struct sock *sk,
struct flowi_common *flic)
{
}
Expand Down
6 changes: 3 additions & 3 deletions include/net/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ static inline struct rtable *ip_route_output(struct net *net, __be32 daddr,
}

static inline struct rtable *ip_route_output_ports(struct net *net, struct flowi4 *fl4,
struct sock *sk,
const struct sock *sk,
__be32 daddr, __be32 saddr,
__be16 dport, __be16 sport,
__u8 proto, __u8 tos, int oif)
Expand Down Expand Up @@ -309,7 +309,7 @@ static inline void ip_route_connect_init(struct flowi4 *fl4, __be32 dst,
static inline struct rtable *ip_route_connect(struct flowi4 *fl4, __be32 dst,
__be32 src, int oif, u8 protocol,
__be16 sport, __be16 dport,
struct sock *sk)
const struct sock *sk)
{
struct net *net = sock_net(sk);
struct rtable *rt;
Expand All @@ -330,7 +330,7 @@ static inline struct rtable *ip_route_connect(struct flowi4 *fl4, __be32 dst,
static inline struct rtable *ip_route_newports(struct flowi4 *fl4, struct rtable *rt,
__be16 orig_sport, __be16 orig_dport,
__be16 sport, __be16 dport,
struct sock *sk)
const struct sock *sk)
{
if (sport != orig_sport || dport != orig_dport) {
fl4->fl4_dport = dport;
Expand Down
7 changes: 4 additions & 3 deletions net/ipv6/datagram.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ static bool ipv6_mapped_addr_any(const struct in6_addr *a)
return ipv6_addr_v4mapped(a) && (a->s6_addr32[3] == 0);
}

static void ip6_datagram_flow_key_init(struct flowi6 *fl6, struct sock *sk)
static void ip6_datagram_flow_key_init(struct flowi6 *fl6,
const struct sock *sk)
{
struct inet_sock *inet = inet_sk(sk);
struct ipv6_pinfo *np = inet6_sk(sk);
const struct inet_sock *inet = inet_sk(sk);
const struct ipv6_pinfo *np = inet6_sk(sk);
int oif = sk->sk_bound_dev_if;

memset(fl6, 0, sizeof(*fl6));
Expand Down
6 changes: 2 additions & 4 deletions net/ipv6/icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1034,11 +1034,9 @@ static int icmpv6_rcv(struct sk_buff *skb)
return 0;
}

void icmpv6_flow_init(struct sock *sk, struct flowi6 *fl6,
u8 type,
void icmpv6_flow_init(const struct sock *sk, struct flowi6 *fl6, u8 type,
const struct in6_addr *saddr,
const struct in6_addr *daddr,
int oif)
const struct in6_addr *daddr, int oif)
{
memset(fl6, 0, sizeof(*fl6));
fl6->saddr = *saddr;
Expand Down
8 changes: 3 additions & 5 deletions net/ipv6/mcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1699,11 +1699,9 @@ mld_scount(struct ifmcaddr6 *pmc, int type, int gdeleted, int sdeleted)
return scount;
}

static void ip6_mc_hdr(struct sock *sk, struct sk_buff *skb,
struct net_device *dev,
const struct in6_addr *saddr,
const struct in6_addr *daddr,
int proto, int len)
static void ip6_mc_hdr(const struct sock *sk, struct sk_buff *skb,
struct net_device *dev, const struct in6_addr *saddr,
const struct in6_addr *daddr, int proto, int len)
{
struct ipv6hdr *hdr;

Expand Down
2 changes: 1 addition & 1 deletion security/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -4396,7 +4396,7 @@ void security_sk_clone(const struct sock *sk, struct sock *newsk)
}
EXPORT_SYMBOL(security_sk_clone);

void security_sk_classify_flow(struct sock *sk, struct flowi_common *flic)
void security_sk_classify_flow(const struct sock *sk, struct flowi_common *flic)
{
call_void_hook(sk_getsecid, sk, &flic->flowic_secid);
}
Expand Down
4 changes: 2 additions & 2 deletions security/selinux/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -5167,12 +5167,12 @@ static void selinux_sk_clone_security(const struct sock *sk, struct sock *newsk)
selinux_netlbl_sk_security_reset(newsksec);
}

static void selinux_sk_getsecid(struct sock *sk, u32 *secid)
static void selinux_sk_getsecid(const struct sock *sk, u32 *secid)
{
if (!sk)
*secid = SECINITSID_ANY_SOCKET;
else {
struct sk_security_struct *sksec = sk->sk_security;
const struct sk_security_struct *sksec = sk->sk_security;

*secid = sksec->sid;
}
Expand Down

0 comments on commit f63cfa1

Please sign in to comment.