Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1050181rdb; Wed, 24 Jan 2024 03:27:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IEa5Kq7dbnMKhiV+zGp1ILf1USK9uZ42IdExC3htNaGYnpAvafXpHS24JfE0O56lVzvGuqM X-Received: by 2002:a05:6902:e02:b0:db7:dacf:ed96 with SMTP id df2-20020a0569020e0200b00db7dacfed96mr550302ybb.119.1706095655540; Wed, 24 Jan 2024 03:27:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706095655; cv=pass; d=google.com; s=arc-20160816; b=XlXCMZzjN0/H8cWWrIngERkoDl9yyNgIEPxcowLOfjaN0KXs7XQbCaPcti6lUMoSK4 YyiFg6OnazPxLFkR9DmxS3gaZ2d+dsIttxG29xJPOkYiBKa0bVDMNPom6QwQNOOz5XNg OsSg8ISdduPOHVLAwHIHdz4Bc8gFI+0rH9aqZA7BPru2t8DVJn+j6scyviQsTYripBJD QEq+L9cURnMT+/2PpW65WeUpDFZ4s616FfrxMHSlY3OHw1cNPNR6ysErAF2VsFzj2Hmh am5yOZUpN5lxjXqKqDWN/k0yILUKbM1sTF4292T5xi6cyDuo36mIlbUu2QFk0k2XWCOu 74pw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:from :dkim-signature; bh=Ap65r/9R9EskpF2TR3kJr+oUyRpHEgTG+2Pl5WqM09E=; fh=N5eH4SEaJMgIYvT1dHg8/vfKwm3kzfe+KS1mPuMUMcg=; b=HqmWI6J5u6FtQctBwR94AZwr7jXkN4gNATPTWQ0j45hh8zfmLUVeMBfpAp4Zu+tAu0 9xgKLsKu0Hk0Ugwf8mD+aommRLL6UdBHLzWb/H5OVEpl/fIFm+S2PJdNQ/1I6+AT8HSH B/Xo75QLC3Q81q/JxH4YDFj0lzPvfxaiQM8VsJNFi5pXnto8xv9CMIVHvWeP6fpWlza7 sd672SgYv5zQNOlIDGCYmDXxu9mLaL9uuefTIOmDP1GZafiv/J1i/UuCBBfI4OtudXlJ VX6QY3u9dPmlN4Qg3e5iadg41R1LtSQMYlqmr7vzl0674JCx/t07wjCzebzGnLqpNRLs UtEw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Y9CyT7/z"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-36857-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36857-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id i12-20020a0c9c8c000000b006864677cd84si8642919qvf.608.2024.01.24.03.27.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 03:27:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36857-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Y9CyT7/z"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-36857-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36857-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4FA0B1C20FF2 for ; Wed, 24 Jan 2024 11:27:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 56FED1B297; Wed, 24 Jan 2024 11:27:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Y9CyT7/z" 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 6CE792C684; Wed, 24 Jan 2024 11:27:10 +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=1706095630; cv=none; b=JZJ2CiStkme3egp0naAN+aBSeLf9FIdYstvb7D95YzDgqsrfoMymdVVeWZKYPKdJF8F85hNKxjXJHi7GTsOdVOEEAMlGUas/Ce3RreMg60slGSU6D/ybvaWo/9xi8nPj/9A6a94Q9lTNX2l+BVhReeG1f+oLnsE4eGQb4jF5P8o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706095630; c=relaxed/simple; bh=alQWMBFXA1hw7IIWXSpJ6i4inmySS5LtlbuTmaNyvl4=; h=From:Subject:Date:Message-Id:MIME-Version:Content-Type:To:Cc; b=CiR4wt/Uch6WAgfDwe4Yhw66szMwDjBmP2OzxvZZGNnlw8V4XQMV7r11eBSKvIU5uWAPId00EnXrmdW/zUsIZjbF6QFKQA7ga1fsfuiepNDGVsGe8vZGQggG8eDYHJI6JgJaZlApmQSE05MyFH7Nfpr3XQPOT8mK7rLmda86BQ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Y9CyT7/z; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59A84C433C7; Wed, 24 Jan 2024 11:27:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706095630; bh=alQWMBFXA1hw7IIWXSpJ6i4inmySS5LtlbuTmaNyvl4=; h=From:Subject:Date:To:Cc:From; b=Y9CyT7/zJOgHijuFWNtRE5BK0H0gmMJs7J47B3RhKobd0Cdg95Ffr0gwjegsbTJo9 l5jFT2D0k8Wyf1dZoIrlgwJABziL/uMh7EqvOQiCy+6H9e0FbnL78Ek/1NQrXTTBFz Yi+KDg63/QF6strX05Jg1NdW6DyP8VWGmY+t6rcCnEPltwieHTEDnB/ORgwltAMHQt 4rw7g0q9i+7z20mO68w9Ez+/gi8Fu2qEXqr+W8u7p4E6jUeBuUZJ0xAn0Zlv0I2WPD x52l2BtjQTejwsCFKqIkqM15PYksEtxlrVS+kzYNrgUpw05Xu/ypl++kRvycDZC1ph dnwJ8F4Z5hbfA== From: Benjamin Tissoires Subject: [PATCH v2 0/3] HID: bpf: couple of upstream fixes Date: Wed, 24 Jan 2024 12:26:56 +0100 Message-Id: <20240124-b4-hid-bpf-fixes-v2-0-052520b1e5e6@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIAAD0sGUC/32NQQ6CMBBFr0Jm7Zh22lB1xT0MiwJTOtEAaQ3RE O5u5QAu3/95/2+QOQlnuFUbJF4lyzwVoFMFffTTyChDYSBFVmky2FmMMmC3BAzy5ox1TVd1CUx kLBRtSXwUxbq3haPk15w+x8Oqf+mfsVWjQu918L0z1jjXPDhN/DzPaYR23/cvIfSokbEAAAA= To: Jiri Kosina , Benjamin Tissoires , Dan Carpenter , Daniel Borkmann , Andrii Nakryiko Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Benjamin Tissoires , stable@vger.kernel.org X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706095628; l=2390; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=alQWMBFXA1hw7IIWXSpJ6i4inmySS5LtlbuTmaNyvl4=; b=j5lHHgQgLoXVZiipVjKowReOGI8kG/sxaAYoHUCxIixkXKDGr6uZidECS+6mEjacbAFlkw3y8 0leuu0JRJH5Bdo74vBNHfnY00B3a2snuwqLxHwVesgj3F0kFQKh3wI/ X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= Hi, This is the v2 of this series of HID-BPF fixes. I have forgotten to include a Fixes tag in the first patch and got a review from Andrii on patch 2. And this first patch made me realize that something was fishy in the refcount of the hid devices. I was not crashing the system even if I accessed the struct hid_device after hid_destroy_device() was called, which was suspicious to say the least. So after some debugging I found the culprit and realized that I had a pretty nice memleak as soon as one HID-BPF program was attached to a HID device. The good thing though is that this ref count prevents a crash in case a HID-BPF program attempts to access a removed HID device when hid_bpf_allocate_context() has been called but not yet released. Anyway, for reference, the cover letter of v1: --- Hi, these are a couple of fixes for hid-bpf. The first one should probably go in ASAP, after the reviews, and the second one is nice to have and doesn't hurt much. Thanks Dan for finding out the issue with bpf_prog_get() Cheers, Benjamin To: Jiri Kosina To: Benjamin Tissoires To: Dan Carpenter To: Daniel Borkmann To: Andrii Nakryiko Cc: Cc: Cc: Signed-off-by: Benjamin Tissoires --- Changes in v2: - add Fixes tags - handled Andrii review (use of __bpf_kfunc_start/end_defs()) - new patch to fetch ref counting of struct hid_device - Link to v1: https://lore.kernel.org/r/20240123-b4-hid-bpf-fixes-v1-0-aa1fac734377@kernel.org --- Benjamin Tissoires (3): HID: bpf: remove double fdget() HID: bpf: actually free hdev memory after attaching a HID-BPF program HID: bpf: use __bpf_kfunc instead of noinline drivers/hid/bpf/hid_bpf_dispatch.c | 101 ++++++++++++++++++++++++++---------- drivers/hid/bpf/hid_bpf_dispatch.h | 4 +- drivers/hid/bpf/hid_bpf_jmp_table.c | 39 +++++++------- include/linux/hid_bpf.h | 11 ---- 4 files changed, 95 insertions(+), 60 deletions(-) --- base-commit: fef018d8199661962b5fc0f0d1501caa54b2b533 change-id: 20240123-b4-hid-bpf-fixes-662908fe2234 Best regards, -- Benjamin Tissoires