public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dcache: error out if the name buffer is too short
@ 2014-01-24 14:04 Denys Vlasenko
  2014-01-24 16:19 ` Oleg Nesterov
  0 siblings, 1 reply; 7+ messages in thread
From: Denys Vlasenko @ 2014-01-24 14:04 UTC (permalink / raw)
  To: Al Viro; +Cc: Denys Vlasenko, Jan Kratochvil, Oleg Nesterov, linux-kernel

This change makes __dentry_path() and d_path()
immediately return ENAMETOOLONG if buflen < 2.

Cc: Jan Kratochvil <jan.kratochvil@redhat.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
---
 fs/dcache.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index cb4a106..2fba276 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -3055,6 +3055,9 @@ char *d_path(const struct path *path, char *buf, int buflen)
 	struct path root;
 	int error;
 
+	if (buflen < 2)
+		return ERR_PTR(-ENAMETOOLONG);
+
 	/*
 	 * We have various synthetic filesystems that never get mounted.  On
 	 * these filesystems dentries are never used for lookup purposes, and
@@ -3122,13 +3125,14 @@ static char *__dentry_path(struct dentry *dentry, char *buf, int buflen)
 	int len, seq = 0;
 	int error = 0;
 
+	if (buflen < 2)
+		goto Elong;
+
 	rcu_read_lock();
 restart:
 	end = buf + buflen;
 	len = buflen;
 	prepend(&end, &len, "\0", 1);
-	if (buflen < 1)
-		goto Elong;
 	/* Get '/' right */
 	retval = end-1;
 	*retval = '/';
-- 
1.8.1.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-01-27 17:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-24 14:04 [PATCH] dcache: error out if the name buffer is too short Denys Vlasenko
2014-01-24 16:19 ` Oleg Nesterov
2014-01-26 15:37   ` Oleg Nesterov
2014-01-26 15:51     ` Oleg Nesterov
2014-01-26 16:35       ` Oleg Nesterov
2014-01-26 17:41         ` Al Viro
2014-01-27 17:40           ` Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox