On 6/13/22 9:18 AM, Michal Privoznik wrote:
For some types of SRIOV interfaces we create a temporary file where the state of the interface is saved before we start modifying it. The file is used then to restore the original configuration when the interface is no longer associated with any guest. For writing the file virFileWriteStr() is used. However, it's given wrong argument: the last argument is supposed to be mode to create the file with but virNetDevSaveNetConfig() passes open(2) flags (O_CREAT|O_TRUNC|O_WRONLY). We need the file to be writable and readable by root only (0600). Therefore, pass that mode instead of gibberish.
Wow. This may be in competition for the longest living "how did this ever work?" bug in the code :-/
Since my name was on the git blame for the most recent change to this line, I had to figure out if it was really me that had misunderstood/misused virFileWriteStr() so grievously (wouldn't be the first or the last time). What I found was that this code had been moved around by multiple different people (including me) since originally being included in new code all the way back in commit cbd8227ee in June 2011.
Anyway, Peter has already acked it, but still Reviewed-by: Laine Stump <laine@xxxxxxxxxx>