From mboxrd@z Thu Jan 1 00:00:00 1970 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C6634D1039D for ; Wed, 26 Nov 2025 10:26:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vOCjI-0002G3-Pi; Wed, 26 Nov 2025 05:26:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vOCjH-0002FU-7f for qemu-devel@nongnu.org; Wed, 26 Nov 2025 05:26:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vOCjF-0007qT-91 for qemu-devel@nongnu.org; Wed, 26 Nov 2025 05:26:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764152788; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=XZP8xUW1n+GNi5Y6J8oCNv4ZQFBP1ZcD++Gc4NVUlPo=; b=QXbtC7W0gE1vdp+rBDWLCLWiOo+cAItml9jS7CD0hq2Mh6LdLsRn4c1tjdHYwXtQJ9zp0e peqpLr0VMy8wEocn6jC6n6cWN9Vr+xRTmUyAB8XQJEZUpRvRUqjIOxcduafZJxm0AeXYWv VvXRb27j/Xv1Qfl60k3xe7BKBAVm2vc= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-328-rU6Iz9RwO-2CZp9vyEHf5g-1; Wed, 26 Nov 2025 05:26:23 -0500 X-MC-Unique: rU6Iz9RwO-2CZp9vyEHf5g-1 X-Mimecast-MFC-AGG-ID: rU6Iz9RwO-2CZp9vyEHf5g_1764152782 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-42b352355a1so292646f8f.1 for ; Wed, 26 Nov 2025 02:26:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1764152782; x=1764757582; darn=nongnu.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=XZP8xUW1n+GNi5Y6J8oCNv4ZQFBP1ZcD++Gc4NVUlPo=; b=tJ4RGgV5rYu6x5nwWTZj91KYacU+c+LjP5iLyROhaTdVfVCGiebTd4suqA9nyDWcZW N/nCQH8+AG6Fyugj7bb+4ZQacO5Vc2FYOZDY6Z1GCaUuaCErGDfgmrXYONhhV+NvuC9+ nERzGNqhDspL3OjhF5Hw4GIrSriHEK83JdP8sfUpHHzWPe4clQBoDVnGgPlq6aPzBbN3 1/qtN7mew4ZZ19cNBYhkYNf+SIMvIGw7WKRHQ9FHKFedEWNS24GDLTpeEjbcDQ0zGj5w QGc2K1jcyiLSWyWiaJJLnDj9Bp/VYbv+ZmRDogKW1KGJFHm9nCv9wtSNk9fKj1gjiEJZ XsdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764152782; x=1764757582; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:c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m9/7+1AvCbVCA6uhfMKuzjlEKzz/ Y5XnE6l9Pp2+2odG4+yIm83Sr19LU4+YDFB8vOkA7d7VQqJS+ X-Received: by 2002:a05:600c:3ba7:b0:46e:59bd:f7e2 with SMTP id 5b1f17b1804b1-477c05139c2mr247437925e9.11.1764152782427; Wed, 26 Nov 2025 02:26:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IEs7p+PFzDqfU6Pg2nRDXlSr3Bjmq6GqGp7g+6wCKbIw3S6B89CRDdJieLYv7g5QbD10T4I1A== X-Received: by 2002:a05:600c:3ba7:b0:46e:59bd:f7e2 with SMTP id 5b1f17b1804b1-477c05139c2mr247437515e9.11.1764152781968; Wed, 26 Nov 2025 02:26:21 -0800 (PST) Received: from ?IPV6:2a01:e0a:280:24f0:576b:abc6:6396:ed4a? ([2a01:e0a:280:24f0:576b:abc6:6396:ed4a]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4790adfb2edsm34356055e9.13.2025.11.26.02.26.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 26 Nov 2025 02:26:21 -0800 (PST) Message-ID: Date: Wed, 26 Nov 2025 11:26:20 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: g_autoptr(Error) From: =?UTF-8?Q?C=C3=A9dric_Le_Goater?= To: Peter Xu , Markus Armbruster Cc: =?UTF-8?Q?Daniel_P=2E_Berrang=C3=A9?= , qemu-devel@nongnu.org, farosas@suse.de, peter.maydell@linaro.org References: <20251125070554.2256181-1-armbru@redhat.com> <871plmk1bc.fsf@pond.sub.org> <87jyzexrly.fsf@pond.sub.org> <769f5a57-7006-4cef-a5cb-12d53b7c30a5@redhat.com> Content-Language: en-US, fr Autocrypt: addr=clg@redhat.com; keydata= xsFNBFu8o3UBEADP+oJVJaWm5vzZa/iLgpBAuzxSmNYhURZH+guITvSySk30YWfLYGBWQgeo 8NzNXBY3cH7JX3/a0jzmhDc0U61qFxVgrPqs1PQOjp7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AAkFAlu8o3UCGwwACgkQUaNDx8/77KEhwg//WqVopd5k 8hQb9VVdk6RQOCTfo6wHhEqgjbXQGlaxKHoXywEQBi8eULbeMQf5l4+tHJWBxswQ93IHBQjK yKyNr4FXseUI5O20XVNYDJZUrhA4yn0e/Af0IX25d94HXQ5sMTWr1qlSK6Zu79lbH3R57w9j hQm9emQEp785ui3A5U2Lqp6nWYWXz0eUZ0Tad2zC71Gg9VazU9MXyWn749s0nXbVLcLS0yop s302Gf3ZmtgfXTX/W+M25hiVRRKCH88yr6it+OMJBUndQVAA/fE9hYom6t/zqA248j0QAV/p LHH3hSirE1mv+7jpQnhMvatrwUpeXrOiEw1nHzWCqOJUZ4SY+HmGFW0YirWV2mYKoaGO2YBU wYF7O9TI3GEEgRMBIRT98fHa0NPwtlTktVISl73LpgVscdW8yg9Gc82oe8FzU1uHjU8b10lU XOMHpqDDEV9//r4ZhkKZ9C4O+YZcTFu+mvAY3GlqivBNkmYsHYSlFsbxc37E1HpTEaSWsGfA HQoPn9qrDJgsgcbBVc1gkUT6hnxShKPp4PlsZVMNjvPAnr5TEBgHkk54HQRhhwcYv1T2QumQ izDiU6iOrUzBThaMhZO3i927SG2DwWDVzZltKrCMD1aMPvb3NU8FOYRhNmIFR3fcalYr+9gD uVKe8BVz4atMOoktmt0GWTOC8P4= In-Reply-To: <769f5a57-7006-4cef-a5cb-12d53b7c30a5@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.152, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On 11/26/25 09:19, Cédric Le Goater wrote: > On 11/25/25 17:15, Peter Xu wrote: >> On Tue, Nov 25, 2025 at 12:46:01PM +0100, Markus Armbruster wrote: >>> Daniel P. Berrangé writes: >>> >>>> On Tue, Nov 25, 2025 at 08:40:07AM +0100, Markus Armbruster wrote: >>>>> g_autoptr(T) is quite useful when the object's extent matches the >>>>> function's. >>>>> >>>>> This isn't the case for an Error object the function propagates to its >>>>> caller.  It is the case for an Error object the function reports or >>>>> handles itself.  However, the functions to report Error also free it. >> >> I'd confess I didn't pay enough attention on how the error API was designed >> deliberately to always free the Error objects before almost whenever >> possible.  But I see now, thanks for the write up. >> >>>>> >>>>> Thus, g_autoptr(Error) is rarely applicable.  We have just three >>>>> instances out of >1100 local Error variables, all in migration code. >>>>> >>>>> Two want to move the error to the MigrationState for later handling / >>>>> reporting.  Since migrate_set_error() doesn't move, but stores a copy, >>>>> the original needs to be freed, and g_autoptr() is correct there.  We >>>>> have 17 more that instead manually free with error_free() or >>>>> error_report_err() right after migrate_set_error(). >>>>> >>>>> We recently discussed storing a copy vs. move the original: >>>>> >>>>>      From: Peter Xu >>>>>      Subject: Re: [PATCH 0/3] migration: Error fixes and improvements >>>>>      Date: Mon, 17 Nov 2025 11:03:37 -0500 >>>>>      Message-ID: >>>>> >>>>> The two g_autoptr() gave me pause when I investigated this topic, simply >>>>> because they deviate from the common pattern migrate_set_error(s, err) >>>>> followed by error_free() or error_report_err(). >>>>> >>>>> The third one became wrong when I cleaned up the reporting (missed in >>>>> the cleanup patch, fixed in the patch I'm replying to).  I suspect my >>>>> mistake escaped review for the same reason I made it: g_autoptr(Error) >>>>> is unusual and not visible in the patch hunk. >>>>> >>>>> Would you like me to replace the two correct uses of g_autoptr(Error) by >>>>> more common usage? >> >> Works for me. >> >> Now I also think it should be good migrate_set_error() follow QEMU's Error >> API design if we decide to stick with it freeing errors in such APIs. >> >> Said that, I wonder if you think we could still consider passing Error** >> into migrate_set_error(), though, which will be a merged solution of >> current Error API and what Marc-Andre proposed on resetting pointers to >> avoid any possible UAF, which I would still slightly prefer personally. >> >> If we rework migrate_set_error() to take ownership first, then we can >> naturally drop the two use cases, and remove the cleanup function. >> >> Markus, please also let me know if you want me to do it. >> >>>> >>>> I had previously proposed g_autoptr(Error) a year or two back and you >>>> rejected it then, so I'm surprised to see that it got into the code, >>>> because it requires explicit opt-in via a G_DEFINE_AUTOPTR_CLEANUP_FUNC. >>>> >>>> Unfortunately it appears exactly that was added earlier this year in >>>> >>>>    commit 18eb55546a54e443d94a4c49286348176ad4b00a >>>>    Author: Maciej S. Szmigiero >>>>    Date:   Tue Mar 4 23:03:35 2025 +0100 >>>> >>>>      error: define g_autoptr() cleanup function for the Error type >>>>      Automatic memory management helps avoid memory safety issues. >>>>      Reviewed-by: Peter Xu >>>>      Signed-off-by: Maciej S. Szmigiero >>>>      Link: https://lore.kernel.org/qemu-devel/a5843c5fa64d7e5239a4316092ec0ef0d10c2320.1741124640.git.maciej.szmigiero@oracle.com >>>>      Signed-off-by: Cédric Le Goater >>> >>> I missed it.  Not he submitter's fault; it was cc'ed to me. >> >> If someone to blame, it's the reviewer. > At end, I was the one who merged this stuff. My bad. > > I felt confident at the time, as it was only a single-line change reviewed > by a subsystem maintainer and the patch was large enough that this didn't s/patch/series/ makes more sense. Sorry for the noise. C. > raise my attention. > > But it should have been treated with greater caution, global features must > be introduced together with concrete usage proposals. I think this would > have raised some unconscious red flags. > > Thanks, > > C. > > > > > >