From patchwork Wed Oct 9 22:06:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Wu X-Patchwork-Id: 13829313 Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40A9217BB0C; Wed, 9 Oct 2024 22:07:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728511621; cv=none; b=ThhiAc/K5IMFhgHkCbAig+bJclJZuvkBZSJTjgZasOO31V/cZQe7Xk6ABu1TphUHXTvgM2EJKaQ3qTGJBc0GLC8LMu6bghmn1VNzvLFeJGO+2uRigLv/2eWf3aw3mfSjvBrfguEuJCTwK6JQaylY+gWE/3GGK/hrFX7VDwCo39I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728511621; c=relaxed/simple; bh=qR4G6cpRTNBNGQbp7qj0gyw0DIUnvfkn2WtpYeir/yc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=CBXJJqCeZP10koWS/Xf7GTnSVqbkxEjT+bUYFXRiK8GQIN2OFM3nYkIrSOd6OFflqJjYkAlDlPbjn49PjYeKJHUNwQdE+Md0OqerwHywbRYZXiOSWv8pQ2YcmGlpRhJ4JpQAnTF5AJZfZ7rYDBhGgbTcjhFTSByR/3ZGuRHtbDU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NVMNCciv; arc=none smtp.client-ip=209.85.128.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NVMNCciv" Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-6e214c3d045so3328277b3.0; Wed, 09 Oct 2024 15:07:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728511619; x=1729116419; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=AFBZjF5Yk4tht/EOD4hcMtQva+b/hCYbw5Gp5MWFIPg=; b=NVMNCciv58oNKZDmrmi6J7uzTPPP1eME8oq0FBU+L/lFvX4vvV5jT0rwt7df/M8ddf LU+NBrgRWPF2gyiW8+Q/Oo3ncNoJh772vYakCx1mP5DdgPFkXpEVbsFl9V3P7HJyzTB3 iT7Thea1rOoGXpwe+L3JdyWNjVMgEl1rV7mWz72PRA3oFfBJ7gRl4+qDX1adVlD2wRf+ q+M9bT/06ito852jS7zLm7tthNer1Kg/nNnNCGpn92TCQ1s+8AjytCXEErrXA1j3LmJR OsjOINlDDI9C48vzyuHfslde1mg2YO1gOJzm8RmEjiWhXnvuxqoSKfQYZeqNWVb7Bnyb xFcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728511619; x=1729116419; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AFBZjF5Yk4tht/EOD4hcMtQva+b/hCYbw5Gp5MWFIPg=; b=aIpYJTsIBLpPse1/9X2fJxfgIDYUQIU+6FrI8SJgOXV5B5ff5zioFkUkuUvpKq6lEi 1VJt4riAfrpoOiskSOwk/2rkm4k1YO6zH/FRwkasCT7x3Bjr63M4plZBunVX/MRQtBGw oWdtwoTCpuV971i2yoDd+/T4IrDCi7Ln6sX5cN0ao9EkgWdyKxCFRsOy6tii+EPNFR0M M2kqr1lWDzLatOxqum04oCrwjWLovw8/jQNEZ7ygzwMc5SBhyYfsIZ2epuRh3gp5lWqT KLFnUNaevKNBgZcYHBdYtAAsYXhXV49pSmPo6Efb5e4NDmtllCWVeu/ynbzHK5GgRnYy hp9g== X-Forwarded-Encrypted: i=1; AJvYcCU3VNgNw5UOUfxrjlirIANmYyr+QLx75j3LjaYMutHW0nR1FvcioCyotBMToj+/17r3GC9as4Nh5fPbMTA=@vger.kernel.org, AJvYcCXMaua0IJaLNNJ4NXyIlvek590oc3waDRDYfMLR60AaiGoC7b32hzgk2iroyA5TG+s34OpbXGao1GW8hgFfnM9DqwXt@vger.kernel.org, AJvYcCXs5jpxLH2ZsCVRe9GImlw2Nwa7p1hDIZtMRNld5LrSNuLEV0oQdTU39NrTXbGTbIHCnDj0u6X27hNGFhJvJEN+@vger.kernel.org X-Gm-Message-State: AOJu0YxWV8BBuJjMDIAQTqwx/Z1A94VxUn8OgTiJxviSwOxpejV38BBB ra4on04o8o4dMTHX5Qh0bxX3riNs7pz10mBZXLz9S9YIlo2qDaqVt1VfNZFl X-Google-Smtp-Source: AGHT+IG3/Du/0WuPBnLSEF0Xuz0WLmIENO+InrEFUnWJT3Z7T4winPWm0D9pFEwZTNKSn6qIG8DYwA== X-Received: by 2002:a05:690c:39d:b0:62c:c684:b1e1 with SMTP id 00721157ae682-6e32217b7d9mr39731187b3.29.1728511618856; Wed, 09 Oct 2024 15:06:58 -0700 (PDT) Received: from dev-ubuntu-0.. (104-15-236-76.lightspeed.rlghnc.sbcglobal.net. [104.15.236.76]) by smtp.googlemail.com with ESMTPSA id 00721157ae682-6e2d926b44esm20294217b3.16.2024.10.09.15.06.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 15:06:58 -0700 (PDT) From: Tyrone Wu To: bpf@vger.kernel.org, wudevelops@gmail.com Cc: kpsingh@kernel.org, mattbobrowski@google.com, song@kernel.org, jolsa@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, yonghong.song@linux.dev, john.fastabend@gmail.com, sdf@fomichev.me, haoluo@google.com, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, mykolal@fb.com, shuah@kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-patches-bot@fb.com Subject: [PATCH bpf v1 1/2] bpf: fix unpopulated path_size when uprobe_multi fields unset Date: Wed, 9 Oct 2024 22:06:37 +0000 Message-ID: <20241009220638.333429-1-wudevelops@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Previously when retrieving `bpf_link_info.uprobe_multi` with `path` and `path_size` fields unset, the `path_size` field is not populated (remains 0). This behavior was inconsistent with how other input/output string buffer fields work, as the field should be populated in cases when: - both buffer and length are set (currently works as expected) - both buffer and length are unset (not working as expected) This patch now fills the `path_size` field when `path` and `path_size` are unset. Fixes: e56fdbfb06e2 ("bpf: Add link_info support for uprobe multi link") Signed-off-by: Tyrone Wu --- kernel/trace/bpf_trace.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index a582cd25ca87..ba34e4f3fa8f 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -3133,7 +3133,8 @@ static int bpf_uprobe_multi_link_fill_link_info(const struct bpf_link *link, struct bpf_uprobe_multi_link *umulti_link; u32 ucount = info->uprobe_multi.count; int err = 0, i; - long left; + char *p, *buf; + long left = 0; if (!upath ^ !upath_size) return -EINVAL; @@ -3147,26 +3148,24 @@ static int bpf_uprobe_multi_link_fill_link_info(const struct bpf_link *link, info->uprobe_multi.pid = umulti_link->task ? task_pid_nr_ns(umulti_link->task, task_active_pid_ns(current)) : 0; - if (upath) { - char *p, *buf; - - upath_size = min_t(u32, upath_size, PATH_MAX); + upath_size = upath_size ? min_t(u32, upath_size, PATH_MAX) : PATH_MAX; + buf = kmalloc(upath_size, GFP_KERNEL); + if (!buf) + return -ENOMEM; + p = d_path(&umulti_link->path, buf, upath_size); + if (IS_ERR(p)) { + kfree(buf); + return PTR_ERR(p); + } + upath_size = buf + upath_size - p; - buf = kmalloc(upath_size, GFP_KERNEL); - if (!buf) - return -ENOMEM; - p = d_path(&umulti_link->path, buf, upath_size); - if (IS_ERR(p)) { - kfree(buf); - return PTR_ERR(p); - } - upath_size = buf + upath_size - p; + if (upath) { left = copy_to_user(upath, p, upath_size); - kfree(buf); - if (left) - return -EFAULT; - info->uprobe_multi.path_size = upath_size; } + kfree(buf); + if (left) + return -EFAULT; + info->uprobe_multi.path_size = upath_size; if (!uoffsets && !ucookies && !uref_ctr_offsets) return 0; From patchwork Wed Oct 9 22:06:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Wu X-Patchwork-Id: 13829314 Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7ABA81E32C2; Wed, 9 Oct 2024 22:07:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728511624; cv=none; b=Z7swuTHjq55r9KEXNFwT6+Zfd30X4I/1aFYAHQ9b7UFZZMBTpmfRb98ZRLPJ7Auaid+b6lzDnIOx2wgGSzJdy4TVL256D6y9yZOSbwrn0EN0wq3b2sEIUKnN0zcql73mi6ZnZBhgKskTh9HeE5vYFfzQUVUMdPu3Dm5LL3VOORQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728511624; c=relaxed/simple; bh=vamGcFrPRyfG19X12b4a/YEYp7dSMGPkZd9DEbWGDM4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dT4lIL93yA2zAVn7J/4NSOspyNFbP/C0WxMKy4YdFyVpPX1r+G2sr70ZIIob9yXeezas1zbF2KYdQqcZAxh/QbNjH2kQMXfqbkDsAecavQLgMCHVQ46enho42ieNLWt3PdqpX8tCbM3qA8FSemFHAW9Guzxnaf7KKlIK37drNxw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ajlEsEXv; arc=none smtp.client-ip=209.85.128.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ajlEsEXv" Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-6e330a7b120so1330677b3.2; Wed, 09 Oct 2024 15:07:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728511622; x=1729116422; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wZGOsm3YR+E73cJ0SGQHJhXA862v5jLb24Y7Aj3c+FE=; b=ajlEsEXv09GzmaWk7BNIG7MOsyUtIRZhxCmwbBmLHgxzH7gXRbMrPYD09E2cml2/2C rppHWyTMrib4L5omndUWBS3ltg38VLVjVnH+3KTIJT9nbsKbv/spAEF5kOn0rNVBbVdg 6hru/P9KlKBp8T+DP7roHnxMWtOVWuMrP19siLbIKe55SdwFmagMt5qfIzIT5EyEBQoC FzUCJU+OzpB2Z8/kckZ3FamC35mPUszZwwB4A+AOcLBHCQk5TPR7pYjdTrfAYvSIC99c rSwcTqDSSDGMw3o2l6phqZj/0uaWZbBqm6OtI17z60iTgSZ21ezOWdHlxUdEWUN5PxK2 jEPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728511622; x=1729116422; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wZGOsm3YR+E73cJ0SGQHJhXA862v5jLb24Y7Aj3c+FE=; b=M0+Jvd4CDBoDcyV+K4YmxWIVwRFhUO+aooaYg7r0NwsCpkf+9EKZeiRCvqyNm4qyVM ub0GMvfNGDnGhC9646wtwAFpbZZEhXrgtJGcFRfaMx3upgzNn01kwwZmJTPxC7DhmOxW Zr8M7n6Cnb52OdTzUCAfGqjgoQBOQE20SxG/OkzddtcohTF5EAa5CL4A+aw70yh3fvwr FkZ5WpTLv/7mk+zWuKXyfpfqDZUPhzEO+LHYaq8143H93LSGtG0IG3x/14QlgFMpsiD1 OZx736HyOd9wjMBPZgcml81OAF8Aih9TGFFGKQAPNuHvkSONgoFOl8c0zDB63P8omDAQ rfEQ== X-Forwarded-Encrypted: i=1; AJvYcCVffa/kvHoihrrMi0R6PehurCp7U1nvz28OBeikQ/sWOgALUvTdlV97RCXntxJjy7uh4RUG2rZlJdJjaBRY02Lv@vger.kernel.org, AJvYcCWaSU2XtXLrKFpfEIItrLUFqfV+7VOo1L/EUjE81c55sYxcMUpv5SZwDm9abkDIPFa1YTM9Kuyw+hDYvO4=@vger.kernel.org, AJvYcCXSRIPxkHQt7BLPn2LP3UbiCqjmfrDHmfHhR+6r7Ym3vO6jdv4WAyZiRab4k+3KZm21PeoJFr8VEHoNvxzF1IgLXTIO@vger.kernel.org X-Gm-Message-State: AOJu0YxG/rYjuNqUc1/X7D4RT6sw1DYGFjr0WKrHR5XDjTU3Pz5rqC+j OYKxGUUowJ96JtsF4uWI7a92mRsY0EXV7NtAJn4TUlNSL55xskZheU9t06FB X-Google-Smtp-Source: AGHT+IF1uyZrUK2/Sy4TPteRgeer5kAxQj+FQiPxRggZ89itv4Zhagt8kBp2ymbhkdbDtg6qJgOcpw== X-Received: by 2002:a05:690c:113:b0:6e3:ceb:ce2b with SMTP id 00721157ae682-6e32250ade9mr39798427b3.44.1728511622150; Wed, 09 Oct 2024 15:07:02 -0700 (PDT) Received: from dev-ubuntu-0.. (104-15-236-76.lightspeed.rlghnc.sbcglobal.net. [104.15.236.76]) by smtp.googlemail.com with ESMTPSA id 00721157ae682-6e2d926b44esm20294217b3.16.2024.10.09.15.07.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 15:07:01 -0700 (PDT) From: Tyrone Wu To: bpf@vger.kernel.org, wudevelops@gmail.com Cc: kpsingh@kernel.org, mattbobrowski@google.com, song@kernel.org, jolsa@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, yonghong.song@linux.dev, john.fastabend@gmail.com, sdf@fomichev.me, haoluo@google.com, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, mykolal@fb.com, shuah@kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-patches-bot@fb.com Subject: [PATCH bpf v1 2/2] selftests/bpf: assert link info uprobe_multi count & path_size if unset Date: Wed, 9 Oct 2024 22:06:38 +0000 Message-ID: <20241009220638.333429-2-wudevelops@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241009220638.333429-1-wudevelops@gmail.com> References: <20241009220638.333429-1-wudevelops@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add assertions in `bpf_link_info.uprobe_multi` test to verify that `count` and `path_size` fields are correctly populated when the fields are unset. This tests a previous bug where the `path_size` field was not populated when `path` and `path_size` were unset. Signed-off-by: Tyrone Wu --- tools/testing/selftests/bpf/prog_tests/fill_link_info.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c index f3932941bbaa..a38cf2a999fe 100644 --- a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c +++ b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c @@ -417,6 +417,13 @@ verify_umulti_link_info(int fd, bool retprobe, __u64 *offsets, if (!ASSERT_NEQ(err, -1, "readlink")) return -1; + memset(&info, 0, sizeof(info)); + err = bpf_link_get_info_by_fd(fd, &info, &len); + + ASSERT_EQ(info.uprobe_multi.count, 3, "info.uprobe_multi.count"); + ASSERT_EQ(info.uprobe_multi.path_size, strlen(path) + 1, + "info.uprobe_multi.path_size"); + for (bit = 0; bit < 8; bit++) { memset(&info, 0, sizeof(info)); info.uprobe_multi.path = ptr_to_u64(path_buf);