Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1056920lql; Tue, 12 Mar 2024 06:21:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUk7Is5jgbhKcYB8JNezD+llM9K8Bh1KCSW92H4jBKxC3Xaf7+Z0XHaOa13s/udW7fUVF4ZZBKB+QFyh5Dpm7vloGiPUDBkWxsskMemVg== X-Google-Smtp-Source: AGHT+IHIFmyuDGChVNEADwWM/Wu65Zoy4C+CBbkGUbY015v1gCEyiGcbELz+IZnstr97SK7rMfir X-Received: by 2002:a9d:61d5:0:b0:6e5:3103:a948 with SMTP id h21-20020a9d61d5000000b006e53103a948mr88029otk.27.1710249690468; Tue, 12 Mar 2024 06:21:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710249690; cv=pass; d=google.com; s=arc-20160816; b=LpXPicSad1lHFkWg7A8elHmiYLqpit4pWn3Dz36ouy0EoEBj4S5EAW4Akz7fq/6KPl SrBQXWrIv8eIjkdUb8++7XXg9ZPu12EWldhhU1ZNJxAXwuIw4gFx7ZIQVKKSfu2LHseO cMqbieNBDvRE1aZRy/d73CREiNT5pA7ZzJQLAukhkvlA3JNVn+sXYprmROVBfzvGN4+T cPfPKNn9Gplfcqw8+kcp4Hxi4uHjIDN0XP8fsMXgcJpvS3Ye98PXr1nhEwZa7aEcxu2R ymg2wJI2IcEeKUr5q5JaQSl0JVow6FR1uM+Yu6lEVdhOhLcb8p9bnB2CkWOyYzX+Y3uB waLg== 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; bh=t/YV+/uevc81Tne8UD4lad56uTf/yogEaVdvijPPX8U=; fh=2kZG7ca5lykaV+0U9ERbUZAA9KMppqjkNyiM1MAmfRU=; b=GaK5gQHum1yVrtMXieqcS/ogeqSyExF7V2cgwv9Arp3WYJ0owW3NFj/p1NDqT1zQiz ahqel4JpeN1Lf81sVvk+Uin0/nNSREtjd8rJKCmzHAFNrUApU8c3eV0QcDjQQnzJqIbH +1vZGx8sb9B4Br4v+xYsM+pQKk3E4FH9GsKJ1/wWEjMN3G48Bb0EtPNgjpj3ZjDxXSF1 l8FZ2LwodlwB4t/e3bOnbu5B1j45IDouuPDTXhhTFBbGeIbbBKfAFq7mAqiWJFVK+nDn ptagUOgKw+92rOYiHtOHvmtzICdCzpwLH0jjTzb+Q+ksshZZvTjgLMUXf9vAfrEwxrGD GU/Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=strlen.de); spf=pass (google.com: domain of linux-kernel+bounces-100283-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100283-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id t19-20020ac85893000000b0042ef271aa5esi7508677qta.579.2024.03.12.06.21.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 06:21:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-100283-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=strlen.de); spf=pass (google.com: domain of linux-kernel+bounces-100283-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100283-linux.lists.archive=gmail.com@vger.kernel.org" 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 F0FDC1C213F7 for ; Tue, 12 Mar 2024 13:21:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 556F47A704; Tue, 12 Mar 2024 13:21:19 +0000 (UTC) Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [91.216.245.30]) (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 D568978298; Tue, 12 Mar 2024 13:21:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.216.245.30 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710249678; cv=none; b=BE/4ELeI8hoBFILnLYOwIrsMsZVzkJGznBUSS0wPLK28PFG1jxCnLF3S5ISoXHmTi54gSnFTBIMIDbVo5MxZIXP39PTuqXmkfNdcPeu+VS46MDMc2sFERTGx96D2eYZaeW7+mW/1meNuRPcLA+ohO6tAODlf9G7X9df4FyaHE4g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710249678; c=relaxed/simple; bh=tjDje4SaiRrTQc6DecP8S8++V0lhjuccYXfYjHPoXJE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VuyC212idw5D8h1B3UrFb+RQuHz9n4TpiOntvkEivL2GcrxZ20mM7kKKal6cp7my0JNfdkpOrOD9rg6oB8oHWediZ2gDRjxShdBzgayQS+dUw8pRGeq1bzUynXDEoM1SGl6/C/v+jt+7SNYT0PT98xxhCBeyoVqUb4Bx2XLSInk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=strlen.de; spf=pass smtp.mailfrom=strlen.de; arc=none smtp.client-ip=91.216.245.30 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=strlen.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=strlen.de Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1rk243-00010Z-Qy; Tue, 12 Mar 2024 14:21:07 +0100 Date: Tue, 12 Mar 2024 14:21:07 +0100 From: Florian Westphal To: Eric Dumazet Cc: Florian Westphal , xingwei lee , pabeni@redhat.com, davem@davemloft.net, kuba@kernel.org, linux-hams@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, ralf@linux-mips.org, syzkaller-bugs@googlegroups.com, samsun1006219@gmail.com Subject: Re: KASAN: slab-use-after-free Read in ip_finish_output Message-ID: <20240312132107.GA1529@breakpoint.cc> References: <20240306103632.GC4420@breakpoint.cc> 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.10.1 (2018-07-13) Eric Dumazet wrote: > > so skb->sk gets propagated down to __ip_finish_output(), long > > after connrack defrag has called skb_orphan(). > > > > No idea yet how to fix it, > > My plan was to refine "inet: frag: Always orphan skbs inside > ip_defrag()" and only do the skb_orphan() > for skb added to a frag_list. > > The head skb would keep a reference to the socket. I tried to follow this but its beyond my abilities. Defrag messes with skb->truesize, and I do not know how to fix that up safely so later calls to destructor won't underflow sk accouting. Furthermore, depending on delivery order, the skb that gets passed to rest of stack might not be the head skb (the one with full l4 header and sk reference), its always the last one that arrived. Existing code skb_morphs() this, see inet_frag_reasm_prepare() and also the ->truesize munging (which is fine only because all skbs are orphans...). So in order to not pass already-released sk to inet output somehow the skb->sk reference needs to be stolen and moved from one sk to another. No idea how to do this, let alone do regression testing for this. see e.g. 48cac18ecf1de82f76259a54402c3adb7839ad01 which added unconditional orphaning in ipv6 netfilter defrag. ATM the only "solution" I see is to completely remove netfilter defrag support for outgoing packets.