All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Cc: Daniel Phillips <phillips@google.com>,
	Rik van Riel <riel@redhat.com>,
	David Miller <davem@davemloft.net>, Andrew Morton <akpm@osdl.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Mike Christie <michaelc@cs.wisc.edu>
Subject: [PATCH 16/21] iscsi: fixup of the ep_connect patch
Date: Wed, 06 Sep 2006 15:16:46 +0200	[thread overview]
Message-ID: <20060906133955.730919000@chello.nl> (raw)
In-Reply-To: 20060906131630.793619000@chello.nl

[-- Attachment #1: iscsi_ep_connect_fix.patch --]
[-- Type: text/plain, Size: 2592 bytes --]

Never hand out kernel pointers, and really never ever ask them back.
Also, iscsi_tcp_conn_bind expects it to be a valid file descriptor.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
CC: Mike Christie <michaelc@cs.wisc.edu>
---
 drivers/scsi/iscsi_tcp.c |   34 ++++++++++++++++++++++++++--------
 1 file changed, 26 insertions(+), 8 deletions(-)

Index: linux-2.6/drivers/scsi/iscsi_tcp.c
===================================================================
--- linux-2.6.orig/drivers/scsi/iscsi_tcp.c
+++ linux-2.6/drivers/scsi/iscsi_tcp.c
@@ -35,6 +35,8 @@
 #include <linux/kfifo.h>
 #include <linux/scatterlist.h>
 #include <linux/mutex.h>
+#include <linux/syscalls.h>
+#include <linux/file.h>
 #include <net/tcp.h>
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_host.h>
@@ -1773,7 +1775,10 @@ iscsi_tcp_ep_connect(struct sockaddr *ds
 		goto release_sock;
 	}
 
-	*ep_handle = (uint64_t)(unsigned long)sock;
+	rc = sock_map_fd(sock);
+	if (rc < 0)
+		goto release_sock;
+	*ep_handle = (uint64_t)rc;
 	return 0;
 
 release_sock:
@@ -1791,12 +1796,7 @@ iscsi_tcp_ep_poll(uint64_t ep_handle, in
 static void
 iscsi_tcp_ep_disconnect(uint64_t ep_handle)
 {
-	struct socket *sock;
-
-	sock = (struct socket *)(unsigned long)ep_handle;
-	if (!sock)
-		return;
-	sock_release(sock);
+	sys_close(ep_handle);
 }
 
 static struct iscsi_cls_conn *
@@ -1846,6 +1846,19 @@ tcp_conn_alloc_fail:
 }
 
 static void
+iscsi_tcp_release_conn(struct iscsi_conn *conn)
+{
+	struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
+
+	if (!tcp_conn->sock)
+		return;
+
+	fput(tcp_conn->sock->file);
+	tcp_conn->sock = NULL;
+	conn->recv_lock = NULL;
+}
+
+static void
 iscsi_tcp_conn_destroy(struct iscsi_cls_conn *cls_conn)
 {
 	struct iscsi_conn *conn = cls_conn->dd_data;
@@ -1855,6 +1868,7 @@ iscsi_tcp_conn_destroy(struct iscsi_cls_
 	if (conn->hdrdgst_en || conn->datadgst_en)
 		digest = 1;
 
+	iscsi_tcp_release_conn(conn);
 	iscsi_conn_teardown(cls_conn);
 
 	/* now free tcp_conn */
@@ -1875,6 +1889,7 @@ iscsi_tcp_conn_stop(struct iscsi_cls_con
 	struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
 
 	iscsi_conn_stop(cls_conn, flag);
+	iscsi_tcp_release_conn(conn);
 	tcp_conn->hdr_size = sizeof(struct iscsi_hdr);
 }
 
@@ -1895,10 +1910,13 @@ iscsi_tcp_conn_bind(struct iscsi_cls_ses
 		printk(KERN_ERR "iscsi_tcp: sockfd_lookup failed %d\n", err);
 		return -EEXIST;
 	}
+	get_file(sock->file);
 
 	err = iscsi_conn_bind(cls_session, cls_conn, is_leading);
-	if (err)
+	if (err) {
+		fput(sock->file);
 		return err;
+	}
 
 	/* bind iSCSI connection and socket */
 	tcp_conn->sock = sock;

--

WARNING: multiple messages have this Message-ID (diff)
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Cc: Daniel Phillips <phillips@google.com>,
	Rik van Riel <riel@redhat.com>,
	David Miller <davem@davemloft.net>, Andrew Morton <akpm@osdl.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Mike Christie <michaelc@cs.wisc.edu>
Subject: [PATCH 16/21] iscsi: fixup of the ep_connect patch
Date: Wed, 06 Sep 2006 15:16:46 +0200	[thread overview]
Message-ID: <20060906133955.730919000@chello.nl> (raw)
In-Reply-To: 20060906131630.793619000@chello.nl

[-- Attachment #1: iscsi_ep_connect_fix.patch --]
[-- Type: text/plain, Size: 2818 bytes --]

Never hand out kernel pointers, and really never ever ask them back.
Also, iscsi_tcp_conn_bind expects it to be a valid file descriptor.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
CC: Mike Christie <michaelc@cs.wisc.edu>
---
 drivers/scsi/iscsi_tcp.c |   34 ++++++++++++++++++++++++++--------
 1 file changed, 26 insertions(+), 8 deletions(-)

Index: linux-2.6/drivers/scsi/iscsi_tcp.c
===================================================================
--- linux-2.6.orig/drivers/scsi/iscsi_tcp.c
+++ linux-2.6/drivers/scsi/iscsi_tcp.c
@@ -35,6 +35,8 @@
 #include <linux/kfifo.h>
 #include <linux/scatterlist.h>
 #include <linux/mutex.h>
+#include <linux/syscalls.h>
+#include <linux/file.h>
 #include <net/tcp.h>
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_host.h>
@@ -1773,7 +1775,10 @@ iscsi_tcp_ep_connect(struct sockaddr *ds
 		goto release_sock;
 	}
 
-	*ep_handle = (uint64_t)(unsigned long)sock;
+	rc = sock_map_fd(sock);
+	if (rc < 0)
+		goto release_sock;
+	*ep_handle = (uint64_t)rc;
 	return 0;
 
 release_sock:
@@ -1791,12 +1796,7 @@ iscsi_tcp_ep_poll(uint64_t ep_handle, in
 static void
 iscsi_tcp_ep_disconnect(uint64_t ep_handle)
 {
-	struct socket *sock;
-
-	sock = (struct socket *)(unsigned long)ep_handle;
-	if (!sock)
-		return;
-	sock_release(sock);
+	sys_close(ep_handle);
 }
 
 static struct iscsi_cls_conn *
@@ -1846,6 +1846,19 @@ tcp_conn_alloc_fail:
 }
 
 static void
+iscsi_tcp_release_conn(struct iscsi_conn *conn)
+{
+	struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
+
+	if (!tcp_conn->sock)
+		return;
+
+	fput(tcp_conn->sock->file);
+	tcp_conn->sock = NULL;
+	conn->recv_lock = NULL;
+}
+
+static void
 iscsi_tcp_conn_destroy(struct iscsi_cls_conn *cls_conn)
 {
 	struct iscsi_conn *conn = cls_conn->dd_data;
@@ -1855,6 +1868,7 @@ iscsi_tcp_conn_destroy(struct iscsi_cls_
 	if (conn->hdrdgst_en || conn->datadgst_en)
 		digest = 1;
 
+	iscsi_tcp_release_conn(conn);
 	iscsi_conn_teardown(cls_conn);
 
 	/* now free tcp_conn */
@@ -1875,6 +1889,7 @@ iscsi_tcp_conn_stop(struct iscsi_cls_con
 	struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
 
 	iscsi_conn_stop(cls_conn, flag);
+	iscsi_tcp_release_conn(conn);
 	tcp_conn->hdr_size = sizeof(struct iscsi_hdr);
 }
 
@@ -1895,10 +1910,13 @@ iscsi_tcp_conn_bind(struct iscsi_cls_ses
 		printk(KERN_ERR "iscsi_tcp: sockfd_lookup failed %d\n", err);
 		return -EEXIST;
 	}
+	get_file(sock->file);
 
 	err = iscsi_conn_bind(cls_session, cls_conn, is_leading);
-	if (err)
+	if (err) {
+		fput(sock->file);
 		return err;
+	}
 
 	/* bind iSCSI connection and socket */
 	tcp_conn->sock = sock;

--

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2006-09-06 13:40 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-06 13:16 [PATCH 00/21] vm deadlock avoidance for NBD, NFS and iSCSI (take 6) Peter Zijlstra
2006-09-06 13:16 ` [PATCH 01/21] mm: serialize access to min_free_kbytes Peter Zijlstra
2006-09-06 13:16   ` Peter Zijlstra
2006-09-06 13:16 ` [PATCH 02/21] net: vm deadlock avoidance core Peter Zijlstra
2006-09-06 13:16   ` Peter Zijlstra
2006-09-06 13:16 ` [PATCH 03/21] mm: add support for non block device backed swap files Peter Zijlstra
2006-09-06 13:16   ` Peter Zijlstra
2006-09-06 13:16 ` [PATCH 04/21] mm: methods for teaching filesystems about PG_swapcache pages Peter Zijlstra
2006-09-06 13:16   ` Peter Zijlstra
2006-09-06 13:16 ` [PATCH 05/21] uml: rename arch/um remove_mapping() Peter Zijlstra
2006-09-06 13:16   ` Peter Zijlstra
2006-09-06 13:16 ` [PATCH 06/21] nfs: teach the NFS client how to treat PG_swapcache pages Peter Zijlstra
2006-09-06 13:16   ` Peter Zijlstra
2006-09-06 13:16 ` [PATCH 07/21] nfs: add a comment explaining the use of PG_private in the NFS client Peter Zijlstra
2006-09-06 13:16   ` Peter Zijlstra
2006-09-06 13:16 ` [PATCH 08/21] nfs: enable swap on NFS Peter Zijlstra
2006-09-06 13:16   ` Peter Zijlstra
2006-09-06 13:16 ` [PATCH 09/21] nfs: make swap on NFS robust Peter Zijlstra
2006-09-06 13:16   ` Peter Zijlstra
2006-09-06 13:16 ` [PATCH 10/21] block: elevator selection and pinning Peter Zijlstra
2006-09-06 13:16   ` Peter Zijlstra
2006-09-06 13:46   ` Jens Axboe
2006-09-06 13:46     ` Jens Axboe
2006-09-07 16:01     ` Peter Zijlstra
2006-09-07 16:01       ` Peter Zijlstra
2006-09-07 16:33       ` Jens Axboe
2006-09-07 16:33         ` Jens Axboe
2006-09-06 13:16 ` [PATCH 11/21] nbd: limit blk_queue Peter Zijlstra
2006-09-06 13:16   ` Peter Zijlstra
2006-09-06 15:17   ` Erik Mouw
2006-09-06 15:17     ` Erik Mouw
2006-09-06 17:45     ` Jens Axboe
2006-09-06 17:45       ` Jens Axboe
2006-09-06 13:16 ` [PATCH 12/21] mm: block device swap notification Peter Zijlstra
2006-09-06 13:16   ` Peter Zijlstra
2006-09-06 13:16 ` [PATCH 13/21] nbd: use swapdev hook to make swap deadlock free Peter Zijlstra
2006-09-06 13:16   ` Peter Zijlstra
2006-09-06 13:16 ` [PATCH 14/21] uml: enable scsi and add iscsi config Peter Zijlstra
2006-09-06 13:16   ` Peter Zijlstra
2006-09-11 15:49   ` Jeff Dike
2006-09-11 15:49     ` Jeff Dike
2006-09-06 13:16 ` [PATCH 15/21] iscsi: kernel side tcp connect Peter Zijlstra
2006-09-06 13:16   ` Peter Zijlstra
2006-09-06 13:16 ` Peter Zijlstra [this message]
2006-09-06 13:16   ` [PATCH 16/21] iscsi: fixup of the ep_connect patch Peter Zijlstra
2006-09-06 13:16 ` [PATCH 17/21] iscsi: add session context to ep_connect Peter Zijlstra
2006-09-06 13:16   ` Peter Zijlstra
2006-09-06 13:16 ` [PATCH 18/21] scsi: propagate the swapdev hook into the scsi stack Peter Zijlstra
2006-09-06 13:16   ` Peter Zijlstra
2006-09-06 13:16 ` [PATCH 19/21] netlink: add SOCK_VMIO support to AF_NETLINK Peter Zijlstra
2006-09-06 13:16   ` Peter Zijlstra
2006-09-06 13:16 ` [PATCH 20/21] mm: a process flags to avoid blocking allocations Peter Zijlstra
2006-09-06 13:16   ` Peter Zijlstra
2006-09-06 13:16 ` [PATCH 21/21] iscsi: support for swapping over iSCSI Peter Zijlstra
2006-09-06 13:16   ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060906133955.730919000@chello.nl \
    --to=a.p.zijlstra@chello.nl \
    --cc=akpm@osdl.org \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=michaelc@cs.wisc.edu \
    --cc=netdev@vger.kernel.org \
    --cc=phillips@google.com \
    --cc=riel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.