From: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
To: "mishra.dhiraj95@gmail.com" <mishra.dhiraj95@gmail.com>
Cc: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
"raphael.zimmer@tu-ilmenau.de" <raphael.zimmer@tu-ilmenau.de>,
"slava@dubeyko.com" <slava@dubeyko.com>,
"ceph-devel@vger.kernel.org" <ceph-devel@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"w@1wt.eu" <w@1wt.eu>, Alex Markuze <amarkuze@redhat.com>,
"idryomov@gmail.com" <idryomov@gmail.com>,
"security@kernel.org" <security@kernel.org>
Subject: RE: [PATCH v4] libceph, ceph: reject oversized mon and MDS data segments
Date: Wed, 6 May 2026 18:35:45 +0000 [thread overview]
Message-ID: <dea43fec11a0416416f93a4980c6ab07f0adce5f.camel@ibm.com> (raw)
In-Reply-To: <CAG8b5tSigSQY4meBi24bYxYGrNsM1A4EAihh=gV0t0M1BCcYSg@mail.gmail.com>
On Wed, 2026-05-06 at 01:37 +0400, Dhiraj Mishra wrote:
>
> Hi Slava,
>
> Yes, both issues can happen on the same message.
>
> The reason we behave differently is that the two cases are not symmetric.
>
> For
>
> front_len > m->front_alloc_len
>
> we can still salvage the message, because the front is just a generic byte
> buffer. Replacing m with
>
> ceph_msg_new(type, front_len, GFP_NOFS, false)
>
> gives us a larger front allocation for the same message type.
>
> For
>
> data_len > m->data_length
>
> there is no analogous generic recovery in this path. ceph_msg_new() here
> is ceph_msg_new2(..., 0, ...), so it creates a message with no data items
> (max_data_items == 0). It only allocates the front buffer; it does not
> provision any data backing. In the tested CEPH_MSG_MON_MAP case, the
> message is intentionally front-only. So if the wire header advertises a
> non-zero data segment, the safe action is to skip the message rather than
> try to invent a data layout.
>
> So the intended flow is:
>
> 1. unknown type: skip
> 2. oversized front: reallocate front if possible
> 3. oversized data: validate against the final m and skip if too large
>
> That is why the data_len check has to stay after the front_len handling.
> If the front_len branch replaces m, we need to validate data_len against
> that final m.
>
> One small detail in the sketch below: after ceph_msg_new() in the
> front_len branch, we still need to handle the case that it returns NULL,
> so either:
>
> if (!m)
> return NULL;
>
> or:
>
> if (m && data_len > m->data_length) {
> ...
> }
>
> is still needed there.
Maybe, I am missing something. But I don't quite follow to you.
We have checked that m is NULL here and exit the method:
if (!m) {
pr_info("alloc_msg unknown type %d\n", type);
*skip = 1;
return m;
}
Now we have valid m pointer. Potentially, ceph_msg_new() could return NULL. And
we simply can check it here:
if (front_len > m->front_alloc_len) {
pr_warn("mon_alloc_msg front %d > prealloc %d (%u#%llu)\n",
front_len, m->front_alloc_len,
(unsigned int)con->peer_name.type,
le64_to_cpu(con->peer_name.num));
ceph_msg_put(m);
m = ceph_msg_new(type, front_len, GFP_NOFS, false);
if (!m)
return m;
}
And we should have valid m here again:
if (data_len > m->data_length) {
pr_warn_ratelimited("mon message data %u > prealloc %zu
(%u#%llu), skipping\n",
data_len, m->data_length,
(unsigned int)con->peer_name.type,
le64_to_cpu(con->peer_name.num));
ceph_msg_put(m);
m = NULL;
*skip = 1;
}
I am simply trying to make the code more clean and without introducing new
errors.
Do we need to check both front_len and data_len? I assume that these fields work
in different situations. Am I right? Could we make these checks more local in
the switch?
Thanks,
Slava.
next prev parent reply other threads:[~2026-05-06 18:36 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-01 19:37 [PATCH v2] libceph: reject monitor replies with oversized data segment Dhiraj Mishra
2026-05-01 21:37 ` Viacheslav Dubeyko
2026-05-02 5:22 ` [PATCH v3] " Dhiraj Mishra
2026-05-04 8:34 ` Raphael Zimmer
2026-05-04 9:16 ` [PATCH v4] libceph, ceph: reject oversized mon and MDS data segments Dhiraj Mishra
2026-05-04 19:46 ` Viacheslav Dubeyko
[not found] ` <CAG8b5tTiRK3AfTRx0hLeTi5GLfQ6sxXxfgUT+xzEqgzzDUMtOg@mail.gmail.com>
2026-05-05 18:48 ` Viacheslav Dubeyko
[not found] ` <CAG8b5tSigSQY4meBi24bYxYGrNsM1A4EAihh=gV0t0M1BCcYSg@mail.gmail.com>
2026-05-06 18:35 ` Viacheslav Dubeyko [this message]
2026-05-07 19:19 ` [PATCH v5] " Dhiraj Mishra
2026-05-08 18:18 ` Viacheslav Dubeyko
2026-05-11 16:24 ` Viacheslav Dubeyko
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=dea43fec11a0416416f93a4980c6ab07f0adce5f.camel@ibm.com \
--to=slava.dubeyko@ibm.com \
--cc=amarkuze@redhat.com \
--cc=ceph-devel@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=idryomov@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mishra.dhiraj95@gmail.com \
--cc=raphael.zimmer@tu-ilmenau.de \
--cc=security@kernel.org \
--cc=slava@dubeyko.com \
--cc=w@1wt.eu \
/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®