All of lore.kernel.org
 help / color / mirror / Atom feed
* [iproute PATCH v2] lib/bpf: Don't leak fp in bpf_find_mntpt()
@ 2017-08-21 14:46 Phil Sutter
  2017-08-22  0:35 ` Stephen Hemminger
  0 siblings, 1 reply; 2+ messages in thread
From: Phil Sutter @ 2017-08-21 14:46 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

If fopen() succeeded but len != PATH_MAX, the function leaks the open
FILE pointer. Fix this by checking len value before calling fopen().

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
---
No change since v1, just resubmitting - I forgot to add it to the
relevant patch chunk when splitting the big series up. Added Daniel's
ACK from his v1 review.
---
 lib/bpf.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/bpf.c b/lib/bpf.c
index 4f52ad4a8f023..1dcb261dc915f 100644
--- a/lib/bpf.c
+++ b/lib/bpf.c
@@ -537,8 +537,11 @@ static const char *bpf_find_mntpt(const char *fstype, unsigned long magic,
 		}
 	}
 
+	if (len != PATH_MAX)
+		return NULL;
+
 	fp = fopen("/proc/mounts", "r");
-	if (fp == NULL || len != PATH_MAX)
+	if (fp == NULL)
 		return NULL;
 
 	while (fscanf(fp, "%*s %" textify(PATH_MAX) "s %99s %*s %*d %*d\n",
-- 
2.13.1

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

* Re: [iproute PATCH v2] lib/bpf: Don't leak fp in bpf_find_mntpt()
  2017-08-21 14:46 [iproute PATCH v2] lib/bpf: Don't leak fp in bpf_find_mntpt() Phil Sutter
@ 2017-08-22  0:35 ` Stephen Hemminger
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2017-08-22  0:35 UTC (permalink / raw)
  To: Phil Sutter; +Cc: netdev

On Mon, 21 Aug 2017 16:46:51 +0200
Phil Sutter <phil@nwl.cc> wrote:

> If fopen() succeeded but len != PATH_MAX, the function leaks the open
> FILE pointer. Fix this by checking len value before calling fopen().
> 
> Signed-off-by: Phil Sutter <phil@nwl.cc>
> Acked-by: Daniel Borkmann <daniel@iogearbox.net>


Thanks, Applied

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

end of thread, other threads:[~2017-08-22  0:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-21 14:46 [iproute PATCH v2] lib/bpf: Don't leak fp in bpf_find_mntpt() Phil Sutter
2017-08-22  0:35 ` Stephen Hemminger

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.