Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp644254rwb; Thu, 18 Aug 2022 09:38:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR7rZnxHtpSMysRneNvG9SM1coh7oDz3fk8nQziUeB5TRkUk/ur/M0353xjINiLf+7wSc+Ka X-Received: by 2002:a63:4802:0:b0:41c:ac9e:1950 with SMTP id v2-20020a634802000000b0041cac9e1950mr3020539pga.376.1660840698423; Thu, 18 Aug 2022 09:38:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660840698; cv=none; d=google.com; s=arc-20160816; b=krvFxS0ruhWLp2TMeBoBA22lVNART+guNcwLhdJvfFL8yKqPbkn5eSmkOzW2truTNC mLngRh2B3aM4JkzA1WwLVh4mzstNTiFvhs+8xws4V3cHj3Zz2fUucYglF+b9Nx0ZiUaW dvOt/PS8KjLb5AjRGgR+ZZvSvTC+NeeH8gH55yAD50Xi7Xup70WSPGphdqo3akQPuGRw 96ir2pnzbgvF8RVn2TUZV4ljX3/xlK0EkSrgiKpb1mqBfKfm0n5KjnFCHhK5E1p/Ga/w +GFzQ1Ab1soeeRX/EIVJzSFljMRtPruoUxsINnGYDBTu4YBAvR2vI6EcCPicvaANZMmo vb2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=dkzdwXAhukUGKkbvYtx/LFK6YpxxPi2tmHux6mvam40=; b=xFdzztM1x0Ap2oC6AJy94aLF5wowUfEV4uPCosMDy5/OC8qOSnGoSYkcrTMwxsJHyc lljdZFUYvg3tz4M7YaXhhXO4EhhASTod3Ay2WHo+FDza6STcwIsUXHRvr2n9e5PZBUMo TqenQyAQUufXUr4Jb8TSmlJ7LZPzMX9vERCZEdQsGiiyT64EynqEyCduoWXYJhsbtTuQ 7qaOoWTsILnt1YAATKUjdQ9l3x6bC0NsoJ8B7dUD9xSHnc70txXkcP+pgI52/Q3ZcjU2 4VWdMEeU0VcD0bbeT1pX1827xjs156vrNsesAFJcV5gPBzdp4WJkrYXbcjeK3uGU/M3h Mgqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lbuKiul3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g16-20020a056a0023d000b00534a1315a54si2142212pfc.138.2022.08.18.09.38.05; Thu, 18 Aug 2022 09:38:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lbuKiul3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233295AbiHRQIm (ORCPT + 99 others); Thu, 18 Aug 2022 12:08:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343624AbiHRQIi (ORCPT ); Thu, 18 Aug 2022 12:08:38 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F341DF38 for ; Thu, 18 Aug 2022 09:08:33 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id c24so1627318pgg.11 for ; Thu, 18 Aug 2022 09:08:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc; bh=dkzdwXAhukUGKkbvYtx/LFK6YpxxPi2tmHux6mvam40=; b=lbuKiul3DBDHslligdJbHEWQKKkH0d+m4Kn5XBM6DDmBF92h/JROOSP6+ssCj74oqq XRSqt0Ah+a2HtDEdIN+dWtjUXRoONv2mBPuHS7sKyca2pDFiNrme23UapxwvsDVDOeGh D2ROiXh0DSs1fKeCDkEXNccJf8SqW1CVUcPDk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=dkzdwXAhukUGKkbvYtx/LFK6YpxxPi2tmHux6mvam40=; b=idrf6cAzkY+2Pn5TYWC3h+NItstRxGBWQGRMZxTctQAXnud5hdN136bbjpgrgYDtJ0 bxclJoOeqhQ9CcwHCkVyFcLt+MCmPFh4snq3ettFJyUWKeMGHM5q6MCFO8KjlOy24Vz9 tXoUgpucdK6hMXr7AUUr0SiM4+qw5KyN0X+bBtRbNQxWQhTXa26WHJGt6ET6XHOsov5Y 5bTcj0PYxAG8N+93V8WpANWPlayV6RHkFeXdotTOtH8kRk64mMiIS5ZmB4fDG15IepZS yE2lakEpoA+NNylAUG4BN02iH1TfILUaR5O9YuR5axWawfeQTI5VvcLccAqDQ9x8oFMr m8cw== X-Gm-Message-State: ACgBeo3v6zcUvkDvTIwSEL6SojvSYmZ8kFfpHKczEGJy7csiIdrPXM58 pc2x1kLpoM1vA2I0vjKF3vEXNg== X-Received: by 2002:a05:6a00:2393:b0:535:58e7:8f90 with SMTP id f19-20020a056a00239300b0053558e78f90mr3605157pfc.84.1660838913039; Thu, 18 Aug 2022 09:08:33 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id ei23-20020a17090ae55700b001f7a76d6f28sm1707494pjb.18.2022.08.18.09.08.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 09:08:32 -0700 (PDT) Date: Thu, 18 Aug 2022 09:08:31 -0700 From: Kees Cook To: Miguel Ojeda Cc: Miguel Ojeda , Linus Torvalds , Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, patches@lists.linux.dev, Jarkko Sakkinen , Alex Gaynor , Geoffrey Thomas , Wedson Almeida Filho , Sven Van Asbroeck , Gary Guo , Boqun Feng , Maciej Falkowski , Wei Liu , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron Subject: Re: [PATCH v9 06/27] rust: add C helpers Message-ID: <202208180905.A6D2C6C00@keescook> References: <20220805154231.31257-1-ojeda@kernel.org> <20220805154231.31257-7-ojeda@kernel.org> <202208171240.8B10053B9D@keescook> <202208171331.FAACB5AD8@keescook> <202208171653.6BAB91F35@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 18, 2022 at 06:03:04PM +0200, Miguel Ojeda wrote: > On Thu, Aug 18, 2022 at 1:56 AM Kees Cook wrote: > > > > Perfect. It may be worth stating this explicitly with the helper. i.e. > > "This is for handling any panic!() calls in core Rust, but should not > > ever be used in the 'kernel' create; failures should be handled." > > I am not sure we should say "ever", because there are sometimes > situations where we statically know a situation is impossible. Of > course, "impossible" in practice is possible -- even if it is due to a > single-event upset. > > For the "statically impossible" cases, we could simply trigger UB > instead of panicking. However, while developing and debugging one > would like to detect bugs as soon as possible. Moreover, in > production, people may have use cases where killing the world is > better as soon as anything "funny" is detected, no matter what. Please, no UB. I will take a panic over UB any day. It'd be best to handle things with some error path, but those are the rare exception. > So we could make it configurable, so that "Rust statically impossible > panics" can be defined as UB, `make_task_dead()` or a full `BUG()`. C is riddled with UB and it's just terrible. Let's make sure we don't continue that mistake. :) > By the way, I should have mentioned the `unwrap()s` too, since they > are pretty much explicit panics. We don't have any in v9 either, but > we do have a couple dozens in the full code (in the 97% not submitted) > in non-test or examples code. Many are of the "statically impossible" > kind, but any that is not merits some discussion, which we can do as > we upstream the different pieces. The simple answer is that if an "impossible" situation can be recovered from, it should error instead of panic. As long as that's the explicit design goal, I think we're good. Yes there will be cases where it is really and truly unrecoverable, but those will be rare and can be well documented. -- Kees Cook