From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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 B31E6329C48 for ; Fri, 13 Feb 2026 10:21:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770978115; cv=none; b=IhjPgsRH2l4lSTOLy5ub7x7pjK4WMecCBBYTJBlrq7u9sQD90Q54OqGeAPSub+cgohpMoj1Vi3y3FOOAcVmcnc6Bf4ao1YZVuQaVXPoY9mFfH0feCru6QdKav5Jo7m4i8j5EeAmxuHQ21zJZySrKDOxf/47URoMHuV4bgXnhJPo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770978115; c=relaxed/simple; bh=So9xWeFEUrm58wRB5ilqa33PpLzyw90FIza6V2SASy8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JG/mgrywvJQ0kYU90Yr+RgMmGN7i/jEZA12q7SOVOD/bSNtCajJvrb0k33vtztbJLgogHbjkaWSUpSyHpLKYKWNr0+x/IuU4AVSxCEygz8Xo06lLPXNrbOW5Ue6r0ZBC31wJ/E045nkqzrXzJUNvLvi4rbDCOz2K86H495U0pW0= 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=FMdr5p8Q; arc=none smtp.client-ip=209.85.128.51 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="FMdr5p8Q" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4806e0f6b69so5878575e9.3 for ; Fri, 13 Feb 2026 02:21:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770978113; x=1771582913; 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=zin/vneRUguhBG4fcbrCXY8+exjw7aASRCjjvjBSKHw=; b=FMdr5p8QGyPvmmg/yxe8o2d4vfqxtKGnZZ5T7wAaR1z0Ixhrzv/wLQuASUONP1UXoF O3HZwuYNEvAK34kFVvIGlAFMsfNGYUFshDtN/27TuH0txdOvJIMj/LLSRfoiaA+UYUmM asCezMH347OGH+2lnmboaI8vIUMETw11aH+z1UDJ0EoabMHL79bTkqoWj3GVSX5cvH62 eoE4fiOY6bXL3BiVVmlkdfBl1ZZQTtNuwQVdQHRwmdE0uoLYZdihoUEsUfu5rjs+dG43 d0RvYjGvoWGeE9nxInY2yrW7GuSragLdFbe3Q55nSVi8P19XYTZi2Soa9GjQ5G1Y/Wzk NqmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770978113; x=1771582913; 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=zin/vneRUguhBG4fcbrCXY8+exjw7aASRCjjvjBSKHw=; b=sPEEtNEoHoEbkOvOoSb2qZUPqgXwL4tE4zZFP0zeEyEzYZXxNWzC/xSGYOgv9WnMlQ tmNvbaT5J5P322+bUG7BiXa15AT69nUa/aPN+KbJEGCMOlYrI9NS1ddOw25lNNMPPgUY Fe5JGOdNZjOrGx6b+TPYW0Ghv8ODFIEUZ98HU6FGj+t8y1VFOg/L/+B9oshA5byeyJ2X yCG1LFdfd2bkM5Qb/4JjVexC55eRYNPiMTb2RoLxVjAam9x8lbUl7CFqplwQmV3+tSgd mY1IKZP6sfwgKFDz1h4I1EwP1uzB74rP53AxeaJss/jcceFOLT6KwPJv5BwYvwnQDGLF tM+g== X-Forwarded-Encrypted: i=1; AJvYcCWBy6ld/S4wWaDEMBeQC5h6kIFrje3EqdRnPUjYu6SUJpJuYOSTuuht4rWAQO2v3UERlyy1gu9kyyxZc3I=@vger.kernel.org X-Gm-Message-State: AOJu0YyvxzARnMU551Th/RCvKF+0mXfkuAuuxv9LnjP8wzf7Vy8Kvi29 e92Iwo7zYT8Dnq+LyeHxzD7XZz14GkdH5anpp9Fct6VObDrx4XzuxluV X-Gm-Gg: AZuq6aK5dWdoScDwmoTwvDT5OQk7763T6F8IMI+bgLjPtUCqKTaaTJ/KafzO5KUQ7BH DsJJT/UIayNZITuLQTGcjXdEh3JuueYvBTNekOw5KNr2j7b54EADhpcbAmOtUo1BkpGZdPCzRwt YduBwcxcCyvq2b8ajOTc6FPsTfkt9zoQNTjjlvb20hK0S2IoJkUXjVFhRb0YEwdrDEbVfoLVRQN Lde5XcuPYe+dNySPZ1lVcB16FwdjofaADO5T86Tt4vLZEPVU4owTcLjGBsrTv0/78y6UD50C9Zx EPuIGnkJbO4F3h720LuOIK8n9IZNAKAuILCSIbke9mrL1dJEbmcgMukisiD56WSYqNUq57fYFPX beJoysHHKRgB14V+3UspFw2pmy6jcfHGtq1JihHfgINoq/DzF4JVSn3GYdyhE472YdfmD8yKOUJ cDaLuexlZmQJCesiCbHSZzUgMSoKAtGIQeGOc2T63rnu0= X-Received: by 2002:a05:600c:474e:b0:479:3a86:dc1f with SMTP id 5b1f17b1804b1-4837109740amr34875915e9.37.1770978112880; Fri, 13 Feb 2026 02:21:52 -0800 (PST) Received: from mail.gmail.com ([2a04:ee41:4:b2de:1ac0:4dff:fe0f:3782]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4834d5e11f5sm243862745e9.4.2026.02.13.02.21.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Feb 2026 02:21:52 -0800 (PST) Date: Fri, 13 Feb 2026 10:29:57 +0000 From: Anton Protopopov To: Dan Carpenter Cc: bpf@vger.kernel.org, linux-kernel Subject: Re: [bug report] bpf: Fix a potential use-after-free of BTF object Message-ID: References: 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: On 26/02/13 08:56AM, Dan Carpenter wrote: > [ Smatch checking is paused while we raise funding. #SadFace > https://lore.kernel.org/all/aTaiGSbWZ9DJaGo7@stanley.mountain/ -dan ] > > Hello Anton Protopopov, > > Commit c81e4322acf0 ("bpf: Fix a potential use-after-free of BTF > object") from Feb 9, 2026 (linux-next), leads to the following Smatch > static checker warning: > > kernel/bpf/verifier.c:25375 add_fd_from_fd_array() > warn: double fget(): 'fd' > > kernel/bpf/verifier.c > 25360 static int add_fd_from_fd_array(struct bpf_verifier_env *env, int fd) > 25361 { > 25362 struct bpf_map *map; > 25363 struct btf *btf; > 25364 CLASS(fd, f)(fd); > > This assigns f = fdget(fd); > > 25365 int err; > 25366 > 25367 map = __bpf_map_get(f); > 25368 if (!IS_ERR(map)) { > 25369 err = __add_used_map(env, map); > 25370 if (err < 0) > 25371 return err; > 25372 return 0; > 25373 } > 25374 > --> 25375 btf = btf_get_by_fd(fd); > ^^ > This re-uses the fd. The reason behind the warning is that the user > could have changed the fd to point to a different file from the > start of the function. True, this could happen. Not sure this is a real problem (if a user replaced this by a valid BTF, well...) > 25376 if (!IS_ERR(btf)) > 25377 return __add_used_btf(env, btf); The problem with this piece of code is that originally I wanted to keep naming/appearance in sync, but the corresponding map/btf functions, historically, behave a bit different... To keep things working and to address the bug report in this thread, one fix is required: - btf = btf_get_by_fd(fd); - if (!IS_ERR(btf)) + btf = __btf_get_by_fd(f); + if (!IS_ERR(btf)) { + btf_get(btf); return __add_used_btf(env, btf); + } I will send this fix later. > 25379 verbose(env, "fd %d is not pointing to valid bpf_map or btf\n", fd); > 25380 return PTR_ERR(map); > 25381 } > > regards, > dan carpenter