public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: swarup <swarupkotikalapudi@gmail.com>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, shuah@kernel.org, hughd@google.com
Subject: Re: + selftests-proc-add-proc-pid-statm-output-validation.patch added to mm-nonmm-unstable branch
Date: Mon, 9 Oct 2023 23:46:57 +0530	[thread overview]
Message-ID: <ZSRDmTwxARRENuqK@swarup-virtual-machine> (raw)
In-Reply-To: <9ce82fc2-4e09-40c4-b5a5-a9a049c2f493@p183>

eOn Mon, Oct 09, 2023 at 09:14:53AM +0300, Alexey Dobriyan wrote:
> On Wed, Oct 04, 2023 at 01:17:00PM -0700, Andrew Morton wrote:
> > 
> > The patch titled
> >      Subject: selftests: proc: add /proc/$(pid)/statm output validation
> > has been added to the -mm mm-nonmm-unstable branch.  Its filename is
> >      selftests-proc-add-proc-pid-statm-output-validation.patch
> > 
> > This patch will shortly appear at
> >      https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/selftests-proc-add-proc-pid-statm-output-validation.patch
> > 
> > This patch will later appear in the mm-nonmm-unstable branch at
> >     git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
> > 
> > Before you just go and hit "reply", please:
> >    a) Consider who else should be cc'ed
> >    b) Prefer to cc a suitable mailing list as well
> >    c) Ideally: find the original patch on the mailing list and do a
> >       reply-to-all to that, adding suitable additional cc's
> > 
> > *** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
> > 
> > The -mm tree is included into linux-next via the mm-everything
> > branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
> > and is updated there every 2-3 working days
> > 
> > ------------------------------------------------------
> > From: Swarup Laxman Kotiaklapudi <swarupkotikalapudi@gmail.com>
> > Subject: selftests: proc: add /proc/$(pid)/statm output validation
> > Date: Wed, 4 Oct 2023 01:13:19 +0530
> > 
> > Add /proc/${pid}/statm validation
> > 
> > /proc/$(pid)/statm output is expected to be:
> >  "0 0 0 * 0 0 0\n"
> > Here * can be any value
> > 
> > Read output of /proc/$(pid)/statm and check except for 4th position, all
> > other positions have value zero.
> > 
> > Link: https://lkml.kernel.org/r/20231003194319.602646-1-swarupkotikalapudi@gmail.com
> > Signed-off-by: Swarup Laxman Kotiaklapudi <swarupkotikalapudi@gmail.com>
> > Cc: Alexey Dobriyan <adobriyan@gmail.com>
> > Cc: Hugh Dickins <hughd@google.com>
> > Cc: Shuah Khan <shuah@kernel.org>
> > Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> > ---
> > 
> >  tools/testing/selftests/proc/proc-empty-vm.c |   57 +++++++++++++++--
> >  1 file changed, 52 insertions(+), 5 deletions(-)
> > 
> > --- a/tools/testing/selftests/proc/proc-empty-vm.c~selftests-proc-add-proc-pid-statm-output-validation
> > +++ a/tools/testing/selftests/proc/proc-empty-vm.c
> > @@ -303,6 +303,56 @@ static int test_proc_pid_smaps_rollup(pi
> >  	}
> >  }
> >  
> > +static int test_proc_pid_statm(pid_t pid)
> > +{
> > +	char buf[4096];
> > +	char *tok;
> > +	char *string;
> > +	int non_zero_value_indx = 4;
> > +	int i = 1;
> > +
> > +	snprintf(buf, sizeof(buf), "/proc/%u/statm", pid);
> > +
> > +	/*
> > +	 *  Output can be "0 0 0 2 0 0 0\n" where "2" can be anything.
> > +	 */
> > +	int fd = open(buf, O_RDONLY);
> > +
> > +	if (fd == -1) {
> > +		if (errno == ENOENT) {
> > +			/*
> > +			 * /proc/${pid}/statm is under CONFIG_PROC_PAGE_MONITOR,
> > +			 * it doesn't necessarily exist.
> > +			 */
> > +			return EXIT_SUCCESS;
> > +		}
> > +		perror("open /proc/${pid}/statm");
> > +		return EXIT_FAILURE;
> > +	} else {
> > +		ssize_t rv = read(fd, buf, sizeof(buf));
> > +
> > +		close(fd);
> > +		assert(rv);
> > +		string = buf;
> > +
> > +		while ((tok = strsep(&string, " ")) != NULL) {
> 
> This is unreliable too. read() doesn't terminate the buffer so this relies
> on termination from
> 
> 	snprintf(buf, sizeof(buf), "/proc/%u/statm", pid);
> 
> Buggy kernel could return a lot of data and overwrite it.

Hi Alexey Dobriyan,
I will try to correct read() function.
Thanks,
Swarup

  parent reply	other threads:[~2023-10-09 18:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20231004201701.87CB5C433C7@smtp.kernel.org>
2023-10-09  6:14 ` + selftests-proc-add-proc-pid-statm-output-validation.patch added to mm-nonmm-unstable branch Alexey Dobriyan
2023-10-09  9:00   ` Alexey Dobriyan
2023-10-09 18:18     ` swarup
2023-10-09 18:16   ` swarup [this message]
2023-10-09 19:20 ` [PATCH v3] selftests:proc Add /proc/$(pid)/statm output validation Swarup Laxman Kotiaklapudi
     [not found] <20231001193740.B716AC433C7@smtp.kernel.org>
2023-10-02 12:38 ` + selftests-proc-add-proc-pid-statm-output-validation.patch added to mm-nonmm-unstable branch Alexey Dobriyan
2023-10-02 17:52   ` swarup

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZSRDmTwxARRENuqK@swarup-virtual-machine \
    --to=swarupkotikalapudi@gmail.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox