From patchwork Thu Dec 19 02:34:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 852334 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 08A3C35960; Thu, 19 Dec 2024 02:35:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734575713; cv=none; b=P9yasWt+rrFmYCfCaAsbhf7fxBMmhtkzgZPgyET+QWI2jUQasGHSCvft81W4sVBSigJiv1Q4o5G//pMfFYhc0AroXjkEZNBCBtyFH8RCurWRciSSVp+DMKNokRW0CN+BLbTlKFo7z+DIxQ4zi3CXflTAMiroyLx77tnsaU90d30= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734575713; c=relaxed/simple; bh=fjvo4dYkUreQMMEsg3L8KRAKXKBd4yx0ng+KH/F5vq8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Uhz5PMSOzmyyUwJit7Ip8pmZ/dGyrowAgz02zk9gYsu3zM8gd4JxVUku9qfB2iQ2osOYrYM7wFfufVu6CimgmSNlLToH2aiQKN1sudlwpVKKa01Rl8286dVCtg9uBRDGUzEtn0VTIbn46gpshIKS2maxoaKVODy7qr8er+U74k8= 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=PtfE3ODB; arc=none smtp.client-ip=209.85.210.179 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="PtfE3ODB" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-728e1799d95so387803b3a.2; Wed, 18 Dec 2024 18:35:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734575711; x=1735180511; 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=GFcOX4O91tQFD6muydW9g9dtgYf4vZjGzF6jEGHBeGo=; b=PtfE3ODBCLFYmX/zn4C8k29GTQcB/j5+bdgyrajaZtlHrFu84fpY/6X3TzSaUgzFqy olra9hev3FHVGxd+7nZXDcRyj/KzzaeZHS0fxC7aa6xD4jxcU2K6e4thieZJaU4z05iI 9LFfEeoAceRFMkSoaP0Yai/10HXIHa/PjM1J2a1cKKJoyBUBnRuKYhwIhiFB1ZeqR6Oe I4bsdPADpFFKHIhVsFzwem/h9/9Q1BQtaOHW35nBhZQYahtKoOesJLC6LLtIbxIUnHUz 9uk/xaHOhmrueSa+zAoaCsrjr5plNtKnmLP7B+/Khc8BNvs3+w5w6r9BvNO6Arfsx35x kkrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734575711; x=1735180511; 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=GFcOX4O91tQFD6muydW9g9dtgYf4vZjGzF6jEGHBeGo=; b=XRy2FjzIfEk4nvZyI3xrVuWjVX/xndZoR00tK9ICDysca9KLqUSjRn3vu26oWFfbe+ eMgkE1UTVlFcTNunB7zTyYa9tGYznsz5a4a6epeIcreolc25WFsMvaAiIXRCJtPsvK8J Y7acSMCaeF2WIBWBMtK3ydyh7gBlBOhcBsYB7U9JTzaOZkH358ZC30QtCFpbmXOBj29v QH/xUwShd1cw53BfosBlllo385lWv4dKDNHSTzJVvOUZ6W5a58I5NF3FxZnkPDmSxCPA CG/gZ+e7xgqnhDTvz10NDdPazzgIm3AbX1dzUMLYPCLp2REsR8cVy2nqTBi7j4P+oY6Q aukg== X-Forwarded-Encrypted: i=1; AJvYcCUMvQnAGddl/WVH4++x6DRGSg3XSqKgH11thKEFRmqLAtDjm9t/+PRVr3v/NYjykqs69wDB2CcwuCo36RY=@vger.kernel.org, AJvYcCVmMZb72x8Mk1+ZKDr2tc96gYfc2UCxJzkXzolOJdNRw9P0i1GDLcmV0yMzLLHG1ePx5pEBBTejtwBLPsqnN62l3eMLbt4S@vger.kernel.org, AJvYcCW12W+L1qmpgX3avhcIbc+O4Vrj4kAtC1hiJUsv5zCOVjAXwqgjfZ7mEchFPWj5PuXkrtE7KSFyTBOIfOA9iG8=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6fq2nMub5YkaL4T6+eloY5JO17ockS8j9Q+Y8D8L++pQmKc9T xp78ULdvptpk3erybUep6HvduQrxtFvYq7je3Q0KgPSmadA/9rMF X-Gm-Gg: ASbGncta9bAy3JF/eoq96i4RNIQOx/4SWRVVJ6vEOAgwwNdlvVM4giAzaciKqs8uPaz 9E96f0Y2q3bJttw/YNLoQNnhWeCIQ6H/2GYjB7ilRfZNi5dz+Tn+gCOEBgbqs9YcKp38N7WxpR9 kgA+5K1heHsYLZdI8oRGQFTwiMGz1rr6PfjnGa3G19veUA6agTsoW7HeqBGxRVeoGXwq05bMqV+ cc/X+xuug5+HKtuj+5RYSI0gulLD1ITe5/xY3DKdojVJ3OEZQqRLfcYUgma6+jF7MOTTtP9rf3u wEMvPWU= X-Google-Smtp-Source: AGHT+IF8uDHPAeHRKoSWXDpZOfxN83+9I3jRkG5wW7qXuv+87XI+9vIxsP70Tcc6kEOf0TdmQfwRSg== X-Received: by 2002:a05:6a20:c6c2:b0:1e1:ca25:8da3 with SMTP id adf61e73a8af0-1e5b4820f26mr9200947637.20.1734575711218; Wed, 18 Dec 2024 18:35:11 -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.06 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 18 Dec 2024 18:35:10 -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 , Vineet Gupta , Thomas Gleixner , Ingo Molnar , Dave Hansen , "H. Peter Anvin" Subject: [PATCH v2 2/5] arch: Remove get_task_comm() and print task comm directly Date: Thu, 19 Dec 2024 10:34:49 +0800 Message-Id: <20241219023452.69907-3-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> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Cc: Vineet Gupta Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" --- arch/arc/kernel/unaligned.c | 5 ++--- arch/x86/kernel/vm86_32.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/arch/arc/kernel/unaligned.c b/arch/arc/kernel/unaligned.c index d2f5ceaaed1b..3b2d8b1bd271 100644 --- a/arch/arc/kernel/unaligned.c +++ b/arch/arc/kernel/unaligned.c @@ -200,7 +200,6 @@ int misaligned_fixup(unsigned long address, struct pt_regs *regs, struct callee_regs *cregs) { struct disasm_state state; - char buf[TASK_COMM_LEN]; /* handle user mode only and only if enabled by sysadmin */ if (!user_mode(regs) || !unaligned_enabled) @@ -212,11 +211,11 @@ int misaligned_fixup(unsigned long address, struct pt_regs *regs, " performance significantly\n. To enable further" " logging of such instances, please \n" " echo 0 > /proc/sys/kernel/ignore-unaligned-usertrap\n", - get_task_comm(buf, current), task_pid_nr(current)); + current->comm, task_pid_nr(current)); } else { /* Add rate limiting if it gets down to it */ pr_warn("%s(%d): unaligned access to/from 0x%lx by PC: 0x%lx\n", - get_task_comm(buf, current), task_pid_nr(current), + current->comm, task_pid_nr(current), address, regs->ret); } diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c index e9e803a4d44c..e6cc84143f3e 100644 --- a/arch/x86/kernel/vm86_32.c +++ b/arch/x86/kernel/vm86_32.c @@ -246,9 +246,8 @@ static long do_sys_vm86(struct vm86plus_struct __user *user_vm86, bool plus) /* VM86_SCREEN_BITMAP had numerous bugs and appears to have no users. */ if (v.flags & VM86_SCREEN_BITMAP) { - char comm[TASK_COMM_LEN]; - - pr_info_once("vm86: '%s' uses VM86_SCREEN_BITMAP, which is no longer supported\n", get_task_comm(comm, current)); + pr_info_once("vm86: '%s' uses VM86_SCREEN_BITMAP, which is no longer supported\n", + current->comm); return -EINVAL; } 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: 852333 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 5186186328; Thu, 19 Dec 2024 02:35:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734575722; cv=none; b=OlNYlm3OKrhtM+wIwhpMfA3MwuG64nkNRuzbM1uQiWPe495TM1LA9aaNZ1PfhE0jhfmMYWc3Z9Tb/Ss452ZCz2Z33nvhDPwm2npNItgzQytx+39b9ah3IhTAusilXqpEdae0MqFRIlZx0RHNch0sGrs+ImdBPyc37kgLV75eLuk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734575722; c=relaxed/simple; bh=uW6gREAjVtJ2OpRjMy/n/Vx7nbzOviJdyVpvyg6VGj0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QoftRPDyod5EtycDT+MQ/98YLVdMzTxZun6BaN/KKbi1gTtePhuo4bdjOR/FCwvKvEGY6A+eivRB2auHwuZTdcRINIV0rAavkgC/HWvlkU54pcFfyUKHwL9AKV2uv/njlZ/k99EQP/O2VvHQiIbPvmOAmuCTzBN0l889DLHTel0= 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=mQAYg0JK; arc=none smtp.client-ip=209.85.210.172 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="mQAYg0JK" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-7292a83264eso280665b3a.0; 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=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=35FnTfH4WG+K4PY792luJMCXMpwCP4Hox12oxUuAxYU=; b=mQAYg0JKmLRdBr5/4QjBadhAuRHMwWvbEoS0m0hdxiUQSfMhUeCXIQz/XP/SDm53Ng 8ZTSS07kKMFUiUcbc3o5L5PEl9uTW7vF+TWBat/+2C/VKaVbCDAmTjf2FALVI4eRnt8k mOul29gPoAkkg0PcYcF1ejYmhK0rOSj6oMKON9HTTrebw4mOYlax5FmgGh8+XaYhb0kJ KmV1E6Lg5ALR3G5fF9g6N/VKvcZKeV5caGItziYoS/7ntsaxRnmxVlVp+aq+UuAPDMhr eU5FfpQkRbuL5BOI3kI/XiapTdD6BPcRTob+rZ/qA0wALiBSLlveSkgzdz+Kwsd1vVVQ IK3Q== 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=TDd1bY45qHi2XwCELq+soYWQBeI7NFLxKjExZv1CwAEaSp73fWP5gNrqBkqX/RKWJ9 Tz6x9ticvyCQMeg1dirgmE0DkB716upMxPI+g3fyPU1XDOjTJFOJI2TdxP+FgiTxbfd6 byIRSbgsntyhqDS0GkZlEoJwe0de62F/7jxjyDw2X3/Srac0Jld7luuuSuoG3z8C5jnL F0+30T6tfvnpr7x8Okl3aEgdmEZVn5JgBJi/V11bx+ypHAdd+RXitSuVIV70qAl+eeMq jAoKer7N0Z2sIQa7e4roI3vHImh5IKJ29tPfOuJMNuIepF+R7e+gYBeDVxsHbWY61Tnb QAIQ== X-Forwarded-Encrypted: i=1; AJvYcCVX44qiDMSSlJYZKAUvDOnO7cKC1fAlyr/vs33XupgqroBEtWMR9xPNVVB8dEMYCgSmzHPea3/T3GJPv2R4DaM=@vger.kernel.org, AJvYcCWKzu8Ourj9MRbKMxDvWvJn+psh4HU00VaCMZ2H0on30wO+OkuaJPYdg0RXDQejZ/c31Lbee2MkK5MdeyY=@vger.kernel.org, AJvYcCXxNEs+3GDcQjFKmgdCQs0t69i/oUjNewb1IM9gpcWJffNYFFwWAoJEhzccj2DEZLQuOVSjvshlXfxlKuK9p0RkppTDUA2F@vger.kernel.org X-Gm-Message-State: AOJu0Yyykx27QYHcWuaDG/IeKS3QAKK9Xg6yQ72a/lTxbSp+7IOSIDOh xaIe5V8u2ukfMRIV73g2yY+wnJ+Qh8NmSSvPuWZVIvYiZX0Pn7KW X-Gm-Gg: ASbGncu9eqymj31JBoc+8U1Cb22hm0EN7CzNGolSHRPVnJAlzy6Ni36Skg1A6+N9F4x PpMljKe/iw1T9rS7wJZNtKJ5XxX8xucfRiIePIgXRX4b5ESCKd/Oc0/pbds9X2vj6R85zsyhrxv caITcp466ashbEr3UcAwzBGPYXV60aFfIuTx7qH7k+RobB8F6abj2uMmKyOkI6XaSiBrzXpBDGl p8UiEoTBB3wI6fXHtwm4C1H+GNMTayGPLWtcoO9MN3JCmvAxCpClngz3bL3Q6xRSDV9SamtgeKR pM8BAJo= 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> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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; }