Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1242225
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!bofh.it!news.nic.it!robomod |
|---|---|
| From | Sergei Zviagintsev <sergei@s15v.net> |
| Newsgroups | linux.kernel |
| Subject | [PATCH 29/44] kdbus: Improve tests on incrementing quota |
| Date | Thu, 08 Oct 2015 13:40:01 +0200 |
| Message-ID | <qhhId-2d4-7@gated-at.bofh.it> (permalink) |
| References | <qhhId-2d4-3@gated-at.bofh.it> |
| X-Original-To | Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Daniel Mack <daniel@zonque.org>, David Herrmann <dh.herrmann@googlemail.com>, Djalal Harouni <tixxdz@opendz.org> |
| Dkim-Signature | v=1; a=rsa-sha1; c=relaxed/relaxed; d=s15v.net; h=cc :date:from:in-reply-to:in-reply-to:message-id:references :references:subject:to:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=IOzIT Qkx+FVoaCflNwP+07HoMOI=; b=yAxjlcAG1fsE2M7C5kBLGgkfq6vfKX7x/6pG9 GD1HYjClGWR8ExuZVTjPAWIHR0fOT8RPvAPqau3sNpU4DO6/iWRMDFMI3YJDXiPH 0xSq7+L8j4fGJBOorqvLeWPCcIvFmXKkEapEoJN818KXfx+t4mKNtmmtSGAVgimL jNrXa4= |
| Dkim-Signature | v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:in-reply-to :message-id:references:references:subject:to:x-sasl-enc :x-sasl-enc; s=smtpout; bh=IOzITQkx+FVoaCflNwP+07HoMOI=; b=ix1SL lKmSSPleiTSakr/sTesnKOEsRR4hped0lUeZIKFOt3hhxHhcyAW8IzodEsk1ak7P Tl00FFJjSKrnsuoQuDoPWgoaXAbgq2lIsNiib/Uuqi/5qv50cso+Sgnhhp9VJEo7 zhtwvmIGg7nmSUnwqXUKci50YWMjX2cpYjFbfc= |
| X-Sasl-Enc | HhaUru57SszS/R/ykqRRjuJlS/bqC8F9qTG/kImEYeV8 1444304042 |
| X-Mailer | git-send-email 1.8.3.1 |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 69 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | linux-kernel@vger.kernel.org, Sergei Zviagintsev <sergei@s15v.net> |
| X-Original-Date | Thu, 8 Oct 2015 14:31:58 +0300 |
| X-Original-Message-ID | <485d5892acb41541de71031c8d05f70d65a82757.1444302968.git.sergei@s15v.net> |
| X-Original-References | <cover.1444302968.git.sergei@s15v.net> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1242225 |
Show key headers only | View raw
- Rewrite
quota->memory + memory > U32_MAX
as
U32_MAX - quota->memory < memory
There is no overflow issue in the original expression on 32-bit
because the previous one (available - quota->memory < memory)
guarantees that quota->memory + memory doesn't exceed `available'
which is <= U32_MAX in that case. But lets replace it with less
ambiguous variant.
- Replace
quota->fds + fds < quota->fds ||
quota->fds + fds > KDBUS_CONN_MAX_FDS_PER_USER
with
quota->fds > KDBUS_CONN_MAX_FDS_PER_USER ||
KDBUS_CONN_MAX_FDS_PER_USER - quota->fds < fds
Reading the code, one can assume that the first original expression
is there to ensure that quota->fds won't overflow after
quota->fds += fds, but what it really does is testing for
size_t overflow in `quota->fds + fds' to be safe in the second
expression (as fds is size_t, quota->fds is converted to bigger
type).
Rewrite it in more obvious way. KDBUS_CONN_MAX_FDS_PER_USER is
checked at compile time to fill in quota->fds type (there is
BUILD_BUG_ON), so no further checks for quota->fds overflow are
needed.
Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
---
ipc/kdbus/connection.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/ipc/kdbus/connection.c b/ipc/kdbus/connection.c
index c57ff2c846ee..b32b4f981618 100644
--- a/ipc/kdbus/connection.c
+++ b/ipc/kdbus/connection.c
@@ -717,12 +717,12 @@ int kdbus_conn_quota_inc(struct kdbus_conn *c, struct kdbus_user *u,
if (available < quota->memory ||
available - quota->memory < memory ||
- quota->memory + memory > U32_MAX)
+ U32_MAX - quota->memory < memory)
return -ENOBUFS;
if (quota->msgs >= KDBUS_CONN_MAX_MSGS)
return -ENOBUFS;
- if (quota->fds + fds < quota->fds ||
- quota->fds + fds > KDBUS_CONN_MAX_FDS_PER_USER)
+ if (quota->fds > KDBUS_CONN_MAX_FDS_PER_USER ||
+ KDBUS_CONN_MAX_FDS_PER_USER - quota->fds < fds)
return -EMFILE;
quota->memory += memory;
--
1.8.3.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next | Find similar | Unroll thread
[PATCH 29/44] kdbus: Improve tests on incrementing quota Sergei Zviagintsev <sergei@s15v.net> - 2015-10-08 13:40 +0200
csiph-web