Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5551040pxj; Wed, 26 May 2021 13:20:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2/vqF1xaWIRpwO0qjLwTgd3npkNdu33CpT4Kw8iKXnO9y14RpWaNEnsyvwI7AemyDtIwb X-Received: by 2002:a05:6402:3511:: with SMTP id b17mr31323edd.71.1622060439471; Wed, 26 May 2021 13:20:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622060439; cv=none; d=google.com; s=arc-20160816; b=N70SupPl4wZCq4gXRwHVskGoan5mEJgt45HyhCPFJ5GAFZGEKrvfdc/0+Ynw5AdVHY V1TD9YR9bGERsV1jNutPV7rD9SGleNk+sjR3Kax9X1Dt+PLs1yr37OC7Tr7T4SYs3IYX u1gKKvKtNaUK9/nJdqDVMJ7hegywhlkJsdThm8MagZz7+1vI3wlQ08WMlUezqWjdxGGu /fKcmvSYsPWgNL834jdpsxbja+y5Ilsz/Wwi7Evjx77VMP6XBt3r5jPxLNfwyixiZAXP hA4mA/pAn8HjVUAH4Zas0hwI3ZozBlYkQ1KXY5zpDFEEjJoXESTSvkiUK/aM39tpwRD6 4Yng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=r8U8l4dAq7fCVZLWXnTICF3fjtWAoL6xPRh5BeEIsGo=; b=pjfZ8GGknbfFFPKBqREy2hA79thfvx7Y7n+mdlc+9rKRmhjjkM47IeY954OxCoTVzF iOtLAyp0JYVX07z68lNOjwP1zzN32+y8QCNCboO9CpK8QbeJxP0Lm9m4w8RBiOTPAkZ5 GLgGjbgdN7HD/ODf9J5RRNwLrWI3B0TXKZW4mWSf2T2Gs0KQ8Fnmcy4xwDNoXPXphDrE 9DcxfGs0M6mNZHVLI18+1LeU7WvqK6jBeZsuZ9jgZ8n9RC0Mh8gollyqNR8Crn4DG+mx akksUNE4g+UtTmKBK3Emp+wguGE95MMvZkap/CyYzH2G5DLrhrhI/xZod6FlV8gEgvph eqlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KGGVhNuD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ce5si370572edb.102.2021.05.26.13.20.09; Wed, 26 May 2021 13:20:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KGGVhNuD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234180AbhEZSwQ (ORCPT + 99 others); Wed, 26 May 2021 14:52:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53734 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233416AbhEZSwP (ORCPT ); Wed, 26 May 2021 14:52:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622055043; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=r8U8l4dAq7fCVZLWXnTICF3fjtWAoL6xPRh5BeEIsGo=; b=KGGVhNuDpGN9uUoZr5w2014IaxcZBiR9rGv73b43NvTlC6+45mM0LbVXCLhXjN0IqMX15r /UttM5frgytZT9QEZSx7A4s5j0Fc9eS1MFsJcNGLTN0zm+XxFR8HpiOS1b1gh5F/g56juY /aJqS7kOxJ2Q3sjarh6SVryow46/DJA= Received: from mail-il1-f199.google.com (mail-il1-f199.google.com [209.85.166.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-595-RlPJoEMdOR2e_8PWwz5pKw-1; Wed, 26 May 2021 14:50:41 -0400 X-MC-Unique: RlPJoEMdOR2e_8PWwz5pKw-1 Received: by mail-il1-f199.google.com with SMTP id 15-20020a920d0f0000b02901c54acae19eso1465183iln.23 for ; Wed, 26 May 2021 11:50:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=r8U8l4dAq7fCVZLWXnTICF3fjtWAoL6xPRh5BeEIsGo=; b=mQUgXAMRxWtuRC9w4gy1J9QcEeHzuOAyYG+obPsGq1aAB6MtE1oUjltxsCx2OTZfME GgdWL5YeNmhea672FZO7uw+hqWCoSLdIGvW1RXcf2AhOBaZSYFjAZCWJ5pxxhCXHrRS5 J/aDO8ZIZ56p60xSx841W+G7Q+AtmyNtQDVbbHNsXd/rk5Kfer6+v+h5D/25ycEHqT+e 70VefWg8kf0LgJvrq1otvLi93PRCUdoE8kX/HmttBFs1o+ky0nkF3/twuDxaegIehhmJ LSHzVjtdswuycpnmV3eHSxgJ5EbWAvPibvWS83YphlotiRvSvZXYoYjjhAtnSbtfX/rs GTIQ== X-Gm-Message-State: AOAM53189q35DXaeFgV11CXYIASWXQqSTTWFEH3pv9Cp6hNfWjVkRoYS NeBE8+YIJ5YgOgXbBDhF2gOKSEVw+rjyfHIopnbNUFstTu+u/Ybjhlr8UVD2U/dkUcWycFm86om fhPw/fbCoCdNygeLpBtY7oOGwwjBUOFoT8JrUZYCg X-Received: by 2002:a05:6e02:1d0b:: with SMTP id i11mr24946564ila.36.1622055040508; Wed, 26 May 2021 11:50:40 -0700 (PDT) X-Received: by 2002:a05:6e02:1d0b:: with SMTP id i11mr24946549ila.36.1622055040300; Wed, 26 May 2021 11:50:40 -0700 (PDT) MIME-Version: 1.0 References: <20210526134039.3448305-1-colin.king@canonical.com> <20210526150133.GQ1955@kadam> <20210526181726.GJ24442@kadam> In-Reply-To: <20210526181726.GJ24442@kadam> From: Alexander Ahring Oder Aring Date: Wed, 26 May 2021 14:50:29 -0400 Message-ID: Subject: Re: [PATCH][next] fs: dlm: Fix memory leak of object mh To: Dan Carpenter Cc: Colin Ian King , Christine Caulfield , David Teigland , cluster-devel@redhat.com, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Wed, May 26, 2021 at 2:24 PM Dan Carpenter wrote: > > On Wed, May 26, 2021 at 04:11:06PM +0100, Colin Ian King wrote: > > On 26/05/2021 16:01, Dan Carpenter wrote: > > > On Wed, May 26, 2021 at 02:40:39PM +0100, Colin King wrote: > > >> From: Colin Ian King > > >> > > >> There is an error return path that is not kfree'ing mh after > > >> it has been successfully allocates. Fix this by free'ing it. > > >> > > >> Addresses-Coverity: ("Resource leak") > > >> Fixes: a070a91cf140 ("fs: dlm: add more midcomms hooks") > > >> Signed-off-by: Colin Ian King > > >> --- > > >> fs/dlm/rcom.c | 1 + > > >> 1 file changed, 1 insertion(+) > > >> > > >> diff --git a/fs/dlm/rcom.c b/fs/dlm/rcom.c > > >> index 085f21966c72..19298edc1573 100644 > > >> --- a/fs/dlm/rcom.c > > >> +++ b/fs/dlm/rcom.c > > >> @@ -393,6 +393,7 @@ static void receive_rcom_lookup(struct dlm_ls *ls, struct dlm_rcom *rc_in) > > >> if (rc_in->rc_id == 0xFFFFFFFF) { > > >> log_error(ls, "receive_rcom_lookup dump from %d", nodeid); > > >> dlm_dump_rsb_name(ls, rc_in->rc_buf, len); > > >> + kfree(mh); > > > > > > Am I looking at the same code as you? (I often am not able to review > > > your patches because you're doing development on stuff that hasn't hit > > > linux-next). Anyway, to me this doesn't seem like the correct fix at > > > all. There are some other things to free and the "mh" pointer is on > > > a bunch of lists so it leads to use after frees. > ^^^^^^^^^^^^^^ > This is sort of impossible, of course, because the struct only has one > list_head so it can only be in one list and not a "bunch of lists". > It is a bunch of lists because mh_handle holds pointers with ref counters to other structures which are part of lists. :) There is a list_del() only if hits zero. > The dlm code seems to be going out of its way to use void pointers and > that makes it difficult to parse with Smatch. > That has been changed on dlm/next. There exists a struct mh_handle * and a dlm_msg * to get rid of void * handles. > But in other subsystems, we could make it a rule that list_heads are > "poison" "init" or "added". If you freed a memory with an "added" > list_head then print a warning. Or if you added a list_head but it was > already in the added state then print a warning. Another idea is that > if you freed a struct mh before the mh->page allocation was freed then > print a warning about the leak. This one is probably more prone to > false positives but there might be workarounds for those. #IdeasToImplement > Currently if a buffer is allocated it is not possible to free it again. The allocated buffer of the page will be transmitted (kernel_sendpage()) out in a contiguous way. If somebody wants to release memory the page buffer needs to be reordered and it can only be done before commit(). - Alex