Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1379193lqm; Thu, 2 May 2024 12:56:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUE5kze0BN5m/lZhkYD8DJ0F2p2cbNOmYGRLpAA1cJeJ1j6CWPNbXwB8k0IHpAjOogJK/7KJLq628IiAdHgSCXak+7XSB2fpdtkOGq9QA== X-Google-Smtp-Source: AGHT+IGCHHIqZjU3QJWLNLG0L2CtJcRh4IXOMWEbxd9E6uzkct94zP+IYKs/HxQ5flFuCoY+qmBc X-Received: by 2002:a05:6808:1524:b0:3c8:643b:7ebe with SMTP id u36-20020a056808152400b003c8643b7ebemr1147064oiw.52.1714679800555; Thu, 02 May 2024 12:56:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714679800; cv=pass; d=google.com; s=arc-20160816; b=jtc7rg7M07KWnK0va8K+wdSXj3Eb2u8Pcdn/5SMHLgwXgak1Vi26NJz0cR2+ggUfip qI1TCYRSU3tKjq5PCPEwmeViH3Un/23Du6J15NPl2IJ9vF8hmDaIVZzi38VpPZKWDK43 AqG8rZ/W9ELfZdDSLKXjMnvpfllzYbN1MSICRzRhO6afUUASyK8slNF/JNngoqFgVoU0 6YTCUMag+d83Q74+TTHrPsVViXac/Hwaz05YiGdD4PRQ2Bn5hKAgkTWNTuTXUf1ET1DA IG1YJrqqh4z+CXO6mi4Q4AyMazj3ATt+ouPrHtcRfWkP8isGGIQHiWXzze16wAjgXrO8 yUtw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=arPW5gD6qYspv+Dw5+o0jCoBQCRjes6FUELPaGgl7+A=; fh=xbjfqPMszNynGJbXcv7MJ0RumrvA+F670E5tceo3zRw=; b=M3MVtMxAG+HbdB380Chc3vrb+iqrT/SbsEKQCMEKE5VIAmbvsHa+2k07w62h8lXvmW X50J+o5xnT4v9PEbjIqNCH6wIfANU1ufU3mvcPcVjwN5B2s12biWQD6pTtAlVt53VQh+ mY7W3lOgS23a4boGD2VWnMDymvMnFf48xhgdWm8CBbCYtEVLigzc5WjEdLeTSmJSDrzf 1/paqSXiPj661nQBO+KnmX7emwrYZMqwtfnl6kmrHllB8TMZdii0erATUtjOACOqMdS5 uqss/6SEM8bJNfuC6ToxQkOLd0NjzSVfqDSxs4roy8ex7G4bQwFdNjuq7w+LsJkshUpJ WPSA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B9rGy0fe; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-166871-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166871-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 hf2-20020a0562140e8200b0069b46024c8fsi1628204qvb.410.2024.05.02.12.56.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 12:56:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-166871-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; dkim=pass header.i=@linaro.org header.s=google header.b=B9rGy0fe; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-166871-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166871-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 EE3F21C212A3 for ; Thu, 2 May 2024 19:56:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 808AF1802C4; Thu, 2 May 2024 19:56:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="B9rGy0fe" 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 04E7C42AB6 for ; Thu, 2 May 2024 19:56:31 +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=1714679793; cv=none; b=K36zQDg3SuciHTdvB7rz3gcCeNXVXjkMqkiEUFGiBJ/2XW7lRN9TRm5RiLNqxnuxBaqF1ZYPYiO9/myzzhO8QThxRvNKA7TNeIybYtVLzAwpORoDgM5+bTmBRUbvx6lNEp2TsBjLMS3SGMQkLSEIVuJyJWM8TdvzeaNTZrEz+Rc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714679793; c=relaxed/simple; bh=NXC4ddXI6s466s+yE7pFTmOsbcHy1eK9kBtpIaQqUHY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Hg/8JkQT6EHIOPfTAhiM/swVhPz5ChLrG4tG90dJtgVszQfrD7B7/bpieoQQGs2Ppy+pxVq//VJNEGyXIRgm8fu0Iv9A2tILTLFyUsDEm+arLmc5sNdn8zOT49Q5JeuLdeIdNUBPlt575zOg3uu6Hc5gxbTjvxd+3s2V3JHnObA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=B9rGy0fe; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-41b869326daso47827095e9.0 for ; Thu, 02 May 2024 12:56:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714679790; x=1715284590; 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=arPW5gD6qYspv+Dw5+o0jCoBQCRjes6FUELPaGgl7+A=; b=B9rGy0feAhBCu/pR/uviC95h0BeUzl38dN/AGq9uaYj6tsdmGYJOIUgjUimWm3KsF7 mzfGWe505YbIONsIRdlsViwFJFWHjTHOaN4jD4/0Qc6lB/TM8jH4AWsxI06wrXrnW8bC Yem/Pn+pUbsg7sUcRpokrk9LMn8YpqQNsfsk2xkjD4GgKYiui1+7bCPrQEQ54da0s/MT /WciwEkeBPuGqZ7uCG+ue6P6TwhyVXmSxaflsBt58q9xgY/xSp61hThRzzdQJ/UMWdkO 5krAL8IFixUcM0V1G/ovjrsybo9/xltkipaQr43hxh2bacwupxltyuoaalA8ispToCzJ 0m+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714679790; x=1715284590; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=arPW5gD6qYspv+Dw5+o0jCoBQCRjes6FUELPaGgl7+A=; b=RoyzxNbAZ8aRBTLAGF41Zv95rQZNwAWvEJ8948OJDEesqrxYPiCY2eBRZwl4ZeFNxs Rouc23BjYOLic+FZ9UXw1iskOGWvL+DCLqA2YI2Iz3oqcWYLdvu2+7HvSW4m2K4dr0W6 wFY5CCc/muDF/B/Lm5EL34q7mO7Qqb32I9WpjRcSlChd40mYBgdlNpy/OlWGlw63dDnS TfG37WMZzcYU77a/TlcL0KHq6h9Er+Ecorcr0B89YC9jUfXEe3NadmKH4eQLvYiwflLi ZjSXxY6IEhR39xY55W5pVRhjbhBEKpROpZ3NNWo2XtKnw2Zc7RxtU+He3Y+orrCPOcd9 APAg== X-Forwarded-Encrypted: i=1; AJvYcCVEwUsT5ylwbBKdtmpGPJ8DSYJVelsvvMh6iE5UohuoKD23fNotnESOVQ1TUWJauGyFmrIzVuxSwj0IWT3x9fNGdaTp+081D05UvHTe X-Gm-Message-State: AOJu0YwTV7cGThI79W192wLGt9gqxvWX466WHyWycIE2pFnSkQvQBVTO cVGzt40Vh2r9339NlBZwtwNGwTru0ZUZYYfTfyNu1HTtK4J9XS1ii6bqs0cJu/w= X-Received: by 2002:a05:600c:1d8c:b0:41a:908c:b841 with SMTP id p12-20020a05600c1d8c00b0041a908cb841mr532673wms.32.1714679790129; Thu, 02 May 2024 12:56:30 -0700 (PDT) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id s20-20020a05600c45d400b0041bde8ddce9sm6741202wmo.36.2024.05.02.12.56.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 12:56:29 -0700 (PDT) Date: Thu, 2 May 2024 22:56:25 +0300 From: Dan Carpenter To: Duoming Zhou Cc: linux-hams@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, jreuter@yaina.de, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, Lars Kellogg-Stedman Subject: Re: [PATCH net 2/2] ax25: fix potential reference counting leak in ax25_addr_ax25dev 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 Thu, May 02, 2024 at 10:43:38PM +0800, Duoming Zhou wrote: > The reference counting of ax25_dev potentially increase more > than once in ax25_addr_ax25dev(), which will cause memory leak. > > In order to fix the above issue, only increase the reference > counting of ax25_dev once, when the res is not null. > > Fixes: d01ffb9eee4a ("ax25: add refcount in ax25_dev to avoid UAF bugs") > Reported-by: Dan Carpenter > Signed-off-by: Duoming Zhou > --- > net/ax25/ax25_dev.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/net/ax25/ax25_dev.c b/net/ax25/ax25_dev.c > index 07723095c60..945af92a7b6 100644 > --- a/net/ax25/ax25_dev.c > +++ b/net/ax25/ax25_dev.c > @@ -37,8 +37,9 @@ ax25_dev *ax25_addr_ax25dev(ax25_address *addr) > for (ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next) > if (ax25cmp(addr, (const ax25_address *)ax25_dev->dev->dev_addr) == 0) { > res = ax25_dev; > - ax25_dev_hold(ax25_dev); > } > + if (res) > + ax25_dev_hold(ax25_dev); ^^^^^^^^ It should be ax25_dev_hold(res); This is the NULL dereference that Lars saw. Thanks for testing, by the way Lars. regards, dan carpenter