Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp931049lqj; Mon, 3 Jun 2024 05:33:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVBxWAvMB1AjaMGM8D18PfjORu0y1bI55HnnRSc+nQw8YtOTcCiR6WoYlNC2gb6wD1LdHEwvDjDE3Ail5M66fsTzNqlFd9/+P0ay4HCyQ== X-Google-Smtp-Source: AGHT+IG8ILAWpjIWIKDgHHqRgrzks+MpFpGDyf5FuWLpyugA/dFA7XonP9pBxHh0RFdoVdZ2y3Bb X-Received: by 2002:a05:6102:134f:b0:47e:a214:8d02 with SMTP id ada2fe7eead31-48bc1cfbc9cmr8708243137.0.1717418026939; Mon, 03 Jun 2024 05:33:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717418026; cv=pass; d=google.com; s=arc-20160816; b=nUbbm0P6nwDzvb7C2Ly1lJ3L74SZumnpOYN6BcIErS5eyb1V2ps+oCrTHFsVDg/FZv fHu9tr5nOBhr5TRb56MkstrH6Rm96KdFsDBrVD0KORHSTNQ5OlZSbMDG18Z+hcdakrkJ 9u652IcqqMDtAxrKgpMwEeB0fcJo864ZI0VXuv2dA8PTUZijmojZGjxlHSXsk3Ajhjkb OYInUYaUSl4UVMBe/K18CumHS+VDTnOARe0nZPX3VGXtmQqvcJPtn849XEH1NC+MdgeZ PXzH2mDi6hFLSLrIHvnL4hw5P+JmUSC4sVdo/CXwrsmq0WBW0e/epLn7LrrwUmkNaSTm QYpA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=1Ru8Np0KrRH/lYPvykLiPbmxJAWT+d6nNSuG8nv7VOk=; fh=X4DP8auLK+egb4hEa2Ej4FL1E9bN3B3hwI+4DsxRjzw=; b=gFK7yd18h0AN5kEr5gBMkAThwwH//2G4rfTSOrIe+pObLUApWOmC7+jljthwuKL6lG /hQrVKjFaP0OQ0+pU0fwaFzXKY4JlqETr+biygL3tAUZP2Xs0Ntcw0KChTVTdFIaeNhM CbZSPMkR0whbtuwZpO4VS6JBB8LmswKh8GevNG5+tv/2RKwRLY+zfGtKpsVlJUn0QolH MpoKURhMnasz6/7oDP7wERolnQS0DSR4I3+7XO7D17oQJxQYu0wsYNZmkAAvTjVBmyhc y0/oLdUbQ94CSBxjYLJ6VlDt4Q2fBNH1/VZAReWuph5Sk8fMuPRvnpLIeeM9DeY3gtJL hCZA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="hP/vHJfZ"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-199115-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199115-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43ff25b6df1si85104841cf.752.2024.06.03.05.33.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 05:33:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199115-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=@gmail.com header.s=20230601 header.b="hP/vHJfZ"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-199115-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199115-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 D1C4A1C23CBB for ; Mon, 3 Jun 2024 12:33:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 29F7712C475; Mon, 3 Jun 2024 12:33:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hP/vHJfZ" Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.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 CEF9612BF23 for ; Mon, 3 Jun 2024 12:33:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717418015; cv=none; b=s0uejELkFC+jMdA1WtwOZTlPFX9q9NSBIo5enYQoo1vdhgBLzA175FXwOfZE4F8r169ZEQ/z0+dJawK2vCcmdHu3oWQ0ZUwzePw7vuWrd4CMt77zVbAcu353eQLJvh6rcvVYURmoiC0fM5otBmjWfez9k4oMJ7+x8NcqFOjlVJI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717418015; c=relaxed/simple; bh=kYIuQsN2L0HfcJb21dz7RS0YauRbygmsFvNM6IcF+4Q=; h=MIME-Version:From:Date:Message-ID:Subject:To:Cc:Content-Type; b=sXbbWpvcxqLyZOp8uILOh/cLHY5G8OAGptFpkSQndIm0TbfVyPPMQnGNrbi5TeX3Oa+oqHea9kHleK7Y4GHGbEfkQs6FsIF1IyYXnQh/Je7DFKABuhNwRKCy4bjdC7wkR5Yy26zeSB97ILnHxaeq9e3Qh8MI5M09s8S9fcl65AM= 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=hP/vHJfZ; arc=none smtp.client-ip=209.85.167.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 Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-52962423ed8so4771779e87.2 for ; Mon, 03 Jun 2024 05:33:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717418012; x=1718022812; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=1Ru8Np0KrRH/lYPvykLiPbmxJAWT+d6nNSuG8nv7VOk=; b=hP/vHJfZi/bHrQ4IuhaBnYngwwZ2sieK1DnZjJdIiIwot+xje1GXPGNRUDB9vwu2dR VbUv9H4Ank2P/V2VKcnk44SqoXGY31aFJ3nLJq7AiuGUaucTr5n67ZHW3FEDQis1379R yK/DYRkEYOmGd2xnAmq81LBGa0XbKYzbILoUKbUKvaKKHa2mV4O3Oz5B0QEuJsRqImYc NWANY+djXBoLuMYN+8Mqzyvgqa35sGIe2xB4Y459b3LjPgcyFtzmfzW3J0pZR5Q/nzZf vWa4dJ3C7vbb0JBeB0L1pIJ23pkDz7SvNMBpXMwe7K2mQ5FQNjIP5MLwYHug2EVWH5k4 abgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717418012; x=1718022812; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=1Ru8Np0KrRH/lYPvykLiPbmxJAWT+d6nNSuG8nv7VOk=; b=LaBzPQWWpeCrVR8Q0FP75NwYM7SVcR1cT6QycvABmjAnBQB3Q9TR9OQRQvB9zfglZN PDzHOsl8pHu23edyvELI/EKy7xOJhqVIXNiZ8yIf01pYfJ62zH2+85+m6YWS9xrxeQER SvoN4KF+Nkw7IwbY0P7WgYDZ4E0Y3WCx3iLDijuGRWkS9hnGckkKSHU0CIJl8ysTdxNi nW3BhacFbuY6PR9Mbwc0nHPH7yk9jLgUs37Hxqzvkf4aqOHYviCsSZRacfPo+6xVmTGA KPOkmC1EC+L5rkN9o8jg1eVbgqNbryJ22dhf3NVnVkWzoptBDvwioullrCln2+0etSV0 dzZw== X-Forwarded-Encrypted: i=1; AJvYcCX4MQikx0KJImrr0OVKR8zGEZasQRadoTSVt1Jl5fPW/DutN4+gMcaWZt7da5sYma1YoXzK1SQQ+bfI8jLlU8JGAXX3t8HvOLas6FJ7 X-Gm-Message-State: AOJu0YylzzH9LDNb9fDbz/2ikOV1UOb+Ciyjx8cb/XI3PYOOvviwhX3G 5TQFI/SYYk4dIjRMhXD+KRi473bjD0dpAWZQkhoqgxLbScT//iRnHPRCHw0YdRK14BSUG4n0JpH iunLvZIcwI7ZJYupov+RKP1hDOE0= X-Received: by 2002:a05:6512:314a:b0:52b:79a5:517a with SMTP id 2adb3069b0e04-52b8959daa7mr5518994e87.33.1717418011642; Mon, 03 Jun 2024 05:33:31 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geunsik Lim Date: Mon, 3 Jun 2024 21:33:19 +0900 Message-ID: Subject: [PATCH] fix: Prevent memory leak by checking for NULL buffer before calling css_put() To: Axel Rasmussen , Vlastimil Babka , Ingo Molnar , Andrew Morton , Thomas Gleixner , Peter Zijlstra , Hugh Dickins Cc: "H. Peter Anvin" , Steven Rostedt , linux-kernel , linux-mm Content-Type: text/plain; charset="UTF-8" This commit addresses a potential memory leak in the `get_mm_memcg_path()` function by explicitly checking if the allocated buffer (`buf`) is NULL before calling the `css_put()` function. The prefix 'css' means abbreviation of cgroup_subsys_state Previously, the code would directly call `css_put()` without checking the value of `buf`, which could lead to a memory leak if the buffer allocation failed. This commit introduces a conditional check to ensure that `css_put()` is only called if `buf` is not NULL. This change enhances the code's robustness and prevents memory leaks, improving overall system stability. **Specific Changes:** * In the `out_put` label, an `if` statement is added to check if `buf` is not NULL before calling `css_put()`. **Benefits:** * Prevents potential memory leaks * Enhances code robustness * Improves system stability Signed-off-by: Geunsik Lim Signed-off-by: Geunsik Lim --- mm/mmap_lock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/mmap_lock.c b/mm/mmap_lock.c index 1854850b4b89..7314045b0e3b 100644 --- a/mm/mmap_lock.c +++ b/mm/mmap_lock.c @@ -213,7 +213,8 @@ static const char *get_mm_memcg_path(struct mm_struct *mm) cgroup_path(memcg->css.cgroup, buf, MEMCG_PATH_BUF_SIZE); out_put: - css_put(&memcg->css); + if (buf != NULL) + css_put(&memcg->css); out: return buf; } -- 2.34.1 ---- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/