Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3815481pxt; Tue, 10 Aug 2021 11:58:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxea1DdCsCWvighzZ0QqTZs+6UArz9TgHDWqq45XCyKAyZmRf0mrtVcpk5Bdr7MqTDgNJHA X-Received: by 2002:a92:6b0a:: with SMTP id g10mr14904ilc.17.1628621882359; Tue, 10 Aug 2021 11:58:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628621882; cv=none; d=google.com; s=arc-20160816; b=Pr370j9Dht34j73ljp7YZPqEQ8TlALKYqYAhiBgwcDXV7FlT9av9u6ED2AtzapuVGE 9DUxrXaQ8SxUSFIbmTKUku3FFN9AAgXrtHViEI91PLoy31BD5PFiyxl7SMpUz0gjNa2x 9hZJdvMTyX+PsGdFmIrtiyyWSnhRl5crujUCg/3+m9sT5Vs6xWKeAsWXmjp3g4+yEtA4 Oe0D4Fw9VbAV0fzmmrBf3YU+VJtXwE2lCAY0JvwwR/PpyusX/gjRSOOWhhj1unKWitWA lKaTTSzlqfSP5jv1AVSPxjjP+93pLs/8exNlaq7DSIeNmK671aHvQigWAPlTbZ67DBA3 qQ1A== 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=5J8TNSHzverklWCIf6vRYydGxpzdFZnm4R0kskdp9cc=; b=Mv/EjHwetvQB/U3NLU0XUDkj/kY+jSRP9zCqebIMeCUhuCxO+Hxz1JsY4JrsMPU3Te afr5CcV+pmyBDFGsQCfI39IuMtu4DMcijJQ6/PWucj6cTArtrXqlbvlB9/PFQxb2Eo58 W4xH9btqRMlUyO54RBokTcR2/7nE5YOaZ3MfvSG0JSfJdtmW+7/wnfX5SaR+d0zFBILn BwF/uh9O9wsT2pnvkXRzTAA43nPkkXFUXzmTHeq5x3XJOOZNpqe1PzxyYLtfnfmsMTUG zrfuHeSljwi9BUJUgNtcN7dE7GIi1TqYV73vcXG3kYikOsQqzkprIjXXkwCr7z3SNW80 Suwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ndautaOo; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b24si21488157jar.119.2021.08.10.11.57.51; Tue, 10 Aug 2021 11:58:02 -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=@google.com header.s=20161025 header.b=ndautaOo; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231975AbhHJS5W (ORCPT + 99 others); Tue, 10 Aug 2021 14:57:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229774AbhHJS5V (ORCPT ); Tue, 10 Aug 2021 14:57:21 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6F44C0613C1 for ; Tue, 10 Aug 2021 11:56:58 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id x27so20892546lfu.5 for ; Tue, 10 Aug 2021 11:56:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5J8TNSHzverklWCIf6vRYydGxpzdFZnm4R0kskdp9cc=; b=ndautaOoQT38CMmBdyfavMBZQUrg4llGLquOvj3ILSUjkPPYbfklhyWsnujm3oeuRe f9IzYajcg7Y1Unc2VFiYw+v2O5d059adb6UQ/chnQ50HQlwUPNHmkI+V0r/qWJHWxGcx +UiNPb6e4jgWnwA76Jp6kE9fW+owItNRsZYgVncNN92BQr2PYDi4DC5QS7OGRpllpqHQ KHx3FECO1R+SyjtFH55pJDHgT5TJn9pXovWEeCRFpibD7ewlW+WOhZvBuDJYClcZx4aV 5bj/H88uu3p8vzO/Vm113dRyqgx9Pk9/HjmWi7pRjwRPw4IQWN3uQW36y3z6bgaQ6SOB eKLw== 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=5J8TNSHzverklWCIf6vRYydGxpzdFZnm4R0kskdp9cc=; b=QRMP+MwNlzWQ9C4Vw96cJyHt3OuUQDgihX1HJsmDtb4QMkj/GVdVoVxCfv/4V/6jtZ hRUSMAbyUg3QuxfO+THRD0xg7c3URfn7+vHGI1GGBdwBb3JFq6rMZoOH5rhFx88dymgp MEAFccrrlwsxIxTSUisNHVkvdwUtPpm83B/uYhhFGVtzisD0aIMGsNDq4nc1Rel3+GvP +iLIsHBe2QGzEBGcwancDBs73Z73uU7cQoio7Kh7PLrXSMTxac8g8UHC2btTPH5jBjkG hJoDPIK+j1YyayaF1fyAplcUXbevzPH0Xw7fBivIUErDxk95dLr8QntrB6UsihsbGpMj 4rdw== X-Gm-Message-State: AOAM531SSdDd3a/lN3BbyV+J741Xr9EBRUu+wFfZ6cIc5T/XbfVCrYAh FPPpD3tpXw0NsfiIapFwLR3bvtDxZltmk3LIGmh3Yw== X-Received: by 2002:ac2:531c:: with SMTP id c28mr24026257lfh.74.1628621817084; Tue, 10 Aug 2021 11:56:57 -0700 (PDT) MIME-Version: 1.0 References: <20210810020441.62806-1-qiuxi1@huawei.com> In-Reply-To: <20210810020441.62806-1-qiuxi1@huawei.com> From: Jann Horn Date: Tue, 10 Aug 2021 20:56:30 +0200 Message-ID: Subject: Re: [PATCH 1/1] coredump: fix memleak in dump_vma_snapshot() To: QiuXi Cc: viro@zeniv.linux.org.uk, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, xiekunxun@huawei.com, young.liuyang@huawei.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 10, 2021 at 4:04 AM QiuXi wrote: > dump_vma_snapshot() allocs memory for *vma_meta, when dump_vma_snapshot() > returns -EFAULT, the memory will be leaked, so we free it correctly. The change itself looks reasonable to me. > Fixes: a07279c9a8cd7 ("binfmt_elf, binfmt_elf_fdpic: use a VMA list snapshot") > Cc: stable@vger.kernel.org # v5.10 But I think this shouldn't be "Cc: stable". The patch only removes a memory leak in a WARN_ON() path, and that WARN_ON() path can only be taken if there is a kernel bug; if we reach this branch, there's a good chance that kernel memory corruption has already occurred. > Signed-off-by: QiuXi > --- > fs/coredump.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/fs/coredump.c b/fs/coredump.c > index 07afb5ddb1c4..19fe5312c10f 100644 > --- a/fs/coredump.c > +++ b/fs/coredump.c > @@ -1127,8 +1127,10 @@ int dump_vma_snapshot(struct coredump_params *cprm, int *vma_count, > > mmap_write_unlock(mm); > > - if (WARN_ON(i != *vma_count)) > + if (WARN_ON(i != *vma_count)) { > + kvfree(*vma_meta); > return -EFAULT; > + } > > *vma_data_size_ptr = vma_data_size; > return 0; > -- > 2.12.3 >