From patchwork Sun Jan 17 04:52:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 365442 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FC60C433DB for ; Sun, 17 Jan 2021 04:53:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CA46A22D75 for ; Sun, 17 Jan 2021 04:53:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725995AbhAQExQ (ORCPT ); Sat, 16 Jan 2021 23:53:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725815AbhAQExP (ORCPT ); Sat, 16 Jan 2021 23:53:15 -0500 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17523C061573 for ; Sat, 16 Jan 2021 20:52:35 -0800 (PST) Received: by mail-pj1-x1044.google.com with SMTP id my11so7056085pjb.1 for ; Sat, 16 Jan 2021 20:52:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/c3AUuHNj8aviLYKvtDgdT//v0Yif6ZnqYACRpUShpI=; b=DSTUciZgm5waG3hnpdK2Zn9VEzLf/iAIDm3JN3IheUhj+IsJFyKZLm1qVuJRrhdgCy eP3eYpZgYe0BzW6klkX08TRak6x/PoVxYRIZ9SCNJSX4T8oo1Gw9rbi9CFXvZjOuB9up R7tEDpEoyy3TsVdsEYVSxkDu1ZOES9oBQe5RzdvNG/l8p+W2wL0AbYC97pFEFyH39LlK SDTAiumqkhXjjx48mxDN1aCXghcpw0uQx/jsyymd/Kbd01JNnEUQXZMKmZ5/NTfhPKy+ brWUTfODomnvSXEfCwHXcJt+ao6tjOI24jwTWQEWt74e4YMpe1DyNg1pilVzBwv9uVbo Qp4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/c3AUuHNj8aviLYKvtDgdT//v0Yif6ZnqYACRpUShpI=; b=Fs7NV80SIowZfBb5hBrz0vni2QSuJQx1tmB+BQcIltufhOhxDEnJDsm/vEFz9VbJfp nsTFI79xio6BilbZoB/rI1JaBOcVvO13XZVq5J2z6oEM0KCCXO5/RJGbbAQGEWSF26ZZ CU28ZVathUlNqJmKOOSB1up96C5D98vLNC5fIWi3nsbtaX8BHFgEZa0lw1g07vZi66pW W5nMhtWeQK/h1FYHTDo1ESrEg9tFQ1Sn9dd4Mwmjv5DLYpew2+3y8pMwjlgsf36EmyAP lKW9TK9ZdR6jjyy4V28hP8HG6f10805RQuF1xyC0H6VkETkB+roMVlL+s7bd3bA6k2zE DVSQ== X-Gm-Message-State: AOAM533l3nVfIIyWcOxcJZ4p0lygjaXMuAUDZKMJUDJArlAJHCux7BKN Mm6nqIm4EM//I5X+bP6ywiQ= X-Google-Smtp-Source: ABdhPJxaxzeLvLpx65EZTx8J4VYkHtwKmblD9WXdXqUqr95IfWQwHFYYHLtT80OvJSfBgClm7BJ6SQ== X-Received: by 2002:a17:90b:1905:: with SMTP id mp5mr16412268pjb.205.1610859153641; Sat, 16 Jan 2021 20:52:33 -0800 (PST) Received: from localhost ([178.236.46.205]) by smtp.gmail.com with ESMTPSA id z11sm12359355pjn.5.2021.01.16.20.52.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jan 2021 20:52:33 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: dong.menglong@zte.com.cn To: 2225233704@qq.com Cc: Menglong Dong , Andrew Morton , Paul Wise , Jakub Wilk , Neil Horman , stable@vger.kernel.org, Linus Torvalds Subject: [PATCH] coredump: fix core_pattern parse error Date: Sun, 17 Jan 2021 12:52:28 +0800 Message-Id: <20210117045228.118959-1-dong.menglong@zte.com.cn> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Menglong Dong 'format_corename()' will splite 'core_pattern' on spaces when it is in pipe mode, and take helper_argv[0] as the path to usermode executable. It works fine in most cases. However, if there is a space between '|' and '/file/path', such as '| /usr/lib/systemd/systemd-coredump %P %u %g', then helper_argv[0] will be parsed as '', and users will get a 'Core dump to | disabled'. It is not friendly to users, as the pattern above was valid previously. Fix this by ignoring the spaces between '|' and '/file/path'. Fixes: 315c69261dd3 ("coredump: split pipe command whitespace before expanding template") Signed-off-by: Menglong Dong Signed-off-by: Andrew Morton Cc: Paul Wise Cc: Jakub Wilk [https://bugs.debian.org/924398] Cc: Neil Horman Cc: Link: https://lkml.kernel.org/r/5fb62870.1c69fb81.8ef5d.af76@mx.google.com Signed-off-by: Linus Torvalds --- fs/coredump.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/coredump.c b/fs/coredump.c index 0cd9056d79cc..c6acfc694f65 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -229,7 +229,8 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm, */ if (ispipe) { if (isspace(*pat_ptr)) { - was_space = true; + if (cn->used != 0) + was_space = true; pat_ptr++; continue; } else if (was_space) {