Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp290878pxf; Thu, 1 Apr 2021 00:57:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkvRXBHxLppVG/Yujz+ydEt8D9LTgB8f6mMPqJUBK2yftFpGT6KicHC9qfC/+A4HlKPXZT X-Received: by 2002:a17:906:1b42:: with SMTP id p2mr7902018ejg.236.1617263825707; Thu, 01 Apr 2021 00:57:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617263825; cv=none; d=google.com; s=arc-20160816; b=QbtjA04zFS6nEJOG57pP+ODPIGSz1feaTV7rGCNiSRiRn0BYcZMXaU8aEM9oj4qA/j Qv4tEa5HAJVBE9ZBYlsYHw6QEzFy8woYhi4W9dzlO4h4M8dvr57pxp+Lvo+o4C8SI4Au 7f89/K9jtF30dxBkSYZmAt3luCTXpM1s71SIt615MvTWXllnGpO97lQUW6MhRwim4wZT jrSVYtcuT3NEkFPesWqR80BFkCLwn79GYLCOdmmY68XMy0FCeZ39tU/1F1kGXcQ11CY0 QE5C/PlKx68nhCjtLiehbwgMiE2r03F7O7pKKo+d8QoqhkpoEseRoBPvZ66zgV+alW7O xh/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=7AcUn3xoZZEmyhZhPx7msf+G6yuROMfX+4IPdOsLIXM=; b=j9Q/0TsgfO4O1kXVGgrJMb7Uaa6+O90+TzjtGjdD4Hril2ahiPXQxnSsd0/V+UYoOw krBKAg9V1NxMQdRRGrJ/qlS2nIihTuPF32S64Brl7ADSpwFhBVf988J2fiAiYJiGotut S6A14YQvYGNSiu2U6O5FlLGWkaey2WrNhXi8NC5eRMjqTFS1bu1eXcC0eZkpdCpJuWGa MheiybH99/aYuZYdAjZwjWJXBBPhHeLZ7VBemgODRwcFUhPzS6bMXA5vqjLWLjv9ZgOE +n1xuNDIYkAYHAyoZ25wguL5IW2aj4SxDAp5A/zncgk2TZViqI42715qsQCjPAgReLT9 9frg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RxBg1fbv; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c8si3721233edw.367.2021.04.01.00.56.43; Thu, 01 Apr 2021 00:57:05 -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=@gmail.com header.s=20161025 header.b=RxBg1fbv; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233080AbhDAHzp (ORCPT + 99 others); Thu, 1 Apr 2021 03:55:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230291AbhDAHzi (ORCPT ); Thu, 1 Apr 2021 03:55:38 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E259C0613E6; Thu, 1 Apr 2021 00:55:38 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id x7so815031wrw.10; Thu, 01 Apr 2021 00:55:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=7AcUn3xoZZEmyhZhPx7msf+G6yuROMfX+4IPdOsLIXM=; b=RxBg1fbvLeuXaeUg1huVHZRHjz94Qh4n1oGBKmxL3+O4hVrFP/QZLEaMJJtuWx5peS C86Gs4KAR3AfFUhlo7TnuBHygbYOqQ2EDFgJt5/nmAvu+X4bEo8ZUYGJQHHMtrA3IbbA J98bVLid0BscpINMXFNQpNfwU7ZJqwwFjbBhUOFO1zuHN9oHEq67r+k/SdwqR4InY+AZ CEQDNg3cd2ogv18xq1wlEKEfaGjVOjSSCSS11huLMiiK3bw/EViUa0lbKc7uoUxPkGcf qt0hfVYh1ZT4DWuTe/NXQ3/xmJSRu8axOwQZl3xATHkgT8mrXxgvDwvry6acqY/gcwl2 uP9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=7AcUn3xoZZEmyhZhPx7msf+G6yuROMfX+4IPdOsLIXM=; b=IT4Qj2N6DFfR6kGIp6SRpgKtHmnfcZuPXZYmbJc6V/hrNf0K1Y2oAohG/neJ1LSARn MENpcJKyIC5tpcTYqnQ5LI+s9YraGs17oXzZYBWENrO3N6q3gKgkC9cHpjO2mnlw+Qvp MgCEyV0uhu8RHKkPBelcxx2HeMx/d1VitaO+vpBbykrJdE+nYpXJGCwwZyCgdb6Xzg5k sP3HZqmmdrZC+M8/Sx7BCQl0Ab2TrKzNyzs38UmX3Jn73xRypAP5KfWPO5YMCArYc0S0 DOBv+oLFnWprQN4TxCEEYbwZd+4Yf544PpqvTZAHHMmuBrb9URFKhyNGIU8STstSpjQ4 YPsg== X-Gm-Message-State: AOAM530j0hlzbUfBL059k5d+mBkGVIurr+fiTrad3i+i2ZNg3gJHha47 ctG4Rx8wKQ0RID2E4berY/s= X-Received: by 2002:a5d:6945:: with SMTP id r5mr7936051wrw.367.1617263737158; Thu, 01 Apr 2021 00:55:37 -0700 (PDT) Received: from LEGION ([39.46.7.73]) by smtp.gmail.com with ESMTPSA id j136sm7565881wmj.35.2021.04.01.00.55.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Apr 2021 00:55:36 -0700 (PDT) Date: Thu, 1 Apr 2021 12:55:31 +0500 From: Muhammad Usama Anjum To: Namjae Jeon , Sergey Senozhatsky , Steve French , Hyunchul Lee , "open list:COMMON INTERNET FILE SYSTEM SERVER (CIFSD)" , "open list:COMMON INTERNET FILE SYSTEM SERVER (CIFSD)" , open list , kernel-janitors@vger.kernel.org, colin.king@canonical.com, dan.carpenter@oracle.com Cc: musamaanjum@gmail.com Subject: [PATCH] cifsd: fix memory leak when loop ends Message-ID: <20210401075531.GA2766105@LEGION> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Memory is being allocated and if veto_list is zero, the loop breaks without cleaning up the allocated memory. In this patch, the length check has been moved before allocation. If loop breaks, the memory isn't allocated in the first place. Thus the memory is being protected from leaking. Signed-off-by: Muhammad Usama Anjum --- fs/cifsd/mgmt/share_config.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/cifsd/mgmt/share_config.c b/fs/cifsd/mgmt/share_config.c index db780febd692..b2bd789af945 100644 --- a/fs/cifsd/mgmt/share_config.c +++ b/fs/cifsd/mgmt/share_config.c @@ -92,14 +92,14 @@ static int parse_veto_list(struct ksmbd_share_config *share, while (veto_list_sz > 0) { struct ksmbd_veto_pattern *p; - p = kzalloc(sizeof(struct ksmbd_veto_pattern), GFP_KERNEL); - if (!p) - return -ENOMEM; - sz = strlen(veto_list); if (!sz) break; + p = kzalloc(sizeof(struct ksmbd_veto_pattern), GFP_KERNEL); + if (!p) + return -ENOMEM; + p->pattern = kstrdup(veto_list, GFP_KERNEL); if (!p->pattern) { ksmbd_free(p); -- 2.25.1