From mboxrd@z Thu Jan 1 00:00:00 1970 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=-8.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no 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 5AF9CECE58C for ; Fri, 11 Oct 2019 15:09:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2F101206CD for ; Fri, 11 Oct 2019 15:09:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bbv7ZbvP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726828AbfJKPJ5 (ORCPT ); Fri, 11 Oct 2019 11:09:57 -0400 Received: from mail-oi1-f176.google.com ([209.85.167.176]:43712 "EHLO mail-oi1-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726692AbfJKPJ4 (ORCPT ); Fri, 11 Oct 2019 11:09:56 -0400 Received: by mail-oi1-f176.google.com with SMTP id t84so8264856oih.10 for ; Fri, 11 Oct 2019 08:09:56 -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=ZJr8HBzMfU7kmiZCz9sHwsjTkr7yVBKTvuMk3ztn6oM=; b=bbv7ZbvPGd2Vy+OW6XTx5v8DO1t5PRQQIoAJ3CmOQOCFC+f4NEnTZbLbCAVKBxwxcH IIngYatL20o7Of46857CmUx5iKZmPTbazlS1+ULBxf1QsIdSeP/YDKCiDFIN++VIzLKG 0g2Ja9ORAfWqhWGb2EM0A/6k18qXtfm4iKtWkLaCsxVA8Gv/gw+bMvouYSK8in6vYkDO czztQZBwBaxe89EtKiMuvMo6XGe728fyynOUlLtMgZ/Tc968p3+fuly7UgUqljSMnyoH LefxFFqhTB19GCYmjNMV6wrAZXtwJg9/Sf8cJapx9ICK8FfZCaBpmPvzdAiF48oOBs3m v7Sw== 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=ZJr8HBzMfU7kmiZCz9sHwsjTkr7yVBKTvuMk3ztn6oM=; b=BLd9zenywRuZIDVOKSFU2UfaUQhITfjgNO1ypshRgHjsAdt+iXFFsAkHgYvn6dz54l GH+qa+qMHn+zpXiS67kqgdMbr0Xu9BdiD6vMevRLETLKmtZcbbnFs4NIMM8rgrni8mko qqheHrWV1+JY9xR8QDblknpePQuCYV+5TeVAZRVnFFXVbzMyN5RTbVzRaLC2QZfobnZa DXWtY6UweMOnXTCE1tTIlhDDYc+RoRec4/DvhU3GrDcyf3jlYvjzH8njVyetDn+MgzXu at30NmHZZEZkKV6yVfmJglhZQaclW+5S8WdKa6c1+CiJR9hGwNSEqWQkxdeeF2CtPxWd fpUA== X-Gm-Message-State: APjAAAXsZtazcODmvHeiY3z8bb6eZ2jVGAGbiKqqtcovHN/5JxZeWlyp 1ClSpmVtK44IjnpQpkpVitF7ej56pNmAvDCwjbsMkQ== X-Google-Smtp-Source: APXvYqxiUBiNWI0ojBaKuc9Wss6TByn/XWZWY72Z0YR+e6hD15VDtY6gxIhOQWm62gzHt+xWgxTf/fn46FfNp0cj1p4= X-Received: by 2002:a05:6808:95:: with SMTP id s21mr12669138oic.68.1570806595398; Fri, 11 Oct 2019 08:09:55 -0700 (PDT) MIME-Version: 1.0 References: <20191008133641.23019-1-ckellner@redhat.com> <20191009160532.20674-1-ckellner@redhat.com> <20191009160532.20674-2-ckellner@redhat.com> In-Reply-To: <20191009160532.20674-2-ckellner@redhat.com> From: Jann Horn Date: Fri, 11 Oct 2019 17:09:29 +0200 Message-ID: Subject: Re: [PATCH v2 2/2] pidfd: add tests for NSpid info in fdinfo To: Christian Kellner Cc: kernel list , Linux API , Christian Kellner , Christian Brauner , Shuah Khan , Andrew Morton , "Peter Zijlstra (Intel)" , Ingo Molnar , Michal Hocko , Thomas Gleixner , Elena Reshetova , Roman Gushchin , Andrea Arcangeli , "Joel Fernandes (Google)" , Al Viro , "Dmitry V. Levin" , "open list:KERNEL SELFTEST FRAMEWORK" Content-Type: text/plain; charset="UTF-8" Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org On Wed, Oct 9, 2019 at 6:10 PM Christian Kellner wrote: > Add tests that check that if pid namespaces are configured the fdinfo > file of a pidfd contains an NSpid: entry containing the process id > in the current and additionally all nested namespaces. [...] > +static int compare_fdinfo_nspid(int pidfd, char *expect, size_t len) > +{ > + char path[512]; > + FILE *f; > + size_t n = 0; > + ssize_t k; > + char *line = NULL; > + int r = -1; > + > + snprintf(path, sizeof(path), "/proc/self/fdinfo/%d", pidfd); (Maybe at some point the selftests code should add some more concise alternative to snprintf() calls on separate lines. A macro or something like that so that you can write stuff like `f = fopen(tprintf("/proc/self/fdinfo/%d", pidfd), "re")`.) > + f = fopen(path, "re"); > + if (!f) > + return -1; > + > + while ((k = getline(&line, &n, f)) != -1) { > + if (strncmp(line, "NSpid:", 6)) > + continue; > + > + line[k - 1] = '\0'; > + ksft_print_msg("Child: fdinfo NSpid line: '%s'.\n", line); > + r = strncmp(line + 6, expect, len); Wouldn't it be better to get rid of the nullbyte assignment and change the strncmp() into a strcmp() here... [...] > + /* The child will have pid 1 in the new pid namespace, > + * so the line must be 'NSPid:\t\t1' > + */ > + n = snprintf(expect, sizeof(expect), "\t%d\t%d", pid, 1); ... and add a "\n" to the format string? It's shorter and doesn't silently ignore it if the line doesn't end at that point.