From patchwork Mon Oct 27 18:51:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 39644 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f71.google.com (mail-ee0-f71.google.com [74.125.83.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 95C012118A for ; Mon, 27 Oct 2014 18:52:26 +0000 (UTC) Received: by mail-ee0-f71.google.com with SMTP id e51sf929325eek.6 for ; Mon, 27 Oct 2014 11:52:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=mKZgGl3R9c7Jn8M9pHJGJ937mu40fUxXA0pAXyH5/ME=; b=cLZfhJ4HyKfCxYcvBeA4mLEbZssxYJXGLRxfvN+pfRf4qCO8c2aCGrwfj+LgWGIZjC b7B6dbzM49RpuJrMTF3ogZrdggowLepe7P5kGqb8D/wV+sCVxAFhE8gjyB1sU/XRRzUY Zd0xI2KgELSvo+Hn/wE83aAABIaBcScJgwpN1QEnRXwn78gOeWWdduljrtGsc7O61lVh VIojft/R8ABU2cs+cx4i2qP287yAbUpgJU0pnuV+C/Lzf9tHRT/XTyXSmGBc5uUB/2S7 WTU/pGCnUgodpXF6TSbrF8Qd74l2odvFbz3b7+bfn1+8P2JPsF7JrabQ+7uTsDyP/d/Q 1MoA== X-Gm-Message-State: ALoCoQn4jv1vSqM2S4Ucm9mu3EBHpLyWP0HcFXjqUXjPMzlygJYewytibAT7hL/tp5/C8HBboROw X-Received: by 10.180.98.165 with SMTP id ej5mr5529501wib.1.1414435945452; Mon, 27 Oct 2014 11:52:25 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.39 with SMTP id y7ls772808lag.0.gmail; Mon, 27 Oct 2014 11:52:25 -0700 (PDT) X-Received: by 10.152.19.37 with SMTP id b5mr659116lae.80.1414435945172; Mon, 27 Oct 2014 11:52:25 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id w2si21314460lag.73.2014.10.27.11.52.24 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 27 Oct 2014 11:52:24 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by mail-lb0-f170.google.com with SMTP id u10so6284367lbd.29 for ; Mon, 27 Oct 2014 11:52:24 -0700 (PDT) X-Received: by 10.152.29.8 with SMTP id f8mr25821579lah.56.1414435944787; Mon, 27 Oct 2014 11:52:24 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.84.229 with SMTP id c5csp352614lbz; Mon, 27 Oct 2014 11:52:24 -0700 (PDT) X-Received: by 10.180.20.162 with SMTP id o2mr12622003wie.57.1414435943914; Mon, 27 Oct 2014 11:52:23 -0700 (PDT) Received: from mail-wg0-f52.google.com (mail-wg0-f52.google.com. [74.125.82.52]) by mx.google.com with ESMTPS id fu1si14858668wjb.120.2014.10.27.11.52.23 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 27 Oct 2014 11:52:23 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 74.125.82.52 as permitted sender) client-ip=74.125.82.52; Received: by mail-wg0-f52.google.com with SMTP id y10so3861115wgg.35 for ; Mon, 27 Oct 2014 11:52:23 -0700 (PDT) X-Received: by 10.194.91.176 with SMTP id cf16mr24192307wjb.60.1414435943620; Mon, 27 Oct 2014 11:52:23 -0700 (PDT) Received: from sundance.lan (cpc4-aztw19-0-0-cust157.18-1.cable.virginm.net. [82.33.25.158]) by mx.google.com with ESMTPSA id bl9sm12778055wib.24.2014.10.27.11.52.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Oct 2014 11:52:22 -0700 (PDT) From: Daniel Thompson To: Greg Kroah-Hartman Cc: Daniel Thompson , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, patches@linaro.org, linaro-kernel@lists.linaro.org, John Stultz , Sumit Semwal , Al Viro Subject: [PATCH v3.18-rc2] staging: android: logger: Fix log corruption regression Date: Mon, 27 Oct 2014 18:51:43 +0000 Message-Id: <1414435903-20002-1-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 1.9.3 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: daniel.thompson@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Since commit cd678fce4280 ("switch logger to ->write_iter()"), any attempt to write to the log results in the log data being written over its own metadata, thus rendering the log unreadable. The problem was first detected when I ran an Android userspace on the v3.18-rc1 kernel. However the issue can also be observed with a non-Android userspace by using echo/cat to write to/from /dev/log_main . This patch resolves the problem by using a temporary to track the status of not-yet-committed writes to the log buffer. Signed-off-by: Daniel Thompson Cc: Al Viro --- drivers/staging/android/logger.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) -- 1.9.3 diff --git a/drivers/staging/android/logger.c b/drivers/staging/android/logger.c index 28b93d3..a673ffa 100644 --- a/drivers/staging/android/logger.c +++ b/drivers/staging/android/logger.c @@ -420,7 +420,7 @@ static ssize_t logger_write_iter(struct kiocb *iocb, struct iov_iter *from) struct logger_log *log = file_get_log(iocb->ki_filp); struct logger_entry header; struct timespec now; - size_t len, count; + size_t len, count, w_off; count = min_t(size_t, iocb->ki_nbytes, LOGGER_ENTRY_MAX_PAYLOAD); @@ -452,11 +452,14 @@ static ssize_t logger_write_iter(struct kiocb *iocb, struct iov_iter *from) memcpy(log->buffer + log->w_off, &header, len); memcpy(log->buffer, (char *)&header + len, sizeof(header) - len); - len = min(count, log->size - log->w_off); + /* Work with a copy until we are ready to commit the whole entry */ + w_off = logger_offset(log, log->w_off + sizeof(struct logger_entry)); - if (copy_from_iter(log->buffer + log->w_off, len, from) != len) { + len = min(count, log->size - w_off); + + if (copy_from_iter(log->buffer + w_off, len, from) != len) { /* - * Note that by not updating w_off, this abandons the + * Note that by not updating log->w_off, this abandons the * portion of the new entry that *was* successfully * copied, just above. This is intentional to avoid * message corruption from missing fragments. @@ -470,7 +473,7 @@ static ssize_t logger_write_iter(struct kiocb *iocb, struct iov_iter *from) return -EFAULT; } - log->w_off = logger_offset(log, log->w_off + count); + log->w_off = logger_offset(log, w_off + count); mutex_unlock(&log->mutex); /* wake up any blocked readers */