[patch] staging: rtl8712: remove unneeded NULL check

2013-09-28 Thread Dan Carpenter
We knew "peventbuf" was a valid pointer and "peventbuf + 2" is also
non-NULL.  I have removed the check.

Signed-off-by: Dan Carpenter 

diff --git a/drivers/staging/rtl8712/rtl8712_cmd.c 
b/drivers/staging/rtl8712/rtl8712_cmd.c
index 088647c..53f247b 100644
--- a/drivers/staging/rtl8712/rtl8712_cmd.c
+++ b/drivers/staging/rtl8712/rtl8712_cmd.c
@@ -471,11 +471,9 @@ void r8712_event_handle(struct _adapter *padapter, uint 
*peventbuf)
if (pevt_priv->event_seq > 127)
pevt_priv->event_seq = 0;
peventbuf = peventbuf + 2; /* move to event content, 8 bytes alignment 
*/
-   if (peventbuf) {
-   event_callback = wlanevents[evt_code].event_callback;
-   if (event_callback)
-   event_callback(padapter, (u8 *)peventbuf);
-   }
+   event_callback = wlanevents[evt_code].event_callback;
+   if (event_callback)
+   event_callback(padapter, (u8 *)peventbuf);
pevt_priv->evt_done_cnt++;
 _abort_event_:
return;
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/1] staging: imx-drm: Remove redundant of_match_ptr

2013-09-28 Thread Sachin Kamat
'imx_ldb_dt_ids' is always compiled in. Hence of_match_ptr() is
not needed.

Signed-off-by: Sachin Kamat 
---
 drivers/staging/imx-drm/imx-ldb.c |3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/imx-drm/imx-ldb.c 
b/drivers/staging/imx-drm/imx-ldb.c
index b81ed41..926f493 100644
--- a/drivers/staging/imx-drm/imx-ldb.c
+++ b/drivers/staging/imx-drm/imx-ldb.c
@@ -466,8 +466,7 @@ static int imx_ldb_probe(struct platform_device *pdev)
 {
struct device_node *np = pdev->dev.of_node;
const struct of_device_id *of_id =
-   of_match_device(of_match_ptr(imx_ldb_dt_ids),
-   &pdev->dev);
+   of_match_device(imx_ldb_dt_ids, &pdev->dev);
struct device_node *child;
const u8 *edidp;
struct imx_ldb *imx_ldb;
-- 
1.7.9.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: Reworking dm-writeboost [was: Re: staging: Add dm-writeboost]

2013-09-28 Thread Akira Hayakawa
Hi,

Two major progress:
1) .ctr accepts segment size so .ctr now accepts 3 arguments:  
 .
2) fold the small files splitted that I suggested in the previous progress 
report.

For 1) 
I use zero length array to dynamically accept the segment size.
writeboost had the parameter embedded previously and one must re-compile the 
code
to change the parameter which badly loses usability was the problem.

For 2)
> Unfortunately I think you went too far with all these different small
> files, I was hoping to see 2 or 3 .c files and a couple .h files.
> 
> Maybe fold all the daemon code into a 1 .c and 1 .h ?
> 
> The core of the writeboost target in dm-writeboost-target.c ?
> 
> And fold all the other data structures into a 1 .c and 1 .h ?
> 
> When folding these files together feel free to use dividers in the code
> like dm-thin.c and dm-cache-target.c do, e.g.:
> 
> /*-*/
As Mike pointed out splitting into almost 20 files went too far.
I aggregated these files into 3 .c files and 3 .h files in total which are 
shown below.

-- Summary --
39 dm-writeboost-daemon.h
46 dm-writeboost-metadata.h
413 dm-writeboost.h
577 dm-writeboost-daemon.c
1129 dm-writeboost-metadata.c
1212 dm-writeboost-target.c
81 dm-writeboost.mod.c

The responsibilities of each .c file
is the policy of this splitting.

a) dm-writeboost-metadata.c
This file knows how the metadata is laid out on cache device.
It can audit/format the cache device metadata
and resume/free the in-core cache metadata from that on the cache device.
Also provides accessor to the in-core metadata resumed.

b) dm-writeboost-target.c
This file contains all the methods to define target type.
In terms of I/O processing, this files only defines
from when bio is accepted to when flush job is queued
which is described as "foreground processing" in the document.
What happens after the job is queued is defined in -daemon.c file.

c) dm-writeboost-daemon.c
This file contains all the daemons as Mike suggested.
Maybe, superblock_recorder should be in the -metadata.c file
but I chose to put it on this file since for unity.

Thanks,
Akira


followed by the current .h files.

-- dm-writeboost-daemon.h --
/*
 * Copyright (C) 2012-2013 Akira Hayakawa 
 *
 * This file is released under the GPL.
 */

#ifndef DM_WRITEBOOST_DAEMON_H
#define DM_WRITEBOOST_DAEMON_H

/**/

void flush_proc(struct work_struct *);

/**/

void queue_barrier_io(struct wb_cache *, struct bio *);
void barrier_deadline_proc(unsigned long data);
void flush_barrier_ios(struct work_struct *);

/**/

void migrate_proc(struct work_struct *);
void wait_for_migration(struct wb_cache *, u64 id);

/**/

void modulator_proc(struct work_struct *);

/**/

void sync_proc(struct work_struct *);

/**/

void recorder_proc(struct work_struct *);

/**/

#endif

-- dm-writeboost-metadata.h --
/*
 * Copyright (C) 2012-2013 Akira Hayakawa 
 *
 * This file is released under the GPL.
 */

#ifndef DM_WRITEBOOST_METADATA_H
#define DM_WRITEBOOST_METADATA_H

/**/

struct segment_header *get_segment_header_by_id(struct wb_cache *, u64 
segment_id);
sector_t calc_mb_start_sector(struct wb_cache *, struct segment_header *, 
cache_nr mb_idx);
bool is_on_buffer(struct wb_cache *, cache_nr mb_idx);

/**/

struct ht_head *ht_get_head(struct wb_cache *, struct lookup_key *);
struct metablock *ht_lookup(struct wb_cache *,
struct ht_head *, struct lookup_key *);
void ht_register(struct wb_cache *, struct ht_head *,
 struct lookup_key *, struct metablock *);
void ht_del(struct wb_cache *, struct metablock *);
void discard_caches_inseg(struct wb_cache *,
  struct segment_header *);

/**/

int __must_check audit_cache_device(struct dm_dev *, struct wb_cache *,
bool *need_format, bool *allow_format);
int __must_check format_cache_device(struct dm_dev *, struct wb_cache *);

/**/

void prepare_segment_header_device(struct segment_header_device *dest,
   struct wb_cache *,
   struct segment_header *src);

/**/

int __must_check resu

Re: [PATCHv2 0/11] staging: usbip: Userland crypto and ACLs

2013-09-28 Thread Dominik Paulus
On Wed, Sep 25, 2013 at 04:36:38PM -0700, Greg Kroah-Hartman wrote:
> Only the first patch could be applied. Can you refresh this series, and
> your other one (fixing the issues pointed out there), and resend them
> please?

We've incorporated all of Dan's fixes and suggestions and rebased the
whole series on staging-next.
We left the protocol version at 0x111, since the code is backwards
compatible with current linux-linus if encryption is disabled.
After reading "NIST Special Publication 800-38D" Appendix C we got some
doubts about the security of our usage of gcm with short (4 bytes) tags,
so we incremented USBIP_AUTHSIZE to 16, just to be safe.

Thanks,
Tobias and Dominik
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCHv3 04/16] staging: usbip: Add ACL support to usbip bind

2013-09-28 Thread Dominik Paulus
Add the command line argument -a (--allow) to usbip bind to specify
networks allowed to attach to the device and code to store the ACLs in
sysfs.

Signed-off-by: Kurt Kanzenbach 
Signed-off-by: Dominik Paulus 
Signed-off-by: Tobias Polzer 
---
 drivers/staging/usbip/userspace/doc/usbip.8  |  8 ++-
 drivers/staging/usbip/userspace/src/usbip_bind.c | 74 
 2 files changed, 69 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/usbip/userspace/doc/usbip.8 
b/drivers/staging/usbip/userspace/doc/usbip.8
index 847aa40..c7ba36f 100644
--- a/drivers/staging/usbip/userspace/doc/usbip.8
+++ b/drivers/staging/usbip/userspace/doc/usbip.8
@@ -60,9 +60,15 @@ Detach an imported USB device.
 .PP
 
 .HP
-\fBbind\fR \-\-busid=<\fIbusid\fR>
+\fBbind\fR \-\-busid=<\fIbusid\fR> [\-\-allow=<\fICIDR mask\fR>...]
 .IP
 Make a device exportable.
+.br
+\-\-allow accepts CIDR masks like 127.0.0.0/8 or fd00::/64
+.br
+Only hosts in (at least) one of the allowed ranges are accepted. If
+\-\-allow is omitted, 0.0.0.0/0 and ::/0 are added to the list. The list can
+be read/written from corresponding \fBusbip_acl\fR file in sysfs after bind.
 .PP
 
 .HP
diff --git a/drivers/staging/usbip/userspace/src/usbip_bind.c 
b/drivers/staging/usbip/userspace/src/usbip_bind.c
index 9ecaf6e..d2739fc 100644
--- a/drivers/staging/usbip/userspace/src/usbip_bind.c
+++ b/drivers/staging/usbip/userspace/src/usbip_bind.c
@@ -37,8 +37,9 @@ enum unbind_status {
 
 static const char usbip_bind_usage_string[] =
"usbip bind \n"
-   "-b, --busid=Bind " USBIP_HOST_DRV_NAME ".ko to device "
-   "on \n";
+   "-b, --busid=Bind " USBIP_HOST_DRV_NAME ".ko to "
+   "device on \n"
+   "-a, --allow=Restrict device access to \n";
 
 void usbip_bind_usage(void)
 {
@@ -46,17 +47,19 @@ void usbip_bind_usage(void)
 }
 
 /* call at unbound state */
-static int bind_usbip(char *busid)
+static int bind_usbip(char *busid, char *allow)
 {
char bus_type[] = "usb";
char attr_name[] = "bind";
char sysfs_mntpath[SYSFS_PATH_MAX];
char bind_attr_path[SYSFS_PATH_MAX];
char intf_busid[SYSFS_BUS_ID_SIZE];
+   char ip_attr_path[SYSFS_PATH_MAX];
struct sysfs_device *busid_dev;
struct sysfs_attribute *bind_attr;
struct sysfs_attribute *bConfValue;
struct sysfs_attribute *bNumIntfs;
+   struct sysfs_attribute *usbip_ip;
int i, failed = 0;
int rc, ret = -1;
 
@@ -101,8 +104,32 @@ static int bind_usbip(char *busid)
dbg("bind driver at %s failed", intf_busid);
failed = 1;
}
+
+   }
+
+   /*
+* store allowed IP ranges
+* specified by `usbip bind -b  --allow `
+*/
+   snprintf(ip_attr_path, sizeof(ip_attr_path),
+   "%s/%s/%s/%s/%s/%s:%.1s.%d/%s",
+   sysfs_mntpath, SYSFS_BUS_NAME, bus_type,
+   SYSFS_DRIVERS_NAME, USBIP_HOST_DRV_NAME, busid,
+   bConfValue->value, 0, "usbip_acl");
+
+   usbip_ip = sysfs_open_attribute(ip_attr_path);
+   if (!usbip_ip) {
+   err("sysfs_open_attribute failed: path=%s",
+   ip_attr_path);
+   goto err_close_busid_dev;
}
 
+   rc = sysfs_write_attribute(usbip_ip, allow, strlen(allow));
+   if (rc)
+   err("sysfs_write_attribute failed");
+
+   sysfs_close_attribute(usbip_ip);
+
if (!failed)
ret = 0;
 
@@ -213,7 +240,7 @@ out:
return status;
 }
 
-static int bind_device(char *busid)
+static int bind_device(char *busid, char *allow)
 {
int rc;
 
@@ -233,7 +260,7 @@ static int bind_device(char *busid)
return -1;
}
 
-   rc = bind_usbip(busid);
+   rc = bind_usbip(busid, allow);
if (rc < 0) {
err("could not bind device to %s", USBIP_HOST_DRV_NAME);
modify_match_busid(busid, 0);
@@ -249,29 +276,52 @@ int usbip_bind(int argc, char *argv[])
 {
static const struct option opts[] = {
{ "busid", required_argument, NULL, 'b' },
+   { "allow", required_argument, NULL, 'a' },
{ NULL,0, NULL,  0  }
};
 
-   int opt;
-   int ret = -1;
+   int opt, rc;
+   char allow[4096];
+   char *device = NULL;
+   struct subnet subnet;
+
+   allow[0] = 0;
 
for (;;) {
-   opt = getopt_long(argc, argv, "b:", opts, NULL);
+   opt = getopt_long(argc, argv, "a:b:", opts, NULL);
 
if (opt == -1)
break;
 
switch (opt) {
+   case 'a':
+   rc = parse_cidr(optarg, &subnet);
+   if (rc < 0) {
+   err("Invalid subnet specified: %s", optarg);
+   go

[PATCHv3 02/16] staging: usbip: Add kernel support for client ACLs

2013-09-28 Thread Dominik Paulus
This patch adds the possibility to stored ACLs for allowed clients for
each stub device in sysfs. It adds a new sysfs entry called "usbip_acl"
for each stub device, containing a list of CIDR masks of allowed
clients. This file will be used by usbip and usbipd to store the ACL.

Signed-off-by: Kurt Kanzenbach 
Signed-off-by: Dominik Paulus 
Signed-off-by: Tobias Polzer 
---
 drivers/staging/usbip/stub.h |  5 +++
 drivers/staging/usbip/stub_dev.c | 68 +++-
 2 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/usbip/stub.h b/drivers/staging/usbip/stub.h
index a73e437..cfe75d1 100644
--- a/drivers/staging/usbip/stub.h
+++ b/drivers/staging/usbip/stub.h
@@ -60,6 +60,11 @@ struct stub_device {
struct list_head unlink_free;
 
wait_queue_head_t tx_waitq;
+
+   /* list of allowed IP addrs */
+   char *acls;
+   /* for locking list operations */
+   spinlock_t ip_lock;
 };
 
 /* private data into urb->priv */
diff --git a/drivers/staging/usbip/stub_dev.c b/drivers/staging/usbip/stub_dev.c
index 76a1ff0..3939b60 100644
--- a/drivers/staging/usbip/stub_dev.c
+++ b/drivers/staging/usbip/stub_dev.c
@@ -142,6 +142,62 @@ err:
 }
 static DEVICE_ATTR(usbip_sockfd, S_IWUSR, NULL, store_sockfd);
 
+/*
+ * This function replaces the current ACL list
+ */
+static ssize_t store_acl(struct device *dev, struct device_attribute *attr,
+   const char *buf, size_t count)
+{
+   struct stub_device *sdev = dev_get_drvdata(dev);
+   int retval = 0;
+
+   if (!sdev)
+   return -ENODEV;
+
+   if (count >= PAGE_SIZE)
+   /* Prevent storing oversized ACLs in kernel memory */
+   return -EINVAL;
+
+   /* Store ACL */
+   spin_lock_irq(&sdev->ip_lock);
+   kfree(sdev->acls);
+   sdev->acls = kstrdup(buf, GFP_KERNEL);
+   if (IS_ERR(sdev->acls)) {
+   retval = PTR_ERR(sdev->acls);
+   sdev->acls = NULL;
+   } else {
+   retval = strlen(sdev->acls);
+   }
+   spin_unlock_irq(&sdev->ip_lock);
+
+   return retval;
+}
+
+/*
+ * This functions prints all allowed IP addrs for this dev
+ */
+static ssize_t show_acl(struct device *dev, struct device_attribute *attr,
+  char *buf)
+{
+   struct stub_device *sdev = dev_get_drvdata(dev);
+   int retval = 0;
+
+   if (!sdev)
+   return -ENODEV;
+
+   spin_lock_irq(&sdev->ip_lock);
+   if (sdev->acls == NULL) {
+   retval = 0;
+   } else {
+   strcpy(buf, sdev->acls);
+   retval = strlen(buf);
+   }
+   spin_unlock_irq(&sdev->ip_lock);
+
+   return retval;
+}
+static DEVICE_ATTR(usbip_acl, S_IWUSR | S_IRUGO, show_acl, store_acl);
+
 static int stub_add_files(struct device *dev)
 {
int err = 0;
@@ -157,9 +213,13 @@ static int stub_add_files(struct device *dev)
err = device_create_file(dev, &dev_attr_usbip_debug);
if (err)
goto err_debug;
+   err = device_create_file(dev, &dev_attr_usbip_acl);
+   if (err)
+   goto err_ip;
 
return 0;
-
+err_ip:
+   device_remove_file(dev, &dev_attr_usbip_debug);
 err_debug:
device_remove_file(dev, &dev_attr_usbip_sockfd);
 err_sockfd:
@@ -173,6 +233,7 @@ static void stub_remove_files(struct device *dev)
device_remove_file(dev, &dev_attr_usbip_status);
device_remove_file(dev, &dev_attr_usbip_sockfd);
device_remove_file(dev, &dev_attr_usbip_debug);
+   device_remove_file(dev, &dev_attr_usbip_acl);
 }
 
 static void stub_shutdown_connection(struct usbip_device *ud)
@@ -306,12 +367,14 @@ static struct stub_device *stub_device_alloc(struct 
usb_device *udev,
sdev->ud.status = SDEV_ST_AVAILABLE;
spin_lock_init(&sdev->ud.lock);
sdev->ud.tcp_socket = NULL;
+   sdev->acls = NULL;
 
INIT_LIST_HEAD(&sdev->priv_init);
INIT_LIST_HEAD(&sdev->priv_tx);
INIT_LIST_HEAD(&sdev->priv_free);
INIT_LIST_HEAD(&sdev->unlink_free);
INIT_LIST_HEAD(&sdev->unlink_tx);
+   spin_lock_init(&sdev->ip_lock);
spin_lock_init(&sdev->priv_lock);
 
init_waitqueue_head(&sdev->tx_waitq);
@@ -511,6 +574,9 @@ static void stub_disconnect(struct usb_interface *interface)
usb_put_dev(sdev->udev);
usb_put_intf(interface);
 
+   /* free ACL list */
+   kfree(sdev->acls);
+
/* free sdev */
busid_priv->sdev = NULL;
stub_device_free(sdev);
-- 
1.8.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCHv3 01/16] staging: usbip: Add support for client authentication

2013-09-28 Thread Dominik Paulus
This patch adds support for authenticating both client and server using
a pre-shared passphrase using SRP (Secure Remote Password) over TLS (see
RFC 5054) using GnuTLS. Both usbip and usbipd now accept a shared secret
as a command line argument. Currently, the established TLS connection is
only used to perform a secure handshake and dropped before the socket is
passed to the kernel. The code may be extended to exchange a session key
over TLS and pass it to the kernel to perform IPsec.

Signed-off-by: Dominik Paulus 
Signed-off-by: Tobias Polzer 
---
 drivers/staging/usbip/userspace/configure.ac   |  14 ++
 drivers/staging/usbip/userspace/doc/usbip.8|   4 +
 drivers/staging/usbip/userspace/doc/usbipd.8   |   5 +
 drivers/staging/usbip/userspace/src/usbip.c|  30 ++-
 drivers/staging/usbip/userspace/src/usbip_attach.c |   2 +-
 drivers/staging/usbip/userspace/src/usbip_list.c   |   2 +-
 .../staging/usbip/userspace/src/usbip_network.c|  81 
 .../staging/usbip/userspace/src/usbip_network.h|   9 +-
 drivers/staging/usbip/userspace/src/usbipd.c   | 217 ++---
 9 files changed, 331 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/usbip/userspace/configure.ac 
b/drivers/staging/usbip/userspace/configure.ac
index 0ee5d92..2208516 100644
--- a/drivers/staging/usbip/userspace/configure.ac
+++ b/drivers/staging/usbip/userspace/configure.ac
@@ -83,6 +83,20 @@ AC_ARG_WITH([tcp-wrappers],
AC_DEFINE([HAVE_LIBWRAP], [1], [use tcp wrapper])],
   [AC_MSG_RESULT([no]); LIBS="$saved_LIBS"])])
 
+# Checks for the GnuTLS library
+AC_ARG_WITH([gnutls],
+   [AS_HELP_STRING([--with-gnutls],
+   [use the GnuTLS library 
for authentication])],
+   dnl [ACTION-IF-GIVEN]
+   [if test "$withval" = "yes"; then
+PKG_CHECK_MODULES([GNUTLS], [gnutls])
+AC_DEFINE([HAVE_GNUTLS], [1], [use gnutls])
+CFLAGS="$CFLAGS $GNUTLS_CFLAGS"
+LDFLAGS="$LDFLAGS $GNUTLS_LIBS"
+fi
+   ],
+   )
+
 # Sets directory containing usb.ids.
 AC_ARG_WITH([usbids-dir],
[AS_HELP_STRING([--with-usbids-dir=DIR],
diff --git a/drivers/staging/usbip/userspace/doc/usbip.8 
b/drivers/staging/usbip/userspace/doc/usbip.8
index a6097be..847aa40 100644
--- a/drivers/staging/usbip/userspace/doc/usbip.8
+++ b/drivers/staging/usbip/userspace/doc/usbip.8
@@ -27,6 +27,10 @@ Log to syslog.
 \fB\-\-tcp-port PORT\fR
 .IP
 Connect to PORT on remote host (used for attach and list --remote).
+
+\fB\-\-auth\fR
+.IP
+Set the password to be used for client authentication. See usbipd(8) for more 
information.
 .PP
 
 .SH COMMANDS
diff --git a/drivers/staging/usbip/userspace/doc/usbipd.8 
b/drivers/staging/usbip/userspace/doc/usbipd.8
index ac4635d..8beb95a 100644
--- a/drivers/staging/usbip/userspace/doc/usbipd.8
+++ b/drivers/staging/usbip/userspace/doc/usbipd.8
@@ -52,6 +52,11 @@ If no FILE specified, use /var/run/usbipd.pid
 \fB\-tPORT\fR, \fB\-\-tcp\-port PORT\fR
 .IP
 Listen on TCP/IP port PORT.
+
+.HP
+\fB\-s\fR, \fB\-\-auth\fR
+.IP
+Sets the password to be used for client authentication. If -a is used, the 
server will only accept connections from authenticated clients. Note: USB 
traffic will still be unencrypted, this currently only serves for 
authentication.
 .PP
 
 \fB\-h\fR, \fB\-\-help\fR
diff --git a/drivers/staging/usbip/userspace/src/usbip.c 
b/drivers/staging/usbip/userspace/src/usbip.c
index 04a5f20..8a5de83 100644
--- a/drivers/staging/usbip/userspace/src/usbip.c
+++ b/drivers/staging/usbip/userspace/src/usbip.c
@@ -25,6 +25,12 @@
 #include 
 #include 
 
+#include "../config.h"
+
+#ifdef HAVE_GNUTLS
+#include 
+#endif
+
 #include "usbip_common.h"
 #include "usbip_network.h"
 #include "usbip.h"
@@ -35,8 +41,12 @@ static int usbip_version(int argc, char *argv[]);
 static const char usbip_version_string[] = PACKAGE_STRING;
 
 static const char usbip_usage_string[] =
-   "usbip [--debug] [--log] [--tcp-port PORT] [version]\n"
-   " [help]  \n";
+   "usbip "
+#ifdef HAVE_GNUTLS
+   "[--auth PASSWORD] "
+#endif
+   "[--debug] [--log] [--tcp-port PORT]\n"
+   " [version] [help]  \n";
 
 static void usbip_usage(void)
 {
@@ -142,6 +152,7 @@ int main(int argc, char *argv[])
{ "debug",no_argument,   NULL, 'd' },
{ "log",  no_argument,   NULL, 'l' },
{ "tcp-port", required_argument, NULL, 't' },
+   { "auth", required_argument, NULL, 's' },
{ NULL,   0, NULL,  0  }
};
 
@@ -152,12 +163,25 @@ int main(int argc, char *argv[])
usbip_use_stderr = 1;
opterr = 0;
for (;;) {
-   opt = getopt_long(argc, argv, "+dl

[PATCHv3 03/16] staging: usbip: Add CIDR matching helper functions

2013-09-28 Thread Dominik Paulus
This patch adds a few utility functions to match IP addresses against
CIDR masks.

Signed-off-by: Dominik Paulus 
Signed-off-by: Tobias Polzer 
---
 drivers/staging/usbip/userspace/src/utils.c | 84 +
 drivers/staging/usbip/userspace/src/utils.h | 15 ++
 2 files changed, 99 insertions(+)

diff --git a/drivers/staging/usbip/userspace/src/utils.c 
b/drivers/staging/usbip/userspace/src/utils.c
index 2d4966e..df40817 100644
--- a/drivers/staging/usbip/userspace/src/utils.c
+++ b/drivers/staging/usbip/userspace/src/utils.c
@@ -74,3 +74,87 @@ int modify_match_busid(char *busid, int add)
 
return ret;
 }
+
+/*
+ * Parses a string of form "ip/prefix" into a subnet mask to dest.
+ * Returns -1 on error, 0 on success
+ */
+int parse_cidr(const char *src, struct subnet *dest)
+{
+   char *ip, *prefix, *saveptr;
+   char *endptr;
+   struct in6_addr ip6;
+   struct in_addr ip4;
+   int bits;
+   long int tmp;
+   char buf[128]; /* For strtok */
+
+   strncpy(buf, src, sizeof(buf));
+   buf[sizeof(buf)-1] = 0;
+
+   ip = strtok_r(buf, "/", &saveptr);
+   prefix = strtok_r(NULL, "/", &saveptr);
+   if (strtok_r(NULL, "/", &saveptr) || !ip ||
+   strlen(src) > sizeof(buf) - 1)
+   return -1;
+
+   if (inet_pton(AF_INET6, ip, &ip6) == 1) {
+   dest->ai_family = AF_INET6;
+   bits = 128;
+   dest->address.ip6 = ip6;
+   } else if (inet_pton(AF_INET, ip, &ip4) == 1) {
+   dest->ai_family = AF_INET;
+   bits = 32;
+   dest->address.ip4 = ip4;
+   } else {
+   return -1;
+   }
+
+   /*
+* We also accept single IPs without an explicitely
+* specified prefix
+*/
+   if (prefix) {
+   tmp = strtol(prefix, &endptr, 10);
+   if (tmp < 0 || tmp > bits || *endptr != '\0')
+   return -1;
+   dest->prefix = tmp;
+   } else {
+   dest->prefix = bits;
+   }
+
+   return 0;
+}
+
+/*
+ * Checks if addr is in range. Expects addr to be a struct in6_addr* if
+ * ai_family == AF_INET6, else struct in_addr*.
+ * Returns 1 if in range, 0 otherwise.
+ */
+int in_range(struct sockaddr_storage *addr, struct subnet range)
+{
+   if (addr->ss_family != range.ai_family)
+   return 0;
+   if (addr->ss_family == AF_INET6) {
+   int i;
+   struct sockaddr_in6 *in6addr = (struct sockaddr_in6 *) addr;
+   unsigned char *ip = in6addr->sin6_addr.s6_addr;
+   for (i = 0; i < range.prefix; ++i) {
+   int idx = i/8, mask = 1 << (7 - i%8);
+   if ((ip[idx] & mask) != (range.address.ip6.s6_addr[idx]
+ & mask))
+   return 0;
+   }
+   } else {
+   int i;
+   struct sockaddr_in *inaddr = (struct sockaddr_in *) addr;
+   uint32_t ip = ntohl(inaddr->sin_addr.s_addr);
+   uint32_t comp = ntohl(range.address.ip4.s_addr);
+   for (i = 0; i < range.prefix; ++i) {
+   int mask = 1 << (31-i);
+   if ((ip & mask) != (comp & mask))
+   return 0;
+   }
+   }
+   return 1;
+}
diff --git a/drivers/staging/usbip/userspace/src/utils.h 
b/drivers/staging/usbip/userspace/src/utils.h
index 5916fd3..a3704ef 100644
--- a/drivers/staging/usbip/userspace/src/utils.h
+++ b/drivers/staging/usbip/userspace/src/utils.h
@@ -19,7 +19,22 @@
 #ifndef __UTILS_H
 #define __UTILS_H
 
+#include 
+#include 
+#include 
+
+struct subnet {
+   int ai_family;
+   int prefix;
+   union {
+   struct in6_addr ip6;
+   struct in_addr ip4;
+   } address;
+};
+
 int modify_match_busid(char *busid, int add);
+int parse_cidr(const char *src, struct subnet *dest);
+int in_range(struct sockaddr_storage *addr, struct subnet range);
 
 #endif /* __UTILS_H */
 
-- 
1.8.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCHv3 15/16] staging: usbip: Update documentation

2013-09-28 Thread Dominik Paulus
From: Tobias Polzer 

README was updated and cleaned. It now contains just one example, which
was updated to use encryption. Also, the new crypto behaviour is
documented. The usbip "port" command has been removed from the README,
as it isn't supported by newer userland versions. One dead link was
removed from the checklist section.

Signed-off-by: Tobias Polzer 
Signed-off-by: Dominik Paulus 
---
 drivers/staging/usbip/userspace/README   | 72 +++-
 drivers/staging/usbip/userspace/doc/usbipd.8 |  4 +-
 2 files changed, 31 insertions(+), 45 deletions(-)

diff --git a/drivers/staging/usbip/userspace/README 
b/drivers/staging/usbip/userspace/README
index 00a1658..01ea616 100644
--- a/drivers/staging/usbip/userspace/README
+++ b/drivers/staging/usbip/userspace/README
@@ -12,56 +12,53 @@
 - sysfsutils >= 2.0.0
sysfsutils library
 
-- libwrap0-dev
+- libwrap0-dev (optional)
tcp wrapper library
 
 - gcc >= 4.0
 
 - libtool, automake >= 1.9, autoconf >= 2.5.0, pkg-config
 
+- libgnutls-dev >= 3.0 (libgnutls28-dev on debian) (optional)
+
 
 [Install]
 0. Generate configuration scripts.
$ ./autogen.sh
 
 1. Compile & install the userspace utilities.
-   $ ./configure [--with-tcp-wrappers=no] [--with-usbids-dir=]
+   $ ./configure [--with-tcp-wrappers=no] [--with-usbids-dir=] 
[--with-gnutls]
$ make install
 
 2. Compile & install USB/IP drivers.
 
 
 [Usage]
-server:# (Physically attach your USB device.)
-
-server:# insmod usbip-core.ko
-server:# insmod usbip-host.ko
-
-server:# usbipd -D
-   - Start usbip daemon.
-
-server:# usbip list -l
-   - List driver assignments for USB devices.
 
-server:# usbip bind --busid 1-2
-   - Bind usbip-host.ko to the device with busid 1-2.
-   - The USB device 1-2 is now exportable to other hosts!
-   - Use `usbip unbind --busid 1-2' to stop exporting the device.
+See usbip(8) and usbipd(8).
 
-client:# insmod usbip-core.ko
-client:# insmod vhci-hcd.ko
+[Security considerations]
+By default, all of the usbip network traffic is unencrypted and
+unauthenticated. As it is mostly parsed in staging quality kernel code, you
+should use usbip in this mode only in absolutely trusted environments.
 
-client:# usbip list --remote 
-   - List exported USB devices on the .
+In addition to the usual methods for secure network tunneling - SSH tunnels,
+IPsec, etc. -, usbip version 1.2.1 supports out-of-the-box crypto for all of
+the network traffic. This requires usbip to be compiled with GnuTLS enabled
+(configure switch: --with-gnutls). Crypto support can be enabled by using
+password authentication. If the --auth flag is set, usbip will not only
+authenticate client and server using the shared passphrase, but also encrypt
+and authenticate all of the following traffic. For the userspace traffic,
+GnuTLS is used, the kernel traffic is encrypted and authenticated using AES-GCM
+with 128bit keys. The session keys are randomly generated and exchanged for
+in userspace for each connection.
 
-client:# usbip attach --remote  --busid 1-2
-   - Connect the remote USB device.
-
-client:# usbip port
-   - Show virtual port status.
-
-client:# usbip detach --port 
-   - Detach the USB device.
+The encryption support has been designed to offer perfect forward secrecy and
+decent security even if using rather weak passwords. Strong passwords are
+mainly needed to provide proper authorization (this is still important, see
+above!) and to secure against man-in-the-middle attacks.
+However, the crypto code still lacks complete review and code auditing. Do not
+rely on it for strong security.
 
 
 [Example]
@@ -72,7 +69,7 @@ Physically attach your USB devices to this host.
 
 trois:# insmod path/to/usbip-core.ko
 trois:# insmod path/to/usbip-host.ko
-trois:# usbipd -D
+trois:# usbipd -sVerySecret -D
 
 In another terminal, let's look up what USB devices are physically
 attached to this host.
@@ -135,7 +132,7 @@ exportable on the host.
 deux:# insmod path/to/usbip-core.ko
 deux:# insmod path/to/vhci-hcd.ko
 
-deux:# usbip list --remote 10.0.0.3
+deux:# usbip --auth VerySecret list --remote 10.0.0.3
 Exportable USB devices
 ==
  - 10.0.0.3
@@ -163,20 +160,9 @@ exportable on the host.
 
 Attach a remote USB device:
 
-deux:# usbip attach --remote 10.0.0.3 --busid 1-1
+deux:# usbip --auth VerySecret attach --remote 10.0.0.3 --busid 1-1
 port 0 attached
 
-Show the devices attached to this client:
-
-deux:# usbip port
-Port 00:  at Full Speed(12Mbps)
-  Prolific Technology, Inc. : unknown product (067b:3507)
-  6-1 -> usbip://10.0.0.3:3240/1-1  (remote bus/dev 001/004)
-  6-1:1.0 used by usb-storage
- /sys/class/scsi_device/0:0:0:0/device
- /sys/class/scsi_host/host0/device
-  

[PATCHv3 14/16] staging: usbip: Add encryption support to kernel

2013-09-28 Thread Dominik Paulus
This adds code performing the actual encryption and authentication
operations in the usbip kernel code. The whole data stream may now be
encrypted and authenticated with AES-GCM and symmetric 128 bit keys.

Signed-off-by: Dominik Paulus 
Signed-off-by: Tobias Polzer 
---
 drivers/staging/usbip/Kconfig|   2 +-
 drivers/staging/usbip/stub.h |   3 +
 drivers/staging/usbip/stub_dev.c |   8 +
 drivers/staging/usbip/usbip_common.c | 351 ++-
 drivers/staging/usbip/usbip_common.h |  22 +++
 drivers/staging/usbip/vhci_hcd.c |   4 +-
 drivers/staging/usbip/vhci_sysfs.c   |  10 +
 7 files changed, 396 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/usbip/Kconfig b/drivers/staging/usbip/Kconfig
index 8860009..87220af 100644
--- a/drivers/staging/usbip/Kconfig
+++ b/drivers/staging/usbip/Kconfig
@@ -1,6 +1,6 @@
 config USBIP_CORE
tristate "USB/IP support"
-   depends on USB && NET
+   depends on USB && NET && CRYPTO_GCM && CRYPTO_AES
default N
---help---
  This enables pushing USB packets over IP to allow remote
diff --git a/drivers/staging/usbip/stub.h b/drivers/staging/usbip/stub.h
index cfe75d1..2aaea3a 100644
--- a/drivers/staging/usbip/stub.h
+++ b/drivers/staging/usbip/stub.h
@@ -26,6 +26,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 #define STUB_BUSID_OTHER 0
 #define STUB_BUSID_REMOV 1
diff --git a/drivers/staging/usbip/stub_dev.c b/drivers/staging/usbip/stub_dev.c
index 0082912..45db24e 100644
--- a/drivers/staging/usbip/stub_dev.c
+++ b/drivers/staging/usbip/stub_dev.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "usbip_common.h"
 #include "stub.h"
@@ -137,6 +138,12 @@ static ssize_t store_sockfd(struct device *dev, struct 
device_attribute *attr,
 
spin_unlock_irq(&sdev->ud.lock);
 
+   if (sdev->ud.use_crypto) {
+   err = usbip_init_crypto(&sdev->ud, sendkey, recvkey);
+   if (err < 0)
+   goto err;
+   }
+
sdev->ud.tcp_rx = kthread_get_run(stub_rx_loop, &sdev->ud,
  "stub_rx");
sdev->ud.tcp_tx = kthread_get_run(stub_tx_loop, &sdev->ud,
@@ -298,6 +305,7 @@ static void stub_shutdown_connection(struct usbip_device 
*ud)
}
 
/* 3. free used data */
+   usbip_deinit_crypto(ud);
stub_device_cleanup_urbs(sdev);
 
/* 4. free stub_unlink */
diff --git a/drivers/staging/usbip/usbip_common.c 
b/drivers/staging/usbip/usbip_common.c
index 83ec279..58106bc 100644
--- a/drivers/staging/usbip/usbip_common.c
+++ b/drivers/staging/usbip/usbip_common.c
@@ -26,6 +26,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include "usbip_common.h"
 
@@ -626,17 +628,362 @@ static void usbip_pack_iso(struct 
usbip_iso_packet_descriptor *iso,
}
 }
 
+int usbip_init_crypto(struct usbip_device *ud, unsigned char *sendkey, unsigned
+   char *recvkey)
+{
+   int ret;
+
+   ud->use_crypto = 1;
+
+   ud->tfm_recv = crypto_alloc_aead("gcm(aes)", 0, 0);
+   if (IS_ERR(ud->tfm_recv))
+   return PTR_ERR(ud->tfm_recv);
+   ud->tfm_send = crypto_alloc_aead("gcm(aes)", 0, 0);
+   if (IS_ERR(ud->tfm_send)) {
+   ret = PTR_ERR(ud->tfm_send);
+   goto err_free_recv;
+   }
+   ret = kfifo_alloc(&ud->recv_queue, RECVQ_SIZE, GFP_KERNEL);
+   if (ret)
+   goto err_free_send;
+
+   if (crypto_aead_setkey(ud->tfm_send, sendkey, USBIP_KEYSIZE) ||
+   crypto_aead_setkey(ud->tfm_recv, recvkey, USBIP_KEYSIZE) ||
+   crypto_aead_setauthsize(ud->tfm_send, USBIP_AUTHSIZE) ||
+   crypto_aead_setauthsize(ud->tfm_recv, USBIP_AUTHSIZE)) {
+   ret = -EINVAL;
+   goto err_free_fifo;
+   }
+
+   ud->ctr_send = 0;
+   ud->ctr_recv = 0;
+
+   return 0;
+
+err_free_fifo:
+   kfifo_free(&ud->recv_queue);
+err_free_send:
+   crypto_free_aead(ud->tfm_send);
+err_free_recv:
+   crypto_free_aead(ud->tfm_recv);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(usbip_init_crypto);
+
+void usbip_deinit_crypto(struct usbip_device *ud)
+{
+   if (ud->use_crypto) {
+   crypto_free_aead(ud->tfm_send);
+   crypto_free_aead(ud->tfm_recv);
+   kfifo_free(&ud->recv_queue);
+   ud->use_crypto = 0;
+   }
+}
+EXPORT_SYMBOL_GPL(usbip_deinit_crypto);
+
+struct tcrypt_result {
+   struct completion completion;
+   int err;
+};
+
+static void tcrypt_complete(struct crypto_async_request *req, int err)
+{
+   struct tcrypt_result *res = req->data;
+
+   if (err == -EINPROGRESS)
+   return;
+
+   res->err = err;
+   complete(&res->completion);
+}
+
+#define USBIP_ENCRYPT 1
+#define USBIP_DECRYPT 0
+/*
+ * Perform encryption/decryption on on

[PATCHv3 05/16] staging: usbip: Add support for ACLs in usbipd

2013-09-28 Thread Dominik Paulus
Interpret the ACLs stored in sysfs in usbipd and reject clients not
matching one of the ACLs.

Signed-off-by: Kurt Kanzenbach 
Signed-off-by: Dominik Paulus 
Signed-off-by: Tobias Polzer 
---
 drivers/staging/usbip/userspace/src/Makefile.am |  2 +-
 drivers/staging/usbip/userspace/src/usbipd.c| 79 +
 2 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/usbip/userspace/src/Makefile.am 
b/drivers/staging/usbip/userspace/src/Makefile.am
index a113003..5161bae 100644
--- a/drivers/staging/usbip/userspace/src/Makefile.am
+++ b/drivers/staging/usbip/userspace/src/Makefile.am
@@ -9,4 +9,4 @@ usbip_SOURCES := usbip.h utils.h usbip.c utils.c 
usbip_network.c \
 usbip_bind.c usbip_unbind.c
 
 
-usbipd_SOURCES := usbip_network.h usbipd.c usbip_network.c
+usbipd_SOURCES := usbip_network.h usbipd.c usbip_network.c utils.c
diff --git a/drivers/staging/usbip/userspace/src/usbipd.c 
b/drivers/staging/usbip/userspace/src/usbipd.c
index 8db2f27..bc1fd19 100644
--- a/drivers/staging/usbip/userspace/src/usbipd.c
+++ b/drivers/staging/usbip/userspace/src/usbipd.c
@@ -48,6 +48,7 @@
 #include "usbip_host_driver.h"
 #include "usbip_common.h"
 #include "usbip_network.h"
+#include "utils.h"
 
 #undef  PROGNAME
 #define PROGNAME "usbipd"
@@ -169,12 +170,69 @@ static void usbipd_help(void)
printf("%s\n", usbipd_help_string);
 }
 
+/*
+ * Checks whether client IP matches at least one
+ * ACL entry
+ *
+ * Returns:
+ * 1  if matches
+ * 0  if not
+ * -1 on error
+ */
+static int check_allowed(char *acls, int sockfd)
+{
+   int rc, match;
+   struct sockaddr_storage sa;
+   char *acl_cpy, *iter, *saveptr;
+   socklen_t sa_len = sizeof(sa);
+
+   rc = getpeername(sockfd, (struct sockaddr *) &sa, &sa_len);
+   if (rc || sa_len > sizeof(sa)) {
+   err("getpeername failed: %s", strerror(errno));
+   return -1;
+   }
+
+   /*
+* We are going to modify our argument,
+* thus, we need to duplicate it.
+*/
+   acl_cpy = strdup(acls);
+   if (!acl_cpy) {
+   err("strdup(): %s", strerror(errno));
+   return -1;
+   }
+
+   match = 0;
+   iter = strtok_r(acl_cpy, "\n", &saveptr);
+   /*
+* Iterate over ACL entries and check for
+* matching one.
+*/
+   while (iter) {
+   struct subnet net;
+
+   if (parse_cidr(iter, &net) < 0) {
+   dbg("parse_cidr() failed");
+   } else if (in_range(&sa, net)) {
+   match = 1;
+   break;
+   }
+
+   iter = strtok_r(NULL, "\n", &saveptr);
+   }
+
+   free(acl_cpy);
+   return match;
+}
+
 static int recv_request_import(int sockfd)
 {
struct op_import_request req;
struct op_common reply;
struct usbip_exported_device *edev;
struct usbip_usb_device pdu_udev;
+   struct sysfs_attribute *usbip_acl;
+   char ip_attr_path[SYSFS_PATH_MAX];
int found = 0;
int error = 0;
int rc;
@@ -206,6 +264,27 @@ static int recv_request_import(int sockfd)
rc = usbip_host_export_device(edev, sockfd);
if (rc < 0)
error = 1;
+
+   /* check for allowed IPs */
+   snprintf(ip_attr_path, sizeof(ip_attr_path), "%s/%s:%d.%d/%s",
+   edev->udev.path, edev->udev.busid,
+   edev->udev.bConfigurationValue, 0, "usbip_acl");
+
+   usbip_acl = sysfs_open_attribute(ip_attr_path);
+   if (usbip_acl) {
+   rc = sysfs_read_attribute(usbip_acl);
+   if (rc < 0) {
+   err("Unable to open sysfs");
+   error = 1;
+   } else if (check_allowed(usbip_acl->value, sockfd) != 
1) {
+   info("Access denied to device %s",
+   edev->udev.busid);
+   error = 1;
+   }
+   sysfs_close_attribute(usbip_acl);
+   } else {
+   err("failed to get ip list");
+   }
} else {
info("requested device not found: %s", req.busid);
error = 1;
-- 
1.8.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCHv3 11/16] staging: usbip: Exchange session keys in userspace

2013-09-28 Thread Dominik Paulus
In preparation for the kernel crypto support, we exchange two - randomly
generated - session keys between usbip and usbipd to be used for
encrypting all traffic generated in kernelspace. We use two different
128-bit keys, one for sending and one for receiving. Both are generated
by the client (usbip, probably has more entropy available than the
server) and transferred over the already established TLS connection.

Signed-off-by: Dominik Paulus 
Signed-off-by: Tobias Polzer 
---
 .../staging/usbip/userspace/libsrc/usbip_common.h  | 21 ++
 .../usbip/userspace/libsrc/usbip_host_driver.c |  5 ++-
 .../usbip/userspace/libsrc/usbip_host_driver.h |  3 +-
 .../staging/usbip/userspace/libsrc/vhci_driver.c   | 19 +++--
 .../staging/usbip/userspace/libsrc/vhci_driver.h   |  9 ++---
 drivers/staging/usbip/userspace/src/usbip_attach.c | 47 +-
 drivers/staging/usbip/userspace/src/usbipd.c   | 32 ---
 7 files changed, 105 insertions(+), 31 deletions(-)

diff --git a/drivers/staging/usbip/userspace/libsrc/usbip_common.h 
b/drivers/staging/usbip/userspace/libsrc/usbip_common.h
index 938ad1c..f804c04 100644
--- a/drivers/staging/usbip/userspace/libsrc/usbip_common.h
+++ b/drivers/staging/usbip/userspace/libsrc/usbip_common.h
@@ -127,6 +127,27 @@ struct usbip_usb_device {
uint8_t bNumInterfaces;
 } __attribute__((packed));
 
+
+/*
+ * These structs contain the configuration
+ * data to be passed to the kernel
+ */
+struct host_conf {
+   int sockfd;
+   uint8_t use_crypto;
+   uint8_t key1[16];
+   uint8_t key2[16];
+};
+struct vhci_conf {
+   uint8_t port;
+   int sockfd;
+   uint32_t devid;
+   uint32_t speed;
+   uint8_t use_crypto;
+   uint8_t key1[16];
+   uint8_t key2[16];
+};
+
 #define to_string(s)   #s
 
 void dump_usb_interface(struct usbip_usb_interface *);
diff --git a/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c 
b/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c
index 71a449c..dd93493 100644
--- a/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c
+++ b/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c
@@ -332,7 +332,8 @@ int usbip_host_refresh_device_list(void)
return 0;
 }
 
-int usbip_host_export_device(struct usbip_exported_device *edev, int sockfd)
+int usbip_host_export_device(struct usbip_exported_device *edev,
+struct host_conf *conf)
 {
char attr_name[] = "usbip_sockfd";
char attr_path[SYSFS_PATH_MAX];
@@ -366,7 +367,7 @@ int usbip_host_export_device(struct usbip_exported_device 
*edev, int sockfd)
return -1;
}
 
-   snprintf(sockfd_buff, sizeof(sockfd_buff), "%d\n", sockfd);
+   snprintf(sockfd_buff, sizeof(sockfd_buff), "%d\n", conf->sockfd);
dbg("write: %s", sockfd_buff);
 
ret = sysfs_write_attribute(attr, sockfd_buff, strlen(sockfd_buff));
diff --git a/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.h 
b/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.h
index 34fd14c..b76e41c 100644
--- a/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.h
+++ b/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.h
@@ -42,7 +42,8 @@ int usbip_host_driver_open(void);
 void usbip_host_driver_close(void);
 
 int usbip_host_refresh_device_list(void);
-int usbip_host_export_device(struct usbip_exported_device *edev, int sockfd);
+int usbip_host_export_device(struct usbip_exported_device *edev,
+struct host_conf *conf);
 struct usbip_exported_device *usbip_host_get_device(int num);
 
 #endif /* __USBIP_HOST_DRIVER_H */
diff --git a/drivers/staging/usbip/userspace/libsrc/vhci_driver.c 
b/drivers/staging/usbip/userspace/libsrc/vhci_driver.c
index 1091bb2..d1d45bb 100644
--- a/drivers/staging/usbip/userspace/libsrc/vhci_driver.c
+++ b/drivers/staging/usbip/userspace/libsrc/vhci_driver.c
@@ -467,8 +467,8 @@ int usbip_vhci_get_free_port(void)
return -1;
 }
 
-int usbip_vhci_attach_device2(uint8_t port, int sockfd, uint32_t devid,
-   uint32_t speed) {
+int usbip_vhci_attach_device(struct vhci_conf *conf)
+{
struct sysfs_attribute *attr_attach;
char buff[200]; /* what size should be ? */
int ret;
@@ -481,7 +481,7 @@ int usbip_vhci_attach_device2(uint8_t port, int sockfd, 
uint32_t devid,
}
 
snprintf(buff, sizeof(buff), "%u %u %u %u",
-   port, sockfd, devid, speed);
+   conf->port, conf->sockfd, conf->devid, conf->speed);
dbg("writing: %s", buff);
 
ret = sysfs_write_attribute(attr_attach, buff, strlen(buff));
@@ -490,25 +490,16 @@ int usbip_vhci_attach_device2(uint8_t port, int sockfd, 
uint32_t devid,
return -1;
}
 
-   dbg("attached port: %d", port);
+   dbg("attached port: %d", conf->port);
 
return 0;
 }
 
-static unsigned long get_devid(uint8_t busnum, uint8_t devnu

[PATCHv3 06/16] staging: usbip: Add proper error reporting

2013-09-28 Thread Dominik Paulus
This patch adds new error codes and features extended error reporting in
op_common packets.

Signed-off-by: Dominik Paulus 
Signed-off-by: Tobias Polzer 
---
 drivers/staging/usbip/userspace/src/usbip_attach.c |  4 +-
 drivers/staging/usbip/userspace/src/usbip_list.c   |  3 +-
 .../staging/usbip/userspace/src/usbip_network.c| 50 --
 .../staging/usbip/userspace/src/usbip_network.h| 17 +++-
 drivers/staging/usbip/userspace/src/usbipd.c   | 29 +++--
 5 files changed, 74 insertions(+), 29 deletions(-)

diff --git a/drivers/staging/usbip/userspace/src/usbip_attach.c 
b/drivers/staging/usbip/userspace/src/usbip_attach.c
index 2363e56..2a3f313 100644
--- a/drivers/staging/usbip/userspace/src/usbip_attach.c
+++ b/drivers/staging/usbip/userspace/src/usbip_attach.c
@@ -147,7 +147,7 @@ static int query_import_device(int sockfd, char *busid)
/* receive a reply */
rc = usbip_net_recv_op_common(sockfd, &code);
if (rc < 0) {
-   err("recv op_common");
+   err("recv op_common: %s", usbip_net_strerror(rc));
return -1;
}
 
@@ -177,7 +177,7 @@ static int attach_device(char *host, char *busid)
 
sockfd = usbip_net_connect(host);
if (sockfd < 0) {
-   err("tcp connect");
+   err("connection attempt failed");
return -1;
}
 
diff --git a/drivers/staging/usbip/userspace/src/usbip_list.c 
b/drivers/staging/usbip/userspace/src/usbip_list.c
index e4fa5b8..ff7acf8 100644
--- a/drivers/staging/usbip/userspace/src/usbip_list.c
+++ b/drivers/staging/usbip/userspace/src/usbip_list.c
@@ -64,7 +64,8 @@ static int get_exported_devices(char *host, int sockfd)
 
rc = usbip_net_recv_op_common(sockfd, &code);
if (rc < 0) {
-   dbg("usbip_net_recv_op_common failed");
+   err("usbip_net_recv_op_common failed: %s",
+   usbip_net_strerror(rc));
return -1;
}
 
diff --git a/drivers/staging/usbip/userspace/src/usbip_network.c 
b/drivers/staging/usbip/userspace/src/usbip_network.c
index 9425cb6..e573cb2 100644
--- a/drivers/staging/usbip/userspace/src/usbip_network.c
+++ b/drivers/staging/usbip/userspace/src/usbip_network.c
@@ -181,7 +181,7 @@ int usbip_net_recv_op_common(int sockfd, uint16_t *code)
rc = usbip_net_recv(sockfd, &op_common, sizeof(op_common));
if (rc < 0) {
dbg("usbip_net_recv failed: %d", rc);
-   goto err;
+   return -ERR_SYSERR;
}
 
PACK_OP_COMMON(0, &op_common);
@@ -189,30 +189,48 @@ int usbip_net_recv_op_common(int sockfd, uint16_t *code)
if (op_common.version != USBIP_VERSION) {
dbg("version mismatch: %d %d", op_common.version,
USBIP_VERSION);
-   goto err;
+   return -ERR_MISMATCH;
}
 
switch (*code) {
case OP_UNSPEC:
break;
default:
-   if (op_common.code != *code) {
+   /*
+* Only accept expected opcode. Exception: OP_REPLY
+* flag set may be sent as a reply to all requests,
+* if only used for status reporting.
+*/
+   if (op_common.code != *code && op_common.code != OP_REPLY) {
dbg("unexpected pdu %#0x for %#0x", op_common.code,
*code);
-   goto err;
+   return -ERR_UNEXPECTED;
}
}
 
-   if (op_common.status != ST_OK) {
-   dbg("request failed at peer: %d", op_common.status);
-   goto err;
-   }
-
*code = op_common.code;
 
-   return 0;
-err:
-   return -1;
+   return -op_common.status;
+}
+
+const char *usbip_net_strerror(int status)
+{
+   static const char *const errs[] = {
+   /* ERR_OK */ "Success",
+   /* ERR_NA */ "Command failed",
+   /* ERR_MISMATCH */ "Protocol version mismatch",
+   /* ERR_SYSERR */ "System error",
+   /* ERR_UNEXPECTED */ "Unexpected opcode received",
+   /* ERR_AUTHREQ */ "Server requires authentication",
+   /* ERR_PERM */ "Permission denied",
+   /* ERR_NOTFOUND */ "Requested device not found",
+   /* ERR_NOAUTH */ "Server doesn't support authentication"
+   };
+   if (status < 0)
+   status = -status;
+   if (status >= (int) (sizeof(errs) / sizeof(*errs)))
+   return "Invalid";
+   return errs[status];
 }
 
 int usbip_net_set_reuseaddr(int sockfd)
@@ -363,6 +381,7 @@ int usbip_net_connect(char *hostname)
 #ifdef HAVE_GNUTLS
if (usbip_srp_password) {
int rc;
+   uint16_t code = OP_REP_STARTTLS;
 
rc = usbip_net_send_op_common(sockfd, OP_REQ_STARTTLS, 0);
if (rc < 0) {
@@ -3

[PATCHv3 16/16] staging: usbip: Increment version number to 1.2.1

2013-09-28 Thread Dominik Paulus
Also increment the kernel module version number to match the
userspace version, as compatibility with old userspace utilities
is now at least partially broken.

Signed-off-by: Dominik Paulus 
Signed-off-by: Tobias Polzer 
---
 drivers/staging/usbip/usbip_common.h | 2 +-
 drivers/staging/usbip/userspace/configure.ac | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/usbip/usbip_common.h 
b/drivers/staging/usbip/usbip_common.h
index 939a232..b315082 100644
--- a/drivers/staging/usbip/usbip_common.h
+++ b/drivers/staging/usbip/usbip_common.h
@@ -31,7 +31,7 @@
 #include 
 #include 
 
-#define USBIP_VERSION "1.0.0"
+#define USBIP_VERSION "1.2.1"
 
 /*
  * Length of the authentication tag associated with each packet, in bytes. Can
diff --git a/drivers/staging/usbip/userspace/configure.ac 
b/drivers/staging/usbip/userspace/configure.ac
index bc08b81..26dabe3 100644
--- a/drivers/staging/usbip/userspace/configure.ac
+++ b/drivers/staging/usbip/userspace/configure.ac
@@ -1,7 +1,7 @@
 dnl Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.59)
-AC_INIT([usbip-utils], [1.1.1], [linux-...@vger.kernel.org])
+AC_INIT([usbip-utils], [1.2.1], [linux-...@vger.kernel.org])
 
 CURRENT=0
 REVISION=1
-- 
1.8.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCHv3 09/16] staging: usbip: Separate protocol/program version

2013-09-28 Thread Dominik Paulus
Not all new program versions necessarily introduce
non-backwards-compatible protocol changes. We thus move the definition
of the protocol version from configure.ac to usbip_network.h, where it
logically belongs to.

Signed-off-by: Dominik Paulus 
Signed-off-by: Tobias Polzer 
---
 drivers/staging/usbip/userspace/configure.ac| 1 -
 drivers/staging/usbip/userspace/src/usbip_network.c | 6 +++---
 drivers/staging/usbip/userspace/src/usbip_network.h | 6 ++
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/usbip/userspace/configure.ac 
b/drivers/staging/usbip/userspace/configure.ac
index 2208516..bc08b81 100644
--- a/drivers/staging/usbip/userspace/configure.ac
+++ b/drivers/staging/usbip/userspace/configure.ac
@@ -2,7 +2,6 @@ dnl Process this file with autoconf to produce a configure 
script.
 
 AC_PREREQ(2.59)
 AC_INIT([usbip-utils], [1.1.1], [linux-...@vger.kernel.org])
-AC_DEFINE([USBIP_VERSION], [0x0111], [binary-coded decimal version number])
 
 CURRENT=0
 REVISION=1
diff --git a/drivers/staging/usbip/userspace/src/usbip_network.c 
b/drivers/staging/usbip/userspace/src/usbip_network.c
index e573cb2..a606e2b 100644
--- a/drivers/staging/usbip/userspace/src/usbip_network.c
+++ b/drivers/staging/usbip/userspace/src/usbip_network.c
@@ -156,7 +156,7 @@ int usbip_net_send_op_common(int sockfd, uint32_t code, 
uint32_t status)
 
memset(&op_common, 0, sizeof(op_common));
 
-   op_common.version = USBIP_VERSION;
+   op_common.version = PROTOCOL_VERSION;
op_common.code= code;
op_common.status  = status;
 
@@ -186,9 +186,9 @@ int usbip_net_recv_op_common(int sockfd, uint16_t *code)
 
PACK_OP_COMMON(0, &op_common);
 
-   if (op_common.version != USBIP_VERSION) {
+   if (op_common.version != PROTOCOL_VERSION) {
dbg("version mismatch: %d %d", op_common.version,
-   USBIP_VERSION);
+   PROTOCOL_VERSION);
return -ERR_MISMATCH;
}
 
diff --git a/drivers/staging/usbip/userspace/src/usbip_network.h 
b/drivers/staging/usbip/userspace/src/usbip_network.h
index d3c1b71..6a41fd8 100644
--- a/drivers/staging/usbip/userspace/src/usbip_network.h
+++ b/drivers/staging/usbip/userspace/src/usbip_network.h
@@ -14,6 +14,12 @@
 
 #include 
 
+/*
+ * Protocol version. Incremented only on non-backwards-compatible
+ * changes.
+ */
+#define PROTOCOL_VERSION 0x111
+
 extern int usbip_port;
 extern char *usbip_port_string;
 extern char *usbip_srp_password;
-- 
1.8.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCHv3 12/16] staging: usbip: Pass session keys to the kernel

2013-09-28 Thread Dominik Paulus
This extends the userspace code to write the generated session keys to
sysfs in hexadecimal encoding after establishing the connection.
The kernel code is modified to parse the session keys.

Signed-off-by: Dominik Paulus 
Signed-off-by: Tobias Polzer 
---
 drivers/staging/usbip/stub_dev.c   | 26 +++-
 drivers/staging/usbip/usbip_common.h   | 10 
 .../staging/usbip/userspace/libsrc/usbip_common.c  | 14 +++
 .../staging/usbip/userspace/libsrc/usbip_common.h  |  2 ++
 .../usbip/userspace/libsrc/usbip_host_driver.c | 15 
 .../staging/usbip/userspace/libsrc/vhci_driver.c   |  8 ---
 drivers/staging/usbip/vhci_sysfs.c | 28 +-
 7 files changed, 94 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/usbip/stub_dev.c b/drivers/staging/usbip/stub_dev.c
index 3939b60..0082912 100644
--- a/drivers/staging/usbip/stub_dev.c
+++ b/drivers/staging/usbip/stub_dev.c
@@ -87,13 +87,37 @@ static ssize_t store_sockfd(struct device *dev, struct 
device_attribute *attr,
int sockfd = 0;
struct socket *socket;
ssize_t err = -EINVAL;
+   char sendkey[USBIP_KEYSIZE], recvkey[USBIP_KEYSIZE];
+   char sendkey_hex[2 * USBIP_KEYSIZE + 1];
+   char recvkey_hex[2 * USBIP_KEYSIZE + 1];
 
if (!sdev) {
dev_err(dev, "sdev is null\n");
return -ENODEV;
}
 
-   sscanf(buf, "%d", &sockfd);
+   /*
+* Read symmetric crypto keys. They are randomly
+* generated by userspace and passed to the kernel
+* via sysfs (encoded in hexadecimal)
+*/
+   if (sscanf(buf, "%d %d %32s %32s", &sockfd, &sdev->ud.use_crypto,
+   sendkey_hex, recvkey_hex) < 1) {
+   dev_err(dev, "Invalid write to sysfs: Invalid sockfd\n");
+   return -EINVAL;
+   }
+   if (sdev->ud.use_crypto) {
+   int i;
+   dev_info(dev, "Using encrypted data transport\n");
+   for (i = USBIP_KEYSIZE - 1; i >= 0; --i) {
+   sendkey_hex[2 * (i + 1)] = 0;
+   sscanf(sendkey_hex + (2 * i), "%2hhX", &sendkey[i]);
+   }
+   for (i = USBIP_KEYSIZE - 1; i >= 0; --i) {
+   recvkey_hex[2 * (i + 1)] = 0;
+   sscanf(recvkey_hex + (2 * i), "%2hhX", &recvkey[i]);
+   }
+   }
 
if (sockfd != -1) {
dev_info(dev, "stub up\n");
diff --git a/drivers/staging/usbip/usbip_common.h 
b/drivers/staging/usbip/usbip_common.h
index 7e6c543..96c87ee 100644
--- a/drivers/staging/usbip/usbip_common.h
+++ b/drivers/staging/usbip/usbip_common.h
@@ -32,6 +32,13 @@
 
 #define USBIP_VERSION "1.0.0"
 
+/*
+ * Length of symmetric keys. Currently, this should be fixed at 16 bytes.
+ * Will break code if changed, look at userspace and stub_dev.c/vhci_sysfs.c
+ * where this constant is used before changing.
+ */
+#define USBIP_KEYSIZE 16
+
 #undef pr_fmt
 
 #ifdef DEBUG
@@ -290,6 +297,9 @@ struct usbip_device {
void (*reset)(struct usbip_device *);
void (*unusable)(struct usbip_device *);
} eh_ops;
+
+   /* Crypto support */
+   int use_crypto;
 };
 
 #define kthread_get_run(threadfn, data, namefmt, ...) \
diff --git a/drivers/staging/usbip/userspace/libsrc/usbip_common.c 
b/drivers/staging/usbip/userspace/libsrc/usbip_common.c
index 17e08e0..1ec9cc9 100644
--- a/drivers/staging/usbip/userspace/libsrc/usbip_common.c
+++ b/drivers/staging/usbip/userspace/libsrc/usbip_common.c
@@ -290,3 +290,17 @@ void usbip_names_get_class(char *buff, size_t size, 
uint8_t class,
 
snprintf(buff, size, "%s / %s / %s (%02x/%02x/%02x)", c, s, p, class, 
subclass, protocol);
 }
+
+/*
+ * Converts a 16-byte key to hexadecimal to be pushed to kernelspace
+ *
+ * Output buffer must be at least 33 bytes long
+ */
+char *keytohex(unsigned char *key, char *out)
+{
+   int i;
+   out[32] = 0;
+   for (i = 0; i != 16; ++i)
+   sprintf(out + (2 * i), "%02X", key[i]);
+   return out;
+}
diff --git a/drivers/staging/usbip/userspace/libsrc/usbip_common.h 
b/drivers/staging/usbip/userspace/libsrc/usbip_common.h
index f804c04..a5d4d21 100644
--- a/drivers/staging/usbip/userspace/libsrc/usbip_common.h
+++ b/drivers/staging/usbip/userspace/libsrc/usbip_common.h
@@ -168,4 +168,6 @@ void usbip_names_get_product(char *buff, size_t size, 
uint16_t vendor,
 void usbip_names_get_class(char *buff, size_t size, uint8_t class,
   uint8_t subclass, uint8_t protocol);
 
+char *keytohex(unsigned char *key, char *out);
+
 #endif /* __USBIP_COMMON_H */
diff --git a/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c 
b/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c
index dd93493..dfcb22d 100644
--- a/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c
+++ b/driv

[PATCHv3 10/16] staging: usbip: TLS for all userspace communication

2013-09-28 Thread Dominik Paulus
This patch extends the TLS support to cover all communication in
userspace. The TLS connection is released shortly before the socket is
passed to the kernel.

This requires for additional connection state to be passed between
functions. We thus replaced the sockfd by a struct containing the TLS
context as well as the fd.

Signed-off-by: Dominik Paulus 
Signed-off-by: Tobias Polzer 
---
 drivers/staging/usbip/userspace/src/usbip_attach.c |  24 +-
 drivers/staging/usbip/userspace/src/usbip_list.c   |  24 +-
 .../staging/usbip/userspace/src/usbip_network.c| 279 +
 .../staging/usbip/userspace/src/usbip_network.h|  49 +++-
 drivers/staging/usbip/userspace/src/usbipd.c   | 244 --
 5 files changed, 358 insertions(+), 262 deletions(-)

diff --git a/drivers/staging/usbip/userspace/src/usbip_attach.c 
b/drivers/staging/usbip/userspace/src/usbip_attach.c
index 651e93a..25c68e2 100644
--- a/drivers/staging/usbip/userspace/src/usbip_attach.c
+++ b/drivers/staging/usbip/userspace/src/usbip_attach.c
@@ -86,7 +86,8 @@ static int record_connection(char *host, char *port, char 
*busid, int rhport)
return 0;
 }
 
-static int import_device(int sockfd, struct usbip_usb_device *udev)
+static int import_device(struct usbip_connection *conn,
+struct usbip_usb_device *udev)
 {
int rc;
int port;
@@ -104,8 +105,10 @@ static int import_device(int sockfd, struct 
usbip_usb_device *udev)
return -1;
}
 
-   rc = usbip_vhci_attach_device(port, sockfd, udev->busnum,
+   usbip_net_bye(conn);
+   rc = usbip_vhci_attach_device(port, conn->sockfd, udev->busnum,
  udev->devnum, udev->speed);
+
if (rc < 0) {
err("import device");
usbip_vhci_driver_close();
@@ -117,7 +120,7 @@ static int import_device(int sockfd, struct 
usbip_usb_device *udev)
return port;
 }
 
-static int query_import_device(int sockfd, char *busid)
+static int query_import_device(struct usbip_connection *conn, char *busid)
 {
int rc;
struct op_import_request request;
@@ -128,7 +131,7 @@ static int query_import_device(int sockfd, char *busid)
memset(&reply, 0, sizeof(reply));
 
/* send a request */
-   rc = usbip_net_send_op_common(sockfd, OP_REQ_IMPORT, 0);
+   rc = usbip_net_send_op_common(conn, OP_REQ_IMPORT, 0);
if (rc < 0) {
err("send op_common");
return -1;
@@ -138,20 +141,20 @@ static int query_import_device(int sockfd, char *busid)
 
PACK_OP_IMPORT_REQUEST(0, &request);
 
-   rc = usbip_net_send(sockfd, (void *) &request, sizeof(request));
+   rc = usbip_net_send(conn, (void *) &request, sizeof(request));
if (rc < 0) {
err("send op_import_request");
return -1;
}
 
/* receive a reply */
-   rc = usbip_net_recv_op_common(sockfd, &code);
+   rc = usbip_net_recv_op_common(conn, &code);
if (rc < 0) {
err("recv op_common: %s", usbip_net_strerror(rc));
return -1;
}
 
-   rc = usbip_net_recv(sockfd, (void *) &reply, sizeof(reply));
+   rc = usbip_net_recv(conn, (void *) &reply, sizeof(reply));
if (rc < 0) {
err("recv op_import_reply");
return -1;
@@ -166,7 +169,7 @@ static int query_import_device(int sockfd, char *busid)
}
 
/* import a device */
-   return import_device(sockfd, &reply.udev);
+   return import_device(conn, &reply.udev);
 }
 
 static int attach_device(char *host, char *busid)
@@ -174,14 +177,15 @@ static int attach_device(char *host, char *busid)
int sockfd;
int rc;
int rhport;
+   struct usbip_connection conn;
 
-   sockfd = usbip_net_connect(host);
+   sockfd = usbip_net_connect(host, &conn);
if (sockfd < 0) {
err("connection attempt failed");
return -1;
}
 
-   rhport = query_import_device(sockfd, busid);
+   rhport = query_import_device(&conn, busid);
if (rhport < 0) {
err("query");
return -1;
diff --git a/drivers/staging/usbip/userspace/src/usbip_list.c 
b/drivers/staging/usbip/userspace/src/usbip_list.c
index ff7acf8..187eb7d 100644
--- a/drivers/staging/usbip/userspace/src/usbip_list.c
+++ b/drivers/staging/usbip/userspace/src/usbip_list.c
@@ -45,7 +45,7 @@ void usbip_list_usage(void)
printf("usage: %s", usbip_list_usage_string);
 }
 
-static int get_exported_devices(char *host, int sockfd)
+static int get_exported_devices(char *host, struct usbip_connection *conn)
 {
char product_name[100];
char class_name[100];
@@ -56,13 +56,13 @@ static int get_exported_devices(char *host, int sockfd)
unsigned int i;
int j, rc;
 
-   rc = usbip_net_send_op_common(sockfd, OP_REQ_DEVLIST, 0);
+   rc = usbip

[PATCHv3 07/16] staging: usbip: Handle usbip being started as user

2013-09-28 Thread Dominik Paulus
usbip now prints an error message when started as user and requiring
root access. Also, some debug messages are changed to error messages so
the command line utilities now print less confusing (and more verbose)
error messages when not used correctly.

Signed-off-by: Dominik Paulus 
Signed-off-by: Tobias Polzer 
---
 drivers/staging/usbip/userspace/src/usbip_attach.c |  3 +++
 drivers/staging/usbip/userspace/src/usbip_bind.c   | 16 ++--
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/usbip/userspace/src/usbip_attach.c 
b/drivers/staging/usbip/userspace/src/usbip_attach.c
index 2a3f313..651e93a 100644
--- a/drivers/staging/usbip/userspace/src/usbip_attach.c
+++ b/drivers/staging/usbip/userspace/src/usbip_attach.c
@@ -210,6 +210,9 @@ int usbip_attach(int argc, char *argv[])
int opt;
int ret = -1;
 
+   if (geteuid() != 0)
+   err("not running as root?");
+
for (;;) {
opt = getopt_long(argc, argv, "r:b:", opts, NULL);
 
diff --git a/drivers/staging/usbip/userspace/src/usbip_bind.c 
b/drivers/staging/usbip/userspace/src/usbip_bind.c
index d2739fc..ab26b30f 100644
--- a/drivers/staging/usbip/userspace/src/usbip_bind.c
+++ b/drivers/staging/usbip/userspace/src/usbip_bind.c
@@ -158,7 +158,7 @@ static int unbind_other(char *busid)
 
busid_dev = sysfs_open_device(bus_type, busid);
if (!busid_dev) {
-   dbg("sysfs_open_device %s failed: %s", busid, strerror(errno));
+   err("sysfs_open_device %s failed: %s", busid, strerror(errno));
return -1;
}
 
@@ -166,7 +166,7 @@ static int unbind_other(char *busid)
bDevClass  = sysfs_get_device_attr(busid_dev, "bDeviceClass");
bNumIntfs  = sysfs_get_device_attr(busid_dev, "bNumInterfaces");
if (!bConfValue || !bDevClass || !bNumIntfs) {
-   dbg("problem getting device attributes: %s",
+   err("problem getting device attributes: %s",
strerror(errno));
goto err_close_busid_dev;
}
@@ -181,7 +181,7 @@ static int unbind_other(char *busid)
 bConfValue->value, i);
intf_dev = sysfs_open_device(bus_type, intf_busid);
if (!intf_dev) {
-   dbg("could not open interface device: %s",
+   err("could not open interface device: %s",
strerror(errno));
goto err_close_busid_dev;
}
@@ -202,14 +202,14 @@ static int unbind_other(char *busid)
/* unbinding */
intf_drv = sysfs_open_driver(bus_type, intf_dev->driver_name);
if (!intf_drv) {
-   dbg("could not open interface driver on %s: %s",
+   err("could not open interface driver on %s: %s",
intf_dev->name, strerror(errno));
goto err_close_intf_dev;
}
 
unbind_attr = sysfs_get_driver_attr(intf_drv, "unbind");
if (!unbind_attr) {
-   dbg("problem getting interface driver attribute: %s",
+   err("problem getting interface driver attribute: %s",
strerror(errno));
goto err_close_intf_drv;
}
@@ -218,7 +218,8 @@ static int unbind_other(char *busid)
   SYSFS_BUS_ID_SIZE);
if (rc < 0) {
/* NOTE: why keep unbinding other interfaces? */
-   dbg("unbind driver at %s failed", intf_dev->bus_id);
+   err("unbind driver at %s failed: %s", intf_dev->bus_id,
+   strerror(errno));
status = UNBIND_ST_FAILED;
}
 
@@ -287,6 +288,9 @@ int usbip_bind(int argc, char *argv[])
 
allow[0] = 0;
 
+   if (geteuid() != 0)
+   err("not running as root?");
+
for (;;) {
opt = getopt_long(argc, argv, "a:b:", opts, NULL);
 
-- 
1.8.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCHv3 13/16] staging: usbip: Wrap kernel_sendmsg()/recvmsg()

2013-09-28 Thread Dominik Paulus
This adds two simple wrappers around kernel_sendmsg() and
kernel_recvmsg() that can be extended to perform additional
cryptographic operations on the data before sending it.

Signed-off-by: Dominik Paulus 
Signed-off-by: Tobias Polzer 
---
 drivers/staging/usbip/stub_rx.c  |  2 +-
 drivers/staging/usbip/stub_tx.c  |  6 ++--
 drivers/staging/usbip/usbip_common.c | 66 
 drivers/staging/usbip/usbip_common.h |  7 +++-
 drivers/staging/usbip/vhci_rx.c  |  2 +-
 drivers/staging/usbip/vhci_tx.c  |  4 +--
 6 files changed, 48 insertions(+), 39 deletions(-)

diff --git a/drivers/staging/usbip/stub_rx.c b/drivers/staging/usbip/stub_rx.c
index db48a78..6ba9969 100644
--- a/drivers/staging/usbip/stub_rx.c
+++ b/drivers/staging/usbip/stub_rx.c
@@ -553,7 +553,7 @@ static void stub_rx_pdu(struct usbip_device *ud)
memset(&pdu, 0, sizeof(pdu));
 
/* receive a pdu header */
-   ret = usbip_recv(ud->tcp_socket, &pdu, sizeof(pdu));
+   ret = usbip_recv(ud, &pdu, sizeof(pdu));
if (ret != sizeof(pdu)) {
dev_err(dev, "recv a header, %d\n", ret);
usbip_event_add(ud, SDEV_EVENT_ERROR_TCP);
diff --git a/drivers/staging/usbip/stub_tx.c b/drivers/staging/usbip/stub_tx.c
index cd5326a..9a9f9e6 100644
--- a/drivers/staging/usbip/stub_tx.c
+++ b/drivers/staging/usbip/stub_tx.c
@@ -257,8 +257,7 @@ static int stub_send_ret_submit(struct stub_device *sdev)
iovnum++;
}
 
-   ret = kernel_sendmsg(sdev->ud.tcp_socket, &msg,
-   iov,  iovnum, txsize);
+   ret = usbip_sendmsg(&sdev->ud, &msg, iov, iovnum, txsize);
if (ret != txsize) {
dev_err(&sdev->interface->dev,
"sendmsg failed!, retval %d for %zd\n",
@@ -332,8 +331,7 @@ static int stub_send_ret_unlink(struct stub_device *sdev)
iov[0].iov_len  = sizeof(pdu_header);
txsize += sizeof(pdu_header);
 
-   ret = kernel_sendmsg(sdev->ud.tcp_socket, &msg, iov,
-1, txsize);
+   ret = usbip_sendmsg(&sdev->ud, &msg, iov, 1, txsize);
if (ret != txsize) {
dev_err(&sdev->interface->dev,
"sendmsg failed!, retval %d for %zd\n",
diff --git a/drivers/staging/usbip/usbip_common.c 
b/drivers/staging/usbip/usbip_common.c
index e3fc749..83ec279 100644
--- a/drivers/staging/usbip/usbip_common.c
+++ b/drivers/staging/usbip/usbip_common.c
@@ -339,7 +339,7 @@ void usbip_dump_header(struct usbip_header *pdu)
 EXPORT_SYMBOL_GPL(usbip_dump_header);
 
 /* Receive data over TCP/IP. */
-int usbip_recv(struct socket *sock, void *buf, int size)
+int usbip_recv(struct usbip_device *ud, void *buf, int size)
 {
int result;
struct msghdr msg;
@@ -352,34 +352,29 @@ int usbip_recv(struct socket *sock, void *buf, int size)
 
usbip_dbg_xmit("enter\n");
 
-   if (!sock || !buf || !size) {
-   pr_err("invalid arg, sock %p buff %p size %d\n", sock, buf,
+   if (!ud || !buf || !size) {
+   pr_err("invalid arg, ud %p buff %p size %d\n", ud, buf,
   size);
return -EINVAL;
}
 
-   do {
-   sock->sk->sk_allocation = GFP_NOIO;
-   iov.iov_base= buf;
-   iov.iov_len = size;
-   msg.msg_name= NULL;
-   msg.msg_namelen = 0;
-   msg.msg_control = NULL;
-   msg.msg_controllen = 0;
-   msg.msg_namelen= 0;
-   msg.msg_flags  = MSG_NOSIGNAL;
-
-   result = kernel_recvmsg(sock, &msg, &iov, 1, size, MSG_WAITALL);
-   if (result <= 0) {
-   pr_debug("receive sock %p buf %p size %u ret %d total 
%d\n",
-sock, buf, size, result, total);
-   goto err;
-   }
-
-   size -= result;
-   buf += result;
-   total += result;
-   } while (size > 0);
+   ud->tcp_socket->sk->sk_allocation = GFP_NOIO;
+   iov.iov_base= buf;
+   iov.iov_len = size;
+   msg.msg_name= NULL;
+   msg.msg_namelen = 0;
+   msg.msg_control = NULL;
+   msg.msg_controllen = 0;
+   msg.msg_namelen= 0;
+   msg.msg_flags  = MSG_NOSIGNAL;
+
+   result = usbip_recvmsg(ud, &msg, &iov, 1, size, MSG_WAITALL);
+
+   if (result < 0) {
+   pr_debug("receive sock %p buf %p size %u ret %d total %d\n",
+ud->tcp_socket, buf, size, result, total);
+   return result;
+   }
 
if (usbip_dbg_flag_xmit) {
if (!in_interrupt())
@@ -393,9 +388,6 @@ int usbip_recv(struct socket *sock, void *buf, int size)
 osize, result, size, total

[PATCHv3 08/16] staging: usbip: Improve debug output

2013-09-28 Thread Dominik Paulus
For IPv6, IP:Port is unreadable.

Signed-off-by: Dominik Paulus 
Signed-off-by: Tobias Polzer 
---
 drivers/staging/usbip/userspace/src/usbipd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/usbip/userspace/src/usbipd.c 
b/drivers/staging/usbip/userspace/src/usbipd.c
index ae572c6..6550460 100644
--- a/drivers/staging/usbip/userspace/src/usbipd.c
+++ b/drivers/staging/usbip/userspace/src/usbipd.c
@@ -519,7 +519,7 @@ static int do_accept(int listenfd)
return -1;
}
 #endif
-   info("connection from %s:%s", host, port);
+   info("connection from %s, port %s", host, port);
 
return connfd;
 }
-- 
1.8.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] Staging: vt6655: 80211mgr: Cleanup of brace coding style issues

2013-09-28 Thread Martin Berglund
Cleanup of a few brace coding style issues.

Signed-off-by: Martin Berglund 
---
 drivers/staging/vt6655/80211mgr.c | 16 ++--
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/vt6655/80211mgr.c 
b/drivers/staging/vt6655/80211mgr.c
index 76c8490..7949d58 100644
--- a/drivers/staging/vt6655/80211mgr.c
+++ b/drivers/staging/vt6655/80211mgr.c
@@ -165,9 +165,8 @@ vMgrDecodeBeacon(
break;
 
case WLAN_EID_RSN:
-   if (pFrame->pRSN == NULL) {
+   if (pFrame->pRSN == NULL)
pFrame->pRSN = (PWLAN_IE_RSN)pItem;
-   }
break;
case WLAN_EID_RSN_WPA:
if (pFrame->pRSNWPA == NULL) {
@@ -382,9 +381,8 @@ vMgrDecodeAssocRequest(
break;
 
case WLAN_EID_RSN:
-   if (pFrame->pRSN == NULL) {
+   if (pFrame->pRSN == NULL)
pFrame->pRSN = (PWLAN_IE_RSN)pItem;
-   }
break;
case WLAN_EID_RSN_WPA:
if (pFrame->pRSNWPA == NULL) {
@@ -556,9 +554,8 @@ vMgrDecodeReassocRequest(
break;
 
case WLAN_EID_RSN:
-   if (pFrame->pRSN == NULL) {
+   if (pFrame->pRSN == NULL)
pFrame->pRSN = (PWLAN_IE_RSN)pItem;
-   }
break;
case WLAN_EID_RSN_WPA:
if (pFrame->pRSNWPA == NULL) {
@@ -742,9 +739,8 @@ vMgrDecodeProbeResponse(
break;
 
case WLAN_EID_RSN:
-   if (pFrame->pRSN == NULL) {
+   if (pFrame->pRSN == NULL)
pFrame->pRSN = (PWLAN_IE_RSN)pItem;
-   }
break;
case WLAN_EID_RSN_WPA:
if (pFrame->pRSNWPA == NULL) {
@@ -858,9 +854,9 @@ vMgrDecodeAuthen(
pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
   + WLAN_AUTHEN_OFF_CHALLENGE);
 
-   if unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) && 
(pItem->byElementID == WLAN_EID_CHALLENGE)) {
+   if (((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len) &&
+   pItem->byElementID == WLAN_EID_CHALLENGE)
pFrame->pChallenge = (PWLAN_IE_CHALLENGE)pItem;
-   }
 
return;
 }
-- 
1.8.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/2] staging: octeon-ethernet: don't assume that CPU 0 is special

2013-09-28 Thread Aaro Koskinen
Currently the driver assumes that CPU 0 is handling all the hard IRQs.
This is wrong in Linux SMP systems where user is allowed to assign to
hardware IRQs to any CPU. The driver will stop working if user sets
smp_affinity so that interrupts end up being handled by other than CPU
0. The patch fixes that.

Signed-off-by: Aaro Koskinen 
---
 drivers/staging/octeon/ethernet-rx.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/octeon/ethernet-rx.c 
b/drivers/staging/octeon/ethernet-rx.c
index e14a1bb..de831c1 100644
--- a/drivers/staging/octeon/ethernet-rx.c
+++ b/drivers/staging/octeon/ethernet-rx.c
@@ -80,6 +80,8 @@ struct cvm_oct_core_state {
 
 static struct cvm_oct_core_state core_state __cacheline_aligned_in_smp;
 
+static int cvm_irq_cpu = -1;
+
 static void cvm_oct_enable_napi(void *_)
 {
int cpu = smp_processor_id();
@@ -112,11 +114,7 @@ static void cvm_oct_no_more_work(void)
 {
int cpu = smp_processor_id();
 
-   /*
-* CPU zero is special.  It always has the irq enabled when
-* waiting for incoming packets.
-*/
-   if (cpu == 0) {
+   if (cpu == cvm_irq_cpu) {
enable_irq(OCTEON_IRQ_WORKQ0 + pow_receive_group);
return;
}
@@ -135,6 +133,7 @@ static irqreturn_t cvm_oct_do_interrupt(int cpl, void 
*dev_id)
 {
/* Disable the IRQ and start napi_poll. */
disable_irq_nosync(OCTEON_IRQ_WORKQ0 + pow_receive_group);
+   cvm_irq_cpu = smp_processor_id();
cvm_oct_enable_napi(NULL);
 
return IRQ_HANDLED;
@@ -547,8 +546,9 @@ void cvm_oct_rx_initialize(void)
cvmx_write_csr(CVMX_POW_WQ_INT_PC, int_pc.u64);
 
 
-   /* Scheduld NAPI now.  This will indirectly enable interrupts. */
+   /* Schedule NAPI now. */
cvm_oct_enable_one_cpu();
+   enable_irq(OCTEON_IRQ_WORKQ0 + pow_receive_group);
 }
 
 void cvm_oct_rx_shutdown(void)
-- 
1.8.4.rc3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/2] staging: octeon-ethernet: allow to use only 1 CPU for packet processing

2013-09-28 Thread Aaro Koskinen
Module parameter max_rx_cpus has off-by-one error. Fix that.

Signed-off-by: Aaro Koskinen 
---
 drivers/staging/octeon/ethernet-rx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/octeon/ethernet-rx.c 
b/drivers/staging/octeon/ethernet-rx.c
index de831c1..fe1ee49 100644
--- a/drivers/staging/octeon/ethernet-rx.c
+++ b/drivers/staging/octeon/ethernet-rx.c
@@ -513,7 +513,7 @@ void cvm_oct_rx_initialize(void)
if (NULL == dev_for_napi)
panic("No net_devices were allocated.");
 
-   if (max_rx_cpus > 1  && max_rx_cpus < num_online_cpus())
+   if (max_rx_cpus >= 1 && max_rx_cpus < num_online_cpus())
atomic_set(&core_state.available_cores, max_rx_cpus);
else
atomic_set(&core_state.available_cores, num_online_cpus());
-- 
1.8.4.rc3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 1/2] staging: octeon-ethernet: don't assume that CPU 0 is special

2013-09-28 Thread Richard Weinberger
Am 28.09.2013 21:50, schrieb Aaro Koskinen:
> Currently the driver assumes that CPU 0 is handling all the hard IRQs.
> This is wrong in Linux SMP systems where user is allowed to assign to
> hardware IRQs to any CPU. The driver will stop working if user sets
> smp_affinity so that interrupts end up being handled by other than CPU
> 0. The patch fixes that.
> 
> Signed-off-by: Aaro Koskinen 
> ---
>  drivers/staging/octeon/ethernet-rx.c | 12 ++--
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/staging/octeon/ethernet-rx.c 
> b/drivers/staging/octeon/ethernet-rx.c
> index e14a1bb..de831c1 100644
> --- a/drivers/staging/octeon/ethernet-rx.c
> +++ b/drivers/staging/octeon/ethernet-rx.c
> @@ -80,6 +80,8 @@ struct cvm_oct_core_state {
>  
>  static struct cvm_oct_core_state core_state __cacheline_aligned_in_smp;
>  
> +static int cvm_irq_cpu = -1;

Why are you introducing a new global variable here?
Can't you pass cvm_irq_cpu as argument to cvm_oct_enable_napi()?

Thanks,
//richard
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 1/2] staging: octeon-ethernet: don't assume that CPU 0 is special

2013-09-28 Thread Richard Weinberger
Am 28.09.2013 21:50, schrieb Aaro Koskinen:
> Currently the driver assumes that CPU 0 is handling all the hard IRQs.
> This is wrong in Linux SMP systems where user is allowed to assign to
> hardware IRQs to any CPU. The driver will stop working if user sets
> smp_affinity so that interrupts end up being handled by other than CPU
> 0. The patch fixes that.

You are right, sorry. I somehow mixed up the function names.

Thanks,
//richard
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 1/2] staging: octeon-ethernet: don't assume that CPU 0 is special

2013-09-28 Thread Aaro Koskinen
Hi,

On Sat, Sep 28, 2013 at 10:40:47PM +0200, Richard Weinberger wrote:
> Am 28.09.2013 21:50, schrieb Aaro Koskinen:
> > Currently the driver assumes that CPU 0 is handling all the hard IRQs.
> > This is wrong in Linux SMP systems where user is allowed to assign to
> > hardware IRQs to any CPU. The driver will stop working if user sets
> > smp_affinity so that interrupts end up being handled by other than CPU
> > 0. The patch fixes that.
> > 
> > Signed-off-by: Aaro Koskinen 
> > ---
> >  drivers/staging/octeon/ethernet-rx.c | 12 ++--
> >  1 file changed, 6 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/staging/octeon/ethernet-rx.c 
> > b/drivers/staging/octeon/ethernet-rx.c
> > index e14a1bb..de831c1 100644
> > --- a/drivers/staging/octeon/ethernet-rx.c
> > +++ b/drivers/staging/octeon/ethernet-rx.c
> > @@ -80,6 +80,8 @@ struct cvm_oct_core_state {
> >  
> >  static struct cvm_oct_core_state core_state __cacheline_aligned_in_smp;
> >  
> > +static int cvm_irq_cpu = -1;
> 
> Why are you introducing a new global variable here?
> Can't you pass cvm_irq_cpu as argument to cvm_oct_enable_napi()?

This information needs to be accessed in cvm_oct_no_more_work().
Maybe I'm missing something obvious, but I don't get how the argument
could be accessed in or passed to napi poll routine which is calling
cvm_oct_no_more_work()?

A.
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel