From: Pavel Shilovsky <piastryyy@gmail.com>
To: Paulo Alcantara <pc@manguebit.com>
Cc: linux-cifs@vger.kernel.org
Subject: Re: [PATCH] cifs.upcall: fix UAF in get_cachename_from_process_env()
Date: Mon, 25 Mar 2024 18:43:36 -0700 [thread overview]
Message-ID: <CAKywueTgWhQMz+_bi01dzCVNfWzceXe8LkqR=AySseFL8wOw-Q@mail.gmail.com> (raw)
In-Reply-To: <20240308150615.339103-1-pc@manguebit.com>
Merged this and the other patch to the next branch. Thanks!
--
Best regards,
Pavel Shilovsky
пт, 8 мар. 2024 г. в 07:06, Paulo Alcantara <pc@manguebit.com>:
>
> Whether lseek(2) fails or @bufsize * 2 > ENV_BUF_MAX, then @buf would
> end up being freed twice. For instance:
>
> cifs-utils-7.0/cifs.upcall.c:501: freed_arg: "free" frees "buf".
> cifs-utils-7.0/cifs.upcall.c:524: double_free: Calling "free" frees
> pointer "buf" which has already been freed.
> 522| }
> 523| out_close:
> 524|-> free(buf);
> 525| close(fd);
> 526| return cachename;
>
> Fix this by setting @buf to NULL after freeing it to prevent UAF.
>
> Fixes: ed97e4ecab4e ("cifs.upcall: allow scraping of KRB5CCNAME out of initiating task's /proc/<pid>/environ file")
> Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.com>
> ---
> cifs.upcall.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/cifs.upcall.c b/cifs.upcall.c
> index 52c03280dbe0..ff6f2bd271bc 100644
> --- a/cifs.upcall.c
> +++ b/cifs.upcall.c
> @@ -498,10 +498,11 @@ retry:
> /* We read to the end of the buffer. Double and try again */
> syslog(LOG_DEBUG, "%s: read to end of buffer (%zu bytes)\n",
> __func__, bufsize);
> - free(buf);
> - bufsize *= 2;
> if (lseek(fd, 0, SEEK_SET) < 0)
> goto out_close;
> + free(buf);
> + buf = NULL;
> + bufsize *= 2;
> goto retry;
> }
>
> --
> 2.44.0
>
prev parent reply other threads:[~2024-03-26 1:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-08 15:06 [PATCH] cifs.upcall: fix UAF in get_cachename_from_process_env() Paulo Alcantara
2024-03-26 1:43 ` Pavel Shilovsky [this message]
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='CAKywueTgWhQMz+_bi01dzCVNfWzceXe8LkqR=AySseFL8wOw-Q@mail.gmail.com' \
--to=piastryyy@gmail.com \
--cc=linux-cifs@vger.kernel.org \
--cc=pc@manguebit.com \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).