Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1183077ybp; Fri, 11 Oct 2019 10:09:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqzME63h/Im8Jkee5nGZMOsLy65k5+sMJt2HpvgwGLUxmDwmQMZQRXVaD0wNZYc5Hb4gJLgG X-Received: by 2002:a17:906:704:: with SMTP id y4mr14817294ejb.259.1570813775727; Fri, 11 Oct 2019 10:09:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570813775; cv=none; d=google.com; s=arc-20160816; b=COI81AXQavHTCEG+G+Zwokq3xjZ7bKXGapeYdOJ/DPlWZg/t9h0FBpv5vC7rttgOhX 8HqK7TJqJJ3zHYV1xNtFfxpIV6/fBi/hCMFIluDVYE6RSXkVeVo7Gr4GqVle7u7uXIGt aVSckE0AG36uwYYdMuk3iMCg5Gd//eHa/LrQiJaZFXb0R3hsdtGDpeS6HLDMIxu/6VX/ RY+clthPfSSNOZ9iUUQ08dmWgEDh9okagoQGehgddb6FB5VI1kYhKURhL9rOM5bOYC5J jC6EEd+MWq+EyYS+noLKNR9dCv9nBwBLZU0fZDmlNa9cu4DYgQwBhoHi/EwoLXWKKeTL BxVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=3Y7MjsSvf1ckOsw9WX3QUf0ByexEamCMMsgOGEZD4Fc=; b=gm47pmv5CRhpp1dSPugCEar2Y7EEwKnWBO2rioYCxPrwfaVCFlBnkwnp1V8iQZ1esF 8o+3D/x02MfdOxIwTQnDT3DrrYeS73iEQmc1V3pyBmmgYkGJfDRwJk8Q43cpGeC+ki1P BemRAjQGspcEVjK44Hr7AGC9cciNjNshBxKj1ENxPXlxNhu6cVedg7KsNWn0Wwe7sYng +zOpmICPTvThcYjsb012FcKtqkGB4EvW4vOOOvZpOHDAMSPHY36Ogu3zIb/lpW71OYz9 z/8VfPMb+hfFNkicdJ8I99t9EoCQsHICk3IJwBQFMFhXqoumIWAUYhir5tytn61SLEAs +Y2A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e5si5735582ejj.70.2019.10.11.10.09.11; Fri, 11 Oct 2019 10:09:35 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728472AbfJKRIy (ORCPT + 99 others); Fri, 11 Oct 2019 13:08:54 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:48859 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728086AbfJKRIx (ORCPT ); Fri, 11 Oct 2019 13:08:53 -0400 Received: from [213.220.153.21] (helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iIyPK-0004El-S2; Fri, 11 Oct 2019 17:08:50 +0000 Date: Fri, 11 Oct 2019 19:08:50 +0200 From: Christian Brauner To: Jann Horn Cc: Christian Kellner , kernel list , Linux API , Christian Kellner , 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" Subject: Re: [PATCH v2 2/2] pidfd: add tests for NSpid info in fdinfo Message-ID: <20191011170848.nbfxzzl5qckkshkr@wittgenstein> References: <20191008133641.23019-1-ckellner@redhat.com> <20191009160532.20674-1-ckellner@redhat.com> <20191009160532.20674-2-ckellner@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 11, 2019 at 05:09:29PM +0200, Jann Horn wrote: > 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. Also, what Christian just told me and what I wanted to suggest is that we add tests for sending around pidfds and reading fdinfo too.