Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PATCH 3/3] tools/hv: Fix permissions of created directory and files

3 views
Skip to first unread message

Tomas Hozza

unread,
Nov 9, 2012, 9:03:40 AM11/9/12
to ol...@aepfle.de, k...@microsoft.com, gre...@linuxfoundation.org, linux-...@vger.kernel.org, de...@linuxdriverproject.org, a...@canonical.com, jaso...@redhat.com, b...@decadent.org.uk, Tomas Hozza
From: Ben Hutchings <b...@decadent.org.uk>

It's silly to create directories without execute permission, or to
give permissions to 'other' but not the group-owner.

Write the permissions in octal and 'ls -l' format since these are much
easier to read than the named macros.

Signed-off-by: Ben Hutchings <b...@decadent.org.uk>
Signed-off-by: Tomas Hozza <tho...@redhat.com>
---
tools/hv/hv_kvp_daemon.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 573b9aa..9609858 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -236,7 +236,7 @@ static int kvp_file_init(void)
int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;

if (access("/var/lib/hyperv", F_OK)) {
- if (mkdir("/var/lib/hyperv", S_IRUSR | S_IWUSR | S_IROTH)) {
+ if (mkdir("/var/lib/hyperv", 0755 /* rwxr-xr-x */)) {
syslog(LOG_ERR, " Failed to create /var/lib/hyperv");
exit(EXIT_FAILURE);
}
@@ -247,7 +247,7 @@ static int kvp_file_init(void)
records_read = 0;
num_blocks = 1;
sprintf(fname, "/var/lib/hyperv/.kvp_pool_%d", i);
- fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH);
+ fd = open(fname, O_RDWR | O_CREAT, 0644 /* rw-r--r-- */);

if (fd == -1)
return 1;
--
1.7.11.7

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Tomas Hozza

unread,
Nov 9, 2012, 9:05:00 AM11/9/12
to ol...@aepfle.de, k...@microsoft.com, gre...@linuxfoundation.org, linux-...@vger.kernel.org, de...@linuxdriverproject.org, a...@canonical.com, jaso...@redhat.com, b...@decadent.org.uk, Tomas Hozza
Initial patch by Ben Hutchings <b...@decadent.org.uk>

We will install this in /usr, so it must use /var/lib for its state.
Only programs installed under /opt should use /var/opt.

Signed-off-by: Tomas Hozza <tho...@redhat.com>
---
tools/hv/hv_kvp_daemon.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 54ecb95..d9b3a74 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -98,7 +98,7 @@ static struct utsname uts_buf;
* The location of the interface configuration file.
*/

-#define KVP_CONFIG_LOC "/var/opt/"
+#define KVP_CONFIG_LOC "/var/lib/"

#define MAX_FILE_NAME 100
#define ENTRIES_PER_BLOCK 50
@@ -235,9 +235,9 @@ static int kvp_file_init(void)
int i;
int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;

- if (access("/var/opt/hyperv", F_OK)) {
- if (mkdir("/var/opt/hyperv", S_IRUSR | S_IWUSR | S_IROTH)) {
- syslog(LOG_ERR, " Failed to create /var/opt/hyperv");
+ if (access("/var/lib/hyperv", F_OK)) {
+ if (mkdir("/var/lib/hyperv", S_IRUSR | S_IWUSR | S_IROTH)) {
+ syslog(LOG_ERR, " Failed to create /var/lib/hyperv");
exit(EXIT_FAILURE);
}
}
@@ -246,7 +246,7 @@ static int kvp_file_init(void)
fname = kvp_file_info[i].fname;
records_read = 0;
num_blocks = 1;
- sprintf(fname, "/var/opt/hyperv/.kvp_pool_%d", i);
+ sprintf(fname, "/var/lib/hyperv/.kvp_pool_%d", i);
fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH);

if (fd == -1)

Tomas Hozza

unread,
Nov 9, 2012, 9:07:39 AM11/9/12
to ol...@aepfle.de, k...@microsoft.com, gre...@linuxfoundation.org, linux-...@vger.kernel.org, de...@linuxdriverproject.org, a...@canonical.com, jaso...@redhat.com, b...@decadent.org.uk, Tomas Hozza
Initial patch by Ben Hutchings <b...@decadent.org.uk>

Standard C strings are arrays of char, not __u8 (unsigned char).
Declare variables and parameters accordingly, and add the necessary
casts.

Signed-off-by: Tomas Hozza <tho...@redhat.com>
---
tools/hv/hv_kvp_daemon.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index d9b3a74..573b9aa 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -300,7 +300,7 @@ static int kvp_file_init(void)
return 0;
}

-static int kvp_key_delete(int pool, __u8 *key, int key_size)
+static int kvp_key_delete(int pool, const char *key, int key_size)
{
int i;
int j, k;
@@ -343,7 +343,7 @@ static int kvp_key_delete(int pool, __u8 *key, int key_size)
return 1;
}

-static int kvp_key_add_or_modify(int pool, __u8 *key, int key_size, __u8 *value,
+static int kvp_key_add_or_modify(int pool, const char *key, int key_size, const char *value,
int value_size)
{
int i;
@@ -397,7 +397,7 @@ static int kvp_key_add_or_modify(int pool, __u8 *key, int key_size, __u8 *value,
return 0;
}

-static int kvp_get_value(int pool, __u8 *key, int key_size, __u8 *value,
+static int kvp_get_value(int pool, const char *key, int key_size, char *value,
int value_size)
{
int i;
@@ -429,8 +429,8 @@ static int kvp_get_value(int pool, __u8 *key, int key_size, __u8 *value,
return 1;
}

-static int kvp_pool_enumerate(int pool, int index, __u8 *key, int key_size,
- __u8 *value, int value_size)
+static int kvp_pool_enumerate(int pool, int index, char *key, int key_size,
+ char *value, int value_size)
{
struct kvp_record *record;

KY Srinivasan

unread,
Nov 9, 2012, 10:53:39 AM11/9/12
to Tomas Hozza, ol...@aepfle.de, gre...@linuxfoundation.org, linux-...@vger.kernel.org, de...@linuxdriverproject.org, a...@canonical.com, jaso...@redhat.com, b...@decadent.org.uk


> -----Original Message-----
> From: Tomas Hozza [mailto:tho...@redhat.com]
> Sent: Friday, November 09, 2012 9:01 AM
> To: ol...@aepfle.de; KY Srinivasan; gre...@linuxfoundation.org; linux-
> ker...@vger.kernel.org; de...@linuxdriverproject.org; a...@canonical.com;
> jaso...@redhat.com; b...@decadent.org.uk
> Cc: Tomas Hozza
> Subject: [PATCH 3/3] tools/hv: Fix permissions of created directory and files
>
> From: Ben Hutchings <b...@decadent.org.uk>
>
> It's silly to create directories without execute permission, or to
> give permissions to 'other' but not the group-owner.
>
> Write the permissions in octal and 'ls -l' format since these are much
> easier to read than the named macros.
>
> Signed-off-by: Ben Hutchings <b...@decadent.org.uk>
> Signed-off-by: Tomas Hozza <tho...@redhat.com>

Acked-by: K. Y. Srinivasan <k...@microsoft.com>

KY Srinivasan

unread,
Nov 9, 2012, 10:57:01 AM11/9/12
to Tomas Hozza, ol...@aepfle.de, gre...@linuxfoundation.org, linux-...@vger.kernel.org, de...@linuxdriverproject.org, a...@canonical.com, jaso...@redhat.com, b...@decadent.org.uk


> -----Original Message-----
> From: Tomas Hozza [mailto:tho...@redhat.com]
> Sent: Friday, November 09, 2012 9:01 AM
> To: ol...@aepfle.de; KY Srinivasan; gre...@linuxfoundation.org; linux-
> ker...@vger.kernel.org; de...@linuxdriverproject.org; a...@canonical.com;
> jaso...@redhat.com; b...@decadent.org.uk
> Cc: Tomas Hozza
Why don't you use the macro defined earlier for the path for /var/lib. Why
not include the hyperv directory as well in the macro.

Regards,

K. Y

KY Srinivasan

unread,
Nov 9, 2012, 10:57:39 AM11/9/12
to Tomas Hozza, ol...@aepfle.de, gre...@linuxfoundation.org, linux-...@vger.kernel.org, de...@linuxdriverproject.org, a...@canonical.com, jaso...@redhat.com, b...@decadent.org.uk


> -----Original Message-----
> From: Tomas Hozza [mailto:tho...@redhat.com]
> Sent: Friday, November 09, 2012 9:01 AM
> To: ol...@aepfle.de; KY Srinivasan; gre...@linuxfoundation.org; linux-
> ker...@vger.kernel.org; de...@linuxdriverproject.org; a...@canonical.com;
> jaso...@redhat.com; b...@decadent.org.uk
> Cc: Tomas Hozza
> Subject: [PATCH 2/3] tools/hv: Fix string types
>
> Initial patch by Ben Hutchings <b...@decadent.org.uk>
>
> Standard C strings are arrays of char, not __u8 (unsigned char).
> Declare variables and parameters accordingly, and add the necessary
> casts.
>
> Signed-off-by: Tomas Hozza <tho...@redhat.com>
Acked-by: K. Y. Srinivasan <k...@microsoft.com>

KY Srinivasan

unread,
Nov 9, 2012, 10:58:41 AM11/9/12
to Tomas Hozza, ol...@aepfle.de, gre...@linuxfoundation.org, linux-...@vger.kernel.org, de...@linuxdriverproject.org, a...@canonical.com, jaso...@redhat.com, b...@decadent.org.uk


> -----Original Message-----
> From: Tomas Hozza [mailto:tho...@redhat.com]
> Sent: Friday, November 09, 2012 9:01 AM
> To: ol...@aepfle.de; KY Srinivasan; gre...@linuxfoundation.org; linux-
> ker...@vger.kernel.org; de...@linuxdriverproject.org; a...@canonical.com;
> jaso...@redhat.com; b...@decadent.org.uk
> Cc: Tomas Hozza
> Subject: [PATCH 3/3] tools/hv: Fix permissions of created directory and files
>
> From: Ben Hutchings <b...@decadent.org.uk>
>
> It's silly to create directories without execute permission, or to
> give permissions to 'other' but not the group-owner.
>
> Write the permissions in octal and 'ls -l' format since these are much
> easier to read than the named macros.
>
> Signed-off-by: Ben Hutchings <b...@decadent.org.uk>
> Signed-off-by: Tomas Hozza <tho...@redhat.com>
Acked-by: K. Y. Srinivasan <k...@microsoft.com>

Tomas Hozza

unread,
Nov 12, 2012, 3:56:06 AM11/12/12
to gre...@linuxfoundation.org, linux-...@vger.kernel.org, de...@linuxdriverproject.org, ol...@aepfle.de, a...@canonical.com, jaso...@redhat.com, k...@microsoft.com, b...@decadent.org.uk, Tomas Hozza
Initial patch by Ben Hutchings <b...@decadent.org.uk>

We will install this in /usr, so it must use /var/lib for its state.
Only programs installed under /opt should use /var/opt.

Signed-off-by: Tomas Hozza <tho...@redhat.com>
---
tools/hv/hv_kvp_daemon.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 54ecb95..d80a612 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -98,7 +98,7 @@ static struct utsname uts_buf;
* The location of the interface configuration file.
*/

-#define KVP_CONFIG_LOC "/var/opt/"
+#define KVP_CONFIG_LOC "/var/lib/hyperv"

#define MAX_FILE_NAME 100
#define ENTRIES_PER_BLOCK 50
@@ -235,9 +235,9 @@ static int kvp_file_init(void)
int i;
int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;

- if (access("/var/opt/hyperv", F_OK)) {
- if (mkdir("/var/opt/hyperv", S_IRUSR | S_IWUSR | S_IROTH)) {
- syslog(LOG_ERR, " Failed to create /var/opt/hyperv");
+ if (access(KVP_CONFIG_LOC, F_OK)) {
+ if (mkdir(KVP_CONFIG_LOC, S_IRUSR | S_IWUSR | S_IROTH)) {
+ syslog(LOG_ERR, " Failed to create %s", KVP_CONFIG_LOC);
exit(EXIT_FAILURE);
}
}
@@ -246,7 +246,7 @@ static int kvp_file_init(void)
fname = kvp_file_info[i].fname;
records_read = 0;
num_blocks = 1;
- sprintf(fname, "/var/opt/hyperv/.kvp_pool_%d", i);
+ sprintf(fname, "%s/.kvp_pool_%d", KVP_CONFIG_LOC, i);
fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH);

if (fd == -1)
@@ -1263,7 +1263,7 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val)
*/

snprintf(if_file, sizeof(if_file), "%s%s%s", KVP_CONFIG_LOC,
- "hyperv/ifcfg-", if_name);
+ "/ifcfg-", if_name);

file = fopen(if_file, "w");

Tomas Hozza

unread,
Nov 12, 2012, 3:56:22 AM11/12/12
to gre...@linuxfoundation.org, linux-...@vger.kernel.org, de...@linuxdriverproject.org, ol...@aepfle.de, a...@canonical.com, jaso...@redhat.com, k...@microsoft.com, b...@decadent.org.uk, Tomas Hozza
From: Ben Hutchings <b...@decadent.org.uk>

It's silly to create directories without execute permission, or to
give permissions to 'other' but not the group-owner.

Write the permissions in octal and 'ls -l' format since these are much
easier to read than the named macros.

Signed-off-by: Ben Hutchings <b...@decadent.org.uk>
Signed-off-by: Tomas Hozza <tho...@redhat.com>
---
tools/hv/hv_kvp_daemon.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index a581b3f..17703c7 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -236,7 +236,7 @@ static int kvp_file_init(void)
int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;

if (access(KVP_CONFIG_LOC, F_OK)) {
- if (mkdir(KVP_CONFIG_LOC, S_IRUSR | S_IWUSR | S_IROTH)) {
+ if (mkdir(KVP_CONFIG_LOC, 0755 /* rwxr-xr-x */)) {
syslog(LOG_ERR, " Failed to create %s", KVP_CONFIG_LOC);
exit(EXIT_FAILURE);
}
@@ -247,7 +247,7 @@ static int kvp_file_init(void)
records_read = 0;
num_blocks = 1;
sprintf(fname, "%s/.kvp_pool_%d", KVP_CONFIG_LOC, i);
- fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH);
+ fd = open(fname, O_RDWR | O_CREAT, 0644 /* rw-r--r-- */);

if (fd == -1)
return 1;

gre...@linuxfoundation.org

unread,
Nov 15, 2012, 6:38:13 PM11/15/12
to KY Srinivasan, Tomas Hozza, ol...@aepfle.de, linux-...@vger.kernel.org, de...@linuxdriverproject.org, a...@canonical.com, jaso...@redhat.com, b...@decadent.org.uk
On Fri, Nov 09, 2012 at 03:56:14PM +0000, KY Srinivasan wrote:
> > -----Original Message-----
> > From: Tomas Hozza [mailto:tho...@redhat.com]

<snip>

KY, there have been a few of these tools/hv patches floating by, and you
haven't acked all of them from what I can tell. I've applied some of
them, but I know I've missed some. Can you please resend the ones I've
missed that Tomas has sent, but I've not applied?

thanks,

greg k-h

KY Srinivasan

unread,
Nov 15, 2012, 6:53:39 PM11/15/12
to gre...@linuxfoundation.org, Tomas Hozza, ol...@aepfle.de, linux-...@vger.kernel.org, de...@linuxdriverproject.org, a...@canonical.com, jaso...@redhat.com, b...@decadent.org.uk


> -----Original Message-----
> From: gre...@linuxfoundation.org [mailto:gre...@linuxfoundation.org]
> Sent: Thursday, November 15, 2012 6:38 PM
> To: KY Srinivasan
> Cc: Tomas Hozza; ol...@aepfle.de; linux-...@vger.kernel.org;
> de...@linuxdriverproject.org; a...@canonical.com; jaso...@redhat.com;
> b...@decadent.org.uk
> Subject: Re: [PATCH 1/3] tools/hv: Fix /var subdirectory
>
> On Fri, Nov 09, 2012 at 03:56:14PM +0000, KY Srinivasan wrote:
> > > -----Original Message-----
> > > From: Tomas Hozza [mailto:tho...@redhat.com]
>
> <snip>
>
> KY, there have been a few of these tools/hv patches floating by, and you
> haven't acked all of them from what I can tell. I've applied some of
> them, but I know I've missed some. Can you please resend the ones I've
> missed that Tomas has sent, but I've not applied?

Will do. I am currently travelling in China and should be back in NJ this weekend. I will
handle these after I get back to NJ.

Regards,

K. Y

KY Srinivasan

unread,
Nov 26, 2012, 3:41:04 PM11/26/12
to Tomas Hozza, gre...@linuxfoundation.org, linux-...@vger.kernel.org, de...@linuxdriverproject.org, ol...@aepfle.de, a...@canonical.com, jaso...@redhat.com, b...@decadent.org.uk


> -----Original Message-----
> From: Tomas Hozza [mailto:tho...@redhat.com]
> Sent: Monday, November 12, 2012 3:55 AM
> To: gre...@linuxfoundation.org; linux-...@vger.kernel.org;
> de...@linuxdriverproject.org; ol...@aepfle.de; a...@canonical.com;
> jaso...@redhat.com; KY Srinivasan; b...@decadent.org.uk
> Cc: Tomas Hozza
> Subject: [PATCH 3/3] tools/hv: Fix permissions of created directory and files
>
> From: Ben Hutchings <b...@decadent.org.uk>
>
> It's silly to create directories without execute permission, or to
> give permissions to 'other' but not the group-owner.
>
> Write the permissions in octal and 'ls -l' format since these are much
> easier to read than the named macros.
>
> Signed-off-by: Ben Hutchings <b...@decadent.org.uk>
> Signed-off-by: Tomas Hozza <tho...@redhat.com>
Acked-by: K. Y. Srinivasan <k...@microsoft.com>

KY Srinivasan

unread,
Nov 26, 2012, 3:43:05 PM11/26/12
to Tomas Hozza, gre...@linuxfoundation.org, linux-...@vger.kernel.org, de...@linuxdriverproject.org, ol...@aepfle.de, a...@canonical.com, jaso...@redhat.com, b...@decadent.org.uk


> -----Original Message-----
> From: Tomas Hozza [mailto:tho...@redhat.com]
> jaso...@redhat.com; KY Srinivasan; b...@decadent.org.uk
> Cc: Tomas Hozza
> Subject: [PATCH 1/3] tools/hv: Fix /var subdirectory
>
> Initial patch by Ben Hutchings <b...@decadent.org.uk>
>
> We will install this in /usr, so it must use /var/lib for its state.
> Only programs installed under /opt should use /var/opt.
>
> Signed-off-by: Tomas Hozza <tho...@redhat.com>
Acked-by: K. Y. Srinivasan <k...@microsoft.com>


gre...@linuxfoundation.org

unread,
Nov 26, 2012, 4:12:27 PM11/26/12
to KY Srinivasan, Tomas Hozza, linux-...@vger.kernel.org, de...@linuxdriverproject.org, ol...@aepfle.de, a...@canonical.com, jaso...@redhat.com, b...@decadent.org.uk
On Mon, Nov 26, 2012 at 08:42:40PM +0000, KY Srinivasan wrote:
>
>
> > -----Original Message-----
> > From: Tomas Hozza [mailto:tho...@redhat.com]
> > Sent: Monday, November 12, 2012 3:55 AM
> > To: gre...@linuxfoundation.org; linux-...@vger.kernel.org;
> > de...@linuxdriverproject.org; ol...@aepfle.de; a...@canonical.com;
> > jaso...@redhat.com; KY Srinivasan; b...@decadent.org.uk
> > Cc: Tomas Hozza
> > Subject: [PATCH 1/3] tools/hv: Fix /var subdirectory
> >
> > Initial patch by Ben Hutchings <b...@decadent.org.uk>
> >
> > We will install this in /usr, so it must use /var/lib for its state.
> > Only programs installed under /opt should use /var/opt.
> >
> > Signed-off-by: Tomas Hozza <tho...@redhat.com>
> Acked-by: K. Y. Srinivasan <k...@microsoft.com>

As I stated before, you need to rediff these, and resend them to me, I
have no more hyperv patches in my queue to apply.

greg k-h

KY Srinivasan

unread,
Nov 26, 2012, 4:16:15 PM11/26/12
to gre...@linuxfoundation.org, Tomas Hozza, linux-...@vger.kernel.org, de...@linuxdriverproject.org, ol...@aepfle.de, a...@canonical.com, jaso...@redhat.com, b...@decadent.org.uk


> -----Original Message-----
> From: gre...@linuxfoundation.org [mailto:gre...@linuxfoundation.org]
> Sent: Monday, November 26, 2012 4:12 PM
> To: KY Srinivasan
> Cc: Tomas Hozza; linux-...@vger.kernel.org; de...@linuxdriverproject.org;
> ol...@aepfle.de; a...@canonical.com; jaso...@redhat.com;
> b...@decadent.org.uk
> Subject: Re: [PATCH 1/3] tools/hv: Fix /var subdirectory
>
> On Mon, Nov 26, 2012 at 08:42:40PM +0000, KY Srinivasan wrote:
> >
> >
> > > -----Original Message-----
> > > From: Tomas Hozza [mailto:tho...@redhat.com]
> > > Sent: Monday, November 12, 2012 3:55 AM
> > > To: gre...@linuxfoundation.org; linux-...@vger.kernel.org;
> > > de...@linuxdriverproject.org; ol...@aepfle.de; a...@canonical.com;
> > > jaso...@redhat.com; KY Srinivasan; b...@decadent.org.uk
> > > Cc: Tomas Hozza
> > > Subject: [PATCH 1/3] tools/hv: Fix /var subdirectory
> > >
> > > Initial patch by Ben Hutchings <b...@decadent.org.uk>
> > >
> > > We will install this in /usr, so it must use /var/lib for its state.
> > > Only programs installed under /opt should use /var/opt.
> > >
> > > Signed-off-by: Tomas Hozza <tho...@redhat.com>
> > Acked-by: K. Y. Srinivasan <k...@microsoft.com>
>
> As I stated before, you need to rediff these, and resend them to me, I
> have no more hyperv patches in my queue to apply.

Will do. There were totally 3 patches that Tomas had sent that I acked today. Tomas, could you
rebase the patches (if needed) and re-send them.

K. Y

Tomas Hozza

unread,
Nov 27, 2012, 2:57:12 AM11/27/12
to gre...@linuxfoundation.org, linux-...@vger.kernel.org, de...@linuxdriverproject.org, ol...@aepfle.de, a...@canonical.com, jaso...@redhat.com, k...@microsoft.com, b...@decadent.org.uk, Tomas Hozza
kvp_get_if_name and kvp_mac_to_if_name copy strings into statically
sized buffers which could be too small to store really long names.

Buffer sizes have been changed to PATH_MAX, include "limits.h" where
PATH_MAX is defined was added and length checks ware added via snprintf.

Signed-off-by: Tomas Hozza <tho...@redhat.com>
---
tools/hv/hv_kvp_daemon.c | 26 +++++++++-----------------
1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index d25a469..90f1f07 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -44,6 +44,7 @@
#include <fcntl.h>
#include <dirent.h>
#include <net/if.h>
+#include <limits.h>

/*
* KVP protocol: The user mode component first registers with the
@@ -592,26 +593,22 @@ static char *kvp_get_if_name(char *guid)
DIR *dir;
struct dirent *entry;
FILE *file;
- char *p, *q, *x;
+ char *p, *x;
char *if_name = NULL;
char buf[256];
char *kvp_net_dir = "/sys/class/net/";
- char dev_id[256];
+ char dev_id[PATH_MAX];

dir = opendir(kvp_net_dir);
if (dir == NULL)
return NULL;

- snprintf(dev_id, sizeof(dev_id), "%s", kvp_net_dir);
- q = dev_id + strlen(kvp_net_dir);
-
while ((entry = readdir(dir)) != NULL) {
/*
* Set the state for the next pass.
*/
- *q = '\0';
- strcat(dev_id, entry->d_name);
- strcat(dev_id, "/device/device_id");
+ snprintf(dev_id, sizeof(dev_id), "%s%s/device/device_id", kvp_net_dir,
+ entry->d_name);

file = fopen(dev_id, "r");
if (file == NULL)
@@ -684,28 +681,23 @@ static char *kvp_mac_to_if_name(char *mac)
DIR *dir;
struct dirent *entry;
FILE *file;
- char *p, *q, *x;
+ char *p, *x;
char *if_name = NULL;
char buf[256];
char *kvp_net_dir = "/sys/class/net/";
- char dev_id[256];
+ char dev_id[PATH_MAX];
int i;

dir = opendir(kvp_net_dir);
if (dir == NULL)
return NULL;

- snprintf(dev_id, sizeof(dev_id), kvp_net_dir);
- q = dev_id + strlen(kvp_net_dir);
-
while ((entry = readdir(dir)) != NULL) {
/*
* Set the state for the next pass.
*/
- *q = '\0';
-
- strcat(dev_id, entry->d_name);
- strcat(dev_id, "/address");
+ snprintf(dev_id, sizeof(dev_id), "%s%s/address", kvp_net_dir,
+ entry->d_name);

file = fopen(dev_id, "r");
if (file == NULL)
--
1.7.11.7

Tomas Hozza

unread,
Nov 27, 2012, 2:57:23 AM11/27/12
to gre...@linuxfoundation.org, linux-...@vger.kernel.org, de...@linuxdriverproject.org, ol...@aepfle.de, a...@canonical.com, jaso...@redhat.com, k...@microsoft.com, b...@decadent.org.uk, Tomas Hozza
Initial patch by Ben Hutchings <b...@decadent.org.uk>

We will install this in /usr, so it must use /var/lib for its state.
Only programs installed under /opt should use /var/opt.

Signed-off-by: Tomas Hozza <tho...@redhat.com>
---
tools/hv/hv_kvp_daemon.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 90f1f07..e266251 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c

Tomas Hozza

unread,
Nov 27, 2012, 2:57:32 AM11/27/12
to gre...@linuxfoundation.org, linux-...@vger.kernel.org, de...@linuxdriverproject.org, ol...@aepfle.de, a...@canonical.com, jaso...@redhat.com, k...@microsoft.com, b...@decadent.org.uk, Tomas Hozza
From: Ben Hutchings <b...@decadent.org.uk>

It's silly to create directories without execute permission, or to
give permissions to 'other' but not the group-owner.

Write the permissions in octal and 'ls -l' format since these are much
easier to read than the named macros.

Signed-off-by: Ben Hutchings <b...@decadent.org.uk>
Signed-off-by: Tomas Hozza <tho...@redhat.com>
---
tools/hv/hv_kvp_daemon.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index e266251..7105c7b 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -236,7 +236,7 @@ static int kvp_file_init(void)
int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;

if (access(KVP_CONFIG_LOC, F_OK)) {
- if (mkdir(KVP_CONFIG_LOC, S_IRUSR | S_IWUSR | S_IROTH)) {
+ if (mkdir(KVP_CONFIG_LOC, 0755 /* rwxr-xr-x */)) {
syslog(LOG_ERR, " Failed to create %s", KVP_CONFIG_LOC);
exit(EXIT_FAILURE);
}
@@ -247,7 +247,7 @@ static int kvp_file_init(void)
records_read = 0;
num_blocks = 1;
sprintf(fname, "%s/.kvp_pool_%d", KVP_CONFIG_LOC, i);
- fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH);
+ fd = open(fname, O_RDWR | O_CREAT, 0644 /* rw-r--r-- */);

if (fd == -1)
return 1;

KY Srinivasan

unread,
Nov 27, 2012, 8:59:24 AM11/27/12
to Tomas Hozza, gre...@linuxfoundation.org, linux-...@vger.kernel.org, de...@linuxdriverproject.org, ol...@aepfle.de, a...@canonical.com, jaso...@redhat.com, b...@decadent.org.uk


> -----Original Message-----
> From: Tomas Hozza [mailto:tho...@redhat.com]
> Sent: Tuesday, November 27, 2012 2:57 AM
> To: gre...@linuxfoundation.org; linux-...@vger.kernel.org;
> de...@linuxdriverproject.org; ol...@aepfle.de; a...@canonical.com;
> jaso...@redhat.com; KY Srinivasan; b...@decadent.org.uk
> Cc: Tomas Hozza
> Subject: [PATCH 1/3] tools/hv: Fix for long file names from readdir
>
> kvp_get_if_name and kvp_mac_to_if_name copy strings into statically
> sized buffers which could be too small to store really long names.
>
> Buffer sizes have been changed to PATH_MAX, include "limits.h" where
> PATH_MAX is defined was added and length checks ware added via snprintf.
>
> Signed-off-by: Tomas Hozza <tho...@redhat.com>
Acked-by: K. Y. Srinivasan <k...@microsoft.com>

KY Srinivasan

unread,
Nov 27, 2012, 9:10:50 AM11/27/12
to Tomas Hozza, gre...@linuxfoundation.org, linux-...@vger.kernel.org, de...@linuxdriverproject.org, ol...@aepfle.de, a...@canonical.com, jaso...@redhat.com, b...@decadent.org.uk


> -----Original Message-----
> From: Tomas Hozza [mailto:tho...@redhat.com]
> Sent: Tuesday, November 27, 2012 2:57 AM
> To: gre...@linuxfoundation.org; linux-...@vger.kernel.org;
> de...@linuxdriverproject.org; ol...@aepfle.de; a...@canonical.com;
> jaso...@redhat.com; KY Srinivasan; b...@decadent.org.uk
> Cc: Tomas Hozza
> Subject: [PATCH 3/3] tools/hv: Fix permissions of created directory and files
>
> From: Ben Hutchings <b...@decadent.org.uk>
>
> It's silly to create directories without execute permission, or to
> give permissions to 'other' but not the group-owner.
>
> Write the permissions in octal and 'ls -l' format since these are much
> easier to read than the named macros.
>
> Signed-off-by: Ben Hutchings <b...@decadent.org.uk>
> Signed-off-by: Tomas Hozza <tho...@redhat.com>
Acked-by: K. Y. Srinivasan <k...@microsoft.com>

KY Srinivasan

unread,
Nov 27, 2012, 9:17:09 AM11/27/12
to Tomas Hozza, gre...@linuxfoundation.org, linux-...@vger.kernel.org, de...@linuxdriverproject.org, ol...@aepfle.de, a...@canonical.com, jaso...@redhat.com, b...@decadent.org.uk


> -----Original Message-----
> From: Tomas Hozza [mailto:tho...@redhat.com]
> Sent: Tuesday, November 27, 2012 2:57 AM
> To: gre...@linuxfoundation.org; linux-...@vger.kernel.org;
> de...@linuxdriverproject.org; ol...@aepfle.de; a...@canonical.com;
> jaso...@redhat.com; KY Srinivasan; b...@decadent.org.uk
> Cc: Tomas Hozza
> Subject: [PATCH 2/3] tools/hv: Fix /var subdirectory
>
> Initial patch by Ben Hutchings <b...@decadent.org.uk>
>
> We will install this in /usr, so it must use /var/lib for its state.
> Only programs installed under /opt should use /var/opt.
>
> Signed-off-by: Tomas Hozza <tho...@redhat.com>
Acked-by: K. Y. Srinivasan <k...@microsoft.com>

Tomas Hozza

unread,
Nov 27, 2012, 3:28:46 PM11/27/12
to Ben Hutchings, gre...@linuxfoundation.org, linux-...@vger.kernel.org, de...@linuxdriverproject.org, ol...@aepfle.de, a...@canonical.com, jaso...@redhat.com, k...@microsoft.com


----- Original Message -----
> On Tue, 2012-11-27 at 08:56 +0100, Tomas Hozza wrote:
> > kvp_get_if_name and kvp_mac_to_if_name copy strings into statically
> > sized buffers which could be too small to store really long names.
> >
> > Buffer sizes have been changed to PATH_MAX, include "limits.h"
> > where
> > PATH_MAX is defined was added and length checks ware added via
> > snprintf.
> [...]
>
> PATH_MAX has nothing to do with any actual kernel limit; it's no more
> meaningful than the current value of 256. Network interface names
> are
> limited to 15 characters, thus the current array is more than long
> enough. So I think this is entirely unnecessary.

This is just for sanity. The value PATH_MAX was chosen after discussion
with K. Y. Srinivasan and Olaf Hering instead of some "magic" number like
256 or 512.

> Using snprintf() is a good idea, but you need to check the return
> value and handle the truncation case somehow.

By using PATH_MAX sized buffer there is no need for handling the truncation
case.


Tomas Hozza

Ben Hutchings

unread,
Nov 27, 2012, 3:41:23 PM11/27/12
to Tomas Hozza, gre...@linuxfoundation.org, linux-...@vger.kernel.org, de...@linuxdriverproject.org, ol...@aepfle.de, a...@canonical.com, jaso...@redhat.com, k...@microsoft.com
On Tue, Nov 27, 2012 at 03:28:25PM -0500, Tomas Hozza wrote:
>
>
> ----- Original Message -----
> > On Tue, 2012-11-27 at 08:56 +0100, Tomas Hozza wrote:
> > > kvp_get_if_name and kvp_mac_to_if_name copy strings into statically
> > > sized buffers which could be too small to store really long names.
> > >
> > > Buffer sizes have been changed to PATH_MAX, include "limits.h"
> > > where
> > > PATH_MAX is defined was added and length checks ware added via
> > > snprintf.
> > [...]
> >
> > PATH_MAX has nothing to do with any actual kernel limit; it's no more
> > meaningful than the current value of 256. Network interface names
> > are
> > limited to 15 characters, thus the current array is more than long
> > enough. So I think this is entirely unnecessary.
>
> This is just for sanity. The value PATH_MAX was chosen after discussion
> with K. Y. Srinivasan and Olaf Hering instead of some "magic" number like
> 256 or 512.

PATH_MAX is a magic name.

> > Using snprintf() is a good idea, but you need to check the return
> > value and handle the truncation case somehow.
>
> By using PATH_MAX sized buffer there is no need for handling the truncation
> case.

You are claiming two contradictory things: sprintf() may overrun the
buffer, so we need the length check provided by snprintf(), but there
is no need to check for truncation because we know the length is
sufficient.

Ben.

--
Ben Hutchings
We get into the habit of living before acquiring the habit of thinking.
- Albert Camus

Tomas Hozza

unread,
Dec 18, 2012, 3:06:32 AM12/18/12
to Ben Hutchings, gre...@linuxfoundation.org, linux-...@vger.kernel.org, de...@linuxdriverproject.org, ol...@aepfle.de, a...@canonical.com, jaso...@redhat.com, k...@microsoft.com
----- Original Message -----
> > This is just for sanity. The value PATH_MAX was chosen after
> > discussion
> > with K. Y. Srinivasan and Olaf Hering instead of some "magic"
> > number like
> > 256 or 512.
>
> PATH_MAX is a magic name.

It is defined in "limits.h". I would welcome some more constructive
argumentation and critics.

> > > Using snprintf() is a good idea, but you need to check the return
> > > value and handle the truncation case somehow.
> >
> > By using PATH_MAX sized buffer there is no need for handling the
> > truncation
> > case.
>
> You are claiming two contradictory things: sprintf() may overrun the
> buffer, so we need the length check provided by snprintf(), but there
> is no need to check for truncation because we know the length is
> sufficient.

So what do you propose? How should it be solved?

Thank you.

Regards,
Tomas Hozza

Greg KH

unread,
Jan 17, 2013, 1:41:23 PM1/17/13
to Ben Hutchings, Tomas Hozza, ol...@aepfle.de, jaso...@redhat.com, linux-...@vger.kernel.org, a...@canonical.com, de...@linuxdriverproject.org
On Tue, Dec 18, 2012 at 12:38:03PM +0000, Ben Hutchings wrote:
> On Tue, 2012-12-18 at 03:06 -0500, Tomas Hozza wrote:
> > ----- Original Message -----
> > > > This is just for sanity. The value PATH_MAX was chosen after
> > > > discussion
> > > > with K. Y. Srinivasan and Olaf Hering instead of some "magic"
> > > > number like
> > > > 256 or 512.
> > >
> > > PATH_MAX is a magic name.
> >
> > It is defined in "limits.h". I would welcome some more constructive
> > argumentation and critics.
>
> It still bears no relation to any actual limit in the C library or Linux
> kernel. So it's no more valid than the previous number.
>
> In the current context we're enumerating /sys/class/net and we know that
> all the interface names in there are limited to IFNAMSIZ-1 = 15 (there
> is also potentially "bonding_masters"). The longest path name we need
> to use is definitely much shorter than even 256 bytes.
>
> > > > > Using snprintf() is a good idea, but you need to check the return
> > > > > value and handle the truncation case somehow.
> > > >
> > > > By using PATH_MAX sized buffer there is no need for handling the
> > > > truncation
> > > > case.
> > >
> > > You are claiming two contradictory things: sprintf() may overrun the
> > > buffer, so we need the length check provided by snprintf(), but there
> > > is no need to check for truncation because we know the length is
> > > sufficient.
> >
> > So what do you propose? How should it be solved?
>
> if (snprintf(dev_id, sizeof(dev_id), ...) >= sizeof(dev_id))
> continue;
>
> Possibly logging a warning.

I agree, I'm dropping this patch from my to-apply queue.

greg k-h
0 new messages