* [PATCH 1/2] Ensure nul-termination of file names read from checkpoint images
@ 2009-10-23 17:58 Matt Helsley
[not found] ` <bb799d3c1e3e27d60dac114992c3e310fe14a9e6.1256320668.git.matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Matt Helsley @ 2009-10-23 17:58 UTC (permalink / raw)
To: Oren Laadan; +Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
Don't rely on the checkpoint image to properly terminate the filename.
Passing PATH_MAX + 1 won't work since it's a maximum -- not the number
of bytes to allocate. Allocate space for the string, copy an amount
according to the header length (limited to < PATH_MAX), and ensure that
it's nul-terminated.
Signed-off-by: Matt Helsley <matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
---
checkpoint/files.c | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/checkpoint/files.c b/checkpoint/files.c
index f6de07e..0564666 100644
--- a/checkpoint/files.c
+++ b/checkpoint/files.c
@@ -443,6 +443,7 @@ struct file *restore_open_fname(struct ckpt_ctx *ctx, int flags)
struct ckpt_hdr *h;
struct file *file;
char *fname;
+ int len;
/* prevent bad input from doing bad things */
if (flags & (O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC))
@@ -451,10 +452,19 @@ struct file *restore_open_fname(struct ckpt_ctx *ctx, int flags)
h = ckpt_read_buf_type(ctx, PATH_MAX, CKPT_HDR_FILE_NAME);
if (IS_ERR(h))
return (struct file *) h;
- fname = (char *) (h + 1);
+ len = h->len - sizeof(*h);
+ fname = kmalloc(len + 1, GFP_KERNEL);
+ if (!fname) {
+ file = NULL;
+ goto out;
+ }
+ strncpy(fname, (char *) (h + 1), len);
+ fname[len] = '\0';
ckpt_debug("fname '%s' flags %#x\n", fname, flags);
file = filp_open(fname, flags, 0);
+ kfree(fname);
+out:
ckpt_hdr_put(ctx, h);
return file;
--
1.5.6.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/2] File name length limit off by sizeof(struct ckpt_hdr)
[not found] ` <bb799d3c1e3e27d60dac114992c3e310fe14a9e6.1256320668.git.matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
@ 2009-10-23 17:58 ` Matt Helsley
[not found] ` <633d58fa4318bd9ae8d9955cfa70d246184c38a5.1256320668.git.matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-10-24 0:23 ` [PATCH 1/2] Ensure nul-termination of file names read from checkpoint images Oren Laadan
1 sibling, 1 reply; 8+ messages in thread
From: Matt Helsley @ 2009-10-23 17:58 UTC (permalink / raw)
To: Oren Laadan; +Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
Unlike the length passed into ckpt_write_obj_type, the maximum length passed
to ckpt_read_buf_type must include the length of the struct ckpt_hdr.
Signed-off-by: Matt Helsley <matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
---
checkpoint/files.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/checkpoint/files.c b/checkpoint/files.c
index 0564666..562c338 100644
--- a/checkpoint/files.c
+++ b/checkpoint/files.c
@@ -449,7 +449,7 @@ struct file *restore_open_fname(struct ckpt_ctx *ctx, int flags)
if (flags & (O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC))
return ERR_PTR(-EINVAL);
- h = ckpt_read_buf_type(ctx, PATH_MAX, CKPT_HDR_FILE_NAME);
+ h = ckpt_read_buf_type(ctx, PATH_MAX + sizeof(*h), CKPT_HDR_FILE_NAME);
if (IS_ERR(h))
return (struct file *) h;
len = h->len - sizeof(*h);
--
1.5.6.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] Ensure nul-termination of file names read from checkpoint images
[not found] ` <bb799d3c1e3e27d60dac114992c3e310fe14a9e6.1256320668.git.matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-10-23 17:58 ` [PATCH 2/2] File name length limit off by sizeof(struct ckpt_hdr) Matt Helsley
@ 2009-10-24 0:23 ` Oren Laadan
[not found] ` <4AE248FC.5000401-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
1 sibling, 1 reply; 8+ messages in thread
From: Oren Laadan @ 2009-10-24 0:23 UTC (permalink / raw)
To: Matt Helsley; +Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
Matt Helsley wrote:
> Don't rely on the checkpoint image to properly terminate the filename.
> Passing PATH_MAX + 1 won't work since it's a maximum -- not the number
> of bytes to allocate. Allocate space for the string, copy an amount
> according to the header length (limited to < PATH_MAX), and ensure that
> it's nul-terminated.
>
> Signed-off-by: Matt Helsley <matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
I dislike unneeded data copy.
See ckpt_read_string() and ckpt_read_payload().
Oren.
> ---
> checkpoint/files.c | 12 +++++++++++-
> 1 files changed, 11 insertions(+), 1 deletions(-)
>
> diff --git a/checkpoint/files.c b/checkpoint/files.c
> index f6de07e..0564666 100644
> --- a/checkpoint/files.c
> +++ b/checkpoint/files.c
> @@ -443,6 +443,7 @@ struct file *restore_open_fname(struct ckpt_ctx *ctx, int flags)
> struct ckpt_hdr *h;
> struct file *file;
> char *fname;
> + int len;
>
> /* prevent bad input from doing bad things */
> if (flags & (O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC))
> @@ -451,10 +452,19 @@ struct file *restore_open_fname(struct ckpt_ctx *ctx, int flags)
> h = ckpt_read_buf_type(ctx, PATH_MAX, CKPT_HDR_FILE_NAME);
> if (IS_ERR(h))
> return (struct file *) h;
> - fname = (char *) (h + 1);
> + len = h->len - sizeof(*h);
> + fname = kmalloc(len + 1, GFP_KERNEL);
> + if (!fname) {
> + file = NULL;
> + goto out;
> + }
> + strncpy(fname, (char *) (h + 1), len);
> + fname[len] = '\0';
> ckpt_debug("fname '%s' flags %#x\n", fname, flags);
>
> file = filp_open(fname, flags, 0);
> + kfree(fname);
> +out:
> ckpt_hdr_put(ctx, h);
>
> return file;
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] File name length limit off by sizeof(struct ckpt_hdr)
[not found] ` <633d58fa4318bd9ae8d9955cfa70d246184c38a5.1256320668.git.matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
@ 2009-10-24 0:29 ` Oren Laadan
[not found] ` <4AE24A59.8020801-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Oren Laadan @ 2009-10-24 0:29 UTC (permalink / raw)
To: Matt Helsley; +Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
Matt Helsley wrote:
> Unlike the length passed into ckpt_write_obj_type, the maximum length passed
> to ckpt_read_buf_type must include the length of the struct ckpt_hdr.
IMHO, the right way to fix this is to change ckpt_read_obj_type().
This will preserve symmetry between checkpoint and restart, and also
fix a similar problem in kernel/groups.c (MAX_GROUPINFO_SIZE).
No need to resend - I'll fix already.
Oren.
>
> Signed-off-by: Matt Helsley <matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
> ---
> checkpoint/files.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/checkpoint/files.c b/checkpoint/files.c
> index 0564666..562c338 100644
> --- a/checkpoint/files.c
> +++ b/checkpoint/files.c
> @@ -449,7 +449,7 @@ struct file *restore_open_fname(struct ckpt_ctx *ctx, int flags)
> if (flags & (O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC))
> return ERR_PTR(-EINVAL);
>
> - h = ckpt_read_buf_type(ctx, PATH_MAX, CKPT_HDR_FILE_NAME);
> + h = ckpt_read_buf_type(ctx, PATH_MAX + sizeof(*h), CKPT_HDR_FILE_NAME);
> if (IS_ERR(h))
> return (struct file *) h;
> len = h->len - sizeof(*h);
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] Ensure nul-termination of file names read from checkpoint images
[not found] ` <4AE248FC.5000401-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
@ 2009-10-24 0:29 ` Oren Laadan
0 siblings, 0 replies; 8+ messages in thread
From: Oren Laadan @ 2009-10-24 0:29 UTC (permalink / raw)
To: Matt Helsley; +Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
Oren Laadan wrote:
>
> Matt Helsley wrote:
>> Don't rely on the checkpoint image to properly terminate the filename.
>> Passing PATH_MAX + 1 won't work since it's a maximum -- not the number
>> of bytes to allocate. Allocate space for the string, copy an amount
>> according to the header length (limited to < PATH_MAX), and ensure that
>> it's nul-terminated.
>>
>> Signed-off-by: Matt Helsley <matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
>
> I dislike unneeded data copy.
> See ckpt_read_string() and ckpt_read_payload().
>
No need to resend -- I'll do the fix.
Oren.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] File name length limit off by sizeof(struct ckpt_hdr)
[not found] ` <4AE24A59.8020801-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
@ 2009-10-24 2:02 ` Matt Helsley
2009-10-27 6:04 ` Serge E. Hallyn
1 sibling, 0 replies; 8+ messages in thread
From: Matt Helsley @ 2009-10-24 2:02 UTC (permalink / raw)
To: Oren Laadan; +Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
On Fri, Oct 23, 2009 at 08:29:13PM -0400, Oren Laadan wrote:
>
>
> Matt Helsley wrote:
> > Unlike the length passed into ckpt_write_obj_type, the maximum length passed
> > to ckpt_read_buf_type must include the length of the struct ckpt_hdr.
>
> IMHO, the right way to fix this is to change ckpt_read_obj_type().
Good point.
> This will preserve symmetry between checkpoint and restart, and also
> fix a similar problem in kernel/groups.c (MAX_GROUPINFO_SIZE).
>
> No need to resend - I'll fix already.
Good, thanks!
Cheers,
-Matt Helsley
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] File name length limit off by sizeof(struct ckpt_hdr)
[not found] ` <4AE24A59.8020801-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-10-24 2:02 ` Matt Helsley
@ 2009-10-27 6:04 ` Serge E. Hallyn
[not found] ` <20091027060413.GA27733-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
1 sibling, 1 reply; 8+ messages in thread
From: Serge E. Hallyn @ 2009-10-27 6:04 UTC (permalink / raw)
To: Oren Laadan; +Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
Quoting Oren Laadan (orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org):
>
>
> Matt Helsley wrote:
> > Unlike the length passed into ckpt_write_obj_type, the maximum length passed
> > to ckpt_read_buf_type must include the length of the struct ckpt_hdr.
>
> IMHO, the right way to fix this is to change ckpt_read_obj_type().
>
> This will preserve symmetry between checkpoint and restart, and also
> fix a similar problem in kernel/groups.c (MAX_GROUPINFO_SIZE).
>
> No need to resend - I'll fix already.
Oren: note with your version of the patch, restore_open_fname()
does 'return len' giving me
checkpoint/files.c: In function 'restore_open_fname':
checkpoint/files.c:457: warning: return makes pointer from integer without a cast
-serge
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] File name length limit off by sizeof(struct ckpt_hdr)
[not found] ` <20091027060413.GA27733-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
@ 2009-10-27 13:02 ` Oren Laadan
0 siblings, 0 replies; 8+ messages in thread
From: Oren Laadan @ 2009-10-27 13:02 UTC (permalink / raw)
To: Serge E. Hallyn; +Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
Serge E. Hallyn wrote:
> Quoting Oren Laadan (orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org):
>>
>> Matt Helsley wrote:
>>> Unlike the length passed into ckpt_write_obj_type, the maximum length passed
>>> to ckpt_read_buf_type must include the length of the struct ckpt_hdr.
>> IMHO, the right way to fix this is to change ckpt_read_obj_type().
>>
>> This will preserve symmetry between checkpoint and restart, and also
>> fix a similar problem in kernel/groups.c (MAX_GROUPINFO_SIZE).
>>
>> No need to resend - I'll fix already.
>
> Oren: note with your version of the patch, restore_open_fname()
> does 'return len' giving me
>
> checkpoint/files.c: In function 'restore_open_fname':
> checkpoint/files.c:457: warning: return makes pointer from integer without a cast
Oops ... that's silly. Fix queued.
Thanks,
Oren.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-10-27 13:02 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-23 17:58 [PATCH 1/2] Ensure nul-termination of file names read from checkpoint images Matt Helsley
[not found] ` <bb799d3c1e3e27d60dac114992c3e310fe14a9e6.1256320668.git.matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-10-23 17:58 ` [PATCH 2/2] File name length limit off by sizeof(struct ckpt_hdr) Matt Helsley
[not found] ` <633d58fa4318bd9ae8d9955cfa70d246184c38a5.1256320668.git.matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-10-24 0:29 ` Oren Laadan
[not found] ` <4AE24A59.8020801-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-10-24 2:02 ` Matt Helsley
2009-10-27 6:04 ` Serge E. Hallyn
[not found] ` <20091027060413.GA27733-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-10-27 13:02 ` Oren Laadan
2009-10-24 0:23 ` [PATCH 1/2] Ensure nul-termination of file names read from checkpoint images Oren Laadan
[not found] ` <4AE248FC.5000401-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-10-24 0:29 ` Oren Laadan
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.