From: Arun KS <arunks.linux@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: viro@zeniv.linux.org.uk, Matthew Wilcox <matthew@wil.cx>,
Bruce Fields <bfields@fieldses.org>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
vinayak menon <vinayakm.list@gmail.com>,
Nagachandra P <nagachandra@gmail.com>,
Vikram MP <mp.vikram@gmail.com>
Subject: [PATCH v1] seq_file: Fix overflow condition in seq_commit
Date: Tue, 20 Aug 2013 10:55:40 +0530 [thread overview]
Message-ID: <CAKZGPANQz5-uyf=uSp_0HxBq1_uH053H0XOohpAaWsbeoy7zhw@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 3802 bytes --]
>From 932a134abeac597f18c86c513704709ad154994b Mon Sep 17 00:00:00 2001
From: Arun KS <arun.ks@broadcom.com>
Date: Mon, 19 Aug 2013 12:06:33 +0530
Subject: seq_file: Fix overflow condition in seq_commit
seq_path()/seq_commit() is treating a d_path() failure as an overflow
condition, but it isn't.
seq_read handles overflow by reallocating more buffer. And this
continues in a loop utill we increase the size of seq buf beyond
KMALLOC_MAX_SIZE and hence a WARN_ON.
[ 363.192565] ------------[ cut here ]------------
[ 363.199462] WARNING: at mm/slab_common.c:377 kmalloc_slab+0x34/0x9c()
[ 363.208557] Modules linked in:
[ 363.212219] CPU: 1 PID: 1742 Comm: Binder_2 Tainted: G W3.10.0+ #17
[ 363.222930] [<c00151c4>] (unwind_backtrace+0x0/0x11c)
from[<c0011a24>] (show_stack+0x10/0x14)
[ 363.235229] [<c0011a24>] (show_stack+0x10/0x14) from
[<c0059fb0>](warn_slowpath_common+0x4c/0x68)
[ 363.247253] [<c0059fb0>] (warn_slowpath_common+0x4c/0x68)
from[<c0059fe4>] (warn_slowpath_null+0x18/0x1c)
[ 363.259307] [<c0059fe4>] (warn_slowpath_null+0x18/0x1c)
from[<c00fa400>] (kmalloc_slab+0x34/0x9c)
[ 363.270812] [<c00fa400>] (kmalloc_slab+0x34/0x9c) from
[<c010ec20>](__kmalloc+0x14/0x1fc)
[ 363.281433] [<c010ec20>] (__kmalloc+0x14/0x1fc) from
[<c012ef70>](seq_read+0x24c/0x438)
[ 363.291992] [<c012ef70>] (seq_read+0x24c/0x438) from
[<c011389c>](vfs_read+0xac/0x124)
[ 363.302398] [<c011389c>] (vfs_read+0xac/0x124) from
[<c0113a38>](SyS_read+0x3c/0x60)
[ 363.312591] [<c0113a38>] (SyS_read+0x3c/0x60) from
[<c000e180>](ret_fast_syscall+0x0/0x48)
[ 363.323303] ---[ end trace 46c6467e2db7bcd4 ]---
Pass -ENOBUFS to seq_commit to signal an overflow condition and a
negative value for all other errors.
Signed-off-by: Arun KS <arun.ks@broadcom.com>
---
fs/seq_file.c | 6 +++---
include/linux/seq_file.h | 12 +++++++-----
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 3135c25..6a33f9c 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -463,7 +463,7 @@ int seq_path(struct seq_file *m, const struct path
*path, const char *esc)
{
char *buf;
size_t size = seq_get_buf(m, &buf);
- int res = -1;
+ int res = -ENOBUFS;
if (size) {
char *p = d_path(path, buf, size);
@@ -487,7 +487,7 @@ int seq_path_root(struct seq_file *m, const struct
path *path,
{
char *buf;
size_t size = seq_get_buf(m, &buf);
- int res = -ENAMETOOLONG;
+ int res = -ENOBUFS;
if (size) {
char *p;
@@ -516,7 +516,7 @@ int seq_dentry(struct seq_file *m, struct dentry
*dentry, const char *esc)
{
char *buf;
size_t size = seq_get_buf(m, &buf);
- int res = -1;
+ int res = -ENOBUFS;
if (size) {
char *p = dentry_path(dentry, buf, size);
diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index 4e32edc..43f51a0 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -7,6 +7,7 @@
#include <linux/mutex.h>
#include <linux/cpumask.h>
#include <linux/nodemask.h>
+#include <linux/errno.h>
struct seq_operations;
struct file;
@@ -66,16 +67,17 @@ static inline size_t seq_get_buf(struct seq_file
*m, char **bufp)
* @num: the number of bytes to commit
*
* Commit @num bytes of data written to a buffer previously acquired
- * by seq_buf_get. To signal an error condition, or that the data
- * didn't fit in the available space, pass a negative @num value.
+ * by seq_buf_get. To signal an overflow condition(data didn't fit
+ * in the available space), pass -ENOBUFS and for other errors pass a
+ * negative @num value.
*/
static inline void seq_commit(struct seq_file *m, int num)
{
- if (num < 0) {
- m->count = m->size;
- } else {
+ if (num >= 0) {
BUG_ON(m->count + num > m->size);
m->count += num;
+ } else if (num == -ENOBUFS)
+ m->count = m->size;
}
}
--
1.8.2
[-- Attachment #2: 0001-seq_file-Fix-overflow-condition-in-seq_commit.patch --]
[-- Type: application/octet-stream, Size: 3814 bytes --]
From 932a134abeac597f18c86c513704709ad154994b Mon Sep 17 00:00:00 2001
From: Arun KS <arun.ks@broadcom.com>
Date: Mon, 19 Aug 2013 12:06:33 +0530
Subject: seq_file: Fix overflow condition in seq_commit
seq_path()/seq_commit() is treating a d_path() failure as an overflow
condition, but it isn't.
seq_read handles overflow by reallocating more buffer. And this
continues in a loop utill we increase the size of seq buf beyond
KMALLOC_MAX_SIZE and hence a WARN_ON.
[ 363.192565] ------------[ cut here ]------------
[ 363.199462] WARNING: at mm/slab_common.c:377 kmalloc_slab+0x34/0x9c()
[ 363.208557] Modules linked in:
[ 363.212219] CPU: 1 PID: 1742 Comm: Binder_2 Tainted: G W3.10.0+ #17
[ 363.222930] [<c00151c4>] (unwind_backtrace+0x0/0x11c) from[<c0011a24>] (show_stack+0x10/0x14)
[ 363.235229] [<c0011a24>] (show_stack+0x10/0x14) from [<c0059fb0>](warn_slowpath_common+0x4c/0x68)
[ 363.247253] [<c0059fb0>] (warn_slowpath_common+0x4c/0x68) from[<c0059fe4>] (warn_slowpath_null+0x18/0x1c)
[ 363.259307] [<c0059fe4>] (warn_slowpath_null+0x18/0x1c) from[<c00fa400>] (kmalloc_slab+0x34/0x9c)
[ 363.270812] [<c00fa400>] (kmalloc_slab+0x34/0x9c) from [<c010ec20>](__kmalloc+0x14/0x1fc)
[ 363.281433] [<c010ec20>] (__kmalloc+0x14/0x1fc) from [<c012ef70>](seq_read+0x24c/0x438)
[ 363.291992] [<c012ef70>] (seq_read+0x24c/0x438) from [<c011389c>](vfs_read+0xac/0x124)
[ 363.302398] [<c011389c>] (vfs_read+0xac/0x124) from [<c0113a38>](SyS_read+0x3c/0x60)
[ 363.312591] [<c0113a38>] (SyS_read+0x3c/0x60) from [<c000e180>](ret_fast_syscall+0x0/0x48)
[ 363.323303] ---[ end trace 46c6467e2db7bcd4 ]---
Pass -ENOBUFS to seq_commit to signal an overflow condition and a
negative value for all other errors.
Signed-off-by: Arun KS <arun.ks@broadcom.com>
---
fs/seq_file.c | 6 +++---
include/linux/seq_file.h | 12 +++++++-----
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 3135c25..6a33f9c 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -463,7 +463,7 @@ int seq_path(struct seq_file *m, const struct path *path, const char *esc)
{
char *buf;
size_t size = seq_get_buf(m, &buf);
- int res = -1;
+ int res = -ENOBUFS;
if (size) {
char *p = d_path(path, buf, size);
@@ -487,7 +487,7 @@ int seq_path_root(struct seq_file *m, const struct path *path,
{
char *buf;
size_t size = seq_get_buf(m, &buf);
- int res = -ENAMETOOLONG;
+ int res = -ENOBUFS;
if (size) {
char *p;
@@ -516,7 +516,7 @@ int seq_dentry(struct seq_file *m, struct dentry *dentry, const char *esc)
{
char *buf;
size_t size = seq_get_buf(m, &buf);
- int res = -1;
+ int res = -ENOBUFS;
if (size) {
char *p = dentry_path(dentry, buf, size);
diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index 4e32edc..43f51a0 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -7,6 +7,7 @@
#include <linux/mutex.h>
#include <linux/cpumask.h>
#include <linux/nodemask.h>
+#include <linux/errno.h>
struct seq_operations;
struct file;
@@ -66,16 +67,17 @@ static inline size_t seq_get_buf(struct seq_file *m, char **bufp)
* @num: the number of bytes to commit
*
* Commit @num bytes of data written to a buffer previously acquired
- * by seq_buf_get. To signal an error condition, or that the data
- * didn't fit in the available space, pass a negative @num value.
+ * by seq_buf_get. To signal an overflow condition(data didn't fit
+ * in the available space), pass -ENOBUFS and for other errors pass a
+ * negative @num value.
*/
static inline void seq_commit(struct seq_file *m, int num)
{
- if (num < 0) {
- m->count = m->size;
- } else {
+ if (num >= 0) {
BUG_ON(m->count + num > m->size);
m->count += num;
+ } else if (num == -ENOBUFS)
+ m->count = m->size;
}
}
--
1.8.2
next reply other threads:[~2013-08-20 5:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-20 5:25 Arun KS [this message]
2013-08-20 5:51 ` [PATCH v1] seq_file: Fix overflow condition in seq_commit Al Viro
2013-08-20 7:21 ` Arun KS
2013-08-20 7:36 ` Al Viro
2013-08-20 8:03 ` Arun KS
2013-08-20 14:04 ` Al Viro
2013-08-21 6:01 ` Arun KS
2013-10-14 22:57 ` Colin Cross
2013-10-15 18:33 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAKZGPANQz5-uyf=uSp_0HxBq1_uH053H0XOohpAaWsbeoy7zhw@mail.gmail.com' \
--to=arunks.linux@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=bfields@fieldses.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matthew@wil.cx \
--cc=mp.vikram@gmail.com \
--cc=nagachandra@gmail.com \
--cc=vinayakm.list@gmail.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).