Gas prices and other goods could remain elevated for months, adding to the political challenge facing the White House in the midterm elections.