Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2027269imu; Fri, 14 Dec 2018 04:44:17 -0800 (PST) X-Google-Smtp-Source: AFSGD/WIXBNhxB9y3qTbBaSrf0h6gb2ZhC6BxbWNrygfhtf/Tl72evL4Tje82Azci3QZL2x81g67 X-Received: by 2002:a65:4784:: with SMTP id e4mr2571155pgs.12.1544791457162; Fri, 14 Dec 2018 04:44:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544791457; cv=none; d=google.com; s=arc-20160816; b=HrL9HcRboMKYqLGpeyy1Qwc0W5gsEM4IlKnoAGaxQtISSyYSNGB9teB9VSndqLTnfD 0L6uwTYNkiwi5fVvpzt4BNOqvmtEtxM2zQEX7YyE00TiQEbck/h9s6aXbIyixQyMnqhj VX/1E9N+erf9fZCzSzNV8l6tdnTpJfVXfLTf8N+s8gXz+jRiwoa8onFrFSCI70Q4yoix VRsfHb4m86a3ZzlcIw96bHtDRe9vYNkAF5BOkdLU08V5fLdFaAHtIaE1yiRe2WXspvoI BTVRgMETnvViGDAYWywoH/5vnr7ogbM8mZL1MavPT2iTFfIbanfH2qa5DU3YQ9+2FRv0 cApQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=EfF8WLOqqvZDiI1KsJvwb+zxmHKqBhKwXR1WM8HdTcQ=; b=YJdkQWLz+56KDL6rWqmnHUJMXEXXFZBunEoucRLC7S+FpKBixeSHgdGhwPNmlOy0ml G/xYTgEDJB6srhsv2cPfcIzTnafFGpjsdH9qfKSJAK6mkTkt/NksqA6HQdmmhw9qOqwq a7GlXZCVmZH++ayOD9LpkoBvOnOEJGq4/FuJhyTylfsZ0hRutzFJL0LcRoI0jhlWFxQ5 DUvWvnpQvOrzq8NBY6KfwigR1L93DzyasKTSa8uxEwoCi0OZqug/HwfKgSQQ53UcNS/f Qwq1KOgs/WyyMdIekfQzEZ9GDKpgsMN6XzigpjckOi7xJ0MZfeuOFl0y5POQWKrMvasJ k/pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PQmV0pBz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k69si4128998pga.176.2018.12.14.04.44.02; Fri, 14 Dec 2018 04:44:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PQmV0pBz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730196AbeLNMnN (ORCPT + 99 others); Fri, 14 Dec 2018 07:43:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:45240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730013AbeLNMCV (ORCPT ); Fri, 14 Dec 2018 07:02:21 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D0AF62146E; Fri, 14 Dec 2018 12:02:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544788940; bh=NjFm7mLiW5o1rE+OpVrr6zIPqwDa5YRFwMM3Nia2mXU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PQmV0pBztrnEboX/YqrF6x7TgQ7BltcyhfjrTom5iy4JAnrhf3Or2m9ui8S6Vl39a 3OzZZ7Q6E4FFHqbW30QP0NUTyFfy16QWu2KyA/szA8SZCuZSbGcNZJVVjjfrIqwvH+ 8XiN5vnW2YhTErD4ITUV9O8KeZYqccDlWrqYVbYI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Quentin Monnet , Jakub Kicinski , Daniel Borkmann , Sasha Levin Subject: [PATCH 4.19 032/142] tools: bpftool: prevent infinite loop in get_fdinfo() Date: Fri, 14 Dec 2018 12:58:37 +0100 Message-Id: <20181214115748.337244816@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181214115747.053633987@linuxfoundation.org> References: <20181214115747.053633987@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 53909030aa29bffe1f8490df62176c2375135652 ] Function getline() returns -1 on failure to read a line, thus creating an infinite loop in get_fdinfo() if the key is not found. Fix it by calling the function only as long as we get a strictly positive return value. Found by copying the code for a key which is not always present... Fixes: 71bb428fe2c1 ("tools: bpf: add bpftool") Signed-off-by: Quentin Monnet Reviewed-by: Jakub Kicinski Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- tools/bpf/bpftool/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c index b3a0709ea7ed..fcaf00621102 100644 --- a/tools/bpf/bpftool/common.c +++ b/tools/bpf/bpftool/common.c @@ -304,7 +304,7 @@ char *get_fdinfo(int fd, const char *key) return NULL; } - while ((n = getline(&line, &line_n, fdi))) { + while ((n = getline(&line, &line_n, fdi)) > 0) { char *value; int len; -- 2.19.1