From: Dan Carpenter <dan.carpenter@linaro.org>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: keescook@chromium.org, Robert Richter <rric@kernel.org>,
Borislav Petkov <bp@alien8.de>, Tony Luck <tony.luck@intel.com>,
James Morse <james.morse@arm.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Sergey Temerkhanov <s.temerkhanov@gmail.com>,
linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org, Borislav Petkov <bp@suse.de>,
linux-edac@vger.kernel.org
Subject: Re: [PATCH v2] EDAC/thunderx: Fix some potential buffer overflow in thunderx_ocx_com_threaded_isr()
Date: Tue, 24 Oct 2023 08:35:33 +0300 [thread overview]
Message-ID: <70bd7480-508a-451d-bc0a-f78e652cf511@kadam.mountain> (raw)
In-Reply-To: <91ec35cd8e2e86fa3d24c2e8ea6970e0437cdfd2.1697908406.git.christophe.jaillet@wanadoo.fr>
On Sat, Oct 21, 2023 at 07:13:51PM +0200, Christophe JAILLET wrote:
> @@ -1127,27 +1128,26 @@ static irqreturn_t thunderx_ocx_com_threaded_isr(int irq, void *irq_id)
> ARRAY_SIZE(ocx->com_err_ctx));
> ctx = &ocx->com_err_ctx[tail];
>
> - snprintf(msg, OCX_MESSAGE_SIZE, "%s: OCX_COM_INT: %016llx",
> - ocx->edac_dev->ctl_name, ctx->reg_com_int);
> -
> decode_register(other, OCX_OTHER_SIZE,
> ocx_com_errors, ctx->reg_com_int);
>
> - strncat(msg, other, OCX_MESSAGE_SIZE);
> + remaining = OCX_MESSAGE_SIZE;
> + remaining -= scnprintf(msg, remaining, "%s: OCX_COM_INT: %016llx%s",
> + ocx->edac_dev->ctl_name, ctx->reg_com_int,
> + other);
>
> for (lane = 0; lane < OCX_RX_LANES; lane++)
> if (ctx->reg_com_int & BIT(lane)) {
> - snprintf(other, OCX_OTHER_SIZE,
> - "\n\tOCX_LNE_INT[%02d]: %016llx OCX_LNE_STAT11[%02d]: %016llx",
> - lane, ctx->reg_lane_int[lane],
> - lane, ctx->reg_lane_stat11[lane]);
> -
> - strncat(msg, other, OCX_MESSAGE_SIZE);
> -
> decode_register(other, OCX_OTHER_SIZE,
> ocx_lane_errors,
> ctx->reg_lane_int[lane]);
> - strncat(msg, other, OCX_MESSAGE_SIZE);
> +
> + remaining -= scnprintf(msg + (OCX_MESSAGE_SIZE - remaining),
> + remaining,
Instead of doing "remaining -=" the canonincal way is "off +=". Then
the snprintf() becomes:
off += scnprintf(msg + off, OCX_MESSAGE_SIZE - off, ""\n\tOCX_...
Your way works but it makes my head hurt.
regards,
dan carpenter
next prev parent reply other threads:[~2023-10-24 5:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-21 17:13 Christophe JAILLET
2023-10-21 19:23 ` Greg KH
2023-10-24 5:35 ` Dan Carpenter [this message]
2023-10-24 5:40 ` Dan Carpenter
2023-10-24 23:39 ` Kees Cook
2023-10-26 17:18 ` Kees Cook
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=70bd7480-508a-451d-bc0a-f78e652cf511@kadam.mountain \
--to=dan.carpenter@linaro.org \
--cc=bp@alien8.de \
--cc=bp@suse.de \
--cc=christophe.jaillet@wanadoo.fr \
--cc=james.morse@arm.com \
--cc=keescook@chromium.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-edac@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=rric@kernel.org \
--cc=s.temerkhanov@gmail.com \
--cc=tony.luck@intel.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
all inboxes | Powered by JetHome®