Skip to contentSkip to conversation

Avoid capable() call in UNIX buffer check unless necessary

PATCH Applied Dan Smith 3 participants 3 messages Nov 18, 2009 – Nov 25, 2009 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Dan Smith

author
#0 lore raw

PATCH 1/1 Avoid capable() call in UNIX buffer check unless necessary

As pointed out by Serge, we shouldn't call capable() unless we know we'll need to exercise the ability.

---
 net/unix/checkpoint.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
net/unix/checkpoint.c +10 -1
index 23040ce..55dfac1 100644
@@ -278,9 +278,18 @@ static int sock_read_buffer_sendmsg(struct ckpt_ctx *ctx,
 		unix_sk(sk)->peer->sk_shutdown &= ~SHUTDOWN_MASK;
 	}
 
-	/* Make sure there's room in the send buffer */
+	/* Make sure there's room in the send buffer: Worst case, we
+	 * give them the benefit of the doubt and set the buffer limit
+	 * to the system default.  This should cover the case where
+	 * the user set the limit low after loading up the buffer.
+	 *
+	 * However, if there isn't room in the buffer and the system
+	 * default won't accommodate them either, then increase the
+	 * limit as needed, only if they have CAP_NET_ADMIN.
+	 */
 	sndbuf = sk->sk_sndbuf;
 	if (((sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc)) < h->lin_len) &&
+	    (h->lin_len > sysctl_wmem_max) &&
 	    capable(CAP_NET_ADMIN))
 		sk->sk_sndbuf += h->lin_len;
 	else
Signature · 1 line
1.6.2.5

A message that is not in the archive (sent off-list or not yet received): 1258557477-28642-1-git-send-email-danms-r/[email protected]

#2 lore raw
Quoted 5 lines · Dan Smith

As pointed out by Serge, we shouldn't call capable() unless we know we'll need to exercise the ability.

thanks

Quoted 30 lines
---
 net/unix/checkpoint.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
net/unix/checkpoint.c +10 -1
index 23040ce..55dfac1 100644
@@ -278,9 +278,18 @@ static int sock_read_buffer_sendmsg(struct ckpt_ctx *ctx,
 		unix_sk(sk)->peer->sk_shutdown &= ~SHUTDOWN_MASK;
 	}
 
-	/* Make sure there's room in the send buffer */
+	/* Make sure there's room in the send buffer: Worst case, we
+	 * give them the benefit of the doubt and set the buffer limit
+	 * to the system default.  This should cover the case where
+	 * the user set the limit low after loading up the buffer.
+	 *
+	 * However, if there isn't room in the buffer and the system
+	 * default won't accommodate them either, then increase the
+	 * limit as needed, only if they have CAP_NET_ADMIN.
+	 */
 	sndbuf = sk->sk_sndbuf;
 	if (((sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc)) < h->lin_len) &&
+	    (h->lin_len > sysctl_wmem_max) &&
 	    capable(CAP_NET_ADMIN))
 		sk->sk_sndbuf += h->lin_len;
 	else
Signature · 1 line
1.6.2.5
Applied
#3 lore raw
In reply to a message not in the archive

Queued for v19-rc2, thanks.

Oren.

Quoted 33 lines · Dan Smith

As pointed out by Serge, we shouldn't call capable() unless we know we'll need to exercise the ability.

---
 net/unix/checkpoint.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
net/unix/checkpoint.c +10 -1
index 23040ce..55dfac1 100644
@@ -278,9 +278,18 @@ static int sock_read_buffer_sendmsg(struct ckpt_ctx *ctx,
 		unix_sk(sk)->peer->sk_shutdown &= ~SHUTDOWN_MASK;
 	}
 
-	/* Make sure there's room in the send buffer */
+	/* Make sure there's room in the send buffer: Worst case, we
+	 * give them the benefit of the doubt and set the buffer limit
+	 * to the system default.  This should cover the case where
+	 * the user set the limit low after loading up the buffer.
+	 *
+	 * However, if there isn't room in the buffer and the system
+	 * default won't accommodate them either, then increase the
+	 * limit as needed, only if they have CAP_NET_ADMIN.
+	 */
 	sndbuf = sk->sk_sndbuf;
 	if (((sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc)) < h->lin_len) &&
+	    (h->lin_len > sysctl_wmem_max) &&
 	    capable(CAP_NET_ADMIN))
 		sk->sk_sndbuf += h->lin_len;
 	else