Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp874530rwj; Thu, 22 Dec 2022 16:39:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXvBlL2XIwJfLc6iO7shT4nu1TXPZH59tAonti4po8QDqTxQWsgFbOh/GiDjgW3m91pefIuM X-Received: by 2002:a17:906:c18d:b0:843:770e:777f with SMTP id g13-20020a170906c18d00b00843770e777fmr3906715ejz.24.1671755971038; Thu, 22 Dec 2022 16:39:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671755971; cv=none; d=google.com; s=arc-20160816; b=d+kpdUOz0JXJT0/eCZwlutPlH4y5x/xJYBrnWC18frRxVQBWtvbA6gDTmIcTB0Abhk oMXZVdhZLNwDWONAmtRr51eWj/xWl+0kJYdR1x08V5Lw8/fxanHP3HyPEpIYaozTgrpf UrFOSJPtzlTuwW63PLc2geV0wJNN9NZ7DIGN7RfMcVmrL0scAZaf+Pdqz9/8s2nqPVlf 9MUfO56tfMM0HcPOj/wgIPNcnyPxRZtxiTYKCJZnJcre8iiiaVpDXtVhSLYmiv/F756x MVvSODPeGWhXKc9bb8Dbmul2MPjAB51LsrUuLFX01bCdgtLKEgnCq3ILh2MTzAwIEs+h 9nZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date; bh=9mryWYtbcRPiZnFJhxjmE6pJiyQSECYs7usoDLbACdQ=; b=z2VU33nDuD9t2CkN7BhFT9+Zfq1vzIes8UZ+s3NIAi4De0v9EganChnndJCDCF/YUh mkaennDhzBKdqkvM7ng5obzd3L+/D8qSomh4hHsGrqfpl2OZGI4pRYUmXG+o4+luhypb yH3gCT++4xcxNjEX65lzNn6WC5WsadzfAyw0qpqZvP68W+SF8syahZsL8DntlvtExele MZ9iKmKUKH9ftV7GBYOc93yCTPcwfgiMgz+/V7Exo1ugQzvkQV/R2TxZ1S3ogg7LHZ7a IKtjhtb530A56vANyobfLjlGo6iU8LvbEOvj+GlMgXSxsToAbkgLid9aE3sWMWToWcUn zRAg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p20-20020a1709060dd400b007ae754729d1si1076013eji.883.2022.12.22.16.39.14; Thu, 22 Dec 2022 16:39:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231233AbiLWAVt (ORCPT + 68 others); Thu, 22 Dec 2022 19:21:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229910AbiLWAVr (ORCPT ); Thu, 22 Dec 2022 19:21:47 -0500 Received: from a3.inai.de (a3.inai.de [IPv6:2a01:4f8:10b:45d8::f5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 911792736; Thu, 22 Dec 2022 16:21:45 -0800 (PST) Received: by a3.inai.de (Postfix, from userid 25121) id AA79D5870460D; Fri, 23 Dec 2022 01:21:42 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by a3.inai.de (Postfix) with ESMTP id A4B4260C29174; Fri, 23 Dec 2022 01:21:42 +0100 (CET) Date: Fri, 23 Dec 2022 01:21:42 +0100 (CET) From: Jan Engelhardt To: oss-security@lists.openwall.com cc: Alejandro Colomar , Michael Kerrisk , linux-kernel@vger.kernel.org, linux-man@vger.kernel.org Subject: Re: [oss-security] [patch] proc.5: tell how to parse /proc/*/stat correctly In-Reply-To: Message-ID: References: User-Agent: Alpine 2.25 (LSU 592 2021-09-18) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thursday 2022-12-22 23:03, Dominique Martinet wrote: >> + >> +Note that \fIcomm\fP can contain space and closing parenthesis characters. >> +Parsing /proc/${pid}/stat with split() or equivalent, or scanf(3) isn't >> +reliable. The correct way is to locate closing parenthesis with strrchr(')') >> +from the end of the buffer and parse integers from there. > >That's still not enough unless new lines are escaped, which they aren't: strrchr does not concern itself with "lines". If your input buffer contains the complete content of /proc/X/stat (and not just a "line" thereof), the strrchr approach appears quite workable.