Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751390Ab3HSLcj (ORCPT ); Mon, 19 Aug 2013 07:32:39 -0400 Received: from mail-oa0-f50.google.com ([209.85.219.50]:64202 "EHLO mail-oa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751186Ab3HSLci (ORCPT ); Mon, 19 Aug 2013 07:32:38 -0400 MIME-Version: 1.0 X-Google-Sender-Delegation: getarunks@gmail.com Date: Mon, 19 Aug 2013 17:02:37 +0530 X-Google-Sender-Auth: PR1CC-_KT82LIyGb6s-nB4H8ZTg Message-ID: Subject: [PATCH] SeqFile: Fix overflow condition From: Arun KS To: viro@zeniv.linux.org.uk, Andrew Morton Cc: Matthew Wilcox , Bruce Fields , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, vinayak menon , Nagachandra P , Vikram MP Content-Type: multipart/mixed; boundary=089e013a282c2473b204e44b4c53 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6209 Lines: 146 --089e013a282c2473b204e44b4c53 Content-Type: text/plain; charset=ISO-8859-1 >From 27f50827e5e81f2a30544b72c1d54c3ee86835cf Mon Sep 17 00:00:00 2001 From: Arun KS Date: Mon, 19 Aug 2013 12:06:33 +0530 Subject: SeqFile: Fix overflow condition seq_path()/seq_commit() is treating a d_path() failure as an overflow condition, but it isn't. Signed-off-by: Arun KS --- 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 #include #include +#include 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.7.6 --089e013a282c2473b204e44b4c53 Content-Type: application/octet-stream; name="0001-SeqFile-Fix-overflow-condition.patch" Content-Disposition: attachment; filename="0001-SeqFile-Fix-overflow-condition.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_hkjlteop1 RnJvbSAyN2Y1MDgyN2U1ZTgxZjJhMzA1NDRiNzJjMWQ1NGMzZWU4NjgzNWNmIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBBcnVuIEtTIDxhcnVuLmtzQGJyb2FkY29tLmNvbT4KRGF0ZTog TW9uLCAxOSBBdWcgMjAxMyAxMjowNjozMyArMDUzMApTdWJqZWN0OiBTZXFGaWxlOiBGaXggb3Zl cmZsb3cgY29uZGl0aW9uCgpzZXFfcGF0aCgpL3NlcV9jb21taXQoKSBpcyB0cmVhd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ieSBzZXFfYnVm X2dldC4gIFRvIHNpZ25hbCBhbiBlcnJvciBjb25kaXRpb24sIG9yIHRoYXQgdGhlIGRhdGEKLSAq IGRpZG4ndCBmaXQgaW4gdGhlIGF2YWlsYWJsZSBzcGFjZSwgcGFzcyBhIG5lZ2F0aXZlIEBudW0g dmFsdWUuCisgKiBieSBzZXFfYnVmX2dldC4gIFRvIHNpZ25hbCBhbiBvdmVyZmxvdyBjb25kaXRp b24oZGF0YSBkaWRuJ3QgZml0CisgKiBpbiB0aGUgYXZhaWxhYmxlIHNwYWNlKSwgcGFzcyAtRU5P QlVGUyBhbmQgZm9yIG90aGVyIGVycm9ycyBwYXNzIGEKKyAqIG5lZ2F0aXZlIEBudW0gdmFsdWUu CiAgKi8KIHN0YXRpYyBpbmxpbmUgdm9pZCBzZXFfY29tbWl0KHN0cnVjdCBzZXFfZmlsZSAqbSwg aW50IG51bSkKIHsKLQlpZiAobnVtIDwgMCkgewotCQltLT5jb3VudCA9IG0tPnNpemU7Ci0JfSBl bHNlIHsKKwlpZiAobnVtID49IDApIHsKIAkJQlVHX09OKG0tPmNvdW50ICsgbnVtID4gbS0+c2l6 ZSk7CiAJCW0tPmNvdW50ICs9IG51bTsKKwl9IGVsc2UgaWYgKG51bSA9PSAtRU5PQlVGUykKKwkJ bS0+Y291bnQgPSBtLT5zaXplOwogCX0KIH0KIAotLSAKMS43LjYKCg== --089e013a282c2473b204e44b4c53-- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/