From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72BB63D47B3 for ; Wed, 8 Apr 2026 17:22:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775668961; cv=none; b=lk9wb+hMh0NF/6rwbhr3cVYxogJDAfeosod9GAJF+F5WI04x48Uk7DlH2DI1uJ7INj0qkDMft4Y9OQVWSBsB05/RwWCirGVFOh6fBUkd9OHcLSTz256/x6XNIuBXTNVDq7GavYKJOpA5djDvHRQHaeipo84m27f/eGAEDhnf460= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775668961; c=relaxed/simple; bh=gNJduQx8uBBAIyt5/XG5cTtxBJWJ2wWwKg9EVpn6lE0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ZQUk6Hs68HqV/Jf02Zp0mJnImDtrTinAhYJMJUhnFBFwUdrZJpY0evqc/1RezgA6g8o+jO2BqlHWIYMGTQVKCZbGVP7xlnr7vQH64NrJTuduTDaSTx/V5H82lBbkRNx+WadQ0iWhFpIOnz7kjG6epQuv1QvCj0hhmdtEwQAlVK8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bynar.io; spf=pass smtp.mailfrom=bynar.io; dkim=pass (2048-bit key) header.d=bynar.io header.i=@bynar.io header.b=Oaii7BFc; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bynar.io Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bynar.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bynar.io header.i=@bynar.io header.b="Oaii7BFc" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-482f454be5bso13817365e9.0 for ; Wed, 08 Apr 2026 10:22:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bynar.io; s=google; t=1775668958; x=1776273758; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=DyRjAExzptaZ37zBDXbJb6e5/hLDzY5/zkTN8PmV6NI=; b=Oaii7BFcfdgtD+RC7d2xsPVPhjXwM8nuzxIspweJl6mn6zyvXxyvnYsAmlkBi6k18P 8z/BIqcG9ooXBmeVjpm4HVWJrYRvTsIWVGfdU5lwGgIK/SySz3sMPe7taWlKdxeYhVda A+RIAPjf3ikRFr7lW4xxFXVKTB//PStJc1ufFQjBFK3KtzXkWu4umnOVWcBmatuFyCej c2TYFWNbw/J0hZCdfSJJ+lwEigKyLTNVogh/cuvvMa50EbBn0SdcFgjm0ofNKX9jliwO m8LS2aCVYAJVBhMk6pbaNsvnMh7wGGmGLTUneryK2tRhQ+IHDrfcDYgWzRTdoSfxKFTM OD1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775668958; x=1776273758; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DyRjAExzptaZ37zBDXbJb6e5/hLDzY5/zkTN8PmV6NI=; b=IuV3rb6K8ss1LdEk3k70L3ius4STW0b+YOSSO9ZVTkdqGQ4eYvHdVMAWr7nNzt91/o zQ9bZxXzkJ9Kx4E8M86jlZZkQ9f25vN6OK53k+kNiQzXA5MnTdeKxj7Nctt3EPVot54f 9L27un32G4t9P0JUnDAV0c8mAg/BWgdTgur2JnqsuXXXzdSUXQQuxGUbadws4K/yoHQ4 q3LYYAdsyRSbU+KmHqPO/0wtFLA5B2GIWcqGhrpqxzoW9IqvsrSTE/axRa7sdyaKjGiQ FWM5Oiu+Ne2Dt3if2TCBuqoMbJRY1WGeh1iJ9CWbt0rNgwtjPPtqXfYkHwzNviumsxTw T4qg== X-Forwarded-Encrypted: i=1; AJvYcCX3GZaJkJRdA94PqQQHI42WIhDQqIBh4X/GM8ZL4Jem4rbXg/qBcilHJe5DgkofH1VQu9NmAkUmwreSkOM=@vger.kernel.org X-Gm-Message-State: AOJu0YzpooIdbYjPWeW6MMJ4BIa+SUH/6D2Jt+iU+zHPJBrxR4ehi+ks 520QCm2FTLb/Z4jp29f+NlU9yZJ+pGzcnXDR0gDpvGEnVGX5Jkf/v9CVV7elL1JnLPmO X-Gm-Gg: AeBDieucg9npntQVboqLk0D5sl/revDP2nl01YiTucc1hvWnQSC++L9UFlGMXzi4MZv aOKAvi+LRd3UakIcaKK1x50YhdWdPxtFRVUWkSG+ICfx1y1vDiJ3RLAJPBVXOtxm21JcrJQ77IL zVI0NlCC7bHeqYkpCwOId/gWgQOvBvNf14GQyzG+/+T/XHlG4uyovbP1yPLwS5sqE9zc7mBecpm 1CLn3kh6h5gNRyo1W7n73b7agNWw/2hvSRqITh82NQASwvaJ5XWJpSaHQ1N9Tg//kOoNcqbNPvC v2vmBl4V0vcHka6R9MfUK1mP5ryB1c1Ngx+OByi+UrTRF5VVZxAHc8KWlUmapyjyy+8s8hr49vF jhnhilEshiHiAY58otd3bZvGRZNmIJ8sKwGpmIsd6kO6GxGdfYnuwUceA82wytSgSV7WLDK4Hnm VCVdVfnuxF2J+IFlZunmLKM6JQRs5IZ9uDaeUtu/i3eiybRD6v/ml8Cgfk X-Received: by 2002:a05:600c:354f:b0:488:c239:d498 with SMTP id 5b1f17b1804b1-488cd557418mr5167705e9.8.1775668957556; Wed, 08 Apr 2026 10:22:37 -0700 (PDT) Received: from ?IPV6:2a06:61c2:d427:0:b321:1c7a:b072:326e? ([2a06:61c2:d427:0:b321:1c7a:b072:326e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488cd1b57f8sm6879605e9.7.2026.04.08.10.22.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Apr 2026 10:22:36 -0700 (PDT) Message-ID: <430cc8b9-21f0-4954-ae36-ec5e63f3ef9d@bynar.io> Date: Wed, 8 Apr 2026 18:22:36 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net] can: raw: fix ro->uniq use-after-free in raw_rcv() To: Oliver Hartkopp , netdev@vger.kernel.org Cc: mkl@pengutronix.de, linux-kernel@vger.kernel.org, linux-can@vger.kernel.org References: <26ec626d-cae7-4418-9782-7198864d070c@bynar.io> Content-Language: en-GB From: Sam P In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 08/04/2026 17:28, Oliver Hartkopp wrote: > Hello Sam, > > many thanks for your investigation and for the provided fix. > Excellent work! > > Btw. you also suggested a different solution with synchronize_rcu(): > > diff --git a/net/can/raw.c b/net/can/raw.c > index eee244ffc31e..5bb9a84f2471 100644 > --- a/net/can/raw.c > +++ b/net/can/raw.c > @@ -431,6 +431,13 @@ static int raw_release(struct socket *sock) >      if (ro->count > 1) >          kfree(ro->filter); > > +    /* > +     * Wait for any in-flight raw_rcv() calls to finish before freeing > +     * ro->uniq.  can_rx_unregister() scheduled deletion via call_rcu(), > +     * but RCU readers (raw_rcv in softirq) may still be active. > +     */ > +    synchronize_rcu(); > + >      ro->ifindex = 0; >      ro->bound = 0; >      ro->dev = NULL; > > > Can you tell why you preferred the destructor solution now? Thank you :) I preferred the destructor solution as it seemed to match the socket lifetime model better and I wasn't sure if the blocking sync in the raw_release() was too heavy-handed for this specific issue, given raw_release() already holds rtnl_lock() and lock_sock(sk). That said, I'm happy to defer to your experience if the sync fix is better suited, I have tested both of them. > And if I see it correctly the UAF problem might also show up with the > kfree(ro->filter) statement we can see at the beginning of the above patch. > > So either free_percpu(ro->uniq) and kfree(ro->filter) should be handled after the finalized synchronize_rcu() process, right? ro->filter isn't accessed in the racey raw_rcv() path as far as I can tell, and I don't *think* there are other racey paths but it wouldn't hurt to handle it just in-case. I think this would be simple with the synchronize_rcu() patch, as you mentioned, but I'm not sure with the destructor. Kind Regards, Sam