Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1651059
| Path | csiph.com!aioe.org!news.servidellagleba.it!bofh.it!news.nic.it!robomod |
|---|---|
| From | Kees Cook <keescook@chromium.org> |
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 02/20] ipc: merge ipc_rcu and kern_ipc_perm |
| Date | Fri, 26 May 2017 05:40:01 +0200 |
| Message-ID | <tLegx-AF-7@gated-at.bofh.it> (permalink) |
| References | <tEZke-1sP-3@gated-at.bofh.it> <tL69k-3pt-3@gated-at.bofh.it> <tL69k-3pt-15@gated-at.bofh.it> <tL6M1-3Ub-7@gated-at.bofh.it> |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=zzU9A+Spyw4dOJyMcIfSjiLy3QQOf5bgGCp2LZ69kxc=; b=NTRMRjR7W0UUt5dwowHWTIltOGkdQB6S9LOMXTeYkiNGO4QmDzkZIivrSAw7AqnjaU pKfuea6RpN5kTBzlBHfnaGnxOQtj7reJG79ojFO6F2zSHL0lCjTKCubtrfU0oFaVGncn OTcOhL0AJDKvxu44VTVBVX044hrNGDpIYPhJFsT+tqIk8ltxQ/IGOS2o6cpZXXTkceMf V8OzzGVRuIsL/dNR/oIgOh/fHm6Ac9NxmSCCp4h7XD9pbTO5ZSxmHrFedGR6vUwN2XBQ RPrwGHQ/1FDdiOvsTF1juh0bDu6iicTnuY/NA9N+eg8z9qopcQkhlmCpv23s/ITvANLe W/8w== |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=zzU9A+Spyw4dOJyMcIfSjiLy3QQOf5bgGCp2LZ69kxc=; b=cYsh31oUFjf8PUfvoAFS6KBoLMnxCUjZQDUTgqnsdFKBZT9W9EI0Avxriv0PnkTJDW qyDhTZ3n3B8OOS/xEtvlx7CR9ed8KHVUOwJg3CtapAvQ5RJi2e9epMGtU4rEcc+cuAj1 +0okJjxAofe9+NecxMo/dGCyyFTHKSd0INiUw= |
| X-Google-Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=zzU9A+Spyw4dOJyMcIfSjiLy3QQOf5bgGCp2LZ69kxc=; b=NQyDQmtllKUYXxtPbMi9eg5MQAbiIXRcmWlVAW405t5oU3n/As1wvyllUe9Oo1Qm88 jz7C0iJVNyOhzXJNl5NePbK1vyW82Kj7wRR7faRMXUb2kFdRqn2yusbelej5YK9/4Yrm hWoR9AQp/MsLpT3OBfVgUOqbIYV84GJCPYVwNObJLQ8qNk/YPwD4iGKOXP98r30afNf/ gZt8Z2mzSb9GOzBKTSrBTwssH1Pnd4hdPoBAdc67O9wweB66y+WEk8N7C1ynJ0GdiiiT IKE5O+Yj3cHokke8zHwd6BhwCEhhtAjmXqy+a82lqfiluElzAVYu+Hh8bNAhdO9SpWAa slNw== |
| X-Gm-Message-State | AODbwcA5qXQmo3pItnN9ouwPulwmPYs7UJykjSAHMrmOF7rMf5ubvcZ0 rHNgaI+dcH11+ywSisD/mKgkYtN0NCdNJ/pzGA== |
| X-Received | by 10.36.55.23 with SMTP id r23mr860864itr.20.1495769846050; Thu, 25 May 2017 20:37:26 -0700 (PDT) |
| MIME-Version | 1.0 |
| X-Google-Sender-Auth | RY5rp6DtuRdqYKKY9ZCCv8fcM-o |
| Content-Type | text/plain; charset="UTF-8" |
| 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 | 100 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | Michael Kerrisk <mtk.manpages@gmail.com>, Andrew Morton <akpm@linux-foundation.org>, LKML <linux-kernel@vger.kernel.org>, 1vier1@web.de, Davidlohr Bueso <dave@stgolabs.net>, Ingo Molnar <mingo@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Fabian Frederick <fabf@skynet.be> |
| X-Original-Date | Thu, 25 May 2017 20:37:25 -0700 |
| X-Original-Message-ID | <CAGXu5jJVDY4YwkcmL4zFWeAHTDD1quVyCAEdYOZQwYjQJRjH0A@mail.gmail.com> |
| X-Original-References | <20170508222345.GA52073@beast> <20170525185107.12869-1-manfred@colorfullife.com> <20170525185107.12869-3-manfred@colorfullife.com> <CAGXu5jJT9uC5DqcLzp8Bz_YjHMN-hk+Rz_qGWeu+EAOG13wk-A@mail.gmail.com> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1651059 |
Show key headers only | View raw
On Thu, May 25, 2017 at 12:34 PM, Kees Cook <keescook@chromium.org> wrote:
> On Thu, May 25, 2017 at 11:50 AM, Manfred Spraul
> <manfred@colorfullife.com> wrote:
>> ipc has two management structures that exist for every id:
>> - struct kern_ipc_perm, it contains e.g. the permissions.
>> - struct ipc_rcu, it contains the rcu head for rcu handling and
>> the refcount.
>>
>> The patch merges both structures.
>> As a bonus, we may save one cacheline, because both structures are
>> cacheline aligned.
>> In addition, it reduces the number of casts, instead most codepaths can
>> use container_of.
>>
>> To simplify code, the ipc_rcu_alloc initializes the allocation to 0.
>
> I don't see this change in the code, only the removal of sem's
> memset(..., 0, ...)?
>
>> diff --git a/ipc/sem.c b/ipc/sem.c
>> index fff8337..bdff6d9 100644
>> --- a/ipc/sem.c
>> +++ b/ipc/sem.c
>> @@ -469,20 +469,20 @@ static int newary(struct ipc_namespace *ns, struct ipc_params *params)
>> if (ns->used_sems + nsems > ns->sc_semmns)
>> return -ENOSPC;
>>
>> + BUILD_BUG_ON(offsetof(struct sem_array, sem_perm) != 0);
>> +
>> size = sizeof(*sma) + nsems * sizeof(sma->sems[0]);
>> - sma = ipc_rcu_alloc(size);
>> + sma = container_of(ipc_rcu_alloc(size), struct sem_array, sem_perm);
>> if (!sma)
>> return -ENOMEM;
>>
>> - memset(sma, 0, size);
>> -
>> sma->sem_perm.mode = (semflg & S_IRWXUGO);
>> sma->sem_perm.key = key;
>>
>> sma->sem_perm.security = NULL;
>> retval = security_sem_alloc(sma);
>> if (retval) {
>> - ipc_rcu_putref(sma, ipc_rcu_free);
>> + ipc_rcu_putref(&sma->sem_perm, ipc_rcu_free);
>> return retval;
>> }
>>
>> [...]
>> diff --git a/ipc/util.c b/ipc/util.c
>> index caec7b1..9dcc08b 100644
>> --- a/ipc/util.c
>> +++ b/ipc/util.c
>> @@ -418,46 +418,43 @@ void ipc_free(void *ptr)
>> }
>>
>> /**
>> - * ipc_rcu_alloc - allocate ipc and rcu space
>> + * ipc_rcu_alloc - allocate ipc space
>> * @size: size desired
>> *
>> - * Allocate memory for the rcu header structure + the object.
>> - * Returns the pointer to the object or NULL upon failure.
>> + * Allocate memory for an ipc object.
>> + * The first member must be struct kern_ipc_perm.
>> */
>> -void *ipc_rcu_alloc(int size)
>> +struct kern_ipc_perm *ipc_rcu_alloc(int size)
>> {
>> /*
>> * We prepend the allocation with the rcu struct
>> */
>> - struct ipc_rcu *out = ipc_alloc(sizeof(struct ipc_rcu) + size);
>> + struct kern_ipc_perm *out = ipc_alloc(size);
>> if (unlikely(!out))
>> return NULL;
>> atomic_set(&out->refcount, 1);
>> - return out + 1;
>> + return out;
>> }
See above:
- newary() loses memset()
- ipc_rcu_alloc() does not gain it
- changelog says "To simplify code, the ipc_rcu_alloc initializes the
allocation to 0." This is what's wanted but the patch doesn't do it.
The actual change that (temporarily) adds memset to ipc_rcu_alloc() is
one of the following patches, but it should be here or bisection may
cause unexpected results for semaphores.
It's a minor issue, since these will likely all land at the same time,
but it's probably still worth fixing.
-Kees
--
Kees Cook
Pixel Security
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
[PATCH 02/20] ipc: merge ipc_rcu and kern_ipc_perm Manfred Spraul <manfred@colorfullife.com> - 2017-05-25 21:00 +0200
Re: [PATCH 02/20] ipc: merge ipc_rcu and kern_ipc_perm Kees Cook <keescook@chromium.org> - 2017-05-25 21:40 +0200
Re: [PATCH 02/20] ipc: merge ipc_rcu and kern_ipc_perm Kees Cook <keescook@chromium.org> - 2017-05-26 05:40 +0200
csiph-web