[PATCH 3/3] mm/shmem.c: check the return value of mpol_to_str()
mpol_to_str() may fail, and not fill the buffer (e.g. -EINVAL), so need check about it, or buffer may not be zero based, and next seq_printf() will cause issue. Signed-off-by: Chen Gang Cc: Cyrill Gorcunov --- mm/shmem.c |5 - 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index e59d332..ae5112f 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -886,11 +886,14 @@ redirty: static int shmem_show_mpol(struct seq_file *seq, struct mempolicy *mpol) { char buffer[64]; + int ret; if (!mpol || mpol->mode == MPOL_DEFAULT) return 0; /* show nothing */ - mpol_to_str(buffer, sizeof(buffer), mpol); + ret = mpol_to_str(buffer, sizeof(buffer), mpol); + if (ret < 0) + return ret; seq_printf(seq, ",mpol=%s", buffer); return 0; -- 1.7.7.6 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 3/3] mm/shmem.c: check the return value of mpol_to_str()
mpol_to_str() may fail, and not fill the buffer (e.g. -EINVAL), so need check about it, or buffer may not be zero based, and next seq_printf() will cause issue. Signed-off-by: Chen Gang gang.c...@asianux.com Cc: Cyrill Gorcunov gorcu...@gmail.com --- mm/shmem.c |5 - 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index e59d332..ae5112f 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -886,11 +886,14 @@ redirty: static int shmem_show_mpol(struct seq_file *seq, struct mempolicy *mpol) { char buffer[64]; + int ret; if (!mpol || mpol-mode == MPOL_DEFAULT) return 0; /* show nothing */ - mpol_to_str(buffer, sizeof(buffer), mpol); + ret = mpol_to_str(buffer, sizeof(buffer), mpol); + if (ret 0) + return ret; seq_printf(seq, ,mpol=%s, buffer); return 0; -- 1.7.7.6 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 3/3] mm/shmem.c: check the return value of mpol_to_str()
mpol_to_str() may fail, and not fill the buffer (e.g. -EINVAL), so need check about it, or buffer may not be zero based, and next seq_printf() will cause issue. Also print related warning when the buffer space is not enough. Signed-off-by: Chen Gang --- mm/shmem.c | 15 ++- 1 files changed, 14 insertions(+), 1 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 75010ba..eb4eec8 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -886,11 +886,24 @@ redirty: static void shmem_show_mpol(struct seq_file *seq, struct mempolicy *mpol) { char buffer[64]; + int ret; if (!mpol || mpol->mode == MPOL_DEFAULT) return; /* show nothing */ - mpol_to_str(buffer, sizeof(buffer), mpol); + ret = mpol_to_str(buffer, sizeof(buffer), mpol); + if (ret < 0) + switch (ret) { + case -ENOSPC: + printk(KERN_WARNING + "in %s: string is truncated in mpol_to_str().\n", + __func__); + default: + printk(KERN_ERR + "in %s: call mpol_to_str() fail, errcode: %d. buffer: %p, size: %zu, pol: %p\n", + __func__, ret, buffer, sizeof(buffer), mpol); + return; + } seq_printf(seq, ",mpol=%s", buffer); } -- 1.7.7.6 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 3/3] mm/shmem.c: check the return value of mpol_to_str()
mpol_to_str() may fail, and not fill the buffer (e.g. -EINVAL), so need check about it, or buffer may not be zero based, and next seq_printf() will cause issue. Also print related warning when the buffer space is not enough. Signed-off-by: Chen Gang gang.c...@asianux.com --- mm/shmem.c | 15 ++- 1 files changed, 14 insertions(+), 1 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 75010ba..eb4eec8 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -886,11 +886,24 @@ redirty: static void shmem_show_mpol(struct seq_file *seq, struct mempolicy *mpol) { char buffer[64]; + int ret; if (!mpol || mpol-mode == MPOL_DEFAULT) return; /* show nothing */ - mpol_to_str(buffer, sizeof(buffer), mpol); + ret = mpol_to_str(buffer, sizeof(buffer), mpol); + if (ret 0) + switch (ret) { + case -ENOSPC: + printk(KERN_WARNING + in %s: string is truncated in mpol_to_str().\n, + __func__); + default: + printk(KERN_ERR + in %s: call mpol_to_str() fail, errcode: %d. buffer: %p, size: %zu, pol: %p\n, + __func__, ret, buffer, sizeof(buffer), mpol); + return; + } seq_printf(seq, ,mpol=%s, buffer); } -- 1.7.7.6 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/