From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 48AF81D6DC5 for ; Wed, 29 Jan 2025 23:15:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738192509; cv=none; b=lkeoHQYwNxTkBrQDuZC5TqTORQQbWrd3dRPITwZnRp7ZCqyjCacZrOqNIGpRj/qH5biuAVjfzUbMLuaPLT4fdpWBCIE0JJXEavQc9w8cO0Mrf8SOUDnGcu9kjrV1nxDMcR59XQAX65sKo9TlNKx5JsXbj8cqJCeRlBc9raoOn0k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738192509; c=relaxed/simple; bh=cBJ8PxMcIwEKwl7X0NV5hUIWYkaTtpL/IAwWeTn1h54=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:References: In-Reply-To:Content-Type; b=hVeB4bfvjsJq+b+OTY02dh1l3X5pRMuXhCNBODixG32Zs1i935dNjlUb46q1JfXjSc+klMwC6+JilIVxo8QuQKm67ARQcPaMhGAakaUP0fQmjuVx2KRsW+G2iOt4250pScMRmxBqwGrH8O3QxxVKIp4OedyINFA9bMdzgnPDOwM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=X/ZbAR/H; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="X/ZbAR/H" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9BC0C4CED1; Wed, 29 Jan 2025 23:15:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738192508; bh=cBJ8PxMcIwEKwl7X0NV5hUIWYkaTtpL/IAwWeTn1h54=; h=Date:From:Subject:To:Cc:References:In-Reply-To:From; b=X/ZbAR/HwUkyDurvsXxlvMlBOUDb532X6pT2O8cPZ2ZUForRN2YP5E3HDCR1lUBRP xTihA5H0wTa1s8g2gVXhfUQ3zw9Ulp+4TCkzspa6XgWjwDqxhPbKTZ7R9XJaThOnMj ry+v5TyEcXqNbtvIS5ch/86vEXQ0hDnDS0GtRjcJxwykukRVzr2caxjvniTVOu4aeJ Q9iMQa/zsqThpyrMJcKmXk5iCQ3Vmbr4lwj6EIuGbyz+XT1++0onLS1HEe5cV3uxpp 44/3OMVA7N0lH2DpZS+4Sk5Ki0GRVFKGzmHnhN41MGkotq1F8QGYCtlg0gb9LwyVFM GOS9AZvSWSeNw== Message-ID: Date: Wed, 29 Jan 2025 23:15:03 +0000 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Quentin Monnet Subject: Re: [PATCH bpf-next] bpftool: Fix readlink usage in get_fd_type To: Viktor Malik , bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa References: <20250129071857.75182-1-vmalik@redhat.com> Content-Language: en-GB In-Reply-To: <20250129071857.75182-1-vmalik@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 2025-01-29 08:18 UTC+0100 ~ Viktor Malik > The `readlink(path, buf, sizeof(buf))` call reads at most sizeof(buf) > bytes and *does not* append null-terminator to buf. With respect to > that, fix two pieces in get_fd_type: > > 1. Change the truncation check to contain sizeof(buf) rather than > sizeof(path). > 2. Append null-terminator to buf. > > Reported by Coverity. > > Signed-off-by: Viktor Malik Nice, thank you! Fixes: 71bb428fe2c1 ("tools: bpf: add bpftool") Reviewed-by: Quentin Monnet