From patchwork Mon Oct 16 18:18:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 826452 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yG66Y2W3qz9sRW for ; Tue, 17 Oct 2017 05:19:32 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756621AbdJPSTR (ORCPT ); Mon, 16 Oct 2017 14:19:17 -0400 Received: from mail.sigma-star.at ([95.130.255.111]:45998 "EHLO mail.sigma-star.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756553AbdJPSS0 (ORCPT ); Mon, 16 Oct 2017 14:18:26 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.sigma-star.at (Postfix) with ESMTP id 779B324E0011; Mon, 16 Oct 2017 20:18:16 +0200 (CEST) Received: from blindfold.corp.sigma-star.at (richard.vpn.sigmapriv.at [10.3.0.5]) by mail.sigma-star.at (Postfix) with ESMTPSA id E2CC324E0010; Mon, 16 Oct 2017 20:18:15 +0200 (CEST) From: Richard Weinberger To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, daniel@iogearbox.net, ast@kernel.org, Richard Weinberger Subject: [PATCH 3/3] bpf: Make sure that ->comm does not change under us. Date: Mon, 16 Oct 2017 20:18:56 +0200 Message-Id: <20171016181856.12497-3-richard@nod.at> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171016181856.12497-1-richard@nod.at> References: <20171016181856.12497-1-richard@nod.at> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Sadly we cannot use get_task_comm() since bpf_get_current_comm() allows truncation. Signed-off-by: Richard Weinberger --- kernel/bpf/helpers.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index 511c9d522cfc..4b042b24524d 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -18,6 +18,7 @@ #include #include #include +#include /* If kernel subsystem is allowing eBPF programs to call this function, * inside its own verifier_ops->get_func_proto() callback it should return @@ -149,7 +150,9 @@ BPF_CALL_2(bpf_get_current_comm, char *, buf, u32, size) { struct task_struct *task = current; + task_lock(task); strncpy(buf, task->comm, size); + task_unlock(task); /* Verifier guarantees that size > 0. For task->comm exceeding * size, guarantee that buf is %NUL-terminated. Unconditionally