Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1523663rdh; Mon, 25 Sep 2023 15:59:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGP74aYA0WonwMPAHhvutDgDRWUWo7BSv6TLMIZq9zRlgQc4m2u/3k3VYZkb2/dn0Lqp4fI X-Received: by 2002:a05:6a20:42a4:b0:15e:108c:35b0 with SMTP id o36-20020a056a2042a400b0015e108c35b0mr6990395pzj.4.1695682769752; Mon, 25 Sep 2023 15:59:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695682769; cv=none; d=google.com; s=arc-20160816; b=z+8z5kc/pOu3PQi+Ghp2XtSg8sTa2+bZ7uoVZ9piCawEJXzGhnPUEKeH+tEmR4fUOz zJG6BN6OuQJoddOs4FOqwV8bUA8Urhl1hNX20p3PZErkts2rUtA56lAbnBM8bV4TwHXs /Qq2rbue+/GA8OH5/CHDCek1IfMX2GFqNRn37L2cA1GUvP4Qi/OLD+XTJA3mgwo4X3oQ HFbueYWERr/6SJI00+puRvsFvIAcXeqcnHe8COaVDBIesUPXvnexWBEgDStL6Hfw8dg9 eR7yTeVrAg+qmxielQcTEVzbJYIsi8Ksn0MhAKulVvke9NqeeHAYnHRj33YikU11s7C3 jWNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :date:dkim-signature; bh=dBleu0jN78l+uvIeZgOInZlyGwL7BuWHC8ozonaYPQY=; fh=NzxGoz2C8fG311LKiw1sBH0veILnB/F87TKwH1iLN4k=; b=cvWGplyeFjvi1OO+zp32AufSG0PWCgjd3sg1xKEdJWRS4t0bB/nenA1KZ6oThs1NGy ukawKhO2mcoOejWGlpzvpGHwvPWaCF8pUheJe3se8JpQekNyFjzkhyNz+w9JBuhg+Hcw xcZpwNCZ5F76Iy55gxCBet6qeyKlyo2tVCwC1MY5xVDBe/KA2sk0uAe5rCgHW/U6wIfF bVx/Zcejh/i9j1hbDEy+sffYJCKgoaotJg++UHofEnW8xUVU62/Azi/PaNutKGHAAITt j+/g5zXv5O0GYw1abIJLeIkl7gXtqY+RHUOZA1YFi+Lhj91cs0LUpvUsdIiwCjsHFNVy dgDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b="g6J/6X/f"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id gd22-20020a17090b0fd600b00271ae22eea7si12938145pjb.117.2023.09.25.15.59.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 15:59:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b="g6J/6X/f"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 335F6808E64C; Mon, 25 Sep 2023 10:01:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229584AbjIYRBH (ORCPT + 99 others); Mon, 25 Sep 2023 13:01:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229966AbjIYRBG (ORCPT ); Mon, 25 Sep 2023 13:01:06 -0400 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71B0710D for ; Mon, 25 Sep 2023 10:00:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1695661255; x=1695920455; bh=dBleu0jN78l+uvIeZgOInZlyGwL7BuWHC8ozonaYPQY=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=g6J/6X/fXeETdS++BX6h2ye9N4wqwJDwNBz+fgVOE3hSonkzZl3NO5tZg7h5P1n2v bBAeMKh/lUH0dbTi1/g+etgbwniH7EsapiFaATMPMmbCkSvPKAMYEc787xCesLxtDa SGdgDZ+jfCi6xgp5d57W1BqGrAwjqeXNTtfFtsqEEp54y+jG81W3TW6Y6ZwBxd1Hzw Gvxbx2H9DdVHopoQj+cu4VaovtPGQKYeneCSKsk/nidRaxPXxGNCbKwTd2fOEyXjgf +tcijNWCvDM8GPRgSdM/UBHuTOOjfzmvRn+fw4nVzQdduGk68kZs0mWCT4iSEkHecy 4REm3i7mAyAUQ== Date: Mon, 25 Sep 2023 17:00:45 +0000 To: Boqun Feng From: Benno Lossin Cc: Alice Ryhl , Wedson Almeida Filho , rust-for-linux@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , linux-kernel@vger.kernel.org, Wedson Almeida Filho Subject: Re: [PATCH v2 2/2] rust: arc: remove `ArcBorrow` in favour of `WithRef` Message-ID: <9d6d6c94-5da6-a56d-4e85-fbf8da26a0b0@proton.me> In-Reply-To: References: <20230923144938.219517-1-wedsonaf@gmail.com> <20230923144938.219517-3-wedsonaf@gmail.com> <969eab7f-ad40-0dfb-18b9-6002fc54e12b@proton.me> <14513589-cc31-8985-8ff6-a97d2882f593@proton.me> Feedback-ID: 71780778:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 25 Sep 2023 10:01:05 -0700 (PDT) On 25.09.23 18:16, Boqun Feng wrote: > On Mon, Sep 25, 2023 at 03:07:44PM +0000, Benno Lossin wrote: >> ```rust >> struct MutatingDrop { >> value: i32, >> } >> >> impl Drop for MutatingDrop { >> fn drop(&mut self) { >> self.value =3D 0; >> } >> } >> >> let arc =3D Arc::new(MutatingDrop { value: 42 }); >> let wr =3D arc.as_with_ref(); // this creates a shared `&` reference to = the MutatingDrop >> let arc2: Arc =3D wr.into(); // increments the reference c= ount to 2 >=20 > More precisely, here we did a >=20 > =09&WithRef<_> -> NonNull> >=20 > conversion, and later on, we may use the `NonNull>` in > `drop` to get a `Box>`. Indeed. >=20 >> drop(arc); // this decrements the reference count to 1 >> drop(arc2); // this decrements the reference count to 0, so it will drop= it >> ``` >> When dropping `arc2` it will run the destructor for `MutatingDrop`, >> which mutates `value`. This is a problem, because the mutable reference >> supplied was derived from a `&`, that is not allowed in Rust. >> >=20 > Is this an UB? I kinda wonder what's the real damage we can get, because > in this case, we just use a reference to carry a value of a pointer, > i.e. >=20 > =09ptr -> reference -> ptr >=20 > I cannot think of any real damage compiler can make, but I'm happy to be > surprised ;-) This is UB, so anything can happen :) --=20 Cheers, Benno