Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp438405rdh; Wed, 14 Feb 2024 01:06:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXx860NT2B2UL9m8rIEsWakjQNsWeyuJhLMHg9ggI4RaMLVd7wMd9r3QMtIjQlLbKNNAPmEzPo91NC3qn7Q0MgWLW+j44nUQPhtufjJhQ== X-Google-Smtp-Source: AGHT+IHc7e6Y20kJ9ieZd9WyS9+KPJ0um6/kY6d/7IyubOWmbtoRECkaPCuUMZVMVHDYzCvUJbbb X-Received: by 2002:ac8:5cd4:0:b0:42c:64e6:f31b with SMTP id s20-20020ac85cd4000000b0042c64e6f31bmr2024028qta.15.1707901565759; Wed, 14 Feb 2024 01:06:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707901565; cv=pass; d=google.com; s=arc-20160816; b=HF5/HT59x6/K2iQhjIuzT+zZ4grbGuXvbsenc3zrRCG2UQQ3hRmEOKr53PcePxZ/5R kazReH92ZtQrs2TPh4rYd4+g3ryxpOB9iWmaYe5m2dsehzq0o8BHFRGaw+J6zoxAPf2D hXGG0fFWSa4S4yckDF2jx9k+m3Ss4Vu0IgK9mvLlGnShOCWwsxd4JA6xQOo52e3dRE/u BmKJHmbIy0S3LOwmV1FDZ5jA9+zpfvl+lJjIWTCnylWVTxiwLlk1O9ers+x4ZbeEuZP/ sk3YMmrvktAqRtNcqkGsFbBY8NCgrZGGTVWFDKyJmyjxt27Kdxnxd2dM/3zLAstnXYhX t4AA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature; bh=8I13Yy1ZnXR0MIiHLrduxDxiApb0ZcnLJeAvn/Kr8OY=; fh=pZI+nZy84KWJ4ZCE0etzIG1rbBGwb0eoOOc6m8GR5Cs=; b=w3CG0LGEilxAN12vU3dh0Zpk80aa9xNH8FuFATPkFzjkrZL+01JLWbB3cW771CVX7Y Jay+DI/dhdCAPTBKQ3pSAJnNKSZAkfckjyjtV1hVDyXeuLfDxGD6+jHT/cyZ71ijSncW vmvQ0ZIQ4RuBbLCPYPg3cW022CPUPRp+mbwa8azsNMTJXbnccHbrSTzgn3iERgO/6i3j moq6pOL4Hm5NMX1OT/JZixv9HcQ1o0GhbyqBGeVMDf2pibWzYlsn5ps1RnS0boY5km5f d5ruAcpZUYGtIf0dED0zCPslRkqTviKvEeC07smXjhCpoWMjG8w+L3TUqO2THe27Y0+i ZeiA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZrgCXMeM; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-64913-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64913-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=2; AJvYcCUiKQy7ok7P7AcBzatnFJWP1irhoDVhYY1FMlAfR26vpYUyBMnAHuQtnEvL9NgdcLKbIUhIHaLmfpqQzn87+TSpTwrWKhy95+Q7OlNgqA== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id j22-20020ac84f96000000b0042c4e74bd72si4516510qtw.462.2024.02.14.01.06.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 01:06:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64913-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZrgCXMeM; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-64913-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64913-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 0D4B31C26D3E for ; Wed, 14 Feb 2024 09:05:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D1BABA27; Wed, 14 Feb 2024 09:05:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZrgCXMeM" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 E411D13FEF for ; Wed, 14 Feb 2024 09:05:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707901507; cv=none; b=dpL2pjuFoj7VZt7MRnopT3e7zBzyi5g2x+mFM091qQB6wXvJgw9j+rJCgWO0Kv6Z7mDGIcPSRdLTte32fVSNC0KoR4cUaxbyx3Kcwr4f9VX3k60B8/uQ1JKYA+lOqgQ66mknrRdKmF3xycUO3QJfrIG1WNF49QS1hN3CynRIP1I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707901507; c=relaxed/simple; bh=U1ZDBd7fTKy88hgKtIZUFJ1jWPAT0hPVgBoYs7PcoQo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NSvsknD9S4F6F2KILLiZpZxXAoZd+8g9Ae0cVe6mFGxuiDrkYVSEBdGK8adQL7lO2pCh6sq2aeUWKe+23uhz/qEKfYBkPVQFsqs2bU4SywNuuId+phH3MSr5sAmLbcnodpTguSejzVX7Ajiyv0fiThlUt5OI2KbG0oYnBvci6jg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZrgCXMeM; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707901504; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=8I13Yy1ZnXR0MIiHLrduxDxiApb0ZcnLJeAvn/Kr8OY=; b=ZrgCXMeMYy27+Ahc18BlZwMSyEozy4mG6f2Cd4psmDB+evaqqIgpiICsPcbP7WNHjm8NFK AGsdAedXGxbpnJDsGYweJZ/TZMy44asqu5FyYuOE1BuNYsFUpKa0ipOV1PEqQGNh7eHYK8 YqhrpJDz+uNZec0rzLUYcYoVMNpkDlk= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-102-UJ9Vona5M6m-jafFVF2hvQ-1; Wed, 14 Feb 2024 04:04:57 -0500 X-MC-Unique: UJ9Vona5M6m-jafFVF2hvQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9B7063CBDF64; Wed, 14 Feb 2024 09:04:56 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.0]) by smtp.corp.redhat.com (Postfix) with SMTP id C8DC1C185C0; Wed, 14 Feb 2024 09:04:51 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Wed, 14 Feb 2024 10:03:39 +0100 (CET) Date: Wed, 14 Feb 2024 10:03:33 +0100 From: Oleg Nesterov To: Tycho Andersen Cc: coverity-bot , Christian Brauner , Nicholas Piggin , Sebastian Andrzej Siewior , Peng Zhang , Ard Biesheuvel , Luis Chamberlain , Heiko Carstens , Andrew Morton , Suren Baghdasaryan , Thomas Gleixner , Mateusz Guzik , Dmitry Vyukov , Tycho Andersen , Mike Christie , "Paul E. McKenney" , linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-next@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: Coverity: __do_sys_pidfd_send_signal(): UNINIT Message-ID: <20240214090332.GA14017@redhat.com> References: <202402131559.B76A34B@keescook> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 On 02/13, Tycho Andersen wrote: > > I think this is a false positive, we have: Agreed, > That said, a default case wouldn't hurt, and we should fix the first > comment anyways, since now we have extensions. > > I'm happy to send a patch or maybe it's better for Christian to fix it > in-tree. I leave this to you and Christian, whatever you prefer. But perhaps we can simplify these checks? Something like below. Oleg. --- a/kernel/signal.c +++ b/kernel/signal.c @@ -3876,10 +3876,6 @@ static struct pid *pidfd_to_pid(const struct file *file) return tgid_pidfd_to_pid(file); } -#define PIDFD_SEND_SIGNAL_FLAGS \ - (PIDFD_SIGNAL_THREAD | PIDFD_SIGNAL_THREAD_GROUP | \ - PIDFD_SIGNAL_PROCESS_GROUP) - /** * sys_pidfd_send_signal - Signal a process through a pidfd * @pidfd: file descriptor of the process @@ -3903,13 +3899,21 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, kernel_siginfo_t kinfo; enum pid_type type; - /* Enforce flags be set to 0 until we add an extension. */ - if (flags & ~PIDFD_SEND_SIGNAL_FLAGS) - return -EINVAL; - - /* Ensure that only a single signal scope determining flag is set. */ - if (hweight32(flags & PIDFD_SEND_SIGNAL_FLAGS) > 1) - return -EINVAL; + switch (flags) { + case 0: + /* but see the PIDFD_THREAD check below */ + type = PIDTYPE_TGID; + break; + case PIDFD_SIGNAL_THREAD: + type = PIDTYPE_PID; + break; + case PIDFD_SIGNAL_THREAD_GROUP: + type = PIDTYPE_TGID; + break; + case PIDFD_SIGNAL_PROCESS_GROUP: + type = PIDTYPE_PGID; + break; + } f = fdget(pidfd); if (!f.file) @@ -3926,24 +3930,8 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, if (!access_pidfd_pidns(pid)) goto err; - switch (flags) { - case 0: - /* Infer scope from the type of pidfd. */ - if (f.file->f_flags & PIDFD_THREAD) - type = PIDTYPE_PID; - else - type = PIDTYPE_TGID; - break; - case PIDFD_SIGNAL_THREAD: + if (!flags && (f.file->f_flags & PIDFD_THREAD)) type = PIDTYPE_PID; - break; - case PIDFD_SIGNAL_THREAD_GROUP: - type = PIDTYPE_TGID; - break; - case PIDFD_SIGNAL_PROCESS_GROUP: - type = PIDTYPE_PGID; - break; - } if (info) { ret = copy_siginfo_from_user_any(&kinfo, info);