From patchwork Thu Mar 21 20:04:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 13599330 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 3E618C6FD1F for ; Thu, 21 Mar 2024 20:04:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDCA26B008A; Thu, 21 Mar 2024 16:04:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B8D666B008C; Thu, 21 Mar 2024 16:04:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A54986B0092; Thu, 21 Mar 2024 16:04:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 97CFB6B008A for ; Thu, 21 Mar 2024 16:04:12 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DDB23A1F5B for ; Thu, 21 Mar 2024 20:04:11 +0000 (UTC) X-FDA: 81922122702.13.33C9CF9 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf26.hostedemail.com (Postfix) with ESMTP id 336BF140021 for ; Thu, 21 Mar 2024 20:04:10 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=IgPoZDTJ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of 3uZL8ZQsKCAgr201qv01q11owwotm.kwutqv25-uus3iks.wzo@flex--justinstitt.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3uZL8ZQsKCAgr201qv01q11owwotm.kwutqv25-uus3iks.wzo@flex--justinstitt.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711051450; a=rsa-sha256; cv=none; b=3Tt4pRHearnAJHVfm8fOAOOze4oSkGAhVBMRCMtj5zkhIRwCaushVsFqbdGqqlif5ZBs3z Qsa1e4gluQVoFhXk2LB56dF+j/8MO47g/rPwWQ1uhtvICLH0k1WynShGyIIqO3ElPF4E7i 263ukxLI8nqD+iQwQWTH/KKWMP+xBO8= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=IgPoZDTJ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of 3uZL8ZQsKCAgr201qv01q11owwotm.kwutqv25-uus3iks.wzo@flex--justinstitt.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3uZL8ZQsKCAgr201qv01q11owwotm.kwutqv25-uus3iks.wzo@flex--justinstitt.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711051450; 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-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=TCBKqThFKtYqhjiY4RMqU+IuZ1w6cv8EE0k+cJlDNnk=; b=FyrwepuTMsZBPl9HxZVgx+HYcZVHdOei+q58zSCDQO+8azKSl2UXF5yW6SJqmit1VB1Rhh myu4jSix05LlZiKtj4RnHc6192uyCDnZF00YG6Br2nz7NWQ1mPvNzHZaKAeivFRTYtra8I TVKxDN/wlQCKKwVPfO17B+OEKYyml/w= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dce775fa8adso2407320276.1 for ; Thu, 21 Mar 2024 13:04:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711051449; x=1711656249; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=TCBKqThFKtYqhjiY4RMqU+IuZ1w6cv8EE0k+cJlDNnk=; b=IgPoZDTJm9laPhLmca8h0EO+4/f1SA1VlD3LbjXQDzMt8v7IrpbhJuZc20Lz1dRcDw qtCS5i/OAsXRHKeN74I5sABhRXK8p1Q47KEwqakwMQ4yqj5jtE1cTvyv1dIMdyc5E7PR sTtMAgMbQjK8G/nREXSRTRVWw51mPpX9ruYRs6M//t4+XY3lGY/WLZPLwZnljLtLcHz9 1mGsTMvWM2yP2xf63mhwWYbN3eTvGf5Q8IknST2IrB2B2pbhC8OAoddst4fwe8esijDy 2mTbGhP0D5wS1dl2mzf16roGl774hVTIANBgJtzNTR4tQMFNorz0OfYg8AdZTr8e3NbC 21wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711051449; x=1711656249; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=TCBKqThFKtYqhjiY4RMqU+IuZ1w6cv8EE0k+cJlDNnk=; b=ZJ1H2ycuiLi6cS27dD66OuRLKHKF7sHNbICPWJsWyOGd170tbBSihI2qSkNtN26zKp Cjw37CGbvUZVMB+a+3BZ2tYg8Hf4/dcrTJgtE2HmxlolcYiWcGWfTr9i1x5oI93uB2mD Hsu8nZqhAk0U3wELkZZfQZl+YVAudNRNmaeIzakWA0O3+TkLZ5Vocp1XXQpsv44c26sA App4+IXJ6CMzoSidJZG0DkHS+hMx3ZK0AJsWM3cpU9AL4xJVg+YNJgp6eJs9d+r3Evp2 c1uXU3U929AVw0QuJhCm0EOwfTj3qXVQ1UKdwv7rpTwBa2Piidk7BqZTml2ta0MzTgBC tcPg== X-Forwarded-Encrypted: i=1; AJvYcCU1/WpwkiX4iB8udixqny27hXf/u+TrS0BxAwrmpj92fjDTiY42uNKh096KAsFbi1uOB25zW3k2t/sS6JW7ffmYy5w= X-Gm-Message-State: AOJu0YzIL52ipuY/JwuDfh2HoGtcjParAu2+MYnC+2SYHUdAoCxYsFxu 2h5vqZRa/wnAJR9AdPF4DYV0qLOQLVxoGoamWtItttJ3olaVSnfAdXrxIZXrh4XDgXuSCPC8s9t MM8/PE5JiSP4V8wjlOlJaSQ== X-Google-Smtp-Source: AGHT+IE5VBN/+0LV/WPi06J13PSBodS0OdOu9MsbtLw0uhdLxrW4h4oP0M2VfdY/eM1a/8qsQNDCacEmRg4kGkc2ng== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6902:2484:b0:dbd:b165:441 with SMTP id ds4-20020a056902248400b00dbdb1650441mr74857ybb.0.1711051449209; Thu, 21 Mar 2024 13:04:09 -0700 (PDT) Date: Thu, 21 Mar 2024 20:04:08 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIALeS/GUC/4XNQQqDMBCF4avIrDslicVqV71HEWmTiQ5oEhKRi nj3pkLXZVb/LL63QaLIlOBWbBBp4cTe5VCnAvTwdD0hm9yghLqIUglMc3Q6rGgTvtjZae5otJ0 1gTVqrFW+ylyrUgrIRohk+X34jzb3wGn2cT3mFvn9/mT5R14kSrTGkKp03dQN3Xvv+5HO2k/Q7 vv+AbD0yg3LAAAA X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1711051448; l=1634; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=S6RP6uWmLdlEXkKQny/wqkGVsqJcl1gAUGPqZ6bCYiM=; b=ltUxZ2cpj94pnvyIBEzmfBEHQXiRRLeDTlLyWbffUabFpLWPDEAtsiKsRij39k9phe/VyFBxJ 50r/4jHF4KlATUMzXLzQG9U+LPWH6633/Y5LV4uwnne1EeG7KX+npD1 X-Mailer: b4 0.12.3 Message-ID: <20240321-strncpy-fs-binfmt_elf_fdpic-c-v2-1-0b6daec6cc56@google.com> Subject: [PATCH v2] binfmt: replace deprecated strncpy From: Justin Stitt To: Alexander Viro , Christian Brauner , Jan Kara , Eric Biederman , Kees Cook Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 336BF140021 X-Stat-Signature: 81h44hee43mzm318kefoj7a7mgaza3ys X-HE-Tag: 1711051449-595861 X-HE-Meta: U2FsdGVkX19U4x2u8U2S3MT2EXGX1NmzR1Ii8VBRc22XZMpRiDMvqbw6yjXQDSyZPgEJRFOZ+OYgizbjhiRnLHFWJuW97lhW61E5Lk+GFrK3T7sabad31MWkCPx0pb5dDMBQBrDSLUJ44V8v3RLJRXjTCDNO9lEfbxE0SfQcRgQnt4ZeU+1SI26SjHgZEHYTPEIPXHa8388UkSUSt15MFIy72theR1BJReI0aab/y6v6tleJ5LN3GcCcYAUFb6mdH+57QBafgIZvVAr0oNz8FYLNJFT+n0IzU3uMfdAadJSWHMQYEUxXy/vtYvxSKAqEF1VXGb3h4MfLHEjoUiE2VSHCUhxz/v0JJVfBgE4WTn05/LPr6hFYvHPBxzrGfrm6Kkmklrjf1KXkMMWVBjQC7qBDbB7cBkub2m4SsayfYdRpgffmx/7aDCmnNC5IDOUZ03PMWzgbuZvyuf402zzi5Yt5korfpuRa8lbTGhiKioy1SYu4bV5hVFDA0Ipr5nePvYAvGkas1iwkT06rOuzslawoNAmnwMhe2fq/48siDYwJrwQBshY4W8EtoAM686FLhj5yiU7Nc9xhxGSS6PgvFzZGe8eLvMs0NNWZ4SP6lNoxRVM20pvrdDJ55K4JWRwmIubwFq8cljYyPiK9wHtPWCwT531qtczIXbfRclp9cEctkr4shLbsrplOdvA4HtX76TDbWiBIZhMncd6j7D8K1WY3ptBTLKuMystk+GiuJobrwILFNRrJeJxBYcfCfuF1wOoLwVQoiHMM/mw0cTI2HtRJIwkH3GKyacRVkIaq49RjNrS3kQcUWp76PsEKb5fphYz5mZzke0vGzlpRrIZ/HHkA4704gnbx+69ok0vWx8e5AT04ZSIx8CpQ3rp9n2+Aew2Y84QPsh6zbah2Yn7AOLPOrSDlT6kZa+/ZcnXGFZVF5LDf988YApc+a3SwMQT92YbSP12GGcJTx9VP6tA ZAwzKGQW wUH1kk+vUM1Sr/BzkwKw5spJbGK6XLgQL90tcWgFpMK4WdWltOPYFargweiX/2rrhWb7Ixhe4tsvVnyMQfhhy31kJWUVPD3sK/B4RnLuuHC3Ocun7eewwnRHW9SE1ycbtEWg20GqmsY/xff9JPXAmTmcg7CfixeMD5+B5DPrtUWglhKVrRxftOCqxDmQFdRK/fJF19BHYLDRLRZE6qZoSCkdnIWALGTP4kU01LEnOzHl1UkIz5sp0ycPgBWhrJlYURvtFVo9X4QzZED70RFysKQK8rtocACTtgF1XmhCZ4IxDvjRvdf/JiP5EQcrTDF/sQHFDm8FV5Th0myRUYvPvp1H8hRJRLvHDybCxH8YhfID+BBpbWV1Y+hcoCkCuwgXtXGVquwYAru0DRjg= 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: List-Subscribe: List-Unsubscribe: strncpy() is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces. There is a _nearly_ identical implementation of fill_psinfo present in binfmt_elf.c -- except that one uses get_task_comm over strncpy(). Let's mirror that in binfmt_elf_fdpic.c Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] Link: https://github.com/KSPP/linux/issues/90 Cc: linux-hardening@vger.kernel.org Signed-off-by: Justin Stitt --- Changes in v2: - use get_task_comm (thanks Eric) - Link to v1: https://lore.kernel.org/r/20240321-strncpy-fs-binfmt_elf_fdpic-c-v1-1-fdde26c8989e@google.com --- Note: build-tested only. Found with: $ rg "strncpy\(" --- fs/binfmt_elf_fdpic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- base-commit: a4145ce1e7bc247fd6f2846e8699473448717b37 change-id: 20240320-strncpy-fs-binfmt_elf_fdpic-c-828286d76310 Best regards, -- Justin Stitt diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c index 1920ed69279b..3314249e8674 100644 --- a/fs/binfmt_elf_fdpic.c +++ b/fs/binfmt_elf_fdpic.c @@ -1359,7 +1359,7 @@ static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p, SET_UID(psinfo->pr_uid, from_kuid_munged(cred->user_ns, cred->uid)); SET_GID(psinfo->pr_gid, from_kgid_munged(cred->user_ns, cred->gid)); rcu_read_unlock(); - strncpy(psinfo->pr_fname, p->comm, sizeof(psinfo->pr_fname)); + get_task_comm(psinfo->pr_fname, p); return 0; }