Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1043658ybp; Fri, 11 Oct 2019 08:10:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxfrRGi2D8ekzt17XLT10mlWLBOFh7A6U4y7+SeOn7I8lU3NP5NLPuXLNNbBVyn+c+lxAgY X-Received: by 2002:a17:906:4d44:: with SMTP id b4mr14988360ejv.105.1570806643381; Fri, 11 Oct 2019 08:10:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570806643; cv=none; d=google.com; s=arc-20160816; b=tsbX76h/pNtaEv2YYRRzuKuXRNnN1qRhdOlBwyAfu42Njco8pm9CowUpTAs5Fthn0T qcldlhDUX4Vjb3lMRvvo1vqA1xac/MeDbEYxZ8fpNJA7VUycHttHaLlpbZvtvRcDqUaL NXF1bHzBL9IPmmQ8AVeSJD+s+lOB3YBZkzW7tfDmxh6Ehrsx77L2RLmEYjhaSqrdKfrd eAi8skDZ21WUv/GF9vFjEsKL8Z0BL09wNZxNyI0NRq7IPbSFY5pjuAzS8VoZ+UBpAD3M LYh4rbqNHqtKpBhAU0aUob2xmfdejICbrK8JCFp76ij1ISrDP5/dTocrBggu26RzvNxe oU0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=ZJr8HBzMfU7kmiZCz9sHwsjTkr7yVBKTvuMk3ztn6oM=; b=WHg8XojzSd/96trRr/4YBkRw9wpo4rV91kU5qvr2RrWp2f854hAtpPwh7Nw601Rdj0 Hqg8uCeaA5b8iIk+vJmCNBm9hqUFwHSwyyV8QB8omJNEXOGkGhTKPrey0c6vhfxkh1Qo JhcgHRuabfGt9Bk/s6Zx6/FTcZKQyPeEw3LM8BCnaXca40Gic4L+bmAHSZbMcmB5GVtz kFpyJVoa/iCECuMnjIOjmoqP416kGZHn5xP5rtAxEkXosSKhHt5cI/K1g8INK1ofAYKe FE3HR643I4dLMOkQlSiMyhFjMu2zBG07eogWCFZbskvRsjcTzqdVBXIvrBzyVtE4dm3u 1AbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=bbv7ZbvP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id b44si6330694ede.451.2019.10.11.08.10.19; Fri, 11 Oct 2019 08:10:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=bbv7ZbvP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727268AbfJKPJ5 (ORCPT + 99 others); Fri, 11 Oct 2019 11:09:57 -0400 Received: from mail-oi1-f170.google.com ([209.85.167.170]:40566 "EHLO mail-oi1-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726800AbfJKPJ4 (ORCPT ); Fri, 11 Oct 2019 11:09:56 -0400 Received: by mail-oi1-f170.google.com with SMTP id k9so8270641oib.7 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=C3o7P7AQBGdAH/KVAVqA8oPEJBbpPY56SUx6fr2s4x2tZ/vQNV1cKwqNENYE+KQNO5 piKiLYs943muGxzLp+6me6p96cxnKkt43BELJ4aeLzb6UPFWnoYTvyWv5QMalPMkJxIa /rnYWGqucW50zYAQanPvfstjEiHfIXFBv0HEiiA/kuRs2JFcw4ZefvpSopr6TjcHGaSU OLPQ87heBFlcmF1nlxCxyaud8I5H5OWzsROUGICv14LM6uJ/jscBPG0lAInea/9RmG4U IQpe1Zp+WPKJTmvXvPvIbJGJgSm74GEKk8dPMfEzq4X7Xk4OYYso3PHke2SRCvBuhLcf vGzg== X-Gm-Message-State: APjAAAXXqj1zgbGMdI97XA95/5CXyzMAFQSprTiuP27UKTmsSFAMDXKd w6Pxi9rG4sW9U97ZMOJIeYedIN3zkwykUMw2OeT348fAYqc= 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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.