From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f45.google.com (mail-dl1-f45.google.com [74.125.82.45]) (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 31BFF250C06 for ; Sun, 11 Jan 2026 20:24:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768163065; cv=none; b=T9byyAmCwgz7NbjKAEsIcbHpGHAyu/ZEO3EV5rlxT9iZrFUm6kVe5OFqY9hBhdaQKHejKGNLEJchLoySPM1uLR9Ip1A3YibXg3uHLvsC4BcCSg6+kM4RAv0UAZz1KgZDYozuhIOuICa0TxHIaFSFftLTl6JFrNRbjeJp+1Ppgxo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768163065; c=relaxed/simple; bh=deIbbfF3aE6NEGow9ffRJxFX9y3yO1u7y4vot9gCTNM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hvzmJrjSKCWS7lJGQUFyR+ZUQc3fHPpo42O6Ee3nU+HUvf94rsCMcN6aEezbmkFNkMy6/O7UrjmeOR0/tB45E7X4TsdZyQ6P9otBaaAc4H6f1snnLEYqtiMN+04Zpek58IgnUbj08wo/MBKKwwfTYBov2I65CPZxD6P/ftfiJ18= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HE1jDNj/; arc=none smtp.client-ip=74.125.82.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HE1jDNj/" Received: by mail-dl1-f45.google.com with SMTP id a92af1059eb24-11f42e97340so5195637c88.0 for ; Sun, 11 Jan 2026 12:24:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768163063; x=1768767863; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=+LlzxQrvrypvBifS3gj3xyozetYMJTVLlEycrj5WMGs=; b=HE1jDNj/Lw1KeGB04EL4YObjLehjmWyjPk8mrTuwomxmidWvwRSmBSYERZRCOkz/90 pCSV45YJcFhZ4Y797zGomK28qF5X3aaERweEaH88Bd0WiIHSDB7orr9GFuo/CkDKJw25 7U06J8DIpwxIrFnKm7KTBOjBDV5JakRexEWdyA+g5zMR2vIxt3hDcrVJ7FJC1I3HM/Q+ 167+hk7vBEO+RvWUGF41QoT6hcofveWUKxnU1N3DdpOa0f2rqBUrA+IxB+Kl2QJuA/00 5jYosY7C07AxGoGHhMoqJBm/pWRsdVLtCRvt6WcbKE7m6g2aZQa0m3J+UqRFldtpYHjn 3FZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768163063; x=1768767863; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+LlzxQrvrypvBifS3gj3xyozetYMJTVLlEycrj5WMGs=; b=Uj9cX0F0pRJrs91TZn7L5THoSYCZJYxOpr6FRHsl7tSa9md/lXh5np1MuI1zGS2k0Q bkXcKb0e6YnET5GynrVQTgV436Q6RpIgcdaribMD+7sgX0s4i33zpqlgBpWXVj7qUZAb G+NDOMoKrachvYp3OE4MmgmaFlcHl0BCiyg2oSejyDp4U7j2YiyWdn090V9pBYD2vwxN ruCoP1EiK3U5QmWSicLjWCGdNsAiJyQOkbG33jwfpfdPy/F+C84xTQw86i7xlt3qDM1i MSJhLg+5+38RCOeobZvOLEbTZKatnRLoWrtbt9rc1+0Cbdw5tN0zPjVfAYfzxGnChqaF 5zrQ== X-Forwarded-Encrypted: i=1; AJvYcCVSuwprKycB8PnygVMjFstHnl8TPbDTO8BLvFOgu632hgHuTrT9VC8ix4EtAPrLKiVp1k4KnGbL1WYPbKM=@vger.kernel.org X-Gm-Message-State: AOJu0Yzrxmh7vZ/VwPnwyGsiebLTxiuMfQ63f7eQlxDIkH95+nIYAMyk rEpReK0uXfRPKHtpBtmqAQMCq1RDgeqvJDxovV1wodFkQVDSZIpl5x0= X-Gm-Gg: AY/fxX5UDb2NxKG1DxPJAkyxe4i8f3IS8v2NpZaLtnD0HdJnIyRTL0TpK/JybQXKrBG 79wLtqABvSB2Eg3qQImQErzCf++Bt/S6pgy4uyfGPXeNGQD0DGMchnW7CexSR7EaG7c1+WTmTsm tqAzOdjK6HOyP+f8S9v+vFXXLnPX35Hw/Dk2pUT6iMGKE4+aJFBAuSWbCslxlFdUcQYsRcDhsqU l0y4chylCky3ij2exQWGWJGgBVmks7UKAYHqSjF8FB8ppB6CSifM82JNfF9Z+o9UVBybKd9efVp UJ2Zj+rDTMmPw8JilvntJV2u3/EtlZ1/oTmKPK1UMziWXB428RWqnXcB/QdLzU0fHA4BllUrVK7 Kmm34y2T5hVevvtGERArkLKEHjSiPvCFL+9RHVVFR7KXh4nJ0QlmhWmTLYQSY9Wk1btZOn9mIfx RHRbOZyyIyXO53Jh5wXDF5DoI4Ds4b9rqqzdswPkG+LZv4axu07J/AxdKC/kB5eHAyrC+La032t w46BQ== X-Google-Smtp-Source: AGHT+IH5t82/4L9yYhR9he01IEguX47jqahDJRJ9kRchowIrWjdKOGkJt8ogG4X/WEXF520AltWuTA== X-Received: by 2002:a05:7022:3708:b0:11a:335d:80d3 with SMTP id a92af1059eb24-121f8afc350mr12072513c88.22.1768163063040; Sun, 11 Jan 2026 12:24:23 -0800 (PST) Received: from localhost (c-76-102-12-149.hsd1.ca.comcast.net. [76.102.12.149]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-121f248c239sm19032604c88.9.2026.01.11.12.24.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jan 2026 12:24:22 -0800 (PST) Date: Sun, 11 Jan 2026 12:24:21 -0800 From: Stanislav Fomichev To: Kery Qi Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, bjorn@kernel.org, hawk@kernel.org, pabeni@redhat.com, magnus.karlsson@intel.com, daniel@iogearbox.net, maciej.fijalkowski@intel.com, kuba@kernel.org, edumazet@google.com, horms@kernel.org, ast@kernel.org, sdf@fomichev.me, john.fastabend@gmail.com Subject: Re: [PATCH bpf] xsk: fix init race causing NPD/UAF in xsk_create() Message-ID: References: <20260109104643.1988-2-qikeyu2017@gmail.com> 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=utf-8 Content-Disposition: inline In-Reply-To: <20260109104643.1988-2-qikeyu2017@gmail.com> On 01/09, Kery Qi wrote: > xsk_init() previously registered the PF_XDP socket family before the > per-net subsystem and other prerequisites (netdevice notifier, caches) > were fully initialized. > > This exposed .create = xsk_create() to user space while per-netns > state (net->xdp.lock/list) was still uninitialized. A task with > CAP_NET_RAW could trigger this during boot/module load by calling > socket(PF_XDP, SOCK_RAW, 0) concurrently with xsk_init(), leading > to a NULL pointer dereference or use-after-free in the list manipulation. > > To fix this, move sock_register() to the end of the initialization > sequence, ensuring that all required kernel structures are ready before > exposing the AF_XDP interface to userspace. > > Accordingly, reorder the error unwind path to ensure proper cleanup > in reverse order of initialization. Also, explicitly add > kmem_cache_destroy() in the error path to prevent leaking > xsk_tx_generic_cache if the registration fails. Is it something that you've hit in real life? xsk_init happens so early during the init process (fs_init) that I don't understand why the oder would matter.