lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Tue, 30 Oct 2018 22:26:22 +0000
From:   "Moger, Babu" <Babu.Moger@....com>
To:     Fenghua Yu <fenghua.yu@...el.com>
CC:     Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>, H Peter Anvin <hpa@...or.com>,
        Tony Luck <tony.luck@...el.com>,
        Peter Zijlstra <peterz@...radead.org>,
        Reinette Chatre <reinette.chatre@...el.com>,
        James Morse <james.morse@....com>,
        Ravi V Shankar <ravi.v.shankar@...el.com>,
        Sai Praneeth Prakhya <sai.praneeth.prakhya@...el.com>,
        Arshiya Hayatkhan Pathan <arshiya.hayatkhan.pathan@...el.com>,
        linux-kernel <linux-kernel@...r.kernel.org>
Subject: RE: Fwd: [PATCH v2 2/8] selftests/resctrl: Add basic resctrl file
 system operations and data

Fenghua,

> -----Original Message-----
> From: Fenghua Yu <fenghua.yu@...el.com>
> Sent: Tuesday, October 30, 2018 1:36 PM
> To: Moger, Babu <Babu.Moger@....com>; Fenghua Yu
> <fenghua.yu@...el.com>
> Cc: Thomas Gleixner <tglx@...utronix.de>; Ingo Molnar
> <mingo@...hat.com>; H Peter Anvin <hpa@...or.com>; Tony Luck
> <tony.luck@...el.com>; Peter Zijlstra <peterz@...radead.org>; Reinette
> Chatre <reinette.chatre@...el.com>; James Morse
> <james.morse@....com>; Ravi V Shankar <ravi.v.shankar@...el.com>; Sai
> Praneeth Prakhya <sai.praneeth.prakhya@...el.com>; Arshiya Hayatkhan
> Pathan <arshiya.hayatkhan.pathan@...el.com>; linux-kernel <linux-
> kernel@...r.kernel.org>
> Subject: Re: Fwd: [PATCH v2 2/8] selftests/resctrl: Add basic resctrl file
> system operations and data
> 
> > From: Moger, Babu <Babu.Moger@....com>
> > > From: Fenghua Yu <fenghua.yu@...el.com>
> > > From: Sai Praneeth Prakhya <sai.praneeth.prakhya@...el.com>
> > >
> > > The basic resctrl file system operations and data are added for future
> > > usage by resctrl selftest tool.
> > >
> > > +     return 0;
> > > +}
> > > +
> > > +char get_sock_num(int cpu_no)
> > > +{
> > > +     char sock_num, phys_pkg_path[1024];
> > > +     FILE *fp;
> > > +
> > > +     sprintf(phys_pkg_path, "%s%d/topology/physical_package_id",
> > > +             PHYS_ID_PATH, cpu_no);
> > > +     fp = fopen(phys_pkg_path, "r");
> >
> > There should corresponding fclose for this. In general, I would check all the
> > fopens in this series. I found few of the files not closed while returning.
> > More comments below.
> >
> > > +     if (!fp || fscanf(fp, "%c", &sock_num) <= 0 || fclose(fp) == EOF) {
> 
> fclose is here.

Yes. It is there. Let's take a case(hypothetical) where fp is valid and fscanf returns -1.

             If( false || true || fclose(fp))

Will this execute fclose?  Or am I missing something here?


> 
> > > +             perror("Could not get socket number");
> > > +
> > > +             return -1;
> > > +     }
> > > +
> > > +      */
> > > +     if (!freopen("/dev/null", "w", stdout))
> > > +             PARENT_EXIT("Unable to direct BM op to /dev/null");
> >
> > Do you need fclose for this before returning from this function?
> 
> This fclose is missing. I will add it.
> 
> > > +     /* Write child pid to con_mon grp */
> > > +     fp = fopen(controlgroup, "w");
> >
> > I don't see corresponding fclose.
> >
> > > +     if (!fp || fprintf(fp, "%d\n", bm_pid) <= 0 || fclose(fp) == EOF) {
> 
> fclose is here:)
> 
> > > +             perror("Failed to write child to con_mon grp");
> > > +
> > > +             return errno;
> > > +     }
> > > +
> > > +     /* Write child pid to mon grp, only for "mbm" */
> > > +     if ((strcmp(resctrl_val, "mbm") == 0)) {
> > > +             if (mongrp) {
> > > +                     fp = fopen(monitorgroup, "w");
> > > +                     if (!fp || fprintf(fp, "%d\n", bm_pid) <= 0 ||
> > > +                         fclose(fp) == EOF) {
> >
> >
> > I feel too many checks at one place.  If fprintf fails,  will it fclose the
> > file? I suggest to separate these checks.
> 
> You are right. I will separate the checks in multiple lines.
> 
> >
> > > +
> > > +             fp = fopen(controlgroup, "w");
> > > +             if (!fp || fprintf(fp, "%s\n", schema) <= 0 ||
> > > +                 fclose(fp) == EOF) {
> >
> > Same comment as above.. If fprintf fails,  will it fclose the file? I suggest
> > to separate these checks.
> 
> Sure.
> 
> I will change code based on your comments.
> 
> Thanks.
> 
> -Fenghua

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ