From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S970560AbdIZUjP (ORCPT ); Tue, 26 Sep 2017 16:39:15 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:46426 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964856AbdIZUjN (ORCPT ); Tue, 26 Sep 2017 16:39:13 -0400 X-Google-Smtp-Source: AOwi7QCXyayfUSfibPwYcNobSBSHVnkxy5IynnqyJCMWE9PpoGjaRd8AS0QJaAiWmH14lJCik5MRGw== Date: Tue, 26 Sep 2017 13:39:09 -0700 From: Eric Biggers To: keyrings@vger.kernel.org Cc: David Howells , Michael Halcrow , linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Eric Biggers , stable@vger.kernel.org Subject: Re: [PATCH v2 1/6] KEYS: fix race between updating and finding negative key Message-ID: <20170926203909.GA126069@gmail.com> References: <20170926201105.126166-1-ebiggers3@gmail.com> <20170926201105.126166-2-ebiggers3@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170926201105.126166-2-ebiggers3@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 26, 2017 at 01:11:00PM -0700, Eric Biggers wrote: > +static void mark_key_instantiated(struct key *key, unsigned int reject_error) > +{ > + unsigned long old, new; > + > + do { > + old = READ_ONCE(key->flags); > + new = (old & ~(KEY_FLAG_NEGATIVE | > + KEY_FLAGS_REJECT_ERROR_MASK)) | > + KEY_FLAG_INSTANTIATED | > + (reject_error ? KEY_FLAG_NEGATIVE : 0) | > + (reject_error << KEY_FLAGS_REJECT_ERROR_SHIFT); > + } while (cmpxchg_release(&key->flags, old, new) != old); > +} Sorry, I realized I screwed this up --- the flags like KEY_FLAG_NEGATIVE need to be (1 << KEY_FLAG_NEGATIVE). I'll send another version which will be better tested... Eric