lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:	Tue, 12 Jul 2016 16:05:40 +0300
From:	Gal Kaplan <kaplangal@...il.com>
To:	linux-kernel@...r.kernel.org
Subject: [BUG] ftrace: Boost asio does not play well with trace_pipe

Hi,
I'm trying to build an application that reads from the ftrace trace
pipes at the debug fs.
I came across an interesting issue,
it seems that when trying to read asynchronously from trace_pipe or
trace_pipe_raw using boost::asio API, the events waiting in pipe being
processed but new events are not reported to boost handlers and the
async read is never called for new events.

I verified the piece of code below works well with manually created
pipes (using mkfifo) but not working with trace_pipe or
trace_pipe_raw.

I would appreciate your opinions on this issue.
Please personally CC me in any answer/comment you post in response to
this issue.

Thanks,
Gal Kaplan


#include <boost/asio.hpp>
#include <string>
#include <iostream>
#include <boost/bind.hpp>

namespace asio = boost::asio;
#ifdef BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR
typedef asio::posix::stream_descriptor stream_descriptor;
#endif

class FileReader
{
    typedef std::shared_ptr<FileReader> FileReaderPtr;
    typedef std::weak_ptr<FileReader> FileReaderWeakPtr;
public:
    static FileReaderWeakPtr Create(asio::io_service& io_service,
const std::string& path);

    void HandleRead(FileReaderPtr me, const boost::system::error_code &error);
private:
    FileReader(asio::io_service& io_service, const std::string& path);
    stream_descriptor m_InputStream;
    char buf[4096];
};

FileReader::FileReaderWeakPtr FileReader::Create(asio::io_service& io_service,

            const std::string& path)
{
    FileReaderPtr ptr(new FileReader(io_service, path));

    ptr->m_InputStream.async_read_some(boost::asio::buffer(ptr->buf),

boost::bind(&FileReader::HandleRead, ptr.get(), ptr,
asio::placeholders::error));
    return ptr;
}

FileReader::FileReader(asio::io_service& io_service, const
std::string& path) : m_InputStream(io_service)
{
    int dev = open(path.c_str(), O_RDWR);
    if (dev == -1) {
        std::cout << "failed to open path - " << path << std::endl;
    }
    else
    {
        m_InputStream.assign(dev);
    }
}

void FileReader::HandleRead(FileReaderPtr me, const
boost::system::error_code &error)
{
    if (!error)
{
        std::string str(me->buf);

        std::cout << "got message: " << str << std::endl;
        m_InputStream.async_read_some(boost::asio::buffer(me->buf),

boost::bind(&FileReader::HandleRead, this, me,
asio::placeholders::error));
    }
    else
    {
        std::cout << "got error - " << error.message() << std::endl;
    }
}


int main()
{
    boost::asio::io_service io_service;
    boost::asio::io_service::work dummy(io_service);

    FileReader::Create(io_service, "/sys/kernel/debug/tracing/trace_pipe");

    io_service.run();
    return 0;
}

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ