From patchwork Thu Dec 19 02:34:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13914394 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1243CE7718A for ; Thu, 19 Dec 2024 02:35:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 478726B0093; Wed, 18 Dec 2024 21:35:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4015F6B0095; Wed, 18 Dec 2024 21:35:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 27B6D6B0096; Wed, 18 Dec 2024 21:35:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 08F366B0093 for ; Wed, 18 Dec 2024 21:35:24 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A63B544022 for ; Thu, 19 Dec 2024 02:35:23 +0000 (UTC) X-FDA: 82910141202.12.CC5FC1D Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf03.hostedemail.com (Postfix) with ESMTP id 05DB420007 for ; Thu, 19 Dec 2024 02:35:06 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=m1j89vRQ; spf=pass (imf03.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734575707; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=35FnTfH4WG+K4PY792luJMCXMpwCP4Hox12oxUuAxYU=; b=AljRTUGpcQJf1KMXrA5M99GaZPyu9me0sLOSvTqqmwjiT8s+s6sTT85dbxD3uNRxgVoaCj 7a9+610Sovv7IpEzOeUN52vJ0faXYEJzFpmIfrP5D4kQpuzB5u01Mc+PgBcL0zxLhQrSnr whLlDzr/VeO8L3KrVQI/uk85GFQ1DJU= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=m1j89vRQ; spf=pass (imf03.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734575707; a=rsa-sha256; cv=none; b=V6i8cTbnMn/voQTjs+YRMEWU0FVkG1Y8gKRPPX69g0c4FashFT+cqQ47k1HWf34IrABlX1 1eTCf6gYv20/TNY7FFkQLZmom5/yy05Pmvm6kDUWq76K8X+cf8Z4VgzX27poGMMaMrFWV1 gRuqpeVzax53BGOPfkeS1pdzO7HAp2Q= Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-728f28744c5so307393b3a.1 for ; Wed, 18 Dec 2024 18:35:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734575720; x=1735180520; darn=kvack.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=35FnTfH4WG+K4PY792luJMCXMpwCP4Hox12oxUuAxYU=; b=m1j89vRQdOXLi1Tnw3xGso0ZmAHK2cvZgixfNFuSpAx4+PmhPVuqnnDDXC+H8c4l3L jhHFGMZ4SShCEBfMfJfJeaVfGbKlsNYmhPnAFw9Pw9FvAwloWoSGfrl4xCeNLffnJtGL C+ihn36VWKO4DM8zifKpC7USWUx8OmdJZwAuVsDzV7xISMdoujv9hWspLmq6wo2qtLl4 iYkBpQo37/jaZXzFon8H22/Kly6pDXN+pTB9QzkgMafAwXHHtN1z5Ttp+Rox7Yf2BJQG UyuDJWZ9Nn+fHTHLDCWsM9MU/STtTA62KJqJ/7t0JtknOxVUq1CTk90t6aMyaemhiilS pJUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734575720; x=1735180520; 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=35FnTfH4WG+K4PY792luJMCXMpwCP4Hox12oxUuAxYU=; b=kD2X82FmZryX2Yyx9RYATJz27TY5+Aded5yG6UoTfx5/T1ZSo2U2d6gl2eUhx/3Dko /5ByQ+rIrnccVxA5bfHXejd9NJtVpZp5BcGNQasD7K7FDIPBEF5K1oyKdx1fD04auIWX m2vXowJjxgQwx6rVYRgZTCgUecw3DmJvXo8I0niqjsLxa3Oo4+6tdvu1F9RPPSuXHRjP Fn2VolPz3M1p3k+RkyTb1VJvGj4K8xo+uW6fT/DHMPpdN/2bBTVqJXC+JPqgr1ZUvetr pojbAFLNYnWipBSkPogfx8AQeh9DFYf3QGkRdwFumvi1GWqjDEGJL3GDZSEun5TNX+P3 wSLw== X-Forwarded-Encrypted: i=1; AJvYcCXMyUcQSlqecWZ6ppEq1RTJjvVdTpRiwmqKFTavqEq0cDiPSMwSF6X/R54v06+4CzWT3eA00jlUxw==@kvack.org X-Gm-Message-State: AOJu0YynBtV3H7n+XSdiDtj12Kh3w2zUI49cYB30LTBz7vOXc5FC0CiA IMQuk7lTzy6km8y/pvUZAr5jTknanXDWcnkL6nBqieVe5ZjIFuhs X-Gm-Gg: ASbGncuOvNggS2ysJ5yFfuM8yFCFefcRIyyLstlJ1lE3l/aC3a2L6mpfEwhNuT4pjkv 7nu2GBytdnk08S3FMMWMw7sxbhwJsuAi1cGfH7c/kQ15IAY1e3Z5/ta2UImEbG2XguSCyVBThWf 2QeZZHM0zSpiZBtuovM/0lm0qIw+M+yOd8/VQDt0Q5kKxypmxbOWb2TBeoa6kjQgsCoXiu7qHIV MtAYksRuGak37dHMNYcHHUpAhwIwt8kvKqh6p0RMPMGXqtpXZF4tUHZJiWN123bQEElNWsqE1gc L+rUseo= X-Google-Smtp-Source: AGHT+IEYa8/cPCrPUtV+8BluujgYPFlXKrKcInk+YdaLokr+l/jazm3QEi9WUGXKVKTvc9yKVja0nA== X-Received: by 2002:a05:6a00:9096:b0:725:e37d:cd35 with SMTP id d2e1a72fcca58-72a8d2c2269mr8262629b3a.18.1734575720422; Wed, 18 Dec 2024 18:35:20 -0800 (PST) Received: from localhost.localdomain ([180.159.118.224]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-842b821da83sm142163a12.40.2024.12.18.18.35.15 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 18 Dec 2024 18:35:20 -0800 (PST) From: Yafang Shao To: akpm@linux-foundation.org Cc: torvalds@linux-foundation.org, pmladek@suse.com, kvalo@kernel.org, bp@alien8.de, andriy.shevchenko@linux.intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, x86@kernel.org, linux-snps-arc@lists.infradead.org, linux-wireless@vger.kernel.org, intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, ocfs2-devel@lists.linux.dev, Yafang Shao , Paul Moore , Kees Cook , James Morris , "Serge E. Hallyn" Subject: [PATCH v2 4/5] security: Remove get_task_comm() and print task comm directly Date: Thu, 19 Dec 2024 10:34:51 +0800 Message-Id: <20241219023452.69907-5-laoar.shao@gmail.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20241219023452.69907-1-laoar.shao@gmail.com> References: <20241219023452.69907-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 05DB420007 X-Stat-Signature: 5dcc8yddbk4u6swceaz1brji1z4i9ojd X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1734575706-465413 X-HE-Meta: U2FsdGVkX1/kX9Umls+7rQW+6l48RbMpOsp9krNE0fPO9fJyqNwOHBWkPFR4ZwJEMG+PeEZhVA71zwzPjT8+PyaqgWwtCG/41GvaXCIBcRKq2cHjAIXWv7QJun57/SHYtvhKd3g12oILKUq9z1Fl5TToadAqN/STN1ez+dPeZJFlKPk+ruluI2MCl+Gg0Lcqh2qGoO/FqndklvHPdWS5Xct1iNCwacVEvsPpt6wlIWreIdAwTQNDZei7DzAwJP7tTgnfLLRiZSRCgNTdyavbISUZBwT2NYz4mj+0q3LTMJABF8d/mIXVQyesOMuSzBcadUz81P368e+U+3kYLK/T6tbj+YhOtD/ll5pzVKG9Ts/XcYh1Mgr5/5jSndXwrtZObcxVQWPiGFlNR77odCfWXeDe/Ry6upZHvSaXYCRJB1qXhKZbCcouLYJFKUcxMVawI9xxVrneLDY7jNc5tSwD8qH1ar7h/dtvnM/fmAk2/ygEhvr81XroVqWS+lqokL2emIJlxSqELYCsNTKf2WbYec+5NWveTXfg2pohB/z3t8ncZxXlmHP9N90MekMXw/a2cJJyRUf8Fw2wSRGdnkKf8kM35P0qrMqXeuI+mY3q1eIdmghjI6XWxRj7QVrXojmKlTQ4GuwnukFgb7djEECiryVJmCvk4qnLApxz5TX1W+6SoLpk+f9ezp/Bs2MjykU4SDKklFXAnjVvdktuIhEsdTCq2Sdt5ZEMdN/LN4L/iV0ZBUFn1ErIilwsoPz60EQ/eA2I+2ugghUASUCEcB8BNY+bIdwu+7m1FKeB+ZqeP+z3cvjPIHOqCr9ZhPxk9J1L2xwuFmY3fhEJmcYgXf7gUKm9xejrK/MgqIi0gcoc2BmlYsief5VnAzOINFWKRHUbCYJFoqCoqDhI5DLoJljVOGD8c00vHXMHbf96NBA21NOali7zNFtBQzPD5LhTcbnzs0XOy0/w64bqno1Z0Jo QIyvq2Hi GwOouWP14DX//mgZdnmEV0vGD6NlVj51NnwIifXjDBWYTeZNIoRdORLDtFV0FnS/1J030t67A7Iu7zd6wciXfs025pM+ISKv391JM+m+cvFlQ8P+ISClOe7wavmSG9uEWlaT8tXzb+92WDztlsUGw1XNCkrj+Bsk3NyWkBjk4g1dvb3zOQByLobAmu/X0RnJpQpE094zfY5HuqnfaRfooEiBslc1LrniYijVY/GDzPbIB28lSEnm7HFrNMysfWWIgdotCY2qSf9A8emt11iBzuATF/W7LoJpgbp2tCMYQXSOnOpg9Vsllw4NhatV409JVibA/7jtwBpg3/1F4quvc9KjVRSLYUeWLRDMX1tMP5bEB0b65joZgFTcN8v9ozks+FDh2j/0twJo6gPjsjQvhoFjelbvCDEddhjIPjwpvfmnIFdxubEsPn4FwIO3tWRJ+nGbNIomP8t17puM1ficih2A1BYFxZ0FSnjvW1mIAxIhq8KydmX/+BbaflmDljBwaGErWIIXqoD/IRXO2rSUJsPgA5bH0XVesQcoQ5hvnTWHsFmHjapqtn1bLilDqp8gWfTsyanTDYCEJAMziw2MBvqGlB5s67O/q9iI2xlQkRdG6xO4UV/z1STRDipnRqkYcFXx7G+AcBYF92HIGn7NCp6JQx2DSd/mYRKAogQgKrDABL3n8qgfJXH0+7NJluqI+7od7hcBKx+7Ve5h1+gJMLQ6xnor9wXDUzHOY X-Bogosity: Ham, tests=bogofilter, spamicity=0.003189, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Since task->comm is guaranteed to be NUL-terminated, we can print it directly without the need to copy it into a separate buffer. This simplifies the code and avoids unnecessary operations. Signed-off-by: Yafang Shao Reviewed-by: Paul Moore Acked-by: Kees Cook Cc: James Morris Cc: "Serge E. Hallyn" --- security/yama/yama_lsm.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c index e1a5e13ea269..1a2d02fee09b 100644 --- a/security/yama/yama_lsm.c +++ b/security/yama/yama_lsm.c @@ -76,7 +76,6 @@ static void report_access(const char *access, struct task_struct *target, struct task_struct *agent) { struct access_report_info *info; - char agent_comm[sizeof(agent->comm)]; assert_spin_locked(&target->alloc_lock); /* for target->comm */ @@ -86,8 +85,7 @@ static void report_access(const char *access, struct task_struct *target, */ pr_notice_ratelimited( "ptrace %s of \"%s\"[%d] was attempted by \"%s\"[%d]\n", - access, target->comm, target->pid, - get_task_comm(agent_comm, agent), agent->pid); + access, target->comm, target->pid, agent->comm, agent->pid); return; }