From patchwork Sat Nov 20 11:27:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12630333 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 2A2A5C433F5 for ; Sat, 20 Nov 2021 11:28:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 56D416B0072; Sat, 20 Nov 2021 06:28:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 51CD86B0073; Sat, 20 Nov 2021 06:28:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3BD086B0074; Sat, 20 Nov 2021 06:28:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0101.hostedemail.com [216.40.44.101]) by kanga.kvack.org (Postfix) with ESMTP id 2D4B56B0072 for ; Sat, 20 Nov 2021 06:28:12 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id D3CB08993A for ; Sat, 20 Nov 2021 11:28:01 +0000 (UTC) X-FDA: 78829084362.17.72F4DBE Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf15.hostedemail.com (Postfix) with ESMTP id D8998D00009A for ; Sat, 20 Nov 2021 11:27:58 +0000 (UTC) Received: by mail-pf1-f180.google.com with SMTP id m14so11583167pfc.9 for ; Sat, 20 Nov 2021 03:28:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z7z8Lk8HQyp7Owzrc1xbHZJuDcW2wrqL7RcrZw36R8w=; b=nQPN6mdVaURVKIXfc1WLRgCv3LcDfgP+BvR5M8bS7uDh9hb7+0CR/cbwG+1w5WOEQ6 Vvjd5bswZ+eUyJf6IEEUJ3X4nw4wp6LYK+qEl+LNZUKwEFNjW+vYQwwd4HwWkThtN0YH ABITWvIYzC1j4vzBdyDj1GadxflpStTg597iJ1sjW6FKKAL2A+fMWGFXVkoP8BJ91FK6 LihypxMER6hOyMDVdKR9ILrkdyvXJgXHUISem4H0h8IzU/5gdbolUTA7vEaLFbVutke5 jGLHaUXCSmHu7IwiQ9TDKfxjeJZp6KdJY/RkGrqg+I9aO0S7/yFjx4eO2ZmmkGhOdER/ uicg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z7z8Lk8HQyp7Owzrc1xbHZJuDcW2wrqL7RcrZw36R8w=; b=L26FxPxePynCXs/CLVqqLrqXR59Us7MDUC4TyKBmq2BFLn2wrCfGDdj4ek/c8/f7tD ymcV+y6Ux3NaL5SAvBH+3wJ5yOUWrwZ4Lni4qjXuXbbkmXQqV5VG70jDTGIb+Fm07Hx2 3m+asSB04UWWSlq9JsBfC8um4KgGUUo+5S+KR+iQTw1HXSHdguEV0M0R6IHrsh/P+J4k o3UWxKk99FcZmOy4ix49Fhl7K7WMnLSmgqvL2JuzLzilxpboIML5knJ4+TIExpyqPQ0S 9g8lCKz4dN4e9QSTcXka6cdHO+iwxXCZGkGdRnQlu4inOL6Kotoxn7iqtxzwrxUPEezw upzg== X-Gm-Message-State: AOAM53044DbdXHvtSMizNPmVZGpC0Q+harIovaWFonfEuhChyZult1eO tN0XxkVbGKpTjwiJ6RbzjeA= X-Google-Smtp-Source: ABdhPJyRIisol+5siMpWb0J3Nc8SIlVbonIjAvGoaujIU+KdXppeIb88o7SguvA8H1tXupl8NMAHhw== X-Received: by 2002:aa7:888d:0:b0:46b:72b2:5d61 with SMTP id z13-20020aa7888d000000b0046b72b25d61mr69933734pfe.73.1637407680517; Sat, 20 Nov 2021 03:28:00 -0800 (PST) Received: from vultr.guest ([66.42.104.82]) by smtp.gmail.com with ESMTPSA id q17sm2835490pfu.117.2021.11.20.03.27.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Nov 2021 03:28:00 -0800 (PST) From: Yafang Shao To: akpm@linux-foundation.org Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Kees Cook , David Hildenbrand , Mathieu Desnoyers , Arnaldo Carvalho de Melo , Alexei Starovoitov , Andrii Nakryiko , Michal Miroslaw , Peter Zijlstra , Steven Rostedt , Matthew Wilcox , Al Viro , Petr Mladek Subject: [PATCH v2 1/7] fs/exec: replace strlcpy with strscpy_pad in __set_task_comm Date: Sat, 20 Nov 2021 11:27:32 +0000 Message-Id: <20211120112738.45980-2-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211120112738.45980-1-laoar.shao@gmail.com> References: <20211120112738.45980-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: D8998D00009A X-Stat-Signature: rhd9grfmkzhfcmrcbn941hipd3f5nn79 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=nQPN6mdV; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com X-HE-Tag: 1637407678-532202 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: strlcpy() can trigger out-of-bound reads on the source string[1], we'd better use strscpy() instead. To make it be robust against full tsk->comm copies that got noticed in other places, we should make sure it's zero padded. [1] https://github.com/KSPP/linux/issues/89 Signed-off-by: Yafang Shao Reviewed-by: Kees Cook Reviewed-by: David Hildenbrand Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Michal Miroslaw Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Matthew Wilcox Cc: David Hildenbrand Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek --- fs/exec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/exec.c b/fs/exec.c index 537d92c41105..51d3cb4e3cdf 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1222,7 +1222,7 @@ void __set_task_comm(struct task_struct *tsk, const char *buf, bool exec) { task_lock(tsk); trace_task_rename(tsk, buf); - strlcpy(tsk->comm, buf, sizeof(tsk->comm)); + strscpy_pad(tsk->comm, buf, sizeof(tsk->comm)); task_unlock(tsk); perf_event_comm(tsk, exec); }