Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp616520lqp; Thu, 21 Mar 2024 10:17:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVkdThSMQQ9d3VE+xtHwhAC24F14DesvUSRuV+LjHnTDzAdYZ1O+lCrrUbhBrtMPCMcNeNaYyLWokfRTDcW+Rrwq1wb8g4A33BcyEYQWQ== X-Google-Smtp-Source: AGHT+IHZEyA5oTKBTaC2r7yi5+/EQ0b44+79mrI90UEe2LRxLG3JTYJoTCc4kWPvTCKQwAPXDkIh X-Received: by 2002:a17:90a:c7d1:b0:29d:f52c:5d40 with SMTP id gf17-20020a17090ac7d100b0029df52c5d40mr204961pjb.15.1711041437226; Thu, 21 Mar 2024 10:17:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711041437; cv=pass; d=google.com; s=arc-20160816; b=mBIst1wUTFvchr7mSmP6mUm5dMkvuPq9q6lYfCbgcvq4rAKqO1pliayKeDmaauY018 br2OyQ353ufV+GGcqQDietk+aTYGBJvm3LtmY71cOOKwihtrKerO8VDAoHqWzXocJzxf 8l69xAQ8kGSODk9ra7CKWWohGbAfecX1JFPVCROhYVGH+IRylw1Y4/TzOt6ODeSCdgCo SESnaAzd7LZ1PTHFjXZE4P9GJSuMQ8tLrMRkuhrpzE92hnOOjPzFzagi1oTAa6DLB1Gu qLunQd+B33FMwSrp422rCSxh6IvB1KXCSA2ul8ch23+JScf6f3lyfpaZ1bZzDhQyC324 XOQw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=subject:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:user-agent:message-id:in-reply-to:date:references:cc:to :from; bh=pG2vThmrEqgGbaYjFbZFq3esOJ9SyW0sC1//fVwokTA=; fh=bxmjr66oCOXdCFh7keE9L4T4Yb2RWGSIORGZbEYYr8c=; b=eoD6e8SWzQwyfCh5R1e8TtACdA2u8NLse7lomn0EUN0gq2a/0TRaP7FT1S9gpqBlI+ LDpAgg09npDlviIC6DjEKlIqFiOnkLxrRXQ47FVTIRQfZVzIB+nu0WKaNZB766TdtI4O wOVn6aH81ZegUkydzZfuIsURY5Mlt45eO8koRLTpPI3fjtgBeM2O0oTiPpSe0Z+xAzF2 W6/hppuIwem9SDe6FvoeP607osvsojnNVTb7YQBftsJE52AkhSYchfFBkoBYbJeww9Oj djxPHV68161sUAdprRZsKz7GkD1Wviz4jku4fxEY5GROmaPG+YQlkT1XBHpP6HHKAYvz iGFQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=xmission.com dmarc=pass fromdomain=xmission.com); spf=pass (google.com: domain of linux-kernel+bounces-110407-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110407-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id i19-20020a17090acf9300b0029dd94f9f8bsi215808pju.99.2024.03.21.10.17.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 10:17:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110407-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=xmission.com dmarc=pass fromdomain=xmission.com); spf=pass (google.com: domain of linux-kernel+bounces-110407-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110407-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id ADCD6B25517 for ; Thu, 21 Mar 2024 16:56:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E97D3135A58; Thu, 21 Mar 2024 16:47:23 +0000 (UTC) Received: from out01.mta.xmission.com (out01.mta.xmission.com [166.70.13.231]) (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 D0D1724A11; Thu, 21 Mar 2024 16:47:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.70.13.231 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711039643; cv=none; b=Tqq/Uxv/8Q+PzjYlWTBsJJVOMu3JfohWTyGzYJNXmi4k+qs0CPxVRXdodc6HEdg+d5BPBIr+lJNVbzWjJZ9Dc/p2ly379roUCqiUNWWVkHl81S70k9MlsbDNCSPuHEC1P8SxQnQ/NqFCnkscDCxca6Jp1bh0IFyZv8uJ7QTLh6A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711039643; c=relaxed/simple; bh=HLVAmMCpgsC0QELrLic5koFr8nwDxNfHSRgxtVBvamw=; h=From:To:Cc:References:Date:In-Reply-To:Message-ID:MIME-Version: Content-Type:Subject; b=SAhvtdoN4TNHDX6H14ZnxM5RXQ0jrb4pV7WWWv+/EvrvIcVAeqQ2JvjycCfder1loC9uNtVI5/UOG6MOQ2HfAiG14h/vBLVGE3ywHyVUkxMP9n3qOyWjdZKTj/zm7ZdwcRfjX++5EEP2AHYaD7CHkbilLrl8yHnngV2/n4l/D1Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com; spf=pass smtp.mailfrom=xmission.com; arc=none smtp.client-ip=166.70.13.231 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xmission.com Received: from in02.mta.xmission.com ([166.70.13.52]:50958) by out01.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1rnLCf-004Jao-FF; Thu, 21 Mar 2024 10:23:41 -0600 Received: from ip68-227-168-167.om.om.cox.net ([68.227.168.167]:60220 helo=email.froward.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1rnLCe-000QNJ-Dr; Thu, 21 Mar 2024 10:23:41 -0600 From: "Eric W. Biederman" To: Justin Stitt Cc: Alexander Viro , Christian Brauner , Jan Kara , Kees Cook , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <20240321-strncpy-fs-binfmt_elf_fdpic-c-v1-1-fdde26c8989e@google.com> Date: Thu, 21 Mar 2024 11:23:34 -0500 In-Reply-To: <20240321-strncpy-fs-binfmt_elf_fdpic-c-v1-1-fdde26c8989e@google.com> (Justin Stitt's message of "Thu, 21 Mar 2024 00:10:59 +0000") Message-ID: <871q83eepl.fsf@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1rnLCe-000QNJ-Dr;;;mid=<871q83eepl.fsf@email.froward.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.168.167;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX1/OG1LEXI8jC5HSB4g9jn0q4xs9g3G9J4M= X-SA-Exim-Connect-IP: 68.227.168.167 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Level: * X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * 0.7 XMSubLong Long Subject * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * 1.2 XM_Multi_Part_URI URI: Long-Multi-Part URIs * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa04 1397; Body=1 Fuz1=1 Fuz2=1] * -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Spam-DCC: XMission; sa04 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: *;Justin Stitt X-Spam-Relay-Country: X-Spam-Timing: total 450 ms - load_scoreonly_sql: 0.06 (0.0%), signal_user_changed: 11 (2.4%), b_tie_ro: 9 (2.1%), parse: 0.96 (0.2%), extract_message_metadata: 4.2 (0.9%), get_uri_detail_list: 1.93 (0.4%), tests_pri_-2000: 3.4 (0.8%), tests_pri_-1000: 2.5 (0.5%), tests_pri_-950: 1.38 (0.3%), tests_pri_-900: 0.90 (0.2%), tests_pri_-90: 182 (40.3%), check_bayes: 180 (40.0%), b_tokenize: 8 (1.7%), b_tok_get_all: 9 (1.9%), b_comp_prob: 3.4 (0.8%), b_tok_touch_all: 157 (34.8%), b_finish: 0.94 (0.2%), tests_pri_0: 226 (50.2%), check_dkim_signature: 0.58 (0.1%), check_dkim_adsp: 2.8 (0.6%), poll_dns_idle: 1.08 (0.2%), tests_pri_10: 2.0 (0.5%), tests_pri_500: 8 (1.9%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH] binfmt: replace deprecated strncpy with strscpy_pad X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Justin Stitt writes: > strncpy() is deprecated for use on NUL-terminated destination strings > [1] and as such we should prefer more robust and less ambiguous string > interfaces. > > In every other location psinfo->pr_fname is used, it's with strscpy_pad. > It's clear that this field needs to be NUL-terminated and potentially > NUL-padded as well. > binfmt_elf.c +1545: > | char *__get_task_comm(char *buf, size_t buf_size, struct task_struct *tsk) > | { > | task_lock(tsk); > | /* Always NUL terminated and zero-padded */ > | strscpy_pad(buf, tsk->comm, buf_size); > | task_unlock(tsk); > | return buf; > | } > > Note that this patch relies on the _new_ 2-argument versions of > strscpy() and strscpy_pad() introduced in Commit e6584c3964f2f ("string: > Allow 2-argument strscpy()"). I am perplexed. Why not use get_task_comm fill_psinfo like binfmt_elf does? It seems very silly to copy half the function without locking and then not copy it's locking as well. Given that the more highly tested binfmt_elf uses get_task_comm I can't imagine a reason why binfmt_elf_fdpic can't use it as well. Eric > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] > Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] > Link: https://github.com/KSPP/linux/issues/90 > Cc: linux-hardening@vger.kernel.org > Signed-off-by: Justin Stitt > --- > Note: build-tested only. > > Found with: $ rg "strncpy\(" > --- > fs/binfmt_elf_fdpic.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c > index 1920ed69279b..0365f14f18fc 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)); > + strscpy_pad(psinfo->pr_fname, p->comm); > > return 0; > } > > --- > base-commit: a4145ce1e7bc247fd6f2846e8699473448717b37 > change-id: 20240320-strncpy-fs-binfmt_elf_fdpic-c-828286d76310 > > Best regards, > -- > Justin Stitt