@@ -285,6 +285,7 @@ struct sk_filter;
285285 * @sk_ack_backlog: current listen backlog
286286 * @sk_max_ack_backlog: listen backlog set in listen()
287287 * @sk_uid: user id of owner
288+ * @sk_ino: inode number (zero if orphaned)
288289 * @sk_prefer_busy_poll: prefer busypolling over softirq processing
289290 * @sk_busy_poll_budget: napi processing budget when busypolling
290291 * @sk_priority: %SO_PRIORITY setting
@@ -512,6 +513,7 @@ struct sock {
512513 u32 sk_ack_backlog ;
513514 u32 sk_max_ack_backlog ;
514515 kuid_t sk_uid ;
516+ unsigned long sk_ino ;
515517 spinlock_t sk_peer_lock ;
516518 int sk_bind_phc ;
517519 struct pid * sk_peer_pid ;
@@ -2027,6 +2029,13 @@ static inline int sk_rx_queue_get(const struct sock *sk)
20272029static inline void sk_set_socket (struct sock * sk , struct socket * sock )
20282030{
20292031 sk -> sk_socket = sock ;
2032+ if (sock ) {
2033+ WRITE_ONCE (sk -> sk_uid , SOCK_INODE (sock )-> i_uid );
2034+ WRITE_ONCE (sk -> sk_ino , SOCK_INODE (sock )-> i_ino );
2035+ } else {
2036+ /* Note: sk_uid is unchanged. */
2037+ WRITE_ONCE (sk -> sk_ino , 0 );
2038+ }
20302039}
20312040
20322041static inline wait_queue_head_t * sk_sleep (struct sock * sk )
@@ -2057,14 +2066,17 @@ static inline void sock_graft(struct sock *sk, struct socket *parent)
20572066 rcu_assign_pointer (sk -> sk_wq , & parent -> wq );
20582067 parent -> sk = sk ;
20592068 sk_set_socket (sk , parent );
2060- sk -> sk_uid = SOCK_INODE (parent )-> i_uid ;
20612069 security_sock_graft (sk , parent );
20622070 write_unlock_bh (& sk -> sk_callback_lock );
20632071}
20642072
2073+ static inline unsigned long sock_i_ino (const struct sock * sk )
2074+ {
2075+ /* Paired with WRITE_ONCE() in sock_graft() and sock_orphan() */
2076+ return READ_ONCE (sk -> sk_ino );
2077+ }
2078+
20652079kuid_t sock_i_uid (struct sock * sk );
2066- unsigned long __sock_i_ino (struct sock * sk );
2067- unsigned long sock_i_ino (struct sock * sk );
20682080
20692081static inline kuid_t sock_net_uid (const struct net * net , const struct sock * sk )
20702082{
@@ -2970,8 +2982,11 @@ int sock_ioctl_inout(struct sock *sk, unsigned int cmd,
29702982int sk_ioctl (struct sock * sk , unsigned int cmd , void __user * arg );
29712983static inline bool sk_is_readable (struct sock * sk )
29722984{
2973- if (sk -> sk_prot -> sock_is_readable )
2974- return sk -> sk_prot -> sock_is_readable (sk );
2985+ const struct proto * prot = READ_ONCE (sk -> sk_prot );
2986+
2987+ if (prot -> sock_is_readable )
2988+ return prot -> sock_is_readable (sk );
2989+
29752990 return false;
29762991}
29772992#endif /* _SOCK_H */
0 commit comments