From patchwork Sun Jul 8 21:01:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10513327 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3F2576032C for ; Sun, 8 Jul 2018 21:06:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31181289DF for ; Sun, 8 Jul 2018 21:06:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 24438289E1; Sun, 8 Jul 2018 21:06:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB3CF289DF for ; Sun, 8 Jul 2018 21:06:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933467AbeGHVFt (ORCPT ); Sun, 8 Jul 2018 17:05:49 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:45471 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933292AbeGHVFq (ORCPT ); Sun, 8 Jul 2018 17:05:46 -0400 Received: by mail-pf0-f194.google.com with SMTP id i26-v6so719223pfo.12; Sun, 08 Jul 2018 14:05:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8aM1k2j6Ljs8a7QqghmRuJpiCg7PJFBEcFzzSa0UZCI=; b=uShBzQj/LW44wtCFABhr9F/KPcDMNPU5VnuDHYdIpZocbFBYuwstdukhag/nOAwJBO jtgspGdaijlzeIGeS05UkZ10jPS9mc7eU85uoPAy9lRNpmMQeRSXbtSxekz7uLZtZSQM 9ig4v48RntCcZFeBBMqABxurj956r4cyi1yUllKvg/FvcGHLj350mT51ceYND5dlr1Gy nDR3sxq3KVnOJHEqZIFEws42UitUkZL2zjbgIHYz/0SrsXGrJZUdpEdAiF3rqxdNPcQr vyyjb4JVKe0SrXGwNksmRpNkvvjPwkEPxn6KNQDKnqyAr7jyzlwLZkDXaRKhK7xTrBIw DyAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8aM1k2j6Ljs8a7QqghmRuJpiCg7PJFBEcFzzSa0UZCI=; b=t74oqkmkN0zi+omSyRiFt59v2ubiaOCd7MMNKnH7SH3zV157vq+aPQRKfiaW9fCwaS IPiydJy561wQMm+iEYT0H66YUVA14RrfUFTeraWRTliqjv4Apw5R/OMWZxZ9MCA2njg8 aLHkJuaLdTWVG1bgqLHh3pumvGBoMKg7CrU8rWWNnguGDjhtYRh2gFpSVWyrhNpe61M2 yyrC3O5jvjmDIXs622C6khiJdoL5OqfZ9qZqBP5VsK9Fou4WUfOHTLbWv9Me94/IoSN6 Lv1i+QvMMlNevpfRXlgndRaHCyJNZIK9RGL9m7xaY50HIAXYXNaywroV0WJBy6rL1eSU iHuQ== X-Gm-Message-State: APt69E0/73IdiWGZ2isgOi6nsP8P2ATeDCu+eFdFpkjWCOs8IfCxL8rq t9/1Us0jFyNNP+JBirpO03c= X-Google-Smtp-Source: AAOMgpdoVvq4yrplIdaZUenCMadR8lKnYOikPWF8R/5zRatE7kZ3t2IA2aZJs/8dEUNtfDCNjBYEWA== X-Received: by 2002:a63:8c0b:: with SMTP id m11-v6mr16720117pgd.372.1531083946119; Sun, 08 Jul 2018 14:05:46 -0700 (PDT) Received: from sol.localdomain (c-67-185-97-198.hsd1.wa.comcast.net. [67.185.97.198]) by smtp.gmail.com with ESMTPSA id x68-v6sm23355681pfb.138.2018.07.08.14.05.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Jul 2018 14:05:45 -0700 (PDT) From: Eric Biggers To: David Howells , Alexander Viro , linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Eric Biggers Subject: [PATCH 16/18] fs_context: de-obfuscate control flow in fscontext_read() Date: Sun, 8 Jul 2018 14:01:52 -0700 Message-Id: <20180708210154.10423-17-ebiggers3@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180708210154.10423-1-ebiggers3@gmail.com> References: <20180708210154.10423-1-ebiggers3@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers Signed-off-by: Eric Biggers --- fs/fsopen.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/fs/fsopen.c b/fs/fsopen.c index 1fbd8b0ca194b..dd38f6b65aace 100644 --- a/fs/fsopen.c +++ b/fs/fsopen.c @@ -161,20 +161,18 @@ static ssize_t fscontext_read(struct file *file, if (ret < 0) return ret; - ret = -ENODATA; - if (log->head != log->tail) { - index = log->tail & (logsize - 1); - p = log->buffer[index]; - need_free = log->need_free & (1 << index); - log->buffer[index] = NULL; - log->need_free &= ~(1 << index); - log->tail++; - ret = 0; + if (log->head == log->tail) { + mutex_unlock(&fc->uapi_mutex); + return -ENODATA; } + index = log->tail & (logsize - 1); + p = log->buffer[index]; + need_free = log->need_free & (1 << index); + log->buffer[index] = NULL; + log->need_free &= ~(1 << index); + log->tail++; mutex_unlock(&fc->uapi_mutex); - if (ret < 0) - return ret; ret = -EMSGSIZE; n = strlen(p);